|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, 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 | + * @bug 8322657 |
| 28 | + * @summary This test defines an application module using the DefineModuleApp. |
| 29 | + * When performing dynamic dump, the modular jar containing the module |
| 30 | + * is in the -cp. The jar listed in the "Class-Path" attribute of the modular |
| 31 | + * jar doesn't exist. VM should not crash during dynamic dump under this scenario. |
| 32 | + * @requires vm.cds |
| 33 | + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds |
| 34 | + * /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes |
| 35 | + * @build jdk.test.whitebox.WhiteBox DefineModuleApp |
| 36 | + * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox |
| 37 | + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar define_module_app.jar DefineModuleApp |
| 38 | + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. ModularJarWithNonExistentJar |
| 39 | + */ |
| 40 | + |
| 41 | +import java.io.File; |
| 42 | +import java.nio.file.Files; |
| 43 | +import java.nio.file.Path; |
| 44 | +import java.nio.file.Paths; |
| 45 | + |
| 46 | +import jdk.test.lib.cds.CDSTestUtils; |
| 47 | +import jdk.test.lib.helpers.ClassFileInstaller; |
| 48 | + |
| 49 | +public class ModularJarWithNonExistentJar extends DynamicArchiveTestBase { |
| 50 | + private static final Path USER_DIR = Paths.get(CDSTestUtils.getOutputDir()); |
| 51 | + |
| 52 | + private static final String TEST_SRC = System.getProperty("test.src"); |
| 53 | + |
| 54 | + private static final Path SRC_DIR = Paths.get(TEST_SRC, "../jigsaw/modulepath/src"); |
| 55 | + private static final Path MODS_DIR = Paths.get("mods"); |
| 56 | + private static final Path MANIFEST_PATH = Paths.get(TEST_SRC, "test-classes/manifest-with-non-existent-jar.txt"); |
| 57 | + |
| 58 | + // the module name of the test module |
| 59 | + private static final String TEST_MODULE = "com.simple"; |
| 60 | + |
| 61 | + // the module main class |
| 62 | + private static final String MAIN_CLASS = "com.simple.Main"; |
| 63 | + |
| 64 | + private static Path moduleDir = null; |
| 65 | + private static Path modularJar = null; |
| 66 | + |
| 67 | + public static void buildTestModule() throws Exception { |
| 68 | + |
| 69 | + // javac -d mods/$TESTMODULE --module-path MOD_DIR src/$TESTMODULE/** |
| 70 | + JarBuilder.compileModule(SRC_DIR.resolve(TEST_MODULE), |
| 71 | + MODS_DIR.resolve(TEST_MODULE), |
| 72 | + MODS_DIR.toString()); |
| 73 | + |
| 74 | + |
| 75 | + moduleDir = Files.createTempDirectory(USER_DIR, "mlib"); |
| 76 | + |
| 77 | + modularJar = moduleDir.resolve(TEST_MODULE + ".jar"); |
| 78 | + String classes = MODS_DIR.resolve(TEST_MODULE).toString(); |
| 79 | + JarBuilder.createModularJarWithManifest(modularJar.toString(), classes, |
| 80 | + MAIN_CLASS, MANIFEST_PATH.toString()); |
| 81 | + } |
| 82 | + |
| 83 | + public static void main(String... args) throws Exception { |
| 84 | + runTest(ModularJarWithNonExistentJar::testDefaultBase); |
| 85 | + } |
| 86 | + |
| 87 | + static void testDefaultBase() throws Exception { |
| 88 | + String topArchiveName = getNewArchiveName("top"); |
| 89 | + doTest(topArchiveName); |
| 90 | + } |
| 91 | + |
| 92 | + private static void doTest(String topArchiveName) throws Exception { |
| 93 | + // compile the module and create the modular jar file |
| 94 | + buildTestModule(); |
| 95 | + String appJar = ClassFileInstaller.getJarPath("define_module_app.jar"); |
| 96 | + dump(topArchiveName, |
| 97 | + "-Xlog:cds,class+path=info", |
| 98 | + "-Xlog:cds+dynamic=debug", |
| 99 | + "-cp", appJar + File.pathSeparator + modularJar.toString(), |
| 100 | + "DefineModuleApp", moduleDir.toString(), TEST_MODULE) |
| 101 | + .assertNormalExit(output -> { |
| 102 | + output.shouldContain("Written dynamic archive 0x"); |
| 103 | + }); |
| 104 | + } |
| 105 | +} |
0 commit comments