1 /* 2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 /* 26 * @test 27 * @summary Test options that are incompatible with use of shared strings 28 * Also test mismatch in oops encoding between dump time and run time 29 * @requires vm.cds.archived.java.heap 30 * @requires (vm.gc=="null") 31 * @library /test/lib /test/hotspot/jtreg/runtime/appcds 32 * @modules java.base/jdk.internal.misc 33 * @modules java.management 34 * jdk.jartool/sun.tools.jar 35 * @build sun.hotspot.WhiteBox 36 * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission 37 * @build HelloString 38 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. IncompatibleOptions 39 * @run main/othervm -XX:+UseStringDeduplication -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. IncompatibleOptions 40 * @run main/othervm -XX:-CompactStrings -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. IncompatibleOptions 41 */ 42 43 import jdk.test.lib.Asserts; 44 import jdk.test.lib.Platform; 45 import jdk.test.lib.process.OutputAnalyzer; 46 47 import sun.hotspot.code.Compiler; 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 63 public static void main(String[] args) throws Exception { 64 appJar = JarBuilder.build("IncompatibleOptions", "HelloString"); 65 66 // Uncompressed OOPs 67 testDump(1, "-XX:+UseG1GC", "-XX:-UseCompressedOops", COOPS_DUMP_WARNING, true); 68 if (Platform.isLinux() && Platform.isX64()) { 69 testDump(1, "-XX:+UnlockExperimentalVMOptions", "-XX:+UseZGC", COOPS_DUMP_WARNING, true); 70 } 71 72 // incompatible GCs 73 testDump(2, "-XX:+UseParallelGC", "", GC_WARNING, false); 74 testDump(3, "-XX:+UseSerialGC", "", GC_WARNING, false); 75 if (!Compiler.isGraalEnabled()) { // Graal does not support CMS 76 testDump(4, "-XX:+UseConcMarkSweepGC", "", GC_WARNING, false); 77 } 78 79 // ======= archive with compressed oops, run w/o 80 testDump(5, "-XX:+UseG1GC", "-XX:+UseCompressedOops", null, false); 81 testExec(5, "-XX:+UseG1GC", "-XX:-UseCompressedOops", 82 COOPS_EXEC_WARNING, true); 83 84 // NOTE: No warning is displayed, by design 85 // Still run, to ensure no crash or exception 86 testExec(6, "-XX:+UseParallelGC", "", "", false); 87 testExec(7, "-XX:+UseSerialGC", "", "", false); 88 if (!Compiler.isGraalEnabled()) { // Graal does not support CMS 89 testExec(8, "-XX:+UseConcMarkSweepGC", "", "", false); 90 } 91 92 // Test various oops encodings, by varying ObjectAlignmentInBytes and heap sizes 93 testDump(9, "-XX:+UseG1GC", "-XX:ObjectAlignmentInBytes=8", null, false); 94 testExec(9, "-XX:+UseG1GC", "-XX:ObjectAlignmentInBytes=16", 95 OBJ_ALIGNMENT_MISMATCH, true); 96 97 // See JDK-8081416 - Oops encoding mismatch with shared strings 98 // produces unclear or incorrect warning 99 // Correct the test case once the above is fixed 100 // @ignore JDK-8081416 - for tracking purposes 101 // for now, run test as is until the proper behavior is determined 102 testDump(10, "-XX:+UseG1GC", "-Xmx1g", null, false); 103 testExec(10, "-XX:+UseG1GC", "-Xmx32g", null, true); 104 105 // CompactStrings must match between dump time and run time 106 testDump(11, "-XX:+UseG1GC", "-XX:-CompactStrings", null, false); 107 testExec(11, "-XX:+UseG1GC", "-XX:+CompactStrings", 108 COMPACT_STRING_MISMATCH, true); 109 testDump(12, "-XX:+UseG1GC", "-XX:+CompactStrings", null, false); 110 testExec(12, "-XX:+UseG1GC", "-XX:-CompactStrings", 111 COMPACT_STRING_MISMATCH, true); 112 } 113 114 static void testDump(int testCaseNr, String collectorOption, String extraOption, 115 String expectedWarning, boolean expectedToFail) throws Exception { 116 117 System.out.println("Testcase: " + testCaseNr); 118 OutputAnalyzer output = TestCommon.dump(appJar, TestCommon.list("Hello"), 119 "-XX:+UseCompressedOops", 120 collectorOption, 121 "-XX:SharedArchiveConfigFile=" + TestCommon.getSourceFile("SharedStringsBasic.txt"), 122 "-Xlog:cds,cds+hashtables", 123 extraOption); 124 125 if (expectedWarning != null) 126 output.shouldContain(expectedWarning); 127 128 if (expectedToFail) { 129 Asserts.assertNE(output.getExitValue(), 0, 130 "JVM is expected to fail, but did not"); 131 } 132 } 133 134 static void testExec(int testCaseNr, String collectorOption, String extraOption, 135 String expectedWarning, boolean expectedToFail) throws Exception { 136 137 OutputAnalyzer output; 138 System.out.println("Testcase: " + testCaseNr); 139 140 // needed, otherwise system considers empty extra option as a 141 // main class param, and fails with "Could not find or load main class" 142 if (!extraOption.isEmpty()) { 143 output = TestCommon.exec(appJar, "-XX:+UseCompressedOops", 144 collectorOption, extraOption, "HelloString"); 145 } else { 146 output = TestCommon.exec(appJar, "-XX:+UseCompressedOops", 147 collectorOption, "HelloString"); 148 } 149 150 if (expectedWarning != null) 151 output.shouldMatch(expectedWarning); 152 153 if (expectedToFail) 154 Asserts.assertNE(output.getExitValue(), 0); 155 else 156 SharedStringsUtils.checkExec(output); 157 } 158 }