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