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 * @requires vm.cds
28 * @summary a simple test to ensure that class is loaded from jar file in --patch-module at runtime
29 * @library ../..
30 * @library /test/hotspot/jtreg/testlibrary
31 * @library /test/lib
32 * @build PatchMain
33 * @run driver Simple
34 */
35
36 import jdk.test.lib.compiler.InMemoryJavaCompiler;
37 import jdk.test.lib.process.OutputAnalyzer;
38
39 public class Simple {
40 private static String moduleJar;
41
42 public static void main(String args[]) throws Throwable {
43
44 // Create a class file in the module java.naming. This class file
45 // will be put in the javanaming.jar file.
46 String source = "package javax.naming.spi; " +
47 "public class NamingManager { " +
48 " static { " +
49 " System.out.println(\"I pass!\"); " +
50 " } " +
51 "}";
52
53 ClassFileInstaller.writeClassToDisk("javax/naming/spi/NamingManager",
54 InMemoryJavaCompiler.compile("javax.naming.spi.NamingManager", source, "--patch-module=java.naming"),
55 System.getProperty("test.classes"));
61 System.out.println("Test dumping with --patch-module");
62 OutputAnalyzer output =
63 TestCommon.dump(null,
64 TestCommon.list("javax/naming/spi/NamingManager"),
65 "--patch-module=java.naming=" + moduleJar,
66 "-Xlog:class+load",
67 "-Xlog:class+path=info",
68 "PatchMain", "javax.naming.spi.NamingManager");
69 output.shouldHaveExitValue(1)
70 .shouldContain("Cannot use the following option when dumping the shared archive: --patch-module");
71
72 TestCommon.run(
73 "-XX:+UnlockDiagnosticVMOptions",
74 "--patch-module=java.naming=" + moduleJar,
75 "-Xlog:class+load",
76 "-Xlog:class+path=info",
77 "PatchMain", "javax.naming.spi.NamingManager")
78 .assertSilentlyDisabledCDS(0, "I pass!");
79
80 // ========================================
81 System.out.println("Dump again without --patch-module");
82 output =
83 TestCommon.dump(null,
84 TestCommon.list("javax/naming/spi/NamingManager"));
85 output.shouldHaveExitValue(0);
86
87 TestCommon.run(
88 "-XX:+UnlockDiagnosticVMOptions",
89 "--patch-module=java.naming=" + moduleJar,
90 "-Xlog:class+load",
91 "-Xlog:class+path=info",
92 "PatchMain", "javax.naming.spi.NamingManager")
93 .assertSilentlyDisabledCDS(0, "I pass!");
94 }
95 }
|
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 * @requires vm.cds
28 * @summary a simple test to ensure that class is loaded from jar file in --patch-module at runtime
29 * @library ../..
30 * @library /test/hotspot/jtreg/testlibrary
31 * @library /test/lib
32 * @build PatchMain
33 * @run driver Simple
34 */
35
36 import jdk.test.lib.cds.CDSTestUtils;
37 import jdk.test.lib.compiler.InMemoryJavaCompiler;
38 import jdk.test.lib.process.OutputAnalyzer;
39
40 public class Simple {
41 private static String moduleJar;
42
43 public static void main(String args[]) throws Throwable {
44
45 // Create a class file in the module java.naming. This class file
46 // will be put in the javanaming.jar file.
47 String source = "package javax.naming.spi; " +
48 "public class NamingManager { " +
49 " static { " +
50 " System.out.println(\"I pass!\"); " +
51 " } " +
52 "}";
53
54 ClassFileInstaller.writeClassToDisk("javax/naming/spi/NamingManager",
55 InMemoryJavaCompiler.compile("javax.naming.spi.NamingManager", source, "--patch-module=java.naming"),
56 System.getProperty("test.classes"));
62 System.out.println("Test dumping with --patch-module");
63 OutputAnalyzer output =
64 TestCommon.dump(null,
65 TestCommon.list("javax/naming/spi/NamingManager"),
66 "--patch-module=java.naming=" + moduleJar,
67 "-Xlog:class+load",
68 "-Xlog:class+path=info",
69 "PatchMain", "javax.naming.spi.NamingManager");
70 output.shouldHaveExitValue(1)
71 .shouldContain("Cannot use the following option when dumping the shared archive: --patch-module");
72
73 TestCommon.run(
74 "-XX:+UnlockDiagnosticVMOptions",
75 "--patch-module=java.naming=" + moduleJar,
76 "-Xlog:class+load",
77 "-Xlog:class+path=info",
78 "PatchMain", "javax.naming.spi.NamingManager")
79 .assertSilentlyDisabledCDS(0, "I pass!");
80
81 // ========================================
82 if (!CDSTestUtils.DYNAMIC_DUMP) {
83 System.out.println("Dump again without --patch-module");
84 output =
85 TestCommon.dump(null,
86 TestCommon.list("javax/naming/spi/NamingManager"));
87 output.shouldHaveExitValue(0);
88
89 TestCommon.run(
90 "-XX:+UnlockDiagnosticVMOptions",
91 "--patch-module=java.naming=" + moduleJar,
92 "-Xlog:class+load",
93 "-Xlog:class+path=info",
94 "PatchMain", "javax.naming.spi.NamingManager")
95 .assertSilentlyDisabledCDS(0, "I pass!");
96 }
97 }
98 }
|