author | ccheung |
Mon, 28 Aug 2017 15:34:04 -0700 | |
changeset 47103 | a993ec29ec75 |
parent 46790 | 8c4deba6a0ee |
permissions | -rw-r--r-- |
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
1 |
/* |
46779
d80ca591ae48
8185436: jtreg: introduce @requires property to disable cds tests
goetz
parents:
45112
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
4 |
* |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
8 |
* |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
13 |
* accompanied this code). |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
14 |
* |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
18 |
* |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
21 |
* questions. |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
22 |
*/ |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
23 |
|
46779
d80ca591ae48
8185436: jtreg: introduce @requires property to disable cds tests
goetz
parents:
45112
diff
changeset
|
24 |
/** |
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
25 |
* @test |
46779
d80ca591ae48
8185436: jtreg: introduce @requires property to disable cds tests
goetz
parents:
45112
diff
changeset
|
26 |
* @requires vm.cds |
41281 | 27 |
* @summary test that --patch-module works with CDS |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40244
diff
changeset
|
28 |
* @library /test/lib |
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
29 |
* @modules java.base/jdk.internal.misc |
41281 | 30 |
* jdk.jartool/sun.tools.jar |
31 |
* @build PatchModuleMain |
|
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
32 |
* @run main PatchModuleCDS |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
33 |
*/ |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
34 |
|
45112
fbec2bfa3839
8180037: move jdk.test.lib.InMemoryJavaCompiler to a separate package
iignatyev
parents:
42876
diff
changeset
|
35 |
import jdk.test.lib.compiler.InMemoryJavaCompiler; |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40244
diff
changeset
|
36 |
import jdk.test.lib.process.OutputAnalyzer; |
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40244
diff
changeset
|
37 |
import jdk.test.lib.process.ProcessTools; |
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
38 |
|
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
39 |
public class PatchModuleCDS { |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
40 |
|
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
41 |
public static void main(String args[]) throws Throwable { |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
42 |
|
41281 | 43 |
// Case 1: Test that --patch-module and -Xshare:dump are compatible |
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
44 |
String filename = "patch_module.jsa"; |
41281 | 45 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
46 |
"-XX:+UnlockDiagnosticVMOptions", |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
47 |
"-XX:SharedArchiveFile=" + filename, |
41281 | 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 |
||
42876
ff8ff9dcccec
8168797: do not load any archived classes from a patched module
jiangli
parents:
41281
diff
changeset
|
55 |
// Case 2: Test that directory in --patch-module is supported for CDS dumping |
41281 | 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", |
|
46790
8c4deba6a0ee
8177741: Fix hotspot tests to use --patch-module instead of -Xmodule
hseigel
parents:
46779
diff
changeset
|
65 |
InMemoryJavaCompiler.compile("javax.naming.spi.NamingManager", source, "--patch-module=java.naming"), |
41281 | 66 |
System.getProperty("test.classes")); |
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
67 |
|
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
68 |
pb = ProcessTools.createJavaProcessBuilder( |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
69 |
"-XX:+UnlockDiagnosticVMOptions", |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
70 |
"-XX:SharedArchiveFile=" + filename, |
41281 | 71 |
"-Xshare:dump", |
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46790
diff
changeset
|
72 |
"--patch-module=java.naming=" + System.getProperty("test.classes"), |
41281 | 73 |
"-Xlog:class+path=info", |
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
74 |
"-version"); |
41281 | 75 |
new OutputAnalyzer(pb.start()) |
42876
ff8ff9dcccec
8168797: do not load any archived classes from a patched module
jiangli
parents:
41281
diff
changeset
|
76 |
.shouldContain("ro space:"); // Make sure archive got created. |
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
77 |
|
41281 | 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); |
|
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
104 |
} |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff
changeset
|
105 |
} |