8279997: check_for_dynamic_dump should not exit vm

Reviewed-by: ccheung, iklam
This commit is contained in:
Yumin Qi 2022-02-11 16:42:07 +00:00
parent e73ee0ca10
commit e75e8cd708
4 changed files with 54 additions and 30 deletions

View File

@ -375,9 +375,10 @@ void DynamicArchive::check_for_dynamic_dump() {
vm_exit_during_initialization("-XX:+RecordDynamicDumpInfo" __THEMSG, NULL);
} else {
assert(ArchiveClassesAtExit != nullptr, "sanity");
vm_exit_during_initialization("-XX:ArchiveClassesAtExit" __THEMSG, NULL);
#undef __THEMSG
warning("-XX:ArchiveClassesAtExit" __THEMSG);
}
#undef __THEMSG
DynamicDumpSharedSpaces = false;
}
}

View File

@ -3576,6 +3576,10 @@ void Arguments::init_shared_archive_paths() {
SharedArchivePath = get_default_shared_archive_path();
SharedArchiveFile = nullptr;
} else {
if (AutoCreateSharedArchive) {
warning("-XX:+AutoCreateSharedArchive is unsupported when base CDS archive is not loaded. Run with -Xlog:cds for more info.");
AutoCreateSharedArchive = false;
}
no_shared_spaces("invalid archive");
}
} else if (base_archive_path == NULL) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, 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
@ -202,5 +202,30 @@ public class ArchiveConsistency extends DynamicArchiveTestBase {
runTwo(nonExistBase, nonExistTop,
appJar, mainClass, isAuto ? 0 : 1,
"Specified shared archive not found (" + nonExistBase + ")");
// following two tests:
// -Xshare:auto -XX:SharedArchiveFile=top.jsa, but base does not exist.
new File(baseArchiveName).delete();
startTest("10. -XX:+AutoCreateSharedArchive -XX:SharedArchiveFile=" + topArchiveName);
run(topArchiveName,
"-Xshare:auto",
"-XX:+AutoCreateSharedArchive",
"-cp",
appJar, mainClass)
.assertNormalExit(output -> {
output.shouldContain("warning: -XX:+AutoCreateSharedArchive is unsupported when base CDS archive is not loaded");
});
startTest("11. -XX:SharedArchiveFile=" + topArchiveName + " -XX:ArchiveClassesAtExit=" + getNewArchiveName("top3"));
run(topArchiveName,
"-Xshare:auto",
"-XX:ArchiveClassesAtExit=" + getNewArchiveName("top3"),
"-cp",
appJar, mainClass)
.assertNormalExit(output -> {
output.shouldContain("VM warning: -XX:ArchiveClassesAtExit is unsupported when base CDS archive is not loaded");
});
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, 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
@ -64,17 +64,6 @@ public class SharedArchiveFileOption extends DynamicArchiveTestBase {
public void run() throws Exception;
}
private static void mustSkipWith(String expectedMsg, MyRunnable r) throws Exception {
try {
r.run();
} catch (SkippedException e) {
System.out.println("Got SkippedException: " + e);
Asserts.assertTrue(e.getMessage().contains(expectedMsg), "SkippedException must have message " + expectedMsg);
return;
}
Asserts.fail("SkippedException should have been thrown");
}
private static void doTest(String baseArchiveName, String topArchiveName) throws Exception {
String appJar = ClassFileInstaller.getJarPath("hello.jar");
String mainClass = "Hello";
@ -205,25 +194,30 @@ public class SharedArchiveFileOption extends DynamicArchiveTestBase {
output.shouldNotMatch("\\[cds,dynamic");
});
{
{
String ERROR = "-XX:ArchiveClassesAtExit is unsupported when base CDS archive is not loaded";
testcase("-XX:ArchiveClassesAtExit with CDS disabled (-Xshare:off)");
mustSkipWith(ERROR, () -> {
dump2(baseArchiveName,
topArchiveName,
"-Xshare:off",
"-cp", appJar, mainClass);
});
dump2(baseArchiveName,
topArchiveName,
"-Xshare:off",
"-Xlog:cds",
"-cp", appJar, mainClass)
.assertNormalExit(output -> {
output.shouldNotMatch("\\[cds,dynamic");
output.shouldContain(ERROR);
});
testcase("-XX:ArchiveClassesAtExit with CDS disabled (Base archive cannot be mapped -- doesn't exist");
mustSkipWith(ERROR, () -> {
dump2(baseArchiveName + ".notExist",
topArchiveName,
"-Xlog:cds",
"-Xshare:auto",
"-cp", appJar, mainClass);
});
dump2(baseArchiveName + ".notExist",
topArchiveName,
"-Xlog:cds",
"-Xshare:auto",
"-cp", appJar, mainClass)
.assertNormalExit(output -> {
output.shouldNotMatch("\\[cds,dynamic");
output.shouldContain(ERROR);
});
testcase("-XX:ArchiveClassesAtExit with CDS disabled (incompatible VM options)");
dump2(baseArchiveName,
@ -233,7 +227,7 @@ public class SharedArchiveFileOption extends DynamicArchiveTestBase {
"-Xshare:auto",
"-Xlog:cds",
"-cp", appJar, mainClass)
.assertAbnormalExit("Cannot use the following option when dumping the shared archive: --patch-module");
.assertAbnormalExit("Cannot use the following option when dumping the shared archive: --patch-module");
}
{