1 /*
   2  * Copyright (c) 2014, 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.OutputAnalyzer;
  25 import jdk.test.lib.ProcessTools;
  26 
  27 import java.lang.management.ManagementFactory;
  28 import java.lang.management.RuntimeMXBean;
  29 import java.util.ArrayList;
  30 import java.util.Collections;
  31 import java.util.List;
  32 
  33 /**
  34  * Executes given test in a separate VM with enabled Tiered Compilation for
  35  * CompilationPolicyChoice 2 and 3
  36  */
  37 public class TransitionsTestExecutor {
  38     public static void main(String[] args) throws Throwable {
  39         if (CompilerWhiteBoxTest.skipOnTieredCompilation(false)) {
  40             return;
  41         }
  42         if (args.length != 1) {
  43             throw new Error("TESTBUG: Test name should be specified");
  44         }
  45         executeTestFor(2, args[0]);
  46         executeTestFor(3, args[0]);
  47     }
  48 
  49     private static void executeTestFor(int compilationPolicy, String testName) throws Throwable {
  50         String policy = "-XX:CompilationPolicyChoice=" + compilationPolicy;
  51 
  52         // Get runtime arguments including VM options given to this executor
  53         RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
  54         List<String> vmArgs = runtime.getInputArguments();
  55 
  56         // Construct execution command with compilation policy choice and test name
  57         List<String> args = new ArrayList<>(vmArgs);
  58         Collections.addAll(args, policy, testName);
  59 
  60         OutputAnalyzer out = ProcessTools.executeTestJvm(args.toArray(new String[args.size()]));
  61         int exitCode = out.getExitValue();
  62         if (exitCode != 0) {
  63             throw new Error("Test execution failed with exit code " + exitCode);
  64         }
  65     }
  66 }