42 import jdk.test.lib.Asserts; 43 import jdk.test.lib.Platform; 44 import jdk.test.lib.process.OutputAnalyzer; 45 46 import sun.hotspot.code.Compiler; 47 import sun.hotspot.gc.GC; 48 49 public class IncompatibleOptions { 50 static final String COOPS_DUMP_WARNING = 51 "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off"; 52 static final String COOPS_EXEC_WARNING = 53 "UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces"; 54 static final String GC_WARNING = 55 "Archived java heap is not supported"; 56 static final String OBJ_ALIGNMENT_MISMATCH = 57 "The shared archive file's ObjectAlignmentInBytes of .* does not equal the current ObjectAlignmentInBytes of"; 58 static final String COMPACT_STRING_MISMATCH = 59 "The shared archive file's CompactStrings setting .* does not equal the current CompactStrings setting"; 60 61 static String appJar; 62 static String[] globalVmOptions; 63 64 public static void main(String[] args) throws Exception { 65 globalVmOptions = args; // specified by "@run main" in IncompatibleOptions_*.java 66 appJar = JarBuilder.build("IncompatibleOptions", "HelloString"); 67 68 // Uncompressed OOPs 69 testDump(1, "-XX:+UseG1GC", "-XX:-UseCompressedOops", COOPS_DUMP_WARNING, true); 70 if (GC.Z.isSupported()) { // ZGC is included in build. 71 testDump(1, "-XX:+UnlockExperimentalVMOptions", "-XX:+UseZGC", COOPS_DUMP_WARNING, true); 72 } 73 74 // incompatible GCs 75 testDump(2, "-XX:+UseParallelGC", "", GC_WARNING, false); 76 testDump(3, "-XX:+UseSerialGC", "", GC_WARNING, false); 77 if (!Compiler.isGraalEnabled()) { // Graal does not support CMS 78 testDump(4, "-XX:+UseConcMarkSweepGC", "", GC_WARNING, false); 79 } 80 81 // ======= archive with compressed oops, run w/o 82 testDump(5, "-XX:+UseG1GC", "-XX:+UseCompressedOops", null, false); 83 testExec(5, "-XX:+UseG1GC", "-XX:-UseCompressedOops", 84 COOPS_EXEC_WARNING, true); 85 101 // Correct the test case once the above is fixed 102 // @ignore JDK-8081416 - for tracking purposes 103 // for now, run test as is until the proper behavior is determined 104 testDump(10, "-XX:+UseG1GC", "-Xmx1g", null, false); 105 testExec(10, "-XX:+UseG1GC", "-Xmx32g", null, true); 106 107 // CompactStrings must match between dump time and run time 108 testDump(11, "-XX:+UseG1GC", "-XX:-CompactStrings", null, false); 109 testExec(11, "-XX:+UseG1GC", "-XX:+CompactStrings", 110 COMPACT_STRING_MISMATCH, true); 111 testDump(12, "-XX:+UseG1GC", "-XX:+CompactStrings", null, false); 112 testExec(12, "-XX:+UseG1GC", "-XX:-CompactStrings", 113 COMPACT_STRING_MISMATCH, true); 114 } 115 116 static void testDump(int testCaseNr, String collectorOption, String extraOption, 117 String expectedWarning, boolean expectedToFail) throws Exception { 118 119 System.out.println("Testcase: " + testCaseNr); 120 OutputAnalyzer output = TestCommon.dump(appJar, TestCommon.list("Hello"), 121 TestCommon.concat(globalVmOptions, 122 "-XX:+UseCompressedOops", 123 collectorOption, 124 "-XX:SharedArchiveConfigFile=" + TestCommon.getSourceFile("SharedStringsBasic.txt"), 125 "-Xlog:cds,cds+hashtables", 126 extraOption)); 127 128 if (expectedWarning != null) { 129 output.shouldContain(expectedWarning); 130 } 131 132 if (expectedToFail) { 133 Asserts.assertNE(output.getExitValue(), 0, 134 "JVM is expected to fail, but did not"); 135 } 136 } 137 138 static void testExec(int testCaseNr, String collectorOption, String extraOption, 139 String expectedWarning, boolean expectedToFail) throws Exception { 140 141 OutputAnalyzer output; 142 System.out.println("Testcase: " + testCaseNr); 143 144 // needed, otherwise system considers empty extra option as a 145 // main class param, and fails with "Could not find or load main class" 146 if (!extraOption.isEmpty()) { 147 output = TestCommon.exec(appJar, 148 TestCommon.concat(globalVmOptions, 149 "-XX:+UseCompressedOops", 150 collectorOption, "-Xlog:cds", extraOption, "HelloString")); 151 } else { 152 output = TestCommon.exec(appJar, 153 TestCommon.concat(globalVmOptions, 154 "-XX:+UseCompressedOops", 155 collectorOption, "-Xlog:cds", "HelloString")); 156 } 157 158 if (expectedWarning != null) { 159 output.shouldMatch(expectedWarning); 160 } 161 162 if (expectedToFail) { 163 Asserts.assertNE(output.getExitValue(), 0); 164 } else { 165 SharedStringsUtils.checkExec(output); 166 } 167 } 168 } | 42 import jdk.test.lib.Asserts; 43 import jdk.test.lib.Platform; 44 import jdk.test.lib.process.OutputAnalyzer; 45 46 import sun.hotspot.code.Compiler; 47 import sun.hotspot.gc.GC; 48 49 public class IncompatibleOptions { 50 static final String COOPS_DUMP_WARNING = 51 "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off"; 52 static final String COOPS_EXEC_WARNING = 53 "UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces"; 54 static final String GC_WARNING = 55 "Archived java heap is not supported"; 56 static final String OBJ_ALIGNMENT_MISMATCH = 57 "The shared archive file's ObjectAlignmentInBytes of .* does not equal the current ObjectAlignmentInBytes of"; 58 static final String COMPACT_STRING_MISMATCH = 59 "The shared archive file's CompactStrings setting .* does not equal the current CompactStrings setting"; 60 61 static String appJar; 62 static String[] vmOptionsPrefix = {}; 63 64 public static void main(String[] args) throws Exception { 65 vmOptionsPrefix = args; // specified by "@run main" in IncompatibleOptions_*.java 66 appJar = JarBuilder.build("IncompatibleOptions", "HelloString"); 67 68 // Uncompressed OOPs 69 testDump(1, "-XX:+UseG1GC", "-XX:-UseCompressedOops", COOPS_DUMP_WARNING, true); 70 if (GC.Z.isSupported()) { // ZGC is included in build. 71 testDump(1, "-XX:+UnlockExperimentalVMOptions", "-XX:+UseZGC", COOPS_DUMP_WARNING, true); 72 } 73 74 // incompatible GCs 75 testDump(2, "-XX:+UseParallelGC", "", GC_WARNING, false); 76 testDump(3, "-XX:+UseSerialGC", "", GC_WARNING, false); 77 if (!Compiler.isGraalEnabled()) { // Graal does not support CMS 78 testDump(4, "-XX:+UseConcMarkSweepGC", "", GC_WARNING, false); 79 } 80 81 // ======= archive with compressed oops, run w/o 82 testDump(5, "-XX:+UseG1GC", "-XX:+UseCompressedOops", null, false); 83 testExec(5, "-XX:+UseG1GC", "-XX:-UseCompressedOops", 84 COOPS_EXEC_WARNING, true); 85 101 // Correct the test case once the above is fixed 102 // @ignore JDK-8081416 - for tracking purposes 103 // for now, run test as is until the proper behavior is determined 104 testDump(10, "-XX:+UseG1GC", "-Xmx1g", null, false); 105 testExec(10, "-XX:+UseG1GC", "-Xmx32g", null, true); 106 107 // CompactStrings must match between dump time and run time 108 testDump(11, "-XX:+UseG1GC", "-XX:-CompactStrings", null, false); 109 testExec(11, "-XX:+UseG1GC", "-XX:+CompactStrings", 110 COMPACT_STRING_MISMATCH, true); 111 testDump(12, "-XX:+UseG1GC", "-XX:+CompactStrings", null, false); 112 testExec(12, "-XX:+UseG1GC", "-XX:-CompactStrings", 113 COMPACT_STRING_MISMATCH, true); 114 } 115 116 static void testDump(int testCaseNr, String collectorOption, String extraOption, 117 String expectedWarning, boolean expectedToFail) throws Exception { 118 119 System.out.println("Testcase: " + testCaseNr); 120 OutputAnalyzer output = TestCommon.dump(appJar, TestCommon.list("Hello"), 121 TestCommon.concat(vmOptionsPrefix, 122 "-XX:+UseCompressedOops", 123 collectorOption, 124 "-XX:SharedArchiveConfigFile=" + TestCommon.getSourceFile("SharedStringsBasic.txt"), 125 "-Xlog:cds,cds+hashtables", 126 extraOption)); 127 128 if (expectedWarning != null) { 129 output.shouldContain(expectedWarning); 130 } 131 132 if (expectedToFail) { 133 Asserts.assertNE(output.getExitValue(), 0, 134 "JVM is expected to fail, but did not"); 135 } 136 } 137 138 static void testExec(int testCaseNr, String collectorOption, String extraOption, 139 String expectedWarning, boolean expectedToFail) throws Exception { 140 141 OutputAnalyzer output; 142 System.out.println("Testcase: " + testCaseNr); 143 144 // needed, otherwise system considers empty extra option as a 145 // main class param, and fails with "Could not find or load main class" 146 if (!extraOption.isEmpty()) { 147 output = TestCommon.exec(appJar, 148 TestCommon.concat(vmOptionsPrefix, 149 "-XX:+UseCompressedOops", 150 collectorOption, "-Xlog:cds", extraOption, "HelloString")); 151 } else { 152 output = TestCommon.exec(appJar, 153 TestCommon.concat(vmOptionsPrefix, 154 "-XX:+UseCompressedOops", 155 collectorOption, "-Xlog:cds", "HelloString")); 156 } 157 158 if (expectedWarning != null) { 159 output.shouldMatch(expectedWarning); 160 } 161 162 if (expectedToFail) { 163 Asserts.assertNE(output.getExitValue(), 0); 164 } else { 165 SharedStringsUtils.checkExec(output); 166 } 167 } 168 } |