diff --git a/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java b/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java index 49544f50032..6e7473c59c1 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java @@ -41,9 +41,10 @@ * @requires vm.cds.supports.aot.class.linking * @library /test/jdk/lib/testlibrary /test/lib * @build InitiatingLoaderTester - * @build BulkLoaderTest + * @build jdk.test.whitebox.WhiteBox BulkLoaderTest * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar BulkLoaderTestApp.jar BulkLoaderTestApp MyUtil InitiatingLoaderTester - * @run driver BulkLoaderTest DYNAMIC + * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. BulkLoaderTest DYNAMIC */ import java.io.File; @@ -80,7 +81,6 @@ public class BulkLoaderTest { // Run without archived FMG -- fail to load { String extraVmArgs[] = { - "-Xshare:on", "-Xlog:cds", "-Djdk.module.showModuleResolution=true" }; diff --git a/test/hotspot/jtreg/runtime/cds/appcds/applications/JavacBench.java b/test/hotspot/jtreg/runtime/cds/appcds/applications/JavacBench.java index 50696c8c1fc..a95119f1a47 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/applications/JavacBench.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/applications/JavacBench.java @@ -35,7 +35,9 @@ * @summary Run JavacBenchApp with the classic dynamic archive workflow * @requires vm.cds * @library /test/lib - * @run driver JavacBench DYNAMIC + * @build jdk.test.whitebox.WhiteBox + * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. JavacBench DYNAMIC */ import jdk.test.lib.cds.CDSAppTester; diff --git a/test/lib/jdk/test/lib/cds/CDSAppTester.java b/test/lib/jdk/test/lib/cds/CDSAppTester.java index d83c3c36e41..3a2fc1e1f69 100644 --- a/test/lib/jdk/test/lib/cds/CDSAppTester.java +++ b/test/lib/jdk/test/lib/cds/CDSAppTester.java @@ -28,6 +28,7 @@ import jdk.test.lib.cds.CDSTestUtils; import jdk.test.lib.process.ProcessTools; import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.StringArrayUtils; +import jdk.test.whitebox.WhiteBox; import jtreg.SkippedException; /* @@ -43,6 +44,7 @@ abstract public class CDSAppTester { private final String staticArchiveFileLog; private final String dynamicArchiveFile; private final String dynamicArchiveFileLog; + private final String tempBaseArchiveFile; private int numProductionRuns = 0; public CDSAppTester(String name) { @@ -58,6 +60,7 @@ abstract public class CDSAppTester { staticArchiveFileLog = staticArchiveFile + ".log"; dynamicArchiveFile = name() + ".dynamic.jsa"; dynamicArchiveFileLog = dynamicArchiveFile + ".log"; + tempBaseArchiveFile = name() + ".temp-base.jsa"; } private String productionRunLog() { @@ -189,9 +192,37 @@ abstract public class CDSAppTester { return executeAndCheck(cmdLine, runMode, staticArchiveFile, staticArchiveFileLog); } + // Creating a dynamic CDS archive (with -XX:ArchiveClassesAtExit=.jsa) requires that the current + // JVM process is using a static archive (which is usually the default CDS archive included in the JDK). + // However, if the JDK doesn't include a default CDS archive that's compatible with the set of + // VM options used by this test, we need to create a temporary static archive to be used with -XX:ArchiveClassesAtExit. + private String getBaseArchiveForDynamicArchive() throws Exception { + WhiteBox wb = WhiteBox.getWhiteBox(); + if (wb.isSharingEnabled()) { + // This current JVM is able to use a default CDS archive included by the JDK, so + // if we launch a JVM child process (with the same set of options as the current JVM), + // that process is also able to use the same default CDS archive for creating + // a dynamic archive. + return null; + } else { + // This current JVM is unable to use a default CDS archive, so let's create a temporary + // static archive to be used with -XX:ArchiveClassesAtExit. + File f = new File(tempBaseArchiveFile); + if (!f.exists()) { + CDSOptions opts = new CDSOptions(); + opts.setArchiveName(tempBaseArchiveFile); + opts.addSuffix("-Djava.class.path="); + OutputAnalyzer out = CDSTestUtils.createArchive(opts); + CDSTestUtils.checkBaseDump(out); + } + return tempBaseArchiveFile; + } + } + private OutputAnalyzer dumpDynamicArchive() throws Exception { RunMode runMode = RunMode.DUMP_DYNAMIC; String[] cmdLine = new String[0]; + String baseArchive = getBaseArchiveForDynamicArchive(); if (isDynamicWorkflow()) { // "classic" dynamic archive cmdLine = StringArrayUtils.concat(vmArgs(runMode), @@ -204,6 +235,9 @@ abstract public class CDSAppTester { "cds+resolve=debug", "class+load=debug")); } + if (baseArchive != null) { + cmdLine = StringArrayUtils.concat(cmdLine, "-XX:SharedArchiveFile=" + baseArchive); + } cmdLine = StringArrayUtils.concat(cmdLine, appCommandLine(runMode)); return executeAndCheck(cmdLine, runMode, dynamicArchiveFile, dynamicArchiveFileLog); } @@ -227,9 +261,9 @@ abstract public class CDSAppTester { logToFile(productionRunLog(), "cds")); if (isStaticWorkflow()) { - cmdLine = StringArrayUtils.concat(cmdLine, "-XX:SharedArchiveFile=" + staticArchiveFile); + cmdLine = StringArrayUtils.concat(cmdLine, "-Xshare:on", "-XX:SharedArchiveFile=" + staticArchiveFile); } else if (isDynamicWorkflow()) { - cmdLine = StringArrayUtils.concat(cmdLine, "-XX:SharedArchiveFile=" + dynamicArchiveFile); + cmdLine = StringArrayUtils.concat(cmdLine, "-Xshare:on", "-XX:SharedArchiveFile=" + dynamicArchiveFile); } if (extraVmArgs != null) {