author | jiangli |
Mon, 21 May 2018 15:15:58 -0400 | |
changeset 50199 | 83d8b3a25f25 |
parent 49739 | 00805b129186 |
child 51675 | b487c1e914d0 |
permissions | -rw-r--r-- |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
1 |
/* |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
4 |
* |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
8 |
* |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
13 |
* accompanied this code). |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
14 |
* |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
18 |
* |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
21 |
* questions. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
22 |
* |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
23 |
*/ |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
24 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
25 |
/** |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
26 |
* @test |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
27 |
* @requires vm.cds |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
28 |
* @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/appcds |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
29 |
* @modules jdk.compiler |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
30 |
* jdk.jartool/sun.tools.jar |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
31 |
* jdk.jlink |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
32 |
* @run main AddReads |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
33 |
* @summary sanity test the --add-reads option |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
34 |
*/ |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
35 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
36 |
import java.io.File; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
37 |
import java.nio.file.Files; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
38 |
import java.nio.file.Path; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
39 |
import java.nio.file.Paths; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
40 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
41 |
import jdk.test.lib.process.OutputAnalyzer; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
42 |
import jdk.testlibrary.ProcessTools; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
43 |
import jdk.testlibrary.Asserts; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
44 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
45 |
public class AddReads { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
46 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
47 |
private static final Path USER_DIR = Paths.get(System.getProperty("user.dir")); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
48 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
49 |
private static final String TEST_SRC = System.getProperty("test.src"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
50 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
51 |
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
52 |
private static final Path MODS_DIR = Paths.get("mods"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
53 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
54 |
// the module name of the test module |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
55 |
private static final String MAIN_MODULE = "com.norequires"; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
56 |
private static final String SUB_MODULE = "org.astro"; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
57 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
58 |
// the module main class |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
59 |
private static final String MAIN_CLASS = "com.norequires.Main"; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
60 |
private static final String APP_CLASS = "org.astro.World"; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
61 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
62 |
private static Path moduleDir = null; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
63 |
private static Path subJar = null; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
64 |
private static Path mainJar = null; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
65 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
66 |
public static void buildTestModule() throws Exception { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
67 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
68 |
// javac -d mods/$TESTMODULE src/$TESTMODULE/** |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
69 |
JarBuilder.compileModule(SRC_DIR.resolve(SUB_MODULE), |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
70 |
MODS_DIR.resolve(SUB_MODULE), |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
71 |
null); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
72 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
73 |
Asserts.assertTrue(CompilerUtils |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
74 |
.compile(SRC_DIR.resolve(MAIN_MODULE), |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
75 |
MODS_DIR.resolve(MAIN_MODULE), |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
76 |
"-cp", MODS_DIR.resolve(SUB_MODULE).toString(), |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
77 |
"--add-reads", "com.norequires=ALL-UNNAMED")); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
78 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
79 |
moduleDir = Files.createTempDirectory(USER_DIR, "mlib"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
80 |
subJar = moduleDir.resolve(SUB_MODULE + ".jar"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
81 |
String classes = MODS_DIR.resolve(SUB_MODULE).toString(); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
82 |
JarBuilder.createModularJar(subJar.toString(), classes, null); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
83 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
84 |
mainJar = moduleDir.resolve(MAIN_MODULE + ".jar"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
85 |
classes = MODS_DIR.resolve(MAIN_MODULE).toString(); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
86 |
JarBuilder.createModularJar(mainJar.toString(), classes, MAIN_CLASS); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
87 |
} |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
88 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
89 |
public static void main(String... args) throws Exception { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
90 |
// compile the modules and create the modular jar files |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
91 |
buildTestModule(); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
92 |
String appClasses[] = {MAIN_CLASS, APP_CLASS}; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
93 |
// create an archive with the classes in the modules built in the |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
94 |
// previous step |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
95 |
OutputAnalyzer output = TestCommon.createArchive( |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
96 |
null, appClasses, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
97 |
"--module-path", moduleDir.toString(), |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
98 |
"--add-modules", SUB_MODULE, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
99 |
"--add-reads", "com.norequires=org.astro", |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
100 |
"-m", MAIN_MODULE); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
101 |
TestCommon.checkDump(output); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
102 |
String prefix[] = {"-cp", "\"\"", "-Xlog:class+load=trace", |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
103 |
"--add-modules", SUB_MODULE, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
104 |
"--add-reads", "com.norequires=org.astro"}; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
105 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
106 |
// run the com.norequires module with the archive with the same args |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
107 |
// used during dump time. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
108 |
// The classes should be loaded from the archive. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
109 |
TestCommon.runWithModules(prefix, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
110 |
null, // --upgrade-module-path |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
111 |
moduleDir.toString(), // --module-path |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
112 |
MAIN_MODULE) // -m |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
113 |
.assertNormalExit(out -> { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
114 |
out.shouldContain("[class,load] com.norequires.Main source: shared objects file") |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
115 |
.shouldContain("[class,load] org.astro.World source: shared objects file"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
116 |
}); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
117 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
118 |
// create an archive with -cp pointing to the jar file containing the |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
119 |
// org.astro module and --module-path pointing to the main module |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
120 |
output = TestCommon.createArchive( |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
121 |
subJar.toString(), appClasses, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
122 |
"--module-path", moduleDir.toString(), |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
123 |
"--add-modules", SUB_MODULE, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
124 |
"--add-reads", "com.norequires=org.astro", |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
125 |
"-m", MAIN_MODULE); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
126 |
TestCommon.checkDump(output); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
127 |
// run the com.norequires module with the archive with the sub-module |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
128 |
// in the -cp and with -add-reads=com.norequires=ALL-UNNAMED |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
129 |
// The main class should be loaded from the archive. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
130 |
// The org.astro.World should be loaded from the jar. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
131 |
String prefix2[] = {"-cp", subJar.toString(), "-Xlog:class+load=trace", |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
132 |
"--add-reads", "com.norequires=ALL-UNNAMED"}; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
133 |
TestCommon.runWithModules(prefix2, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
134 |
null, // --upgrade-module-path |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
135 |
moduleDir.toString(), // --module-path |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
136 |
MAIN_MODULE) // -m |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
137 |
.assertNormalExit(out -> { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
138 |
out.shouldContain("[class,load] com.norequires.Main source: shared objects file") |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
139 |
.shouldMatch(".class.load. org.astro.World source:.*org.astro.jar"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
140 |
}); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
141 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
142 |
} |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff
changeset
|
143 |
} |