1 /* 2 * Copyright (c) 2014, 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 CommandLineFlagCombo 27 * @requires vm.cds 28 * @requires (vm.gc=="null") 29 * @summary Test command line flag combinations that 30 * could likely affect the behaviour of AppCDS 31 * @library /test/lib 32 * @modules java.base/jdk.internal.misc 33 * 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 * @compile test-classes/Hello.java 38 * @run main/othervm/timeout=240 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. CommandLineFlagCombo 39 */ 40 41 import jdk.test.lib.BuildHelper; 42 import jdk.test.lib.Platform; 43 import jdk.test.lib.process.OutputAnalyzer; 44 45 import sun.hotspot.code.Compiler; 46 47 public class CommandLineFlagCombo { 48 49 // shared base address test table 50 private static final String[] testTable = { 51 "-XX:+UseG1GC", "-XX:+UseSerialGC", "-XX:+UseParallelGC", "-XX:+UseConcMarkSweepGC", 52 "-XX:+FlightRecorder", 53 "-XX:+UseLargePages", // may only take effect on machines with large-pages 54 "-XX:+UseCompressedClassPointers", 55 "-XX:+UseCompressedOops", 56 "-XX:ObjectAlignmentInBytes=16", 57 "-XX:ObjectAlignmentInBytes=32", 58 "-XX:ObjectAlignmentInBytes=64" 59 }; 60 61 public static void main(String[] args) throws Exception { 62 String appJar = JarBuilder.getOrCreateHelloJar(); 63 String classList[] = {"Hello"}; 64 65 for (String testEntry : testTable) { 66 System.out.println("CommandLineFlagCombo = " + testEntry); 67 68 if (skipTestCase(testEntry)) 69 continue; 70 71 OutputAnalyzer dumpOutput = TestCommon.dump(appJar, classList, testEntry); 72 TestCommon.checkDump(dumpOutput, "Loading classes to share"); 73 74 OutputAnalyzer execOutput = TestCommon.exec(appJar, testEntry, "Hello"); 75 TestCommon.checkExec(execOutput, "Hello World"); 76 } 77 78 for (int i=0; i<2; i++) { 79 String g1Flag, serialFlag; 80 81 // Interned strings are supported only with G1GC. However, we should not crash if: 82 // 0: archive has shared strings, but run time doesn't support shared strings 83 // 1: archive has no shared strings, but run time supports shared strings 84 85 String dump_g1Flag = "-XX:" + (i == 0 ? "+" : "-") + "UseG1GC"; 86 String run_g1Flag = "-XX:" + (i != 0 ? "+" : "-") + "UseG1GC"; 87 String dump_serialFlag = "-XX:" + (i != 0 ? "+" : "-") + "UseSerialGC"; 88 String run_serialFlag = "-XX:" + (i == 0 ? "+" : "-") + "UseSerialGC"; 89 90 OutputAnalyzer dumpOutput = TestCommon.dump( 91 appJar, classList, dump_g1Flag, dump_serialFlag); 92 93 TestCommon.checkDump(dumpOutput, "Loading classes to share"); 94 95 OutputAnalyzer execOutput = TestCommon.exec(appJar, run_g1Flag, run_serialFlag, "Hello"); 96 TestCommon.checkExec(execOutput, "Hello World"); 97 } 98 } 99 100 private static boolean skipTestCase(String testEntry) throws Exception { 101 if (Platform.is32bit()) 102 { 103 if (testEntry.equals("-XX:+UseCompressedOops") || 104 testEntry.equals("-XX:+UseCompressedClassPointers") || 105 testEntry.contains("ObjectAlignmentInBytes") ) 106 { 107 System.out.println("Test case not applicable on 32-bit platforms"); 108 return true; 109 } 110 } 111 112 if (Compiler.isGraalEnabled() && testEntry.equals("-XX:+UseConcMarkSweepGC")) 113 { 114 System.out.println("Graal does not support CMS"); 115 return true; 116 } 117 118 return false; 119 } 120 }