1 /* 2 * Copyright (c) 2014, 2015, 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 import jdk.test.lib.*; 25 26 /* 27 * @test CheckCompileThresholdScaling 28 * @bug 8059604 29 * @summary "Add CompileThresholdScaling flag to control when methods are first compiled (with +/-TieredCompilation)" 30 * @library /testlibrary 31 * @modules java.base/sun.misc 32 * java.management 33 * @run main CheckCompileThresholdScaling 34 */ 35 36 public class CheckCompileThresholdScaling { 37 38 // The flag CompileThresholdScaling scales compilation thresholds 39 // in the following way: 40 // 41 // - if CompileThresholdScaling==1.0, the default threshold values 42 // are used; 43 // 44 // - if CompileThresholdScaling>1.0, threshold values are scaled 45 // up (e.g., CompileThresholdScalingPercentage=1.2 scales up 46 // thresholds by a factor of 1.2X); 47 // 48 // - if CompileThresholdScaling<1.0, threshold values are scaled 49 // down; 50 // 51 // - if CompileThresholdScaling==0, compilation is disabled 52 // (equivalent to using -Xint). 53 // 54 // With tiered compilation enabled, the values of the following 55 // flags are changed: 56 // 57 // Tier0InvokeNotifyFreqLog, Tier0BackedgeNotifyFreqLog, 58 // Tier3InvocationThreshold, Tier3MinInvocationThreshold, 59 // Tier3CompileThreshold, Tier3BackEdgeThreshold, 60 // Tier2InvokeNotifyFreqLog, Tier2BackedgeNotifyFreqLog, 61 // Tier3InvokeNotifyFreqLog, Tier3BackedgeNotifyFreqLog, 62 // Tier23InlineeNotifyFreqLog, Tier4InvocationThreshold, 63 // Tier4MinInvocationThreshold, Tier4CompileThreshold, 64 // Tier4BackEdgeThreshold 65 // 66 // With tiered compilation disabled the value of CompileThreshold 67 // is scaled. 68 private static final String[][] NON_TIERED_ARGUMENTS = { 69 { 70 "-XX:-TieredCompilation", 71 "-XX:+PrintFlagsFinal", 72 "-XX:CompileThreshold=1000", 73 "-version" 74 }, 75 { 76 "-XX:-TieredCompilation", 77 "-XX:+PrintFlagsFinal", 78 "-XX:CompileThreshold=1000", 79 "-XX:CompileThresholdScaling=1.25", 80 "-version" 81 }, 82 { 83 "-XX:-TieredCompilation", 84 "-XX:+PrintFlagsFinal", 85 "-XX:CompileThreshold=1000", 86 "-XX:CompileThresholdScaling=0.75", 87 "-version" 88 }, 89 { 90 "-XX:-TieredCompilation", 91 "-XX:+PrintFlagsFinal", 92 "-XX:CompileThreshold=1000", 93 "-XX:CompileThresholdScaling=0.0", 94 "-version" 95 }, 96 { 97 "-XX:-TieredCompilation", 98 "-XX:+PrintFlagsFinal", 99 "-XX:CompileThreshold=0", 100 "-XX:CompileThresholdScaling=0.75", 101 "-version" 102 } 103 104 }; 105 106 private static final String[][] NON_TIERED_EXPECTED_OUTPUTS = { 107 { 108 "intx CompileThreshold := 1000 {pd product}", 109 "double CompileThresholdScaling = 1.000000 {product}" 110 }, 111 { 112 "intx CompileThreshold := 1250 {pd product}", 113 "double CompileThresholdScaling := 1.250000 {product}" 114 }, 115 { 116 "intx CompileThreshold := 750 {pd product}", 117 "double CompileThresholdScaling := 0.750000 {product}" 118 }, 119 { 120 "intx CompileThreshold := 1000 {pd product}", 121 "double CompileThresholdScaling := 0.000000 {product}", 122 "interpreted mode" 123 }, 124 { 125 "intx CompileThreshold := 0 {pd product}", 126 "double CompileThresholdScaling := 0.750000 {product}", 127 "interpreted mode" 128 } 129 }; 130 131 private static final String[][] TIERED_ARGUMENTS = { 132 { 133 "-XX:+TieredCompilation", 134 "-XX:+PrintFlagsFinal", 135 "-XX:Tier0InvokeNotifyFreqLog=7", 136 "-XX:Tier0BackedgeNotifyFreqLog=10", 137 "-XX:Tier3InvocationThreshold=200", 138 "-XX:Tier3MinInvocationThreshold=100", 139 "-XX:Tier3CompileThreshold=2000", 140 "-XX:Tier3BackEdgeThreshold=60000", 141 "-XX:Tier2InvokeNotifyFreqLog=11", 142 "-XX:Tier2BackedgeNotifyFreqLog=14", 143 "-XX:Tier3InvokeNotifyFreqLog=10", 144 "-XX:Tier3BackedgeNotifyFreqLog=13", 145 "-XX:Tier23InlineeNotifyFreqLog=20", 146 "-XX:Tier4InvocationThreshold=5000", 147 "-XX:Tier4MinInvocationThreshold=600", 148 "-XX:Tier4CompileThreshold=15000", 149 "-XX:Tier4BackEdgeThreshold=40000", 150 "-version" 151 }, 152 { 153 "-XX:+TieredCompilation", 154 "-XX:+PrintFlagsFinal", 155 "-XX:Tier0InvokeNotifyFreqLog=7", 156 "-XX:Tier0BackedgeNotifyFreqLog=10", 157 "-XX:Tier3InvocationThreshold=200", 158 "-XX:Tier3MinInvocationThreshold=100", 159 "-XX:Tier3CompileThreshold=2000", 160 "-XX:Tier3BackEdgeThreshold=60000", 161 "-XX:Tier2InvokeNotifyFreqLog=11", 162 "-XX:Tier2BackedgeNotifyFreqLog=14", 163 "-XX:Tier3InvokeNotifyFreqLog=10", 164 "-XX:Tier3BackedgeNotifyFreqLog=13", 165 "-XX:Tier23InlineeNotifyFreqLog=20", 166 "-XX:Tier4InvocationThreshold=5000", 167 "-XX:Tier4MinInvocationThreshold=600", 168 "-XX:Tier4CompileThreshold=15000", 169 "-XX:Tier4BackEdgeThreshold=40000", 170 "-XX:CompileThresholdScaling=0.75", 171 "-version" 172 }, 173 { 174 "-XX:+TieredCompilation", 175 "-XX:+PrintFlagsFinal", 176 "-XX:Tier0InvokeNotifyFreqLog=7", 177 "-XX:Tier0BackedgeNotifyFreqLog=10", 178 "-XX:Tier3InvocationThreshold=200", 179 "-XX:Tier3MinInvocationThreshold=100", 180 "-XX:Tier3CompileThreshold=2000", 181 "-XX:Tier3BackEdgeThreshold=60000", 182 "-XX:Tier2InvokeNotifyFreqLog=11", 183 "-XX:Tier2BackedgeNotifyFreqLog=14", 184 "-XX:Tier3InvokeNotifyFreqLog=10", 185 "-XX:Tier3BackedgeNotifyFreqLog=13", 186 "-XX:Tier23InlineeNotifyFreqLog=20", 187 "-XX:Tier4InvocationThreshold=5000", 188 "-XX:Tier4MinInvocationThreshold=600", 189 "-XX:Tier4CompileThreshold=15000", 190 "-XX:Tier4BackEdgeThreshold=40000", 191 "-XX:CompileThresholdScaling=1.25", 192 "-version" 193 }, 194 { 195 "-XX:+TieredCompilation", 196 "-XX:+PrintFlagsFinal", 197 "-XX:Tier0InvokeNotifyFreqLog=7", 198 "-XX:Tier0BackedgeNotifyFreqLog=10", 199 "-XX:Tier3InvocationThreshold=200", 200 "-XX:Tier3MinInvocationThreshold=100", 201 "-XX:Tier3CompileThreshold=2000", 202 "-XX:Tier3BackEdgeThreshold=60000", 203 "-XX:Tier2InvokeNotifyFreqLog=11", 204 "-XX:Tier2BackedgeNotifyFreqLog=14", 205 "-XX:Tier3InvokeNotifyFreqLog=10", 206 "-XX:Tier3BackedgeNotifyFreqLog=13", 207 "-XX:Tier23InlineeNotifyFreqLog=20", 208 "-XX:Tier4InvocationThreshold=5000", 209 "-XX:Tier4MinInvocationThreshold=600", 210 "-XX:Tier4CompileThreshold=15000", 211 "-XX:Tier4BackEdgeThreshold=40000", 212 "-XX:CompileThresholdScaling=2.0", 213 "-version" 214 }, 215 { 216 "-XX:+TieredCompilation", 217 "-XX:+PrintFlagsFinal", 218 "-XX:Tier0InvokeNotifyFreqLog=7", 219 "-XX:Tier0BackedgeNotifyFreqLog=10", 220 "-XX:Tier3InvocationThreshold=200", 221 "-XX:Tier3MinInvocationThreshold=100", 222 "-XX:Tier3CompileThreshold=2000", 223 "-XX:Tier3BackEdgeThreshold=60000", 224 "-XX:Tier2InvokeNotifyFreqLog=11", 225 "-XX:Tier2BackedgeNotifyFreqLog=14", 226 "-XX:Tier3InvokeNotifyFreqLog=10", 227 "-XX:Tier3BackedgeNotifyFreqLog=13", 228 "-XX:Tier23InlineeNotifyFreqLog=20", 229 "-XX:Tier4InvocationThreshold=5000", 230 "-XX:Tier4MinInvocationThreshold=600", 231 "-XX:Tier4CompileThreshold=15000", 232 "-XX:Tier4BackEdgeThreshold=40000", 233 "-XX:CompileThresholdScaling=0.0", 234 "-version" 235 } 236 }; 237 238 private static final String[][] TIERED_EXPECTED_OUTPUTS = { 239 { 240 "intx Tier0BackedgeNotifyFreqLog := 10 {product}", 241 "intx Tier0InvokeNotifyFreqLog := 7 {product}", 242 "intx Tier23InlineeNotifyFreqLog := 20 {product}", 243 "intx Tier2BackedgeNotifyFreqLog := 14 {product}", 244 "intx Tier2InvokeNotifyFreqLog := 11 {product}", 245 "intx Tier3BackEdgeThreshold := 60000 {product}", 246 "intx Tier3BackedgeNotifyFreqLog := 13 {product}", 247 "intx Tier3CompileThreshold := 2000 {product}", 248 "intx Tier3InvocationThreshold := 200 {product}", 249 "intx Tier3InvokeNotifyFreqLog := 10 {product}", 250 "intx Tier3MinInvocationThreshold := 100 {product}", 251 "intx Tier4BackEdgeThreshold := 40000 {product}", 252 "intx Tier4CompileThreshold := 15000 {product}", 253 "intx Tier4InvocationThreshold := 5000 {product}", 254 "intx Tier4MinInvocationThreshold := 600 {product}", 255 "double CompileThresholdScaling = 1.000000 {product}" 256 }, 257 { 258 "intx Tier0BackedgeNotifyFreqLog := 9 {product}", 259 "intx Tier0InvokeNotifyFreqLog := 6 {product}", 260 "intx Tier23InlineeNotifyFreqLog := 19 {product}", 261 "intx Tier2BackedgeNotifyFreqLog := 13 {product}", 262 "intx Tier2InvokeNotifyFreqLog := 10 {product}", 263 "intx Tier3BackEdgeThreshold := 45000 {product}", 264 "intx Tier3BackedgeNotifyFreqLog := 12 {product}", 265 "intx Tier3CompileThreshold := 1500 {product}", 266 "intx Tier3InvocationThreshold := 150 {product}", 267 "intx Tier3InvokeNotifyFreqLog := 9 {product}", 268 "intx Tier3MinInvocationThreshold := 75 {product}", 269 "intx Tier4BackEdgeThreshold := 30000 {product}", 270 "intx Tier4CompileThreshold := 11250 {product}", 271 "intx Tier4InvocationThreshold := 3750 {product}", 272 "intx Tier4MinInvocationThreshold := 450 {product}", 273 "double CompileThresholdScaling := 0.750000 {product}" 274 }, 275 { 276 "intx Tier0BackedgeNotifyFreqLog := 10 {product}", 277 "intx Tier0InvokeNotifyFreqLog := 7 {product}", 278 "intx Tier23InlineeNotifyFreqLog := 20 {product}", 279 "intx Tier2BackedgeNotifyFreqLog := 14 {product}", 280 "intx Tier2InvokeNotifyFreqLog := 11 {product}", 281 "intx Tier3BackEdgeThreshold := 75000 {product}", 282 "intx Tier3BackedgeNotifyFreqLog := 13 {product}", 283 "intx Tier3CompileThreshold := 2500 {product}", 284 "intx Tier3InvocationThreshold := 250 {product}", 285 "intx Tier3InvokeNotifyFreqLog := 10 {product}", 286 "intx Tier3MinInvocationThreshold := 125 {product}", 287 "intx Tier4BackEdgeThreshold := 50000 {product}", 288 "intx Tier4CompileThreshold := 18750 {product}", 289 "intx Tier4InvocationThreshold := 6250 {product}", 290 "intx Tier4MinInvocationThreshold := 750 {product}", 291 "double CompileThresholdScaling := 1.250000 {product}" 292 }, 293 { 294 "intx Tier0BackedgeNotifyFreqLog := 11 {product}", 295 "intx Tier0InvokeNotifyFreqLog := 8 {product}", 296 "intx Tier23InlineeNotifyFreqLog := 21 {product}", 297 "intx Tier2BackedgeNotifyFreqLog := 15 {product}", 298 "intx Tier2InvokeNotifyFreqLog := 12 {product}", 299 "intx Tier3BackEdgeThreshold := 120000 {product}", 300 "intx Tier3BackedgeNotifyFreqLog := 14 {product}", 301 "intx Tier3CompileThreshold := 4000 {product}", 302 "intx Tier3InvocationThreshold := 400 {product}", 303 "intx Tier3InvokeNotifyFreqLog := 11 {product}", 304 "intx Tier3MinInvocationThreshold := 200 {product}", 305 "intx Tier4BackEdgeThreshold := 80000 {product}", 306 "intx Tier4CompileThreshold := 30000 {product}", 307 "intx Tier4InvocationThreshold := 10000 {product}", 308 "intx Tier4MinInvocationThreshold := 1200 {product}", 309 "double CompileThresholdScaling := 2.000000 {product}" 310 }, 311 { 312 "intx Tier0BackedgeNotifyFreqLog := 10 {product}", 313 "intx Tier0InvokeNotifyFreqLog := 7 {product}", 314 "intx Tier23InlineeNotifyFreqLog := 20 {product}", 315 "intx Tier2BackedgeNotifyFreqLog := 14 {product}", 316 "intx Tier2InvokeNotifyFreqLog := 11 {product}", 317 "intx Tier3BackEdgeThreshold := 60000 {product}", 318 "intx Tier3BackedgeNotifyFreqLog := 13 {product}", 319 "intx Tier3CompileThreshold := 2000 {product}", 320 "intx Tier3InvocationThreshold := 200 {product}", 321 "intx Tier3InvokeNotifyFreqLog := 10 {product}", 322 "intx Tier3MinInvocationThreshold := 100 {product}", 323 "intx Tier4BackEdgeThreshold := 40000 {product}", 324 "intx Tier4CompileThreshold := 15000 {product}", 325 "intx Tier4InvocationThreshold := 5000 {product}", 326 "intx Tier4MinInvocationThreshold := 600 {product}", 327 "double CompileThresholdScaling := 0.000000 {product}", 328 "interpreted mode" 329 } 330 }; 331 332 private static void verifyValidOption(String[] arguments, String[] expected_outputs, boolean tiered) throws Exception { 333 ProcessBuilder pb; 334 OutputAnalyzer out; 335 336 pb = ProcessTools.createJavaProcessBuilder(arguments); 337 out = new OutputAnalyzer(pb.start()); 338 339 try { 340 for (String expected_output : expected_outputs) { 341 out.shouldContain(expected_output); 342 } 343 out.shouldHaveExitValue(0); 344 } catch (RuntimeException e) { 345 // Check if tiered compilation is available in this JVM 346 // Version. Throw exception only if it is available. 347 if (!(tiered && out.getOutput().contains("TieredCompilation is disabled in this release."))) { 348 throw new RuntimeException(e); 349 } 350 } 351 } 352 353 public static void main(String[] args) throws Exception { 354 355 if (NON_TIERED_ARGUMENTS.length != NON_TIERED_EXPECTED_OUTPUTS.length) { 356 throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs in non-tiered mode of operation does not match."); 357 } 358 359 if (TIERED_ARGUMENTS.length != TIERED_EXPECTED_OUTPUTS.length) { 360 throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs in tiered mode of operation."); 361 } 362 363 // Check if thresholds are scaled properly in non-tiered mode of operation 364 for (int i = 0; i < NON_TIERED_ARGUMENTS.length; i++) { 365 verifyValidOption(NON_TIERED_ARGUMENTS[i], NON_TIERED_EXPECTED_OUTPUTS[i], false); 366 } 367 368 // Check if thresholds are scaled properly in tiered mode of operation 369 for (int i = 0; i < TIERED_ARGUMENTS.length; i++) { 370 verifyValidOption(TIERED_ARGUMENTS[i], TIERED_EXPECTED_OUTPUTS[i], true); 371 } 372 } 373 }