8243947: [TESTBUG] hotspot/jtreg:hotspot_appcds_dynamic fails when the JDK doesn't have default CDS archive

Generate a default CDS archive when necessary before running AppCDS dynamic tests.

Reviewed-by: iklam
This commit is contained in:
Calvin Cheung 2020-05-14 20:34:18 +00:00
parent 95b8e9eaa3
commit 71cc95e4b1
25 changed files with 203 additions and 118 deletions

View File

@ -137,6 +137,22 @@ public class TestCommon extends CDSTestUtils {
return createArchive(appJarDir, appJar, classList, suffix);
}
/**
* Dump the base archive. The JDK's default class list is used (unless otherwise specified
* in cmdLineSuffix).
*/
public static OutputAnalyzer dumpBaseArchive(String baseArchiveName, String ... cmdLineSuffix)
throws Exception
{
CDSOptions opts = new CDSOptions();
opts.setArchiveName(baseArchiveName);
opts.addSuffix(cmdLineSuffix);
opts.addSuffix("-Djava.class.path=");
OutputAnalyzer out = CDSTestUtils.createArchive(opts);
CDSTestUtils.checkBaseDump(out);
return out;
}
// Create AppCDS archive using most common args - convenience method
public static OutputAnalyzer createArchive(String appJar, String classList[],
String... suffix) throws Exception {
@ -158,6 +174,9 @@ public class TestCommon extends CDSTestUtils {
// Simulate -Xshare:dump with -XX:ArchiveClassesAtExit. See comments around patchJarForDynamicDump()
private static final Class tmp = DynamicDumpHelper.class;
// name of the base archive to be used for dynamic dump
private static String tempBaseArchive = null;
// Create AppCDS archive using appcds options
public static OutputAnalyzer createArchive(AppCDSOptions opts)
throws Exception {
@ -182,9 +201,14 @@ public class TestCommon extends CDSTestUtils {
}
if (DYNAMIC_DUMP) {
File baseArchive = null;
if (tempBaseArchive == null || !(new File(tempBaseArchive)).isFile()) {
tempBaseArchive = getNewArchiveName("tempBaseArchive");
dumpBaseArchive(tempBaseArchive);
}
cmd.add("-Xshare:on");
cmd.add("-XX:SharedArchiveFile=" + tempBaseArchive);
cmd.add("-XX:ArchiveClassesAtExit=" + opts.archiveName);
cmd.add("-Xlog:cds");
cmd.add("-Xlog:cds+dynamic");
boolean mainModuleSpecified = false;

View File

@ -29,7 +29,9 @@
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @compile ../test-classes/Hello.java
* @compile ../test-classes/HelloMore.java
* @run driver AppendClasspath
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. AppendClasspath
*/
import java.io.File;

View File

@ -60,7 +60,7 @@ public class ArchiveConsistency extends DynamicArchiveTestBase {
static void testCustomBase() throws Exception {
String topArchiveName = getNewArchiveName("top2");
String baseArchiveName = getNewArchiveName("base");
dumpBaseArchive(baseArchiveName);
TestCommon.dumpBaseArchive(baseArchiveName);
doTest(baseArchiveName, topArchiveName);
}

View File

@ -29,9 +29,10 @@
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
* @build ArrayKlassesApp
* @run driver ClassFileInstaller -jar ArrayKlasses.jar
* ArrayKlassesApp
* @run driver ArrayKlasses
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar ArrayKlasses.jar ArrayKlassesApp
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. ArrayKlasses
*/
public class ArrayKlasses extends DynamicArchiveTestBase {

View File

@ -31,8 +31,10 @@
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
* @build StrConcatApp
* @build MissingDependent
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar missingDependent.jar MissingDependent
* @run driver ClassResolutionFailure
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. ClassResolutionFailure
*/
public class ClassResolutionFailure extends DynamicArchiveTestBase {

View File

@ -31,8 +31,10 @@
* @bug 8231610
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes
* @build Hello
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar hello.jar Hello
* @run driver DynamicArchiveRelocationTest
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. DynamicArchiveRelocationTest
*/
import jdk.test.lib.process.OutputAnalyzer;
@ -93,7 +95,7 @@ public class DynamicArchiveRelocationTest extends DynamicArchiveTestBase {
// (1) Dump base archive (static)
OutputAnalyzer out = dumpBaseArchive(baseArchiveName, unlockArg, dumpBaseRelocArg, logArg);
OutputAnalyzer out = TestCommon.dumpBaseArchive(baseArchiveName, unlockArg, dumpBaseRelocArg, logArg);
if (dump_base_reloc) {
out.shouldContain("ArchiveRelocationMode == 1: always allocate class space at an alternative address");
out.shouldContain("Relocating archive from");

View File

@ -28,6 +28,7 @@ import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.cds.CDSOptions;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.cds.CDSTestUtils.Result;
import sun.hotspot.WhiteBox;
/**
* Base class for test cases in test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/
@ -35,6 +36,8 @@ import jdk.test.lib.cds.CDSTestUtils.Result;
class DynamicArchiveTestBase {
private static boolean executedIn_run = false;
private static final WhiteBox WB = WhiteBox.getWhiteBox();
public static interface DynamicArchiveTest {
public void run() throws Exception;
}
@ -104,6 +107,9 @@ class DynamicArchiveTestBase {
"-XX:ArchiveClassesAtExit=" + topArchiveName);
// to allow dynamic archive tests to be run in the "rt-non-cds-mode"
cmdLine = TestCommon.concat(cmdLine, "-Xshare:auto");
if (baseArchiveName == null && isUseSharedSpacesDisabled()) {
baseArchiveName = getTempBaseArchive();
}
if (baseArchiveName != null) {
cmdLine = TestCommon.concat(cmdLine, "-XX:SharedArchiveFile=" + baseArchiveName);
}
@ -114,6 +120,9 @@ class DynamicArchiveTestBase {
public static Result dump2_WB(String baseArchiveName, String topArchiveName, String ... cmdLineSuffix)
throws Exception
{
if (baseArchiveName == null && isUseSharedSpacesDisabled()) {
baseArchiveName = getTempBaseArchive();
}
return dump2(baseArchiveName, topArchiveName,
TestCommon.concat(wbRuntimeArgs(), cmdLineSuffix));
}
@ -131,28 +140,12 @@ class DynamicArchiveTestBase {
}
/**
* Dump the base archive. The JDK's default class list is used (unless otherwise specified
* in cmdLineSuffix).
*/
public static OutputAnalyzer dumpBaseArchive(String baseArchiveName, String ... cmdLineSuffix)
throws Exception
{
CDSOptions opts = new CDSOptions();
opts.setArchiveName(baseArchiveName);
opts.addSuffix(cmdLineSuffix);
opts.addSuffix("-Djava.class.path=");
OutputAnalyzer out = CDSTestUtils.createArchive(opts);
CDSTestUtils.checkDump(out);
return out;
}
/**
* Same as dumpBaseArchive, but also add WhiteBox to the bootcp
* Same as TestCommon.dumpBaseArchive, but also add WhiteBox to the bootcp
*/
public static void dumpBaseArchive_WB(String baseArchiveName, String ... cmdLineSuffix)
throws Exception
{
dumpBaseArchive(baseArchiveName,
TestCommon.dumpBaseArchive(baseArchiveName,
TestCommon.concat("-Xbootclasspath/a:" + getWhiteBoxJar(), cmdLineSuffix));
}
@ -182,6 +175,9 @@ class DynamicArchiveTestBase {
if (baseArchiveName == null && topArchiveName == null) {
throw new RuntimeException("Both baseArchiveName and topArchiveName cannot be null at the same time.");
}
if (baseArchiveName == null && isUseSharedSpacesDisabled()) {
baseArchiveName = getTempBaseArchive();
}
String archiveFiles = (baseArchiveName == null) ? topArchiveName :
(topArchiveName == null) ? baseArchiveName :
baseArchiveName + File.pathSeparator + topArchiveName;
@ -198,6 +194,9 @@ class DynamicArchiveTestBase {
if (baseArchiveName == null && topArchiveName == null) {
throw new RuntimeException("Both baseArchiveName and topArchiveName cannot be null at the same time.");
}
if (baseArchiveName == null && isUseSharedSpacesDisabled()) {
baseArchiveName = getTempBaseArchive();
}
String archiveFiles = (baseArchiveName == null) ? topArchiveName :
(topArchiveName == null) ? baseArchiveName :
baseArchiveName + File.pathSeparator + topArchiveName;
@ -263,4 +262,35 @@ class DynamicArchiveTestBase {
dump(topArchiveName, cmdLineSuffix).assertNormalExit();
run(topArchiveName, cmdLineSuffix).assertNormalExit();
}
private static String tempBaseArchive;
/**
* Return the name of a base archive.
* It will generate one if one doesn't exist.
*/
private static String getTempBaseArchive() throws Exception {
if (tempBaseArchive == null) {
tempBaseArchive = getNewArchiveName("tempBaseArchive");
TestCommon.dumpBaseArchive(tempBaseArchive);
}
return tempBaseArchive;
}
/**
* Return true if the UseSharedSpaces flag has been disabled.
* By default, the VM will be started with -Xshare:auto.
* The UseSharedSpaces flag will be disabled by the VM if there's some
* problem in using the default CDS archive. It could happen under some
* situations such as follows:
* - the default CDS archive wasn't generated during build time because
* the JDK was built via cross-compilation on a different platform;
* - the VM under test was started with a different options than the ones
* when the default CDS archive was built. E.g. the VM was started with
* -XX:+UseZGC which implicitly disabled the UseCompressedOoops and the
* UseCompressedClassPointers options. Those "compressed" options were
* enabled when the default CDS archive was built.
*/
private static boolean isUseSharedSpacesDisabled() {
return (WB.getBooleanVMFlag("UseSharedSpaces") == false);
}
}

View File

@ -39,8 +39,8 @@ import java.util.ArrayList;
* @build LoadClasses
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar loadclasses.jar LoadClasses
* @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox
* @run driver/timeout=500 DynamicLotsOfClasses
* @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm/timeout=500 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./whitebox.jar DynamicLotsOfClasses
*/
public class DynamicLotsOfClasses extends DynamicArchiveTestBase {

View File

@ -29,12 +29,14 @@
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
* @build ExcludedClassesApp
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar ExcludedClasses.jar
* ExcludedClassesApp
* ExcludedClassesApp$NotLinkedSuper
* ExcludedClassesApp$NotLinkedChild
* ExcludedClassesApp$NotLinkedInterface
* @run driver ExcludedClasses
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. ExcludedClasses
*/
public class ExcludedClasses extends DynamicArchiveTestBase {

View File

@ -28,8 +28,10 @@
* @requires vm.cds
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes
* @build Hello
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar hello.jar Hello
* @run driver HelloDynamic
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. HelloDynamic
*/
public class HelloDynamic extends DynamicArchiveTestBase {
@ -48,7 +50,7 @@ public class HelloDynamic extends DynamicArchiveTestBase {
static void testCustomBase() throws Exception {
String topArchiveName = getNewArchiveName("top2");
String baseArchiveName = getNewArchiveName("base");
dumpBaseArchive(baseArchiveName);
TestCommon.dumpBaseArchive(baseArchiveName);
doTest(baseArchiveName, topArchiveName);
}

View File

@ -31,8 +31,8 @@
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar hello.jar HelloUnload ClassUnloadCommon ClassUnloadCommon$1 ClassUnloadCommon$TestFailure
* @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
* @run driver HelloDynamicCustom
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar HelloDynamicCustom
*/
import java.io.File;

View File

@ -34,8 +34,8 @@
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar hello.jar HelloUnload ClassUnloadCommon ClassUnloadCommon$1 ClassUnloadCommon$TestFailure
* @run driver ClassFileInstaller -jar hello_custom.jar CustomLoadee
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
* @run driver HelloDynamicCustomUnload
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar HelloDynamicCustomUnload
*/
import java.io.File;

View File

@ -29,9 +29,9 @@
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
* @build TestJIT
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run driver ClassFileInstaller -jar testjit.jar TestJIT
* @run driver JITInteraction
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar JITInteraction
*/
public class JITInteraction extends DynamicArchiveTestBase {

View File

@ -30,8 +30,10 @@
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
* @build LinkClassApp
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar link_class_app.jar LinkClassApp Parent Child Parent2 Child2 MyShutdown
* @run driver LinkClassTest
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. LinkClassTest
*/
public class LinkClassTest extends DynamicArchiveTestBase {

View File

@ -99,23 +99,23 @@ public class MainModuleOnly extends DynamicArchiveTestBase {
// create an archive with both -cp and --module-path in the command line.
// Only the class in the modular jar in the --module-path will be archived;
// the class in the modular jar in the -cp won't be archived.
dump2(null, topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug",
"-cp", destJar.toString(),
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE1)
.assertNormalExit(output -> {
output.shouldContain("Buffer-space to target-space delta")
.shouldContain("Written dynamic archive 0x");
});
// run with the archive using the same command line as in dump time.
// The main class should be loaded from the archive.
run2(null, topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
dump(topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug",
"-cp", destJar.toString(),
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE1)
.assertNormalExit(output -> {
output.shouldContain("Buffer-space to target-space delta")
.shouldContain("Written dynamic archive 0x");
});
// run with the archive using the same command line as in dump time.
// The main class should be loaded from the archive.
run(topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE1)
.assertNormalExit(output -> {
output.shouldContain("[class,load] com.simple.Main source: shared objects file")
.shouldHaveExitValue(0);
@ -124,22 +124,22 @@ public class MainModuleOnly extends DynamicArchiveTestBase {
// run with the archive with the main class name inserted before the -m.
// The main class name will be picked up before the module name. So the
// main class should be loaded from the jar in the -cp.
run2(null, topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--module-path", moduleDir.toString(),
MAIN_CLASS, "-m", TEST_MODULE1)
run(topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--module-path", moduleDir.toString(),
MAIN_CLASS, "-m", TEST_MODULE1)
.assertNormalExit(out ->
out.shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"));
// run with the archive with exploded module. Since during dump time, we
// only archive classes from the modular jar in the --module-path, the
// main class should be loaded from the exploded module directory.
run2(null, topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--module-path", MODS_DIR.toString(),
"-m", TEST_MODULE1 + "/" + MAIN_CLASS)
run(topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--module-path", MODS_DIR.toString(),
"-m", TEST_MODULE1 + "/" + MAIN_CLASS)
.assertNormalExit(out -> {
out.shouldMatch(".class.load. com.simple.Main source:.*com.simple")
.shouldContain(MODS_DIR.toString());
@ -148,12 +148,12 @@ public class MainModuleOnly extends DynamicArchiveTestBase {
// run with the archive with the --upgrade-module-path option.
// CDS will be disabled with this options and the main class will be
// loaded from the modular jar.
run2(null, topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--upgrade-module-path", moduleDir.toString(),
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE1)
run(topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--upgrade-module-path", moduleDir.toString(),
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE1)
.assertSilentlyDisabledCDS(out -> {
out.shouldHaveExitValue(0)
.shouldMatch("CDS is disabled when the.*option is specified")
@ -165,12 +165,12 @@ public class MainModuleOnly extends DynamicArchiveTestBase {
// run with the archive with the --limit-modules option.
// CDS will be disabled with this options and the main class will be
// loaded from the modular jar.
run2(null, topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--limit-modules", "java.base," + TEST_MODULE1,
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE1)
run(topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--limit-modules", "java.base," + TEST_MODULE1,
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE1)
.assertSilentlyDisabledCDS(out -> {
out.shouldHaveExitValue(0)
.shouldMatch("CDS is disabled when the.*option is specified")
@ -182,12 +182,12 @@ public class MainModuleOnly extends DynamicArchiveTestBase {
// run with the archive with the --patch-module option.
// CDS will be disabled with this options and the main class will be
// loaded from the modular jar.
run2(null, topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--patch-module", TEST_MODULE1 + "=" + MODS_DIR.toString(),
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE1)
run(topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--patch-module", TEST_MODULE1 + "=" + MODS_DIR.toString(),
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE1)
.assertSilentlyDisabledCDS(out -> {
out.shouldHaveExitValue(0)
.shouldMatch("CDS is disabled when the.*option is specified")
@ -198,21 +198,21 @@ public class MainModuleOnly extends DynamicArchiveTestBase {
// run with the archive and the jar with modified timestamp.
// It should fail due to timestamp of the jar doesn't match the one
// used during dump time.
run2(null, topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE1)
run(topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace",
"-cp", destJar.toString(),
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE1)
.assertAbnormalExit(
"A jar file is not the one used while building the shared archive file:");
// create an archive with a non-empty directory in the --module-path.
// The dumping process will exit with an error due to non-empty directory
// in the --module-path.
dump2(null, topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug",
"-cp", destJar.toString(),
"--module-path", MODS_DIR.toString(),
"-m", TEST_MODULE1 + "/" + MAIN_CLASS)
dump(topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug",
"-cp", destJar.toString(),
"--module-path", MODS_DIR.toString(),
"-m", TEST_MODULE1 + "/" + MAIN_CLASS)
.assertAbnormalExit(output -> {
output.shouldMatch("Error: non-empty directory.*com.simple");
});
@ -254,12 +254,12 @@ public class MainModuleOnly extends DynamicArchiveTestBase {
System.out.println("Caught IOException from Files.copy(). Cannot continue.");
return;
}
dump2(null, topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug",
"-cp", destJar.toString(),
"-Xlog:exceptions=trace",
"--module-path", longDirJar.toString(),
"-m", TEST_MODULE1)
dump(topArchiveName,
"-Xlog:cds+dynamic=debug,cds=debug",
"-cp", destJar.toString(),
"-Xlog:exceptions=trace",
"--module-path", longDirJar.toString(),
"-m", TEST_MODULE1)
.ifAbnormalExit(output -> {
output.shouldMatch("os::stat error.*CDS dump aborted");
});

View File

@ -32,6 +32,7 @@
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes
* /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
* @build MethodSortingApp
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar method_sorting.jar
* MethodSortingApp
* MethodSortingApp$HelloA
@ -44,7 +45,8 @@
* MethodSortingApp$ImplementorA1
* MethodSortingApp$ImplementorB
* MethodSortingApp$ImplementorB1
* @run driver MethodSorting
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. MethodSorting
*/
public class MethodSorting extends DynamicArchiveTestBase {

View File

@ -30,9 +30,9 @@ import java.io.File;
* @requires vm.cds
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes
* @build GenericTestApp sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run driver ClassFileInstaller -jar GenericTestApp.jar GenericTestApp
* @run driver MissingArchive
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar MissingArchive
*/
public class MissingArchive extends DynamicArchiveTestBase {
@ -56,7 +56,7 @@ public class MissingArchive extends DynamicArchiveTestBase {
static void test(String args[]) throws Exception {
String topArchiveName = getNewArchiveName("top");
String baseArchiveName = getNewArchiveName("base");
dumpBaseArchive(baseArchiveName);
TestCommon.dumpBaseArchive(baseArchiveName);
String appJar = ClassFileInstaller.getJarPath("GenericTestApp.jar");
String mainClass = "GenericTestApp";

View File

@ -38,8 +38,10 @@
*
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
* @build StrConcatApp
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar strConcatApp.jar StrConcatApp
* @run driver NoClassToArchive
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. NoClassToArchive
*/
import java.io.File;
@ -61,7 +63,7 @@ public class NoClassToArchive extends DynamicArchiveTestBase {
// (1) Test with default base archive + top archive
static void testDefaultBase() throws Exception {
String topArchiveName = getNewArchiveName("top");
doTest(null, topArchiveName);
doTest(topArchiveName);
}
// (2) Test with custom base archive + top archive
@ -83,15 +85,15 @@ public class NoClassToArchive extends DynamicArchiveTestBase {
}
}
private static void doTest(String baseArchiveName, String topArchiveName) throws Exception {
dump2(baseArchiveName, topArchiveName,
private static void doTest(String topArchiveName) throws Exception {
dump(topArchiveName,
"-Xlog:cds",
"-Xlog:cds+dynamic=debug",
"-Xlog:class+load=trace",
"-version")
.assertNormalExit(output -> checkWarning(output));
dump2(baseArchiveName, topArchiveName,
dump(topArchiveName,
"-Xlog:cds",
"-Xlog:cds+dynamic=debug",
"-Xlog:class+load=trace",
@ -114,7 +116,7 @@ public class NoClassToArchive extends DynamicArchiveTestBase {
TestCommon.checkExecReturn(output, 0, true, "length = 0");
// create a custom base archive based on the class list
dumpBaseArchive(baseArchiveName, "-XX:SharedClassListFile=" + classList);
TestCommon.dumpBaseArchive(baseArchiveName, "-XX:SharedClassListFile=" + classList);
// create a dynamic archive with the custom base archive
// no class should be included in the dynamic archive

View File

@ -27,9 +27,11 @@
* @summary Test relative paths specified in the -cp.
* @requires vm.cds
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @build sun.hotspot.WhiteBox
* @compile ../test-classes/Hello.java
* @compile ../test-classes/HelloMore.java
* @run driver RelativePath
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. RelativePath
*/
import java.io.File;

View File

@ -28,8 +28,10 @@
* @requires vm.cds
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes
* @build Hello
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar hello.jar Hello
* @run driver SharedArchiveFileOption
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. SharedArchiveFileOption
*/
import java.io.File;
@ -44,8 +46,8 @@ public class SharedArchiveFileOption extends DynamicArchiveTestBase {
String topArchiveName = getNewArchiveName("top");
String baseArchiveName = getNewArchiveName("base");
baseArchiveName2 = getNewArchiveName("base2");
dumpBaseArchive(baseArchiveName);
dumpBaseArchive(baseArchiveName2);
TestCommon.dumpBaseArchive(baseArchiveName);
TestCommon.dumpBaseArchive(baseArchiveName2);
doTest(baseArchiveName, topArchiveName);
}

View File

@ -34,8 +34,8 @@ import java.nio.file.Paths;
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes
* @compile ../test-classes/Hello.java
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
* @run driver UnsupportedBaseArchive
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar UnsupportedBaseArchive
*/
public class UnsupportedBaseArchive extends DynamicArchiveTestBase {
@ -103,7 +103,7 @@ public class UnsupportedBaseArchive extends DynamicArchiveTestBase {
// create a base archive with the --module-path option
buildTestModule();
baseArchiveName = getNewArchiveName("base-with-module");
dumpBaseArchive(baseArchiveName,
TestCommon.dumpBaseArchive(baseArchiveName,
"-cp", srcJar.toString(),
"--module-path", moduleDir.toString(),
"-m", TEST_MODULE);

View File

@ -29,8 +29,10 @@
* defined to the PlatformClassLoader and AppClassLoader.
* @requires vm.cds
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @build sun.hotspot.WhiteBox
* @compile ../test-classes/Hello.java
* @run main/othervm -Dtest.cds.copy.child.stdout=false UnusedCPDuringDump
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Dtest.cds.copy.child.stdout=false -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. UnusedCPDuringDump
*/
import java.io.File;

View File

@ -33,7 +33,7 @@ import java.io.File;
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
* @run driver ClassFileInstaller -jar GenericTestApp.jar GenericTestApp
* @run driver ClassFileInstaller -jar WrongJar.jar GenericTestApp
* @run driver WrongTopClasspath
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar WrongTopClasspath
*/
public class WrongTopClasspath extends DynamicArchiveTestBase {
@ -45,7 +45,7 @@ public class WrongTopClasspath extends DynamicArchiveTestBase {
static void test(String args[]) throws Exception {
String topArchiveName = getNewArchiveName("top");
String baseArchiveName = getNewArchiveName("base");
dumpBaseArchive(baseArchiveName);
TestCommon.dumpBaseArchive(baseArchiveName);
String appJar = ClassFileInstaller.getJarPath("GenericTestApp.jar");
String wrongJar = ClassFileInstaller.getJarPath("WrongJar.jar");

View File

@ -31,7 +31,9 @@
* /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive
* @modules java.base/jdk.internal.misc
* jdk.httpserver
* @run driver DynamicLoaderConstraintsTest
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. DynamicLoaderConstraintsTest
*/
import com.sun.net.httpserver.HttpExchange;

View File

@ -283,6 +283,12 @@ public class CDSTestUtils {
return output;
}
// check result of dumping base archive
public static OutputAnalyzer checkBaseDump(OutputAnalyzer output) throws Exception {
output.shouldContain("Loading classes to share");
output.shouldHaveExitValue(0);
return output;
}
// A commonly used convenience methods to create an archive and check the results
// Creates an archive and checks for errors