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
  27  * @bug 8132525
  28  * @summary Check that correct range of values for CICompilerCount are allowed depending on whether tiered is enabled or not
  29  * @library /test/lib /
  30  * @modules java.base/jdk.internal.misc
  31  *          java.management
  32  * @run driver compiler.arguments.CheckCICompilerCount
  33  */
  34 
  35 package compiler.arguments;
  36 
  37 import jdk.test.lib.process.OutputAnalyzer;
  38 import jdk.test.lib.process.ProcessTools;
  39 
  40 public class CheckCICompilerCount {
  41     private static final String[][] NON_TIERED_ARGUMENTS = {
  42         {
  43             "-server",
  44             "-XX:-TieredCompilation",
  45             "-XX:+PrintFlagsFinal",
  46             "-XX:CICompilerCount=0",
  47             "-version"
  48         },
  49         {
  50             "-server",
  51             "-XX:-TieredCompilation",
  52             "-XX:+PrintFlagsFinal",
  53             "-XX:CICompilerCount=1",
  54             "-version"
  55         },
  56         {
  57             "-client",
  58             "-XX:-TieredCompilation",
  59             "-XX:+PrintFlagsFinal",
  60             "-XX:CICompilerCount=0",
  61             "-version"
  62         },
  63         {
  64             "-client",
  65             "-XX:-TieredCompilation",
  66             "-XX:+PrintFlagsFinal",
  67             "-XX:CICompilerCount=1",
  68             "-version"
  69         }
  70     };
  71 
  72     private static final String[][] NON_TIERED_EXPECTED_OUTPUTS = {
  73         {
  74             "CICompilerCount (0) must be at least 1",
  75             "Improperly specified VM option 'CICompilerCount=0'"
  76         },
  77         {
  78             "intx CICompilerCount                          = 1                                        {product} {command line}"
  79         },
  80         {
  81             "CICompilerCount (0) must be at least 1",
  82             "Improperly specified VM option 'CICompilerCount=0'"
  83         },
  84         {
  85             "intx CICompilerCount                          = 1                                        {product} {command line}"
  86         }
  87     };
  88 
  89     private static final int[] NON_TIERED_EXIT = {
  90         1,
  91         0,
  92         1,
  93         0
  94     };
  95 
  96     private static final String[][] TIERED_ARGUMENTS = {
  97         {
  98             "-server",
  99             "-XX:+TieredCompilation",
 100             "-XX:+PrintFlagsFinal",
 101             "-XX:CICompilerCount=1",
 102             "-version"
 103         },
 104         {
 105             "-server",
 106             "-XX:+TieredCompilation",
 107             "-XX:+PrintFlagsFinal",
 108             "-XX:CICompilerCount=2",
 109             "-version"
 110         },
 111         {
 112             "-client",
 113             "-XX:+TieredCompilation",
 114             "-XX:+PrintFlagsFinal",
 115             "-XX:CICompilerCount=1",
 116             "-version"
 117         },
 118         {
 119             "-client",
 120             "-XX:+TieredCompilation",
 121             "-XX:+PrintFlagsFinal",
 122             "-XX:CICompilerCount=2",
 123             "-version"
 124         }
 125     };
 126 
 127     private static final String[][] TIERED_EXPECTED_OUTPUTS = {
 128         {
 129             "CICompilerCount (1) must be at least 2",
 130             "Improperly specified VM option 'CICompilerCount=1'"
 131         },
 132         {
 133             "intx CICompilerCount                          = 2                                        {product} {command line, ergonomic}"
 134         },
 135         {
 136             "CICompilerCount (1) must be at least 2",
 137             "Improperly specified VM option 'CICompilerCount=1'"
 138         },
 139         {
 140             "intx CICompilerCount                          = 2                                        {product} {command line, ergonomic}"
 141         }
 142     };
 143 
 144     private static final int[] TIERED_EXIT = {
 145         1,
 146         0,
 147         1,
 148         0
 149     };
 150 
 151     private static void verifyValidOption(String[] arguments, String[] expected_outputs, int exit, boolean tiered) throws Exception {
 152         ProcessBuilder pb;
 153         OutputAnalyzer out;
 154 
 155         pb = ProcessTools.createJavaProcessBuilder(arguments);
 156         out = new OutputAnalyzer(pb.start());
 157 
 158         try {
 159             out.shouldHaveExitValue(exit);
 160             for (String expected_output : expected_outputs) {
 161                 out.shouldContain(expected_output);
 162             }
 163         } catch (RuntimeException e) {
 164             // Check if tiered compilation is available in this JVM
 165             // Version. Throw exception only if it is available.
 166             if (!(tiered && out.getOutput().contains("-XX:+TieredCompilation not supported in this VM"))) {
 167                 throw new RuntimeException(e);
 168             }
 169         }
 170     }
 171 
 172     public static void main(String[] args) throws Exception {
 173         if (NON_TIERED_ARGUMENTS.length != NON_TIERED_EXPECTED_OUTPUTS.length || NON_TIERED_ARGUMENTS.length != NON_TIERED_EXIT.length) {
 174             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.");
 175         }
 176 
 177         if (TIERED_ARGUMENTS.length != TIERED_EXPECTED_OUTPUTS.length || TIERED_ARGUMENTS.length != TIERED_EXIT.length) {
 178             throw new RuntimeException("Test is set up incorrectly: length of arguments, expected outputs and exit codes in tiered mode of operation do not match.");
 179         }
 180 
 181         for (int i = 0; i < NON_TIERED_ARGUMENTS.length; i++) {
 182             verifyValidOption(NON_TIERED_ARGUMENTS[i], NON_TIERED_EXPECTED_OUTPUTS[i], NON_TIERED_EXIT[i], false);
 183         }
 184 
 185         for (int i = 0; i < TIERED_ARGUMENTS.length; i++) {
 186             verifyValidOption(TIERED_ARGUMENTS[i], TIERED_EXPECTED_OUTPUTS[i], TIERED_EXIT[i], true);
 187         }
 188     }
 189 }