1 /* 2 * Copyright (c) 2015, 2016, 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 * @test CheckCheckCICompilerCount 26 * @bug 8130858 8132525 8162881 27 * @summary Check that correct range of values for CICompilerCount are allowed depending on whether tiered is enabled or not 28 * @library /test/lib / 29 * @requires vm.flagless 30 * @modules java.base/jdk.internal.misc 31 * java.management 32 * @run driver compiler.arguments.CheckCICompilerCount 33 */ 34 35 package compiler.arguments; 36 37 import jdk.test.lib.process.OutputAnalyzer; 38 import jdk.test.lib.process.ProcessTools; 39 40 public class CheckCICompilerCount { 41 private static final String[][] NON_TIERED_ARGUMENTS = { 42 { 43 "-server", 44 "-XX:-TieredCompilation", 45 "-XX:+PrintFlagsFinal", 46 "-XX:CICompilerCount=0", 47 "-version" 48 }, 49 { 50 "-server", 51 "-XX:-TieredCompilation", 52 "-XX:+PrintFlagsFinal", 53 "-XX:CICompilerCount=1", 54 "-version" 55 }, 56 { 57 "-server", 58 "-XX:+PrintFlagsFinal", 59 "-XX:CICompilerCount=1", 60 "-XX:-TieredCompilation", 61 "-version" 62 }, 63 { 64 "-client", 65 "-XX:-TieredCompilation", 66 "-XX:+PrintFlagsFinal", 67 "-XX:CICompilerCount=0", 68 "-version" 69 }, 70 { 71 "-client", 72 "-XX:-TieredCompilation", 73 "-XX:+PrintFlagsFinal", 74 "-XX:CICompilerCount=1", 75 "-version" 76 }, 77 { 78 "-client", 79 "-XX:+PrintFlagsFinal", 80 "-XX:CICompilerCount=1", 81 "-XX:-TieredCompilation", 82 "-version" 83 } 84 }; 85 86 private static final String[] NON_TIERED_EXPECTED_OUTPUTS = { 87 "CICompilerCount (0) must be at least 1", 88 "intx CICompilerCount = 1 {product} {command line}", 89 "intx CICompilerCount = 1 {product} {command line}", 90 "CICompilerCount (0) must be at least 1", 91 "intx CICompilerCount = 1 {product} {command line}", 92 "intx CICompilerCount = 1 {product} {command line}" 93 }; 94 95 private static final int[] NON_TIERED_EXIT = { 96 1, 97 0, 98 0, 99 1, 100 0, 101 0 102 }; 103 104 private static final String[][] TIERED_ARGUMENTS = { 105 { 106 "-server", 107 "-XX:+TieredCompilation", 108 "-XX:+PrintFlagsFinal", 109 "-XX:CICompilerCount=1", 110 "-version" 111 }, 112 { 113 "-server", 114 "-XX:+TieredCompilation", 115 "-XX:TieredStopAtLevel=1", 116 "-XX:+PrintFlagsFinal", 117 "-XX:CICompilerCount=1", 118 "-version" 119 }, 120 { 121 "-server", 122 "-XX:+TieredCompilation", 123 "-XX:+PrintFlagsFinal", 124 "-XX:CICompilerCount=1", 125 "-XX:TieredStopAtLevel=1", 126 "-version" 127 }, 128 { 129 "-server", 130 "-XX:+TieredCompilation", 131 "-XX:+PrintFlagsFinal", 132 "-XX:CICompilerCount=2", 133 "-version" 134 }, 135 { 136 "-client", 137 "-XX:+TieredCompilation", 138 "-XX:+PrintFlagsFinal", 139 "-XX:CICompilerCount=1", 140 "-version" 141 }, 142 { 143 "-client", 144 "-XX:+TieredCompilation", 145 "-XX:TieredStopAtLevel=1", 146 "-XX:+PrintFlagsFinal", 147 "-XX:CICompilerCount=1", 148 "-version" 149 }, 150 { 151 "-client", 152 "-XX:+TieredCompilation", 153 "-XX:+PrintFlagsFinal", 154 "-XX:CICompilerCount=1", 155 "-XX:TieredStopAtLevel=1", 156 "-version" 157 }, 158 { 159 "-client", 160 "-XX:+TieredCompilation", 161 "-XX:+PrintFlagsFinal", 162 "-XX:CICompilerCount=2", 163 "-version" 164 } 165 }; 166 167 private static final String[] TIERED_EXPECTED_OUTPUTS = { 168 "CICompilerCount (1) must be at least 2", 169 "intx CICompilerCount = 1 {product} {command line}", 170 "intx CICompilerCount = 1 {product} {command line}", 171 "intx CICompilerCount = 2 {product} {command line}", 172 "CICompilerCount (1) must be at least 2", 173 "intx CICompilerCount = 1 {product} {command line}", 174 "intx CICompilerCount = 1 {product} {command line}", 175 "intx CICompilerCount = 2 {product} {command line}", 176 }; 177 178 private static final int[] TIERED_EXIT = { 179 1, 180 0, 181 0, 182 0, 183 1, 184 0, 185 0, 186 0 187 }; 188 189 private static void verifyValidOption(String[] arguments, String expected_output, int exit, boolean tiered) throws Exception { 190 ProcessBuilder pb; 191 OutputAnalyzer out; 192 193 pb = ProcessTools.createJavaProcessBuilder(arguments); 194 out = new OutputAnalyzer(pb.start()); 195 196 try { 197 out.shouldHaveExitValue(exit); 198 out.shouldContain(expected_output); 199 } catch (RuntimeException e) { 200 // Check if tiered compilation is available in this JVM 201 // Version. Throw exception only if it is available. 202 if (!(tiered && out.getOutput().contains("-XX:+TieredCompilation not supported in this VM"))) { 203 throw new RuntimeException(e); 204 } 205 } 206 } 207 208 public static void main(String[] args) throws Exception { 209 if (NON_TIERED_ARGUMENTS.length != NON_TIERED_EXPECTED_OUTPUTS.length || NON_TIERED_ARGUMENTS.length != NON_TIERED_EXIT.length) { 210 throw new RuntimeException("Test is set up incorrectly: length of arguments, expected outputs and exit codes in non-tiered mode of operation do not match."); 211 } 212 213 if (TIERED_ARGUMENTS.length != TIERED_EXPECTED_OUTPUTS.length || TIERED_ARGUMENTS.length != TIERED_EXIT.length) { 214 throw new RuntimeException("Test is set up incorrectly: length of arguments, expected outputs and exit codes in tiered mode of operation do not match."); 215 } 216 217 for (int i = 0; i < NON_TIERED_ARGUMENTS.length; i++) { 218 verifyValidOption(NON_TIERED_ARGUMENTS[i], NON_TIERED_EXPECTED_OUTPUTS[i], NON_TIERED_EXIT[i], false); 219 } 220 221 for (int i = 0; i < TIERED_ARGUMENTS.length; i++) { 222 verifyValidOption(TIERED_ARGUMENTS[i], TIERED_EXPECTED_OUTPUTS[i], TIERED_EXIT[i], true); 223 } 224 } 225 }