1 /*
   2  * Copyright (c) 2015, 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 jdk.test.lib.*;
  25 
  26 /*
  27  * @test CheckCheckCICompilerCount
  28  * @bug 8130858
  29  * @summary Check that correct range of values for CICompilerCount are allowed depending on whether tiered is enabled or not
  30  * @library /testlibrary
  31  * @modules java.base/sun.misc
  32  *          java.management
  33  * @run main CheckCICompilerCount
  34  */
  35 
  36 public class CheckCICompilerCount {
  37     private static final String[][] NON_TIERED_ARGUMENTS = {
  38         {
  39             "-XX:-TieredCompilation",
  40             "-XX:+PrintFlagsFinal",
  41             "-XX:CICompilerCount=0",
  42             "-version"
  43         },
  44         {
  45             "-XX:-TieredCompilation",
  46             "-XX:+PrintFlagsFinal",
  47             "-XX:CICompilerCount=1",
  48             "-version"
  49         }
  50     };
  51 
  52     private static final String[][] NON_TIERED_EXPECTED_OUTPUTS = {
  53         {
  54             "CICompilerCount=0 must be at least 1",
  55             "Improperly specified VM option 'CICompilerCount=0'"
  56         },
  57         {
  58             "intx CICompilerCount                          := 1                                   {product}"
  59         }
  60     };
  61 
  62     private static final int[] NON_TIERED_EXIT = {
  63         1,
  64         0
  65     };
  66 
  67     private static final String[][] TIERED_ARGUMENTS = {
  68         {
  69             "-XX:+TieredCompilation",
  70             "-XX:+PrintFlagsFinal",
  71             "-XX:CICompilerCount=1",
  72             "-version"
  73         },
  74         {
  75             "-XX:+TieredCompilation",
  76             "-XX:+PrintFlagsFinal",
  77             "-XX:CICompilerCount=2",
  78             "-version"
  79         }
  80     };
  81 
  82     private static final String[][] TIERED_EXPECTED_OUTPUTS = {
  83         {
  84             "CICompilerCount=1 must be at least 2",
  85             "Improperly specified VM option 'CICompilerCount=1'"
  86         },
  87         {
  88             "intx CICompilerCount                          := 2                                   {product}"
  89         }
  90     };
  91 
  92     private static final int[] TIERED_EXIT = {
  93         1,
  94         0
  95     };
  96 
  97     private static void verifyValidOption(String[] arguments, String[] expected_outputs, int exit, boolean tiered) throws Exception {
  98         ProcessBuilder pb;
  99         OutputAnalyzer out;
 100 
 101         pb = ProcessTools.createJavaProcessBuilder(arguments);
 102         out = new OutputAnalyzer(pb.start());
 103 
 104         try {
 105             out.shouldHaveExitValue(exit);
 106             for (String expected_output : expected_outputs) {
 107                 out.shouldContain(expected_output);
 108             }
 109         } catch (RuntimeException e) {
 110             // Check if tiered compilation is available in this JVM
 111             // Version. Throw exception only if it is available.
 112             if (!(tiered && out.getOutput().contains("TieredCompilation is disabled in this release."))) {
 113                 throw new RuntimeException(e);
 114             }
 115         }
 116     }
 117 
 118     public static void main(String[] args) throws Exception {
 119         if (NON_TIERED_ARGUMENTS.length != NON_TIERED_EXPECTED_OUTPUTS.length || NON_TIERED_ARGUMENTS.length != NON_TIERED_EXIT.length) {
 120             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.");
 121         }
 122 
 123         if (TIERED_ARGUMENTS.length != TIERED_EXPECTED_OUTPUTS.length || TIERED_ARGUMENTS.length != TIERED_EXIT.length) {
 124             throw new RuntimeException("Test is set up incorrectly: length of arguments, expected outputs and exit codes in tiered mode of operation do not match.");
 125         }
 126 
 127         for (int i = 0; i < NON_TIERED_ARGUMENTS.length; i++) {
 128             verifyValidOption(NON_TIERED_ARGUMENTS[i], NON_TIERED_EXPECTED_OUTPUTS[i], NON_TIERED_EXIT[i], false);
 129         }
 130 
 131         for (int i = 0; i < TIERED_ARGUMENTS.length; i++) {
 132             verifyValidOption(TIERED_ARGUMENTS[i], TIERED_EXPECTED_OUTPUTS[i], TIERED_EXIT[i], true);
 133         }
 134     }
 135 }