diff --git a/test/hotspot/jtreg/runtime/SharedArchiveFile/MaxMetaspaceSize.java b/test/hotspot/jtreg/runtime/SharedArchiveFile/MaxMetaspaceSize.java index 765e423034a..c59449d6b1c 100644 --- a/test/hotspot/jtreg/runtime/SharedArchiveFile/MaxMetaspaceSize.java +++ b/test/hotspot/jtreg/runtime/SharedArchiveFile/MaxMetaspaceSize.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,11 +24,13 @@ /** * @test * @requires vm.cds + * @requires vm.flagless * @bug 8067187 8200078 * @summary Testing CDS dumping with the -XX:MaxMetaspaceSize= option * @library /test/lib * @modules java.base/jdk.internal.misc * java.management + * @run driver MaxMetaspaceSize */ import java.util.ArrayList; @@ -45,12 +47,11 @@ public static void main(String[] args) throws Exception { if (Platform.is64bit()) { processArgs.add("-XX:MaxMetaspaceSize=3m"); processArgs.add("-XX:CompressedClassSpaceSize=1m"); - processArgs.add("-XX:InitialBootClassLoaderMetaspaceSize=1m"); } else { processArgs.add("-XX:MaxMetaspaceSize=1m"); } - String msg = "Failed allocating metaspace object"; + String msg = "OutOfMemoryError: Metaspace"; ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(processArgs); CDSTestUtils.executeAndLog(pb, "dump").shouldContain(msg).shouldHaveExitValue(1); } diff --git a/test/hotspot/jtreg/runtime/SharedArchiveFile/SharedStrings.java b/test/hotspot/jtreg/runtime/SharedArchiveFile/SharedStrings.java index 22ff4c771c7..c314ea89218 100644 --- a/test/hotspot/jtreg/runtime/SharedArchiveFile/SharedStrings.java +++ b/test/hotspot/jtreg/runtime/SharedArchiveFile/SharedStrings.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,17 +26,17 @@ * @summary Check to make sure that shared strings in the bootstrap CDS archive * are actually shared * @requires vm.cds.archived.java.heap + * @requires vm.flagless * @library /test/lib - * @modules java.base/jdk.internal.misc - * java.management * @build SharedStringsWb sun.hotspot.WhiteBox - * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox * @run driver SharedStrings */ import jdk.test.lib.cds.CDSTestUtils; import jdk.test.lib.process.ProcessTools; import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.helpers.ClassFileInstaller; public class SharedStrings { public static void main(String[] args) throws Exception { diff --git a/test/hotspot/jtreg/runtime/appcds/MoveJDKTest.java b/test/hotspot/jtreg/runtime/appcds/MoveJDKTest.java index 45202705958..c5ad8e53873 100644 --- a/test/hotspot/jtreg/runtime/appcds/MoveJDKTest.java +++ b/test/hotspot/jtreg/runtime/appcds/MoveJDKTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,12 +27,10 @@ * @summary Test that CDS still works when the JDK is moved to a new directory * @bug 8272345 * @requires vm.cds + * @requires vm.flagless * @comment This test doesn't work on Windows because it depends on symlinks * @requires os.family != "windows" * @library /test/lib - * @modules java.base/jdk.internal.misc - * java.management - * jdk.jartool/sun.tools.jar * @compile test-classes/Hello.java * @run driver MoveJDKTest */ @@ -42,19 +40,21 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import jdk.test.lib.cds.CDSTestUtils; import jdk.test.lib.process.OutputAnalyzer; public class MoveJDKTest { public static void main(String[] args) throws Exception { String java_home_src = System.getProperty("java.home"); - String java_home_dst = System.getProperty("user.dir") + File.separator + "moved_jdk"; + String java_home_dst = CDSTestUtils.getOutputDir() + File.separator + "moved_jdk"; TestCommon.startNewArchiveName(); String jsaFile = TestCommon.getCurrentArchiveName(); String jsaOpt = "-XX:SharedArchiveFile=" + jsaFile; { ProcessBuilder pb = makeBuilder(java_home_src + "/bin/java", "-Xshare:dump", jsaOpt); - TestCommon.executeAndLog(pb, "dump"); + TestCommon.executeAndLog(pb, "dump") + .shouldHaveExitValue(0); } { ProcessBuilder pb = makeBuilder(java_home_src + "/bin/java", @@ -63,6 +63,7 @@ public static void main(String[] args) throws Exception { "-Xlog:class+path=info", "-version"); OutputAnalyzer out = TestCommon.executeAndLog(pb, "exec-src"); + out.shouldHaveExitValue(0); out.shouldNotContain("shared class paths mismatch"); out.shouldNotContain("BOOT classpath mismatch"); } @@ -78,6 +79,7 @@ public static void main(String[] args) throws Exception { "-Xlog:class+path=info", "-version"); OutputAnalyzer out = TestCommon.executeAndLog(pb, "exec-dst"); + out.shouldHaveExitValue(0); out.shouldNotContain("shared class paths mismatch"); out.shouldNotContain("BOOT classpath mismatch"); } @@ -91,7 +93,8 @@ public static void main(String[] args) throws Exception { "-Xshare:dump", dumptimeBootAppendOpt, jsaOpt); - TestCommon.executeAndLog(pb, "dump"); + TestCommon.executeAndLog(pb, "dump") + .shouldHaveExitValue(0); } { String runtimeBootAppendOpt = dumptimeBootAppendOpt + System.getProperty("path.separator") + helloJar; @@ -102,9 +105,20 @@ public static void main(String[] args) throws Exception { "-Xlog:class+path=info", "-version"); OutputAnalyzer out = TestCommon.executeAndLog(pb, "exec-dst"); + out.shouldHaveExitValue(0); out.shouldNotContain("shared class paths mismatch"); out.shouldNotContain("BOOT classpath mismatch"); } + + // Test with no modules image in the /lib directory + renameModulesFile(java_home_dst); + { + ProcessBuilder pb = makeBuilder(java_home_dst + "/bin/java", + "-version"); + OutputAnalyzer out = TestCommon.executeAndLog(pb, "exec-missing-modules"); + out.shouldHaveExitValue(1); + out.shouldContain("Failed setting boot class path."); + } } // Do a cheap clone of the JDK. Most files can be sym-linked. However, $JAVA_HOME/bin/java and $JAVA_HOME/lib/.../libjvm.so" @@ -142,6 +156,24 @@ static void clone(File src, File dst) throws Exception { } } + static void renameModulesFile(String javaHome) throws Exception { + String modulesDir = javaHome + File.separator + "lib"; + File origModules = new File(modulesDir, "modules"); + if (!origModules.exists()) { + throw new RuntimeException("modules file not found"); + } + + File renamedModules = new File(modulesDir, "orig_modules"); + if (renamedModules.exists()) { + throw new RuntimeException("found orig_modules unexpectedly"); + } + + boolean success = origModules.renameTo(renamedModules); + if (!success) { + throw new RuntimeException("rename modules file failed"); + } + } + static ProcessBuilder makeBuilder(String... args) throws Exception { System.out.print("["); for (String s : args) { @@ -152,12 +184,12 @@ static ProcessBuilder makeBuilder(String... args) throws Exception { } private static String copyFakeModulesFromHelloJar() throws Exception { - String classDir = System.getProperty("test.classes"); + String outDir = CDSTestUtils.getOutputDir(); String newFile = "hello.modules"; - String path = classDir + File.separator + newFile; + String path = outDir + File.separator + newFile; - Files.copy(Paths.get(classDir, "hello.jar"), - Paths.get(classDir, newFile), + Files.copy(Paths.get(outDir, "hello.jar"), + Paths.get(outDir, newFile), StandardCopyOption.REPLACE_EXISTING); return path; } diff --git a/test/hotspot/jtreg/runtime/appcds/VerifyWithDefaultArchive.java b/test/hotspot/jtreg/runtime/appcds/VerifyWithDefaultArchive.java new file mode 100644 index 00000000000..aa65bb38b1c --- /dev/null +++ b/test/hotspot/jtreg/runtime/appcds/VerifyWithDefaultArchive.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021, Alibaba Group Holding Limited. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test + * @bug 8264337 + * @summary test default cds archive when turning on VerifySharedSpaces + * @requires vm.flagless + * @requires vm.cds + * @library /test/lib + * @run driver VerifyWithDefaultArchive + */ + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class VerifyWithDefaultArchive { + public static void main(String... args) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:cds", "-XX:+VerifySharedSpaces", "-version"); + OutputAnalyzer out = new OutputAnalyzer(pb.start()); + out.shouldNotContain("relocation bitmap CRC error"); + out.shouldHaveExitValue(0); + } +} diff --git a/test/hotspot/jtreg/runtime/appcds/cacheObject/ArchivedModuleWithCustomImageTest.java b/test/hotspot/jtreg/runtime/appcds/cacheObject/ArchivedModuleWithCustomImageTest.java index 5deb0b8f624..1469dd4dd17 100644 --- a/test/hotspot/jtreg/runtime/appcds/cacheObject/ArchivedModuleWithCustomImageTest.java +++ b/test/hotspot/jtreg/runtime/appcds/cacheObject/ArchivedModuleWithCustomImageTest.java @@ -1,5 +1,5 @@ -/** - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. +/* + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,15 +25,12 @@ * @test * @summary Test archived module graph with custom runtime image * @requires vm.cds.archived.java.heap - * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/appcds - * @modules java.base/jdk.internal.module - * java.management - * jdk.jlink - * jdk.compiler + * @requires vm.flagless + * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/cds/appcds * @build sun.hotspot.WhiteBox * @compile CheckArchivedModuleApp.java - * @run driver ClassFileInstaller -jar app.jar CheckArchivedModuleApp - * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar CheckArchivedModuleApp + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox * @run driver ArchivedModuleWithCustomImageTest */ @@ -45,6 +42,7 @@ import jdk.test.lib.compiler.CompilerUtils; import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.helpers.ClassFileInstaller; public class ArchivedModuleWithCustomImageTest { private static final String JAVA_HOME = System.getProperty("java.home"); @@ -110,7 +108,7 @@ private static void testArchivedModuleUsingImage(Path image) String[] dumpCmd = { customJava.toString(), "-XX:SharedArchiveFile=./ArchivedModuleWithCustomImageTest.jsa", - "-Xshare:dump"}; + "-Xshare:dump", "-Xlog:cds"}; printCommand(dumpCmd); ProcessBuilder pbDump = new ProcessBuilder(); pbDump.command(dumpCmd); diff --git a/test/hotspot/jtreg/runtime/appcds/jcmd/JCmdTestDynamicDump.java b/test/hotspot/jtreg/runtime/appcds/jcmd/JCmdTestDynamicDump.java new file mode 100644 index 00000000000..febc70aea0e --- /dev/null +++ b/test/hotspot/jtreg/runtime/appcds/jcmd/JCmdTestDynamicDump.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test + * @bug 8259070 + * @summary Test jcmd to dump dynamic shared archive. + * @requires vm.cds + * @requires vm.flagless + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds + * @modules jdk.jcmd/sun.tools.common:+open + * @compile ../test-classes/Hello.java JCmdTestDumpBase.java + * @build sun.hotspot.WhiteBox + * @build JCmdTestLingeredApp JCmdTestDynamicDump + * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm/timeout=480 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI JCmdTestDynamicDump + */ + +import java.io.File; + +import jdk.test.lib.apps.LingeredApp; +import jdk.test.lib.cds.CDSTestUtils; +import jdk.test.lib.JDKToolFinder; + +public class JCmdTestDynamicDump extends JCmdTestDumpBase { + static final String DYNAMIC_DUMP_FILE = "mydynamic"; + static final String[] DYNAMIC_MESSAGES = {"JCmdTestLingeredApp source: shared objects file (top)", + "LingeredApp source: shared objects file (top)", + "Hello source: shared objects file (top)"}; + static void test() throws Exception { + setIsStatic(false); + buildJars(); + + LingeredApp app = null; + long pid; + + int test_count = 1; + // Test dynamic dump with -XX:+RecordDynamicDumpInfo. + print2ln(test_count++ + " Test dynamic dump with -XX:+RecordDynamicDumpInfo."); + app = createLingeredApp("-cp", allJars, "-XX:+RecordDynamicDumpInfo"); + pid = app.getPid(); + test(DYNAMIC_DUMP_FILE + "01.jsa", pid, noBoot, EXPECT_PASS, DYNAMIC_MESSAGES); + + // Test dynamic dump twice to same process. + print2ln(test_count++ + " Test dynamic dump second time to the same process."); + test("02.jsa", pid, noBoot, EXPECT_PASS); + app.stopApp(); + + // Test dynamic dump with -XX:-RecordDynamicDumpInfo. + print2ln(test_count++ + " Test dynamic dump with -XX:-RecordDynamicDumpInfo."); + app = createLingeredApp("-cp", allJars); + pid = app.getPid(); + test("01.jsa", pid, noBoot, EXPECT_FAIL); + app.stopApp(); + + // Test dynamic dump with default archive name (null). + print2ln(test_count++ + " Test dynamic dump with default archive name (null)."); + app = createLingeredApp("-cp", allJars, "-XX:+RecordDynamicDumpInfo"); + pid = app.getPid(); + test(null, pid, noBoot, EXPECT_PASS, DYNAMIC_MESSAGES); + app.stopApp(); + + // Test dynamic dump with flags -XX:+RecordDynamicDumpInfo -XX:-DynamicDumpSharedSpaces. + print2ln(test_count++ + " Test dynamic dump with flags -XX:+RecordDynamicDumpInfo -XX:-DynamicDumpSharedSpaces."); + app = createLingeredApp("-cp", allJars, "-XX:+RecordDynamicDumpInfo", "-XX:-DynamicDumpSharedSpaces"); + pid = app.getPid(); + test(null, pid, noBoot, EXPECT_PASS, DYNAMIC_MESSAGES); + app.stopApp(); + + // Test dynamic dump with flags -XX:-DynamicDumpSharedSpaces -XX:+RecordDynamicDumpInfo. + print2ln(test_count++ + " Test dynamic dump with flags -XX:-DynamicDumpSharedSpaces -XX:+RecordDynamicDumpInfo."); + app = createLingeredApp("-cp", allJars, "-XX:-DynamicDumpSharedSpaces", "-XX:+RecordDynamicDumpInfo"); + pid = app.getPid(); + test(null, pid, noBoot, EXPECT_PASS, DYNAMIC_MESSAGES); + app.stopApp(); + + // Test dynamic with -Xbootclasspath/a:boot.jar + print2ln(test_count++ + " Test dynamic with -Xbootclasspath/a:boot.jar"); + app = createLingeredApp("-cp", testJar, "-Xbootclasspath/a:" + bootJar, "-XX:+RecordDynamicDumpInfo"); + pid = app.getPid(); + test(null, pid, useBoot, EXPECT_PASS, DYNAMIC_MESSAGES); + app.stopApp(); + + // Test -XX:+RecordDynamicDump -XX:SharedArchiveFile=test_static.jsa + print2ln(test_count++ + " Test -XX:+RecordDynamicDumpInfo -XX:SharedArchiveFile=test_static.jsa"); + // Dump a static archive as base (here do not use the default classes.jsa) + String archiveFile = "test_static.jsa"; + dumpStaticArchive(archiveFile); + app = createLingeredApp("-cp", allJars, "-XX:+RecordDynamicDumpInfo", + "-XX:SharedArchiveFile=" + archiveFile); + pid = app.getPid(); + test(null, pid, noBoot, EXPECT_PASS, DYNAMIC_MESSAGES); + app.stopApp(); + + // Test dynamic dump with -XX:ArchiveClassAtExit will fail. + print2ln(test_count++ + " Test dynamic dump with -XX:ArchiveClassAtExit will fail."); + app = createLingeredApp("-cp", allJars, + "-Xshare:auto", + "-XX:+RecordDynamicDumpInfo", + "-XX:ArchiveClassesAtExit=AnyName.jsa"); + if (app != null) { + if (app.getProcess().isAlive()) { + throw new RuntimeException("The JCmdTestLingeredApp should not start up!"); + } + } + } + + // Dump a static archive, not using TestCommon.dump(...), we do not take jtreg args. + private static void dumpStaticArchive(String archiveFile) throws Exception { + String javapath = JDKToolFinder.getJDKTool("java"); + String cmd[] = {javapath, "-Xshare:dump", "-XX:SharedArchiveFile=" + archiveFile}; + // Do not use ProcessTools.createTestJvm(cmd) here, it copies jtreg env. + ProcessBuilder pb = new ProcessBuilder(cmd); + CDSTestUtils.executeAndLog(pb, "dump") + .shouldHaveExitValue(0); + File file = new File(archiveFile); + if (!file.exists()) { + throw new RuntimeException("Cannot dump classes to archive file " + archiveFile); + } + } + + public static void main(String... args) throws Exception { + runTest(JCmdTestDynamicDump::test); + } +}