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