|
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 AppCDS tests for testing -Xbootclasspath/a |
|
28 * @requires vm.cds & !vm.graal.enabled |
|
29 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds |
|
30 * @modules jdk.jartool/sun.tools.jar |
|
31 * @compile src/jdk/test/Main.java |
|
32 * @compile src/com/sun/tools/javac/MyMain.jasm |
|
33 * @compile src/sun/nio/cs/ext/MyClass.java |
|
34 * @compile src/sun/nio/cs/ext1/MyClass.java |
|
35 * @run driver BootAppendTests |
|
36 */ |
|
37 |
|
38 import java.io.File; |
|
39 import java.nio.file.Path; |
|
40 import java.nio.file.Paths; |
|
41 import jdk.test.lib.cds.CDSOptions; |
|
42 import jdk.test.lib.cds.CDSTestUtils; |
|
43 import jdk.test.lib.process.ProcessTools; |
|
44 import jdk.test.lib.process.OutputAnalyzer; |
|
45 |
|
46 public class BootAppendTests { |
|
47 private static final String TEST_SRC = System.getProperty("test.src"); |
|
48 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); |
|
49 private static final Path CLASSES_DIR = Paths.get("classes"); |
|
50 |
|
51 private static final String MAIN_CLASS = "jdk.test.Main"; |
|
52 private static final String APP_MODULE_CLASS = "com/sun/tools/javac/MyMain"; |
|
53 private static final String BOOT_APPEND_MODULE_CLASS = "sun/nio/cs/ext/MyClass"; |
|
54 private static final String BOOT_APPEND_CLASS = "sun/nio/cs/ext1/MyClass"; |
|
55 private static final String[] ARCHIVE_CLASSES = |
|
56 {APP_MODULE_CLASS, BOOT_APPEND_MODULE_CLASS, BOOT_APPEND_CLASS}; |
|
57 |
|
58 private static String appJar; |
|
59 private static String bootAppendJar; |
|
60 private static String testArchiveName; |
|
61 |
|
62 public static void main(String... args) throws Exception { |
|
63 dumpArchive(); |
|
64 |
|
65 System.out.println("TESTCASE: 1: testBootAppendModuleClassWithoutAppCDS"); |
|
66 testBootAppendModuleClassWithoutAppCDS(); |
|
67 |
|
68 System.out.println("TESTCASE: 2" ); |
|
69 testBootAppendModuleClassWithAppCDS(); |
|
70 |
|
71 System.out.println("TESTCASE: 3" ); |
|
72 testBootAppendExcludedModuleClassWithoutAppCDS(); |
|
73 |
|
74 System.out.println("TESTCASE: 4" ); |
|
75 testBootAppendExcludedModuleClassWithAppCDS(); |
|
76 |
|
77 System.out.println("TESTCASE: 5" ); |
|
78 testBootAppendClassWithoutAppCDS(); |
|
79 |
|
80 System.out.println("TESTCASE: 6" ); |
|
81 testBootAppendClassWithAppCDS(); |
|
82 |
|
83 System.out.println("TESTCASE: 7" ); |
|
84 testBootAppendAppModuleClassWithoutAppCDS(); |
|
85 |
|
86 System.out.println("TESTCASE: 9" ); |
|
87 testBootAppendAppModuleClassWithAppCDS(); |
|
88 |
|
89 System.out.println("TESTCASE: 9" ); |
|
90 testBootAppendAppExcludeModuleClassWithoutAppCDS(); |
|
91 |
|
92 System.out.println("TESTCASE: 10" ); |
|
93 testBootAppendAppExcludeModuleClassAppCDS(); |
|
94 } |
|
95 |
|
96 static void dumpArchive() throws Exception { |
|
97 JarBuilder.build("classpathtests", "jdk/test/Main"); |
|
98 appJar = TestCommon.getTestJar("classpathtests.jar"); |
|
99 |
|
100 JarBuilder.build("bootAppend", |
|
101 APP_MODULE_CLASS, BOOT_APPEND_MODULE_CLASS, BOOT_APPEND_CLASS); |
|
102 bootAppendJar = TestCommon.getTestJar("bootAppend.jar"); |
|
103 |
|
104 OutputAnalyzer output1 = TestCommon.dump( |
|
105 appJar, TestCommon.list(ARCHIVE_CLASSES), "-Xbootclasspath/a:" + bootAppendJar); |
|
106 TestCommon.checkDump(output1); |
|
107 |
|
108 if (!TestCommon.isUnableToMap(output1)) { |
|
109 // Make sure all the classes were successfully archived. |
|
110 for (String archiveClass : ARCHIVE_CLASSES) { |
|
111 output1.shouldNotContain("Preload Warning: Cannot find " + archiveClass); |
|
112 } |
|
113 } |
|
114 |
|
115 testArchiveName = TestCommon.getCurrentArchiveName(); |
|
116 } |
|
117 |
|
118 // Test #1: A class in package defined in boot module |
|
119 // - should not be loaded from the -Xbootclasspath/a without AppCDS |
|
120 public static void testBootAppendModuleClassWithoutAppCDS() throws Exception { |
|
121 CDSOptions opts = (new CDSOptions()) |
|
122 .addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar) |
|
123 .setArchiveName(testArchiveName) |
|
124 .addSuffix(MAIN_CLASS, "Test #1", BOOT_APPEND_MODULE_CLASS, "false"); |
|
125 |
|
126 CDSTestUtils.runWithArchiveAndCheck(opts); |
|
127 } |
|
128 |
|
129 // Test #2: A shared class in package defined in boot module that's archived |
|
130 // from -Xbootclasspath/a |
|
131 // - should not be loaded by AppCDS |
|
132 public static void testBootAppendModuleClassWithAppCDS() throws Exception { |
|
133 OutputAnalyzer output = TestCommon.exec( |
|
134 appJar, |
|
135 "-Xbootclasspath/a:" + bootAppendJar, |
|
136 MAIN_CLASS, |
|
137 "Test #2", BOOT_APPEND_MODULE_CLASS, "false"); |
|
138 TestCommon.checkExec(output); |
|
139 } |
|
140 |
|
141 |
|
142 // Test #3: A class in excluded package defined in boot module |
|
143 // - should be loaded from the -Xbootclasspath/a by the boot classloader |
|
144 public static void testBootAppendExcludedModuleClassWithoutAppCDS() throws Exception { |
|
145 TestCommon.run( |
|
146 "-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar, |
|
147 "-Xlog:class+load=info", |
|
148 "--limit-modules", "java.base", |
|
149 MAIN_CLASS, "Test #3", BOOT_APPEND_MODULE_CLASS, "true", "BOOT") |
|
150 .assertSilentlyDisabledCDS(out -> { |
|
151 out.shouldHaveExitValue(0) |
|
152 .shouldMatch(".class.load. sun.nio.cs.ext.MyClass source:.*bootAppend.jar"); |
|
153 }); |
|
154 } |
|
155 |
|
156 // Test #4: A shared class in excluded package that's archived from |
|
157 // -Xbootclasspath/a |
|
158 // - should be loaded from the jar since AppCDS will be disabled with |
|
159 // the --limit-modules option |
|
160 public static void testBootAppendExcludedModuleClassWithAppCDS() throws Exception { |
|
161 TestCommon.run( |
|
162 "-cp", appJar, "-Xbootclasspath/a:" + bootAppendJar, |
|
163 "-Xlog:class+load=info", |
|
164 "--limit-modules", "java.base", |
|
165 MAIN_CLASS, |
|
166 "Test #4", BOOT_APPEND_MODULE_CLASS, "true", "BOOT") |
|
167 .assertSilentlyDisabledCDS(out -> { |
|
168 out.shouldHaveExitValue(0) |
|
169 .shouldMatch(".class.load. sun.nio.cs.ext.MyClass source:.*bootAppend.jar"); |
|
170 }); |
|
171 } |
|
172 |
|
173 |
|
174 // Test #5: A class not in package defined in boot module |
|
175 // - should be loaded from the -Xbootclasspath/a without AppCDS |
|
176 public static void testBootAppendClassWithoutAppCDS() throws Exception { |
|
177 CDSOptions opts = (new CDSOptions()) |
|
178 .addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar) |
|
179 .setArchiveName(testArchiveName) |
|
180 .addSuffix(MAIN_CLASS, "Test #5", BOOT_APPEND_CLASS, "true", "BOOT"); |
|
181 |
|
182 CDSTestUtils.runWithArchiveAndCheck(opts); |
|
183 } |
|
184 |
|
185 |
|
186 // Test #6: A shared class not in package defined in boot module that's |
|
187 // archived from -Xbootclasspath/a |
|
188 // - should be loaded from the archive by the bootstrap class loader |
|
189 public static void testBootAppendClassWithAppCDS() throws Exception { |
|
190 OutputAnalyzer output = TestCommon.exec( |
|
191 appJar, |
|
192 "-Xbootclasspath/a:" + bootAppendJar, |
|
193 "-XX:+TraceClassLoading", |
|
194 MAIN_CLASS, |
|
195 "Test #6", BOOT_APPEND_CLASS, "true", "BOOT"); |
|
196 TestCommon.checkExec(output); |
|
197 if (!TestCommon.isUnableToMap(output)) |
|
198 output.shouldContain("[class,load] sun.nio.cs.ext1.MyClass source: shared objects file"); |
|
199 } |
|
200 |
|
201 |
|
202 // Test #7: A class in package defined in jimage app module |
|
203 // - should not be loaded from the -Xbootclasspath/a without AppCDS |
|
204 public static void testBootAppendAppModuleClassWithoutAppCDS() throws Exception { |
|
205 CDSOptions opts = (new CDSOptions()) |
|
206 .addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar) |
|
207 .setArchiveName(testArchiveName) |
|
208 .addSuffix(MAIN_CLASS, "Test #7", APP_MODULE_CLASS, "false"); |
|
209 |
|
210 CDSTestUtils.runWithArchiveAndCheck(opts); |
|
211 } |
|
212 |
|
213 |
|
214 // Test #8: A shared class in package defined in jimage app module that's |
|
215 // archived from -Xbootclasspath/a |
|
216 // - should not be loaded from the archive |
|
217 public static void testBootAppendAppModuleClassWithAppCDS() throws Exception { |
|
218 OutputAnalyzer output = TestCommon.exec( |
|
219 appJar, |
|
220 "-Xbootclasspath/a:" + bootAppendJar, |
|
221 MAIN_CLASS, |
|
222 "Test #8", APP_MODULE_CLASS, "false"); |
|
223 TestCommon.checkExec(output); |
|
224 } |
|
225 |
|
226 |
|
227 // Test #9: A class in excluded package defined in jimage app module |
|
228 // - should be loaded from the -Xbootclasspath/a without AppCDS |
|
229 public static void testBootAppendAppExcludeModuleClassWithoutAppCDS() |
|
230 throws Exception { |
|
231 |
|
232 TestCommon.run( |
|
233 "-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar, |
|
234 "-Xlog:class+load=info", |
|
235 "--limit-modules", "java.base", |
|
236 MAIN_CLASS, "Test #9", APP_MODULE_CLASS, "true", "BOOT") |
|
237 .assertSilentlyDisabledCDS(out -> { |
|
238 out.shouldHaveExitValue(0) |
|
239 .shouldMatch(".class.load. com.sun.tools.javac.MyMain source:.*bootAppend.jar"); |
|
240 }); |
|
241 } |
|
242 |
|
243 // Test #10: A shared class in excluded package defined in jimage app module |
|
244 // - should be loaded from the -Xbootclasspath/a with AppCDS |
|
245 public static void testBootAppendAppExcludeModuleClassAppCDS() throws Exception { |
|
246 TestCommon.run( |
|
247 "-cp", appJar, "-Xbootclasspath/a:" + bootAppendJar, |
|
248 "-Xlog:class+load=info", |
|
249 "--limit-modules", "java.base", |
|
250 MAIN_CLASS, "Test #10", APP_MODULE_CLASS, "true", "BOOT") |
|
251 .assertSilentlyDisabledCDS(out -> { |
|
252 out.shouldHaveExitValue(0) |
|
253 .shouldMatch(".class.load. com.sun.tools.javac.MyMain source:.*bootAppend.jar"); |
|
254 }); |
|
255 } |
|
256 } |