1 /*
2 * Copyright (c) 2015, 2017, 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 */
33 */
34
35 import jdk.test.lib.compiler.InMemoryJavaCompiler;
36 import jdk.test.lib.process.OutputAnalyzer;
37 import jdk.test.lib.process.ProcessTools;
38
39 public class PatchModuleCDS {
40
41 public static void main(String args[]) throws Throwable {
42
43 // Case 1: Test that --patch-module and -Xshare:dump are compatible
44 String filename = "patch_module.jsa";
45 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
46 "-XX:+UnlockDiagnosticVMOptions",
47 "-XX:SharedArchiveFile=" + filename,
48 "-Xshare:dump",
49 "--patch-module=java.naming=no/such/directory",
50 "-Xlog:class+path=info",
51 "-version");
52 new OutputAnalyzer(pb.start())
53 .shouldContain("ro space:"); // Make sure archive got created.
54
55 // Case 2: Test that directory in --patch-module is supported for CDS dumping
56 // Create a class file in the module java.base.
57 String source = "package javax.naming.spi; " +
58 "public class NamingManager { " +
59 " static { " +
60 " System.out.println(\"I pass!\"); " +
61 " } " +
62 "}";
63
64 ClassFileInstaller.writeClassToDisk("javax/naming/spi/NamingManager",
65 InMemoryJavaCompiler.compile("javax.naming.spi.NamingManager", source, "--patch-module=java.naming"),
66 System.getProperty("test.classes"));
67
68 pb = ProcessTools.createJavaProcessBuilder(
69 "-XX:+UnlockDiagnosticVMOptions",
70 "-XX:SharedArchiveFile=" + filename,
71 "-Xshare:dump",
72 "--patch-module=java.naming=" + System.getProperty("test.classes"),
73 "-Xlog:class+path=info",
74 "-version");
75 new OutputAnalyzer(pb.start())
76 .shouldContain("ro space:"); // Make sure archive got created.
77
78 // Case 3a: Test CDS dumping with jar file in --patch-module
79 BasicJarBuilder.build("javanaming", "javax/naming/spi/NamingManager");
80 String moduleJar = BasicJarBuilder.getTestJar("javanaming.jar");
81 pb = ProcessTools.createJavaProcessBuilder(
82 "-XX:+UnlockDiagnosticVMOptions",
83 "-XX:SharedArchiveFile=" + filename,
84 "-Xshare:dump",
85 "--patch-module=java.naming=" + moduleJar,
86 "-Xlog:class+load",
87 "-Xlog:class+path=info",
88 "PatchModuleMain", "javax.naming.spi.NamingManager");
89 new OutputAnalyzer(pb.start())
90 .shouldContain("ro space:"); // Make sure archive got created.
91
92 // Case 3b: Test CDS run with jar file in --patch-module
93 pb = ProcessTools.createJavaProcessBuilder(
94 "-XX:+UnlockDiagnosticVMOptions",
95 "-XX:SharedArchiveFile=" + filename,
96 "-Xshare:auto",
97 "--patch-module=java.naming=" + moduleJar,
98 "-Xlog:class+load",
99 "-Xlog:class+path=info",
100 "PatchModuleMain", "javax.naming.spi.NamingManager");
101 new OutputAnalyzer(pb.start())
102 .shouldContain("I pass!")
103 .shouldHaveExitValue(0);
104 }
105 }
|
1 /*
2 * Copyright (c) 2015, 2018, 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 */
33 */
34
35 import jdk.test.lib.compiler.InMemoryJavaCompiler;
36 import jdk.test.lib.process.OutputAnalyzer;
37 import jdk.test.lib.process.ProcessTools;
38
39 public class PatchModuleCDS {
40
41 public static void main(String args[]) throws Throwable {
42
43 // Case 1: Test that --patch-module and -Xshare:dump are compatible
44 String filename = "patch_module.jsa";
45 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
46 "-XX:+UnlockDiagnosticVMOptions",
47 "-XX:SharedArchiveFile=" + filename,
48 "-Xshare:dump",
49 "--patch-module=java.naming=no/such/directory",
50 "-Xlog:class+path=info",
51 "-version");
52 new OutputAnalyzer(pb.start())
53 // --patch-module is not supported during CDS dumping
54 .shouldContain("Cannot use the following option when dumping the shared archive: --patch-module");
55
56 // Case 2: Test that directory in --patch-module is supported for CDS dumping
57 // Create a class file in the module java.base.
58 String source = "package javax.naming.spi; " +
59 "public class NamingManager { " +
60 " static { " +
61 " System.out.println(\"I pass!\"); " +
62 " } " +
63 "}";
64
65 ClassFileInstaller.writeClassToDisk("javax/naming/spi/NamingManager",
66 InMemoryJavaCompiler.compile("javax.naming.spi.NamingManager", source, "--patch-module=java.naming"),
67 System.getProperty("test.classes"));
68
69 pb = ProcessTools.createJavaProcessBuilder(
70 "-XX:+UnlockDiagnosticVMOptions",
71 "-XX:SharedArchiveFile=" + filename,
72 "-Xshare:dump",
73 "--patch-module=java.naming=" + System.getProperty("test.classes"),
74 "-Xlog:class+path=info",
75 "-version");
76 new OutputAnalyzer(pb.start())
77 // --patch-module is not supported during CDS dumping
78 .shouldContain("Cannot use the following option when dumping the shared archive: --patch-module");
79
80 // Case 3a: Test CDS dumping with jar file in --patch-module
81 BasicJarBuilder.build("javanaming", "javax/naming/spi/NamingManager");
82 String moduleJar = BasicJarBuilder.getTestJar("javanaming.jar");
83 pb = ProcessTools.createJavaProcessBuilder(
84 "-XX:+UnlockDiagnosticVMOptions",
85 "-XX:SharedArchiveFile=" + filename,
86 "-Xshare:dump",
87 "--patch-module=java.naming=" + moduleJar,
88 "-Xlog:class+load",
89 "-Xlog:class+path=info",
90 "PatchModuleMain", "javax.naming.spi.NamingManager");
91 new OutputAnalyzer(pb.start())
92 // --patch-module is not supported during CDS dumping
93 .shouldContain("Cannot use the following option when dumping the shared archive: --patch-module");
94
95 // Case 3b: Test CDS run with jar file in --patch-module
96 pb = ProcessTools.createJavaProcessBuilder(
97 "-XX:+UnlockDiagnosticVMOptions",
98 "-XX:SharedArchiveFile=" + filename,
99 "-Xshare:auto",
100 "--patch-module=java.naming=" + moduleJar,
101 "-Xlog:class+load",
102 "-Xlog:class+path=info",
103 "PatchModuleMain", "javax.naming.spi.NamingManager");
104 new OutputAnalyzer(pb.start())
105 .shouldContain("I pass!")
106 .shouldHaveExitValue(0);
107 }
108 }
|