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