Skip to content

Commit

Permalink
8344822: CDS BulkLoaderTest.java#dynamic fails with COH
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, ccheung
  • Loading branch information
iklam committed Nov 28, 2024
1 parent f51363e commit 8485cb1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,7 +81,6 @@ public static void main(String[] args) throws Exception {
// Run without archived FMG -- fail to load
{
String extraVmArgs[] = {
"-Xshare:on",
"-Xlog:cds",
"-Djdk.module.showModuleResolution=true"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 36 additions & 2 deletions test/lib/jdk/test/lib/cds/CDSAppTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;

/*
Expand All @@ -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) {
Expand All @@ -58,6 +60,7 @@ public CDSAppTester(String name) {
staticArchiveFileLog = staticArchiveFile + ".log";
dynamicArchiveFile = name() + ".dynamic.jsa";
dynamicArchiveFileLog = dynamicArchiveFile + ".log";
tempBaseArchiveFile = name() + ".temp-base.jsa";
}

private String productionRunLog() {
Expand Down Expand Up @@ -189,9 +192,37 @@ private OutputAnalyzer dumpStaticArchive() throws Exception {
return executeAndCheck(cmdLine, runMode, staticArchiveFile, staticArchiveFileLog);
}

// Creating a dynamic CDS archive (with -XX:ArchiveClassesAtExit=<foo>.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),
Expand All @@ -204,6 +235,9 @@ private OutputAnalyzer dumpDynamicArchive() throws Exception {
"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);
}
Expand All @@ -227,9 +261,9 @@ public OutputAnalyzer productionRun(String[] extraVmArgs, String[] extraAppArgs)
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) {
Expand Down

0 comments on commit 8485cb1

Please sign in to comment.