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 /* 25 * @test CorrectnessTest 26 * @bug 8038418 27 * @library /testlibrary /testlibrary/whitebox 28 * @compile execution/TypeConflict.java execution/TypeProfile.java 29 * execution/MethodHandleDelegate.java 30 * @build CorrectnessTest 31 * @build OffTest 32 * @run main ClassFileInstaller sun.hotspot.WhiteBox 33 * sun.hotspot.WhiteBox$WhiteBoxPermission 34 * @run main/timeout=1200 OffTest 35 */ 36 37 import com.oracle.java.testlibrary.OutputAnalyzer; 38 import com.oracle.java.testlibrary.ProcessTools; 39 import scenarios.ProfilingType; 40 41 import java.util.Random; 42 43 public class OffTest { 44 private static final String[] OPTIONS = { 45 "-Xbootclasspath/a:.", 46 "-XX:+IgnoreUnrecognizedVMOptions", 47 "-XX:+UnlockExperimentalVMOptions", 48 "-XX:+UnlockDiagnosticVMOptions", 49 "-XX:+WhiteBoxAPI", 50 "-XX:CompileCommand=exclude,execution/*::methodNotToCompile", 51 "-XX:CompileCommand=dontinline,scenarios/Scenario::collectReturnType", 52 "", // -XX:TypeProfileLevel=? 53 "", // -XX:?UseTypeSpeculation 54 CorrectnessTest.class.getName(), 55 "", // ProfilingType.name() 56 }; 57 58 private static final String TYPE_PROFILE_LEVEL = "TypeProfileLevel"; 59 private static final String USE_TYPE_SPECULATION = "UseTypeSpeculation"; 60 private static final int TYPE_PROFILE_LEVEL_LENGTH = 3; 61 private static final int TYPE_PROFILE_LEVEL_BOUND = 3; 62 private static final int DEFAULT_COUNT = 10; 63 private static final int PROFILING_TYPE_INDEX = OPTIONS.length - 1; 64 private static final int TYPE_PROFILE_INDEX = OPTIONS.length - 4; 65 private static final int USE_TYPE_SPECULATION_INDEX = OPTIONS.length - 3; 66 private static final Random RNG; 67 68 static { 69 String str = System.getProperty("seed"); 70 long seed = str != null ? Long.parseLong(str) : new Random().nextLong(); 71 RNG = new Random(seed); 72 System.out.printf("-Dseed=%d%n", seed); 73 } 74 75 public static void main(String[] args) throws Exception { 76 int count = DEFAULT_COUNT; 77 if (args.length > 0) { 78 count = Integer.parseInt(args[0]) ; 79 } 80 for (int i = 0; i < count; ++i) { 81 runTest(); 82 } 83 } 84 85 private static void runTest() throws Exception { 86 String useTypeSpeculation = "-XX:" + (RNG.nextBoolean() ? "+" : "-") + USE_TYPE_SPECULATION; 87 String typeProfileLevel = "-XX:" + TYPE_PROFILE_LEVEL + "=" + randomTypeProfileLevel(); 88 ProfilingType type = randomProfileType(); 89 OPTIONS[TYPE_PROFILE_INDEX] = typeProfileLevel; 90 OPTIONS[USE_TYPE_SPECULATION_INDEX] = useTypeSpeculation; 91 OPTIONS[PROFILING_TYPE_INDEX] = type.name(); 92 ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(/* addTestVmOptions= */ true, OPTIONS); 93 OutputAnalyzer outputAnalyzer = new OutputAnalyzer(processBuilder.start()); 94 outputAnalyzer.shouldHaveExitValue(0); 95 } 96 97 private static ProfilingType randomProfileType() { 98 ProfilingType[] value = ProfilingType.values(); 99 return value[RNG.nextInt(value.length)]; 100 } 101 102 private static String randomTypeProfileLevel() { 103 StringBuilder stringBuilder = new StringBuilder(); 104 for (int i = 0; i < TYPE_PROFILE_LEVEL_LENGTH; ++i) { 105 stringBuilder.append(RNG.nextInt(TYPE_PROFILE_LEVEL_BOUND)); 106 } 107 return stringBuilder.toString(); 108 } 109 }