1 /*
   2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /*
  26  * @test
  27  * @summary Hello World test for AppCDS custom loader support
  28  * @requires vm.cds
  29  * @requires vm.cds.custom.loaders
  30  * @library /test/lib /test/hotspot/jtreg/runtime/cds /runtime/testlibrary
  31  * @modules java.base/jdk.internal.misc
  32  *          java.management
  33  * @compile test-classes/HelloUnload.java test-classes/CustomLoadee.java
  34  * @build sun.hotspot.WhiteBox ClassUnloadCommon
  35  * @run driver ClassFileInstaller -jar hello.jar HelloUnload ClassUnloadCommon ClassUnloadCommon$1 ClassUnloadCommon$TestFailure
  36  * @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee
  37  * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
  38  * @run driver HelloCustom
  39  */
  40 
  41 import jdk.test.lib.process.OutputAnalyzer;
  42 import sun.hotspot.WhiteBox;
  43 
  44 public class HelloCustom {
  45     public static void main(String[] args) throws Exception {
  46         run();
  47     }
  48     public static void run(String... extra_runtime_args) throws Exception {
  49         String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar");
  50         String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
  51 
  52         String appJar = ClassFileInstaller.getJarPath("hello.jar");
  53         String customJarPath = ClassFileInstaller.getJarPath("hello_custom.jar");
  54 
  55         // Dump the archive
  56         String classlist[] = new String[] {
  57             "HelloUnload",
  58             "java/lang/Object id: 1",
  59             "CustomLoadee id: 2 super: 1 source: " + customJarPath
  60         };
  61 
  62         OutputAnalyzer output;
  63         TestCommon.testDump(appJar, classlist,
  64                             // command-line arguments ...
  65                             use_whitebox_jar);
  66 
  67         output = TestCommon.exec(appJar,
  68                                  TestCommon.concat(extra_runtime_args,
  69                                      // command-line arguments ...
  70                                      use_whitebox_jar,
  71                                      "-XX:+UnlockDiagnosticVMOptions",
  72                                      "-XX:+WhiteBoxAPI",
  73                                      "HelloUnload", customJarPath, "true", "true"));
  74         TestCommon.checkExec(output);
  75     }
  76 }