Skip to content

Commit 8485cb1

Browse files
committed
8344822: CDS BulkLoaderTest.java#dynamic fails with COH
Reviewed-by: dholmes, ccheung
1 parent f51363e commit 8485cb1

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141
* @requires vm.cds.supports.aot.class.linking
4242
* @library /test/jdk/lib/testlibrary /test/lib
4343
* @build InitiatingLoaderTester
44-
* @build BulkLoaderTest
44+
* @build jdk.test.whitebox.WhiteBox BulkLoaderTest
4545
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar BulkLoaderTestApp.jar BulkLoaderTestApp MyUtil InitiatingLoaderTester
46-
* @run driver BulkLoaderTest DYNAMIC
46+
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
47+
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. BulkLoaderTest DYNAMIC
4748
*/
4849

4950
import java.io.File;
@@ -80,7 +81,6 @@ public static void main(String[] args) throws Exception {
8081
// Run without archived FMG -- fail to load
8182
{
8283
String extraVmArgs[] = {
83-
"-Xshare:on",
8484
"-Xlog:cds",
8585
"-Djdk.module.showModuleResolution=true"
8686
};

test/hotspot/jtreg/runtime/cds/appcds/applications/JavacBench.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
* @summary Run JavacBenchApp with the classic dynamic archive workflow
3636
* @requires vm.cds
3737
* @library /test/lib
38-
* @run driver JavacBench DYNAMIC
38+
* @build jdk.test.whitebox.WhiteBox
39+
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
40+
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. JavacBench DYNAMIC
3941
*/
4042

4143
import jdk.test.lib.cds.CDSAppTester;

test/lib/jdk/test/lib/cds/CDSAppTester.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import jdk.test.lib.process.ProcessTools;
2929
import jdk.test.lib.process.OutputAnalyzer;
3030
import jdk.test.lib.StringArrayUtils;
31+
import jdk.test.whitebox.WhiteBox;
3132
import jtreg.SkippedException;
3233

3334
/*
@@ -43,6 +44,7 @@ abstract public class CDSAppTester {
4344
private final String staticArchiveFileLog;
4445
private final String dynamicArchiveFile;
4546
private final String dynamicArchiveFileLog;
47+
private final String tempBaseArchiveFile;
4648
private int numProductionRuns = 0;
4749

4850
public CDSAppTester(String name) {
@@ -58,6 +60,7 @@ public CDSAppTester(String name) {
5860
staticArchiveFileLog = staticArchiveFile + ".log";
5961
dynamicArchiveFile = name() + ".dynamic.jsa";
6062
dynamicArchiveFileLog = dynamicArchiveFile + ".log";
63+
tempBaseArchiveFile = name() + ".temp-base.jsa";
6164
}
6265

6366
private String productionRunLog() {
@@ -189,9 +192,37 @@ private OutputAnalyzer dumpStaticArchive() throws Exception {
189192
return executeAndCheck(cmdLine, runMode, staticArchiveFile, staticArchiveFileLog);
190193
}
191194

195+
// Creating a dynamic CDS archive (with -XX:ArchiveClassesAtExit=<foo>.jsa) requires that the current
196+
// JVM process is using a static archive (which is usually the default CDS archive included in the JDK).
197+
// However, if the JDK doesn't include a default CDS archive that's compatible with the set of
198+
// VM options used by this test, we need to create a temporary static archive to be used with -XX:ArchiveClassesAtExit.
199+
private String getBaseArchiveForDynamicArchive() throws Exception {
200+
WhiteBox wb = WhiteBox.getWhiteBox();
201+
if (wb.isSharingEnabled()) {
202+
// This current JVM is able to use a default CDS archive included by the JDK, so
203+
// if we launch a JVM child process (with the same set of options as the current JVM),
204+
// that process is also able to use the same default CDS archive for creating
205+
// a dynamic archive.
206+
return null;
207+
} else {
208+
// This current JVM is unable to use a default CDS archive, so let's create a temporary
209+
// static archive to be used with -XX:ArchiveClassesAtExit.
210+
File f = new File(tempBaseArchiveFile);
211+
if (!f.exists()) {
212+
CDSOptions opts = new CDSOptions();
213+
opts.setArchiveName(tempBaseArchiveFile);
214+
opts.addSuffix("-Djava.class.path=");
215+
OutputAnalyzer out = CDSTestUtils.createArchive(opts);
216+
CDSTestUtils.checkBaseDump(out);
217+
}
218+
return tempBaseArchiveFile;
219+
}
220+
}
221+
192222
private OutputAnalyzer dumpDynamicArchive() throws Exception {
193223
RunMode runMode = RunMode.DUMP_DYNAMIC;
194224
String[] cmdLine = new String[0];
225+
String baseArchive = getBaseArchiveForDynamicArchive();
195226
if (isDynamicWorkflow()) {
196227
// "classic" dynamic archive
197228
cmdLine = StringArrayUtils.concat(vmArgs(runMode),
@@ -204,6 +235,9 @@ private OutputAnalyzer dumpDynamicArchive() throws Exception {
204235
"cds+resolve=debug",
205236
"class+load=debug"));
206237
}
238+
if (baseArchive != null) {
239+
cmdLine = StringArrayUtils.concat(cmdLine, "-XX:SharedArchiveFile=" + baseArchive);
240+
}
207241
cmdLine = StringArrayUtils.concat(cmdLine, appCommandLine(runMode));
208242
return executeAndCheck(cmdLine, runMode, dynamicArchiveFile, dynamicArchiveFileLog);
209243
}
@@ -227,9 +261,9 @@ public OutputAnalyzer productionRun(String[] extraVmArgs, String[] extraAppArgs)
227261
logToFile(productionRunLog(), "cds"));
228262

229263
if (isStaticWorkflow()) {
230-
cmdLine = StringArrayUtils.concat(cmdLine, "-XX:SharedArchiveFile=" + staticArchiveFile);
264+
cmdLine = StringArrayUtils.concat(cmdLine, "-Xshare:on", "-XX:SharedArchiveFile=" + staticArchiveFile);
231265
} else if (isDynamicWorkflow()) {
232-
cmdLine = StringArrayUtils.concat(cmdLine, "-XX:SharedArchiveFile=" + dynamicArchiveFile);
266+
cmdLine = StringArrayUtils.concat(cmdLine, "-Xshare:on", "-XX:SharedArchiveFile=" + dynamicArchiveFile);
233267
}
234268

235269
if (extraVmArgs != null) {

0 commit comments

Comments
 (0)