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