< prev index next > test/hotspot/jtreg/runtime/cds/appcds/AOTFlags.java
Print this page
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar hello.jar Hello
* @run driver AOTFlags
*/
import java.io.File;
+ import java.util.Map;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.helpers.ClassFileInstaller;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
positiveTests();
negativeTests();
}
static void positiveTests() throws Exception {
+ String hasTrainingDataPattern = "MethodTrainingData *= *[1-9]";
+ String noTrainingDataPattern = "MethodTrainingData *= *0";
+ String hasCachedCodePattern = "Shared file region .cc. .: *[1-9]";
+ String noCachedCodePattern = "Shared file region .cc. .: *0";
+ String hasMappedCachedCodePattern = "Mapped [0-9]+ bytes at address 0x[0-9a-f]+ from AOT Code Cache";
+
//----------------------------------------------------------------------
printTestCase("Training Run");
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTMode=record",
"-XX:AOTConfiguration=" + aotConfigFile,
"-cp", appJar, helloClass);
OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "train");
out.shouldContain("Hello World");
out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
+ out.shouldMatch(hasTrainingDataPattern);
+ out.shouldMatch(noCachedCodePattern);
out.shouldHaveExitValue(0);
//----------------------------------------------------------------------
printTestCase("Assembly Phase (AOTClassLinking unspecified -> should be enabled by default)");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-Xlog:cds",
"-cp", appJar);
out = CDSTestUtils.executeAndLog(pb, "asm");
out.shouldContain("Dumping shared data to file:");
out.shouldMatch("cds.*hello[.]aot");
+ out.shouldMatch(hasTrainingDataPattern);
+ out.shouldMatch(hasCachedCodePattern);
out.shouldHaveExitValue(0);
//----------------------------------------------------------------------
printTestCase("Production Run with AOTCache");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTCache=" + aotCacheFile,
"-Xlog:cds",
+ "-Xlog:scc*",
"-cp", appJar, helloClass);
out = CDSTestUtils.executeAndLog(pb, "prod");
out.shouldContain("Using AOT-linked classes: true (static archive: has aot-linked classes)");
out.shouldContain("Opened AOT cache hello.aot.");
out.shouldContain("Hello World");
+ out.shouldMatch(hasMappedCachedCodePattern);
out.shouldHaveExitValue(0);
//----------------------------------------------------------------------
printTestCase("AOTMode=off");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTMode=create",
"-XX:-AOTClassLinking",
"-XX:AOTConfiguration=" + aotConfigFile,
"-XX:AOTCache=" + aotCacheFile,
! "-Xlog:cds",
"-cp", appJar);
out = CDSTestUtils.executeAndLog(pb, "asm");
out.shouldContain("Dumping shared data to file:");
out.shouldMatch("cds.*hello[.]aot");
out.shouldHaveExitValue(0);
//----------------------------------------------------------------------
printTestCase("Production Run with AOTCache, which was created with -XX:-AOTClassLinking");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTCache=" + aotCacheFile,
"-Xlog:cds",
"-cp", appJar, helloClass);
out = CDSTestUtils.executeAndLog(pb, "prod");
out.shouldContain("Using AOT-linked classes: false (static archive: no aot-linked classes)");
out.shouldContain("Opened AOT cache hello.aot.");
out.shouldContain("Hello World");
out.shouldHaveExitValue(0);
}
static void negativeTests() throws Exception {
//----------------------------------------------------------------------
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTMode=create",
"-XX:-AOTClassLinking",
"-XX:AOTConfiguration=" + aotConfigFile,
"-XX:AOTCache=" + aotCacheFile,
! "-Xlog:cds=debug",
"-cp", appJar);
out = CDSTestUtils.executeAndLog(pb, "asm");
out.shouldContain("Dumping shared data to file:");
out.shouldMatch("cds.*hello[.]aot");
+ out.shouldMatch(noTrainingDataPattern);
+ out.shouldMatch(noCachedCodePattern);
out.shouldHaveExitValue(0);
//----------------------------------------------------------------------
printTestCase("Production Run with AOTCache, which was created with -XX:-AOTClassLinking");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTCache=" + aotCacheFile,
"-Xlog:cds",
+ "-Xlog:scc*",
"-cp", appJar, helloClass);
out = CDSTestUtils.executeAndLog(pb, "prod");
out.shouldContain("Using AOT-linked classes: false (static archive: no aot-linked classes)");
out.shouldContain("Opened AOT cache hello.aot.");
out.shouldContain("Hello World");
+ out.shouldNotMatch(hasMappedCachedCodePattern);
+ out.shouldHaveExitValue(0);
+
+ //----------------------------------------------------------------------
+ printTestCase("Training run with -XX:-AOTClassLinking, but assembly run with -XX:+AOTClassLinking");
+ pb = ProcessTools.createLimitedTestJavaProcessBuilder(
+ "-XX:AOTMode=record",
+ "-XX:-AOTClassLinking",
+ "-XX:AOTConfiguration=" + aotConfigFile,
+ "-Xlog:cds=debug",
+ "-cp", appJar, helloClass);
+ out = CDSTestUtils.executeAndLog(pb, "train");
+ out.shouldContain("Hello World");
+ out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
+ out.shouldHaveExitValue(0);
+
+ pb = ProcessTools.createLimitedTestJavaProcessBuilder(
+ "-XX:AOTMode=create",
+ "-XX:+AOTClassLinking",
+ "-XX:AOTConfiguration=" + aotConfigFile,
+ "-XX:AOTCache=" + aotCacheFile,
+ "-Xlog:cds=debug",
+ "-cp", appJar);
+ out = CDSTestUtils.executeAndLog(pb, "asm");
+ out.shouldContain("Dumping shared data to file:");
+ out.shouldMatch("cds.*hello[.]aot");
+ out.shouldHaveExitValue(0);
+
+ //----------------------------------------------------------------------
+ printTestCase("One step training run (JEP-JDK-8354330");
+
+ // Set all AOTMode/AOTCacheOutput/AOTConfiguration
+ pb = ProcessTools.createLimitedTestJavaProcessBuilder(
+ "-XX:AOTMode=record",
+ "-XX:AOTCacheOutput=" + aotCacheFile,
+ "-XX:AOTConfiguration=" + aotConfigFile,
+ "-Xlog:cds=debug",
+ "-cp", appJar, helloClass);
+ out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
+ out.shouldContain("Hello World");
+ out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
+ out.shouldContain("AOTCache creation is complete: hello.aot");
+ out.shouldHaveExitValue(0);
+
+ // Set AOTCacheOutput/AOTConfiguration only; Ergo for: AOTMode=record
+ pb = ProcessTools.createLimitedTestJavaProcessBuilder(
+ "-XX:AOTCacheOutput=" + aotCacheFile,
+ "-XX:AOTConfiguration=" + aotConfigFile,
+ "-Xlog:cds=debug",
+ "-cp", appJar, helloClass);
+ out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
+ out.shouldContain("Hello World");
+ out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
+ out.shouldContain("AOTCache creation is complete: hello.aot");
+ out.shouldHaveExitValue(0);
+
+ // Set AOTCacheOutput only; Ergo for: AOTMode=record, AOTConfiguration=<temp>
+ pb = ProcessTools.createLimitedTestJavaProcessBuilder(
+ "-XX:AOTCacheOutput=" + aotCacheFile,
+ "-Xlog:cds=debug",
+ "-cp", appJar, helloClass);
+ out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
+ out.shouldContain("Hello World");
+ out.shouldContain("Temporary AOTConfiguration recorded: " + aotCacheFile + ".config");
+ out.shouldContain("AOTCache creation is complete: hello.aot");
+ out.shouldHaveExitValue(0);
+
+ //----------------------------------------------------------------------
+ printTestCase("AOT_TOOL_OPTIONS (JEP-JDK-8354330");
+
+ pb = ProcessTools.createLimitedTestJavaProcessBuilder(
+ "-XX:AOTMode=record",
+ "-XX:AOTCacheOutput=" + aotCacheFile,
+ "-XX:AOTConfiguration=" + aotConfigFile,
+ "-Xlog:cds=debug",
+ "-cp", appJar, helloClass);
+ Map<String, String> env = pb.environment();
+ // The "-Xshare:off" below should be treated as part of a property value and not
+ // a VM option by itself
+ env.put("AOT_TOOL_OPTIONS", "-Dsome.option='foo -Xshare:off ' -Xmx512m -XX:-AOTClassLinking");
+ out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
+ out.shouldContain("Hello World");
+ out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
+ out.shouldContain("AOTCache creation is complete: hello.aot");
+ out.shouldMatch("Picked up JAVA_TOOL_OPTIONS: .*-Dsome.option=foo' '-Xshare:off' '");
+
+ // -XX:-AOTClassLinking should take effect in the assembly process.
+ out.shouldMatch("aot-linked =[ ]+0,");
+ out.shouldNotMatch("aot-linked =[ ]+[1-9]");
out.shouldHaveExitValue(0);
}
static void negativeTests() throws Exception {
//----------------------------------------------------------------------
out = CDSTestUtils.executeAndLog(pb, "neg");
out.shouldContain("AOTConfiguration can only be used with -XX:AOTMode=record or -XX:AOTMode=create");
out.shouldNotHaveExitValue(0);
//----------------------------------------------------------------------
! printTestCase("Use AOTMode without AOTConfiguration");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTMode=record",
"-cp", appJar, helloClass);
out = CDSTestUtils.executeAndLog(pb, "neg");
! out.shouldContain("-XX:AOTMode=record cannot be used without setting AOTConfiguration");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTMode=create",
"-cp", appJar, helloClass);
out = CDSTestUtils.executeAndLog(pb, "neg");
out.shouldContain("AOTConfiguration can only be used with -XX:AOTMode=record or -XX:AOTMode=create");
out.shouldNotHaveExitValue(0);
//----------------------------------------------------------------------
! printTestCase("Use AOTMode without AOTCacheOutput or AOTConfiguration");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTMode=record",
"-cp", appJar, helloClass);
out = CDSTestUtils.executeAndLog(pb, "neg");
! out.shouldContain("-XX:AOTMode=record cannot be used without setting AOTCacheOutput or AOTConfiguration");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTMode=create",
"-cp", appJar, helloClass);
out = CDSTestUtils.executeAndLog(pb, "neg");
out.shouldContain("AOTCache must not be specified when using -XX:AOTMode=record");
out.shouldNotHaveExitValue(0);
//----------------------------------------------------------------------
! printTestCase("AOTCache not specified with -XX:AOTMode=create");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTMode=create",
"-XX:AOTConfiguration=" + aotConfigFile,
"-cp", appJar, helloClass);
out = CDSTestUtils.executeAndLog(pb, "neg");
! out.shouldContain("AOTCache must be specified when using -XX:AOTMode=create");
out.shouldNotHaveExitValue(0);
//----------------------------------------------------------------------
printTestCase("No such config file");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
out = CDSTestUtils.executeAndLog(pb, "neg");
out.shouldContain("AOTCache must not be specified when using -XX:AOTMode=record");
out.shouldNotHaveExitValue(0);
//----------------------------------------------------------------------
! printTestCase("AOTCache/AOTCacheOutput not specified with -XX:AOTMode=create");
+ pb = ProcessTools.createLimitedTestJavaProcessBuilder(
+ "-XX:AOTMode=create",
+ "-XX:AOTConfiguration=" + aotConfigFile,
+ "-cp", appJar, helloClass);
+
+ out = CDSTestUtils.executeAndLog(pb, "neg");
+ out.shouldContain("AOTCache or AOTCacheOutput must be specified when using -XX:AOTMode=create");
+ out.shouldNotHaveExitValue(0);
+
+ //----------------------------------------------------------------------
+ printTestCase("AOTCache and AOTCacheOutput have different values");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:AOTMode=create",
"-XX:AOTConfiguration=" + aotConfigFile,
+ "-XX:AOTCache=aaa",
+ "-XX:AOTCacheOutput=bbb",
"-cp", appJar, helloClass);
out = CDSTestUtils.executeAndLog(pb, "neg");
! out.shouldContain("AOTCache and AOTCacheOutput have different values");
out.shouldNotHaveExitValue(0);
//----------------------------------------------------------------------
printTestCase("No such config file");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
out.shouldHaveExitValue(1);
}
static int testNum = 0;
static void printTestCase(String s) {
! System.out.println("vvvvvvv TEST CASE " + testNum + ": " + s + " starts here vvvvvvv");
testNum++;
}
}
out.shouldHaveExitValue(1);
}
static int testNum = 0;
static void printTestCase(String s) {
! System.out.println("vvvvvvv TEST CASE " + testNum + ": " + s + ": starts here vvvvvvv");
testNum++;
}
}
< prev index next >