< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/ClassPathAttr.java

Print this page

173 
174     String cp = TestCommon.getTestJar("cpattr6.jar");
175     String nonExistPath = CDSTestUtils.getOutputDir() + File.separator + "cpattrX.jar";
176     (new File(nonExistPath)).delete();
177 
178     TestCommon.testDump(cp, TestCommon.list("CpAttr6"),
179         "-Xlog:class+path");
180 
181     TestCommon.run(
182         "-Xlog:class+path",
183         "-cp", cp,
184         "CpAttr6")
185       .assertNormalExit(output -> {
186           output.shouldMatch("should be non-existent: .*cpattrX.jar");
187         });
188 
189     // Now make nonExistPath exist. CDS still loads, but archived non-system classes will not be used.
190     Files.copy(Paths.get(cp), Paths.get(nonExistPath),
191                StandardCopyOption.REPLACE_EXISTING);
192 
193     TestCommon.run(
194         "-Xlog:class+path",
195         "-cp", cp,
196         "CpAttr6")
197       .assertNormalExit(output -> {
198           output.shouldMatch("Archived non-system classes are disabled because the file .*cpattrX.jar exists");
199         });







200   }
201 
202   static void testClassPathAttrJarOnCP() throws Exception {
203     String helloJar = JarBuilder.getOrCreateHelloJar();
204     String jar1 = TestCommon.getTestJar("cpattr1.jar");
205     String cp = jar1 + File.pathSeparator + helloJar;
206 
207     // The cpattr1.jar contains "Class-Path: cpattr2.jar".
208     // The cpattr2.jar contains "Class-Path: cpattr3.jar cpattr5_123456789_223456789_323456789_42345678.jar".
209     // With -cp cpattr1:hello.jar, the following shared paths should be stored in the CDS archive:
210     // cpattr1.jar:cpattr2.jar:cpattr3.jar:cpattr5_123456789_223456789_323456789_42345678.jari:hello.jar
211     TestCommon.testDump(cp, TestCommon.list("Hello"), "-Xlog:class+path");
212 
213     // Run with the same -cp apattr1.jar:hello.jar. The Hello class should be
214     // loaded from the archive.
215     TestCommon.run("-Xlog:class+path,class+load",
216                    "-cp", cp,
217                    "Hello")
218               .assertNormalExit(output -> {
219                   output.shouldContain("Hello source: shared objects file");

173 
174     String cp = TestCommon.getTestJar("cpattr6.jar");
175     String nonExistPath = CDSTestUtils.getOutputDir() + File.separator + "cpattrX.jar";
176     (new File(nonExistPath)).delete();
177 
178     TestCommon.testDump(cp, TestCommon.list("CpAttr6"),
179         "-Xlog:class+path");
180 
181     TestCommon.run(
182         "-Xlog:class+path",
183         "-cp", cp,
184         "CpAttr6")
185       .assertNormalExit(output -> {
186           output.shouldMatch("should be non-existent: .*cpattrX.jar");
187         });
188 
189     // Now make nonExistPath exist. CDS still loads, but archived non-system classes will not be used.
190     Files.copy(Paths.get(cp), Paths.get(nonExistPath),
191                StandardCopyOption.REPLACE_EXISTING);
192 
193     CDSTestUtils.Result result = TestCommon.run(
194         "-Xlog:class+path",
195         "-cp", cp,
196         "CpAttr6");
197     if (CDSTestUtils.isAOTClassLinkingEnabled()) {
198         result.assertAbnormalExit(output -> {
199                 output.shouldMatch("CDS archive has aot-linked classes. It cannot be used because the file .*cpattrX.jar exists");
200             });
201 
202     } else {
203         result.assertNormalExit(output -> {
204                 output.shouldMatch("Archived non-system classes are disabled because the file .*cpattrX.jar exists");
205             });
206     }
207   }
208 
209   static void testClassPathAttrJarOnCP() throws Exception {
210     String helloJar = JarBuilder.getOrCreateHelloJar();
211     String jar1 = TestCommon.getTestJar("cpattr1.jar");
212     String cp = jar1 + File.pathSeparator + helloJar;
213 
214     // The cpattr1.jar contains "Class-Path: cpattr2.jar".
215     // The cpattr2.jar contains "Class-Path: cpattr3.jar cpattr5_123456789_223456789_323456789_42345678.jar".
216     // With -cp cpattr1:hello.jar, the following shared paths should be stored in the CDS archive:
217     // cpattr1.jar:cpattr2.jar:cpattr3.jar:cpattr5_123456789_223456789_323456789_42345678.jari:hello.jar
218     TestCommon.testDump(cp, TestCommon.list("Hello"), "-Xlog:class+path");
219 
220     // Run with the same -cp apattr1.jar:hello.jar. The Hello class should be
221     // loaded from the archive.
222     TestCommon.run("-Xlog:class+path,class+load",
223                    "-cp", cp,
224                    "Hello")
225               .assertNormalExit(output -> {
226                   output.shouldContain("Hello source: shared objects file");
< prev index next >