Fri, 11 Apr 2014 18:46:35 +0400
8038418: New tests development for type profiling and speculation
Reviewed-by: roland, iignatyev
Contributed-by: Pavel Punegov <pavel.punegov@oracle.com>
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/compiler/types/correctness/CorrectnessTest.java Fri Apr 11 18:46:35 2014 +0400 1.3 @@ -0,0 +1,159 @@ 1.4 +/* 1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test CorrectnessTest 1.29 + * @bug 8038418 1.30 + * @library /testlibrary /testlibrary/whitebox 1.31 + * @compile execution/TypeConflict.java execution/TypeProfile.java 1.32 + * execution/MethodHandleDelegate.java 1.33 + * @build CorrectnessTest 1.34 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 1.35 + * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions 1.36 + * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 1.37 + * -XX:TypeProfileLevel=222 -XX:+UseTypeSpeculation 1.38 + * -XX:CompileCommand=exclude,execution/*::methodNotToCompile 1.39 + * -XX:CompileCommand=dontinline,scenarios/Scenario::collectReturnType 1.40 + * CorrectnessTest RETURN 1.41 + * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions 1.42 + * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 1.43 + * -XX:TypeProfileLevel=222 -XX:+UseTypeSpeculation 1.44 + * -XX:CompileCommand=exclude,execution/*::methodNotToCompile 1.45 + * -XX:CompileCommand=dontinline,scenarios/Scenario::collectReturnType 1.46 + * CorrectnessTest PARAMETERS 1.47 + * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions 1.48 + * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 1.49 + * -XX:TypeProfileLevel=222 -XX:+UseTypeSpeculation 1.50 + * -XX:CompileCommand=exclude,execution/*::methodNotToCompile 1.51 + * -XX:CompileCommand=dontinline,scenarios/Scenario::collectReturnType 1.52 + * CorrectnessTest ARGUMENTS 1.53 + * @summary Tests correctness of type usage with type profiling and speculations 1.54 + */ 1.55 + 1.56 +import com.oracle.java.testlibrary.Asserts; 1.57 +import com.oracle.java.testlibrary.Platform; 1.58 +import execution.Execution; 1.59 +import execution.MethodHandleDelegate; 1.60 +import execution.TypeConflict; 1.61 +import execution.TypeProfile; 1.62 +import hierarchies.*; 1.63 +import scenarios.*; 1.64 +import sun.hotspot.WhiteBox; 1.65 + 1.66 +import java.lang.reflect.Constructor; 1.67 +import java.lang.reflect.Method; 1.68 +import java.util.ArrayList; 1.69 +import java.util.List; 1.70 +import java.util.function.BiFunction; 1.71 + 1.72 +public class CorrectnessTest { 1.73 + private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 1.74 + 1.75 + public static void main(String[] args) { 1.76 + if (!Platform.isServer()) { 1.77 + System.out.println("ALL TESTS SKIPPED"); 1.78 + } 1.79 + Asserts.assertGTE(args.length, 1); 1.80 + ProfilingType profilingType = ProfilingType.valueOf(args[0]); 1.81 + if (runTests(profilingType)) { 1.82 + System.out.println("ALL TESTS PASSED"); 1.83 + } else { 1.84 + throw new RuntimeException("SOME TESTS FAILED"); 1.85 + } 1.86 + } 1.87 + 1.88 + @SuppressWarnings("unchecked") 1.89 + public static boolean runTests(ProfilingType profilingType) { 1.90 + boolean result = true; 1.91 + 1.92 + List<Execution> executionList = new ArrayList<>(); 1.93 + executionList.add(new TypeConflict()); 1.94 + executionList.add(new TypeProfile()); 1.95 + for (int i = 0, n = executionList.size(); i < n; i++) { 1.96 + executionList.add(new MethodHandleDelegate(executionList.get(i))); 1.97 + } 1.98 + 1.99 + List<TypeHierarchy> hierarchyList = new ArrayList<>(); 1.100 + hierarchyList.add(new DefaultMethodInterface.Hierarchy()); 1.101 + hierarchyList.add(new DefaultMethodInterface2.Hierarchy()); 1.102 + hierarchyList.add(new Linear.Hierarchy()); 1.103 + hierarchyList.add(new Linear2.Hierarchy()); 1.104 + hierarchyList.add(new OneRank.Hierarchy()); 1.105 + for (int i = 0, n = hierarchyList.size(); i < n; i++) { 1.106 + hierarchyList.add(new NullableType(hierarchyList.get(i))); 1.107 + } 1.108 + 1.109 + List<BiFunction<ProfilingType, TypeHierarchy, Scenario<?, ?>>> testCasesConstructors 1.110 + = new ArrayList<>(); 1.111 + testCasesConstructors.add(ArrayCopy::new); 1.112 + testCasesConstructors.add(ArrayReferenceStore::new); 1.113 + testCasesConstructors.add(ClassIdentity::new); 1.114 + testCasesConstructors.add(ClassInstanceOf::new); 1.115 + testCasesConstructors.add(ClassIsInstance::new); 1.116 + testCasesConstructors.add(ReceiverAtInvokes::new); 1.117 + testCasesConstructors.add(CheckCast::new); 1.118 + 1.119 + for (TypeHierarchy hierarchy : hierarchyList) { 1.120 + for (BiFunction<ProfilingType, TypeHierarchy, Scenario<?, ?>> constructor : testCasesConstructors) { 1.121 + for (Execution execution : executionList) { 1.122 + Scenario<?, ?> scenario = constructor.apply(profilingType, hierarchy); 1.123 + if (scenario.isApplicable()) { 1.124 + result &= executeTest(hierarchy, execution, scenario); 1.125 + } 1.126 + } 1.127 + } 1.128 + } 1.129 + return result; 1.130 + } 1.131 + 1.132 + /** 1.133 + * Executes test case 1.134 + * 1.135 + * @param hierarchy type hierarchy for the test 1.136 + * @param execution execution scenario 1.137 + * @param scenario test scenario executed with given Execution 1.138 + */ 1.139 + private static boolean executeTest(TypeHierarchy hierarchy, Execution execution, Scenario<?, ?> scenario) { 1.140 + boolean testCaseResult = false; 1.141 + String testName = hierarchy.getClass().getName() + " :: " + scenario.getName() + " @ " + execution.getName(); 1.142 + clearAllMethodsState(scenario.getClass()); 1.143 + try { 1.144 + execution.execute(scenario); 1.145 + testCaseResult = true; 1.146 + } catch (Exception e) { 1.147 + System.err.println(testName + " failed with exception " + e); 1.148 + e.printStackTrace(); 1.149 + } 1.150 + System.out.println((testCaseResult ? "PASSED: " : "FAILED: ") + testName); 1.151 + return testCaseResult; 1.152 + } 1.153 + 1.154 + private static void clearAllMethodsState(Class aClass) { 1.155 + while (aClass != null) { 1.156 + for (Method m : aClass.getDeclaredMethods()) { 1.157 + WHITE_BOX.clearMethodState(m); 1.158 + } 1.159 + aClass = aClass.getSuperclass(); 1.160 + } 1.161 + } 1.162 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/compiler/types/correctness/OffTest.java Fri Apr 11 18:46:35 2014 +0400 2.3 @@ -0,0 +1,108 @@ 2.4 +/* 2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test CorrectnessTest 2.29 + * @bug 8038418 2.30 + * @library /testlibrary /testlibrary/whitebox 2.31 + * @compile execution/TypeConflict.java execution/TypeProfile.java 2.32 + * execution/MethodHandleDelegate.java 2.33 + * @build CorrectnessTest 2.34 + * @build OffTest 2.35 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 2.36 + * @run main/timeout=1200 OffTest 2.37 + */ 2.38 + 2.39 +import com.oracle.java.testlibrary.OutputAnalyzer; 2.40 +import com.oracle.java.testlibrary.ProcessTools; 2.41 +import scenarios.ProfilingType; 2.42 + 2.43 +import java.util.Random; 2.44 + 2.45 +public class OffTest { 2.46 + private static final String[] OPTIONS = { 2.47 + "-Xbootclasspath/a:.", 2.48 + "-XX:+IgnoreUnrecognizedVMOptions", 2.49 + "-XX:+UnlockExperimentalVMOptions", 2.50 + "-XX:+UnlockDiagnosticVMOptions", 2.51 + "-XX:+WhiteBoxAPI", 2.52 + "-XX:CompileCommand=exclude,execution/*::methodNotToCompile", 2.53 + "-XX:CompileCommand=dontinline,scenarios/Scenario::collectReturnType", 2.54 + "", // -XX:TypeProfileLevel=? 2.55 + "", // -XX:?UseTypeSpeculation 2.56 + CorrectnessTest.class.getName(), 2.57 + "", // ProfilingType.name() 2.58 + }; 2.59 + 2.60 + private static final String TYPE_PROFILE_LEVEL = "TypeProfileLevel"; 2.61 + private static final String USE_TYPE_SPECULATION = "UseTypeSpeculation"; 2.62 + private static final int TYPE_PROFILE_LEVEL_LENGTH = 3; 2.63 + private static final int TYPE_PROFILE_LEVEL_BOUND = 3; 2.64 + private static final int DEFAULT_COUNT = 10; 2.65 + private static final int PROFILING_TYPE_INDEX = OPTIONS.length - 1; 2.66 + private static final int TYPE_PROFILE_INDEX = OPTIONS.length - 4; 2.67 + private static final int USE_TYPE_SPECULATION_INDEX = OPTIONS.length - 3; 2.68 + private static final Random RNG; 2.69 + 2.70 + static { 2.71 + String str = System.getProperty("seed"); 2.72 + long seed = str != null ? Long.parseLong(str) : new Random().nextLong(); 2.73 + RNG = new Random(seed); 2.74 + System.out.printf("-Dseed=%d%n", seed); 2.75 + } 2.76 + 2.77 + public static void main(String[] args) throws Exception { 2.78 + int count = DEFAULT_COUNT; 2.79 + if (args.length > 0) { 2.80 + count = Integer.parseInt(args[0]) ; 2.81 + } 2.82 + for (int i = 0; i < count; ++i) { 2.83 + runTest(); 2.84 + } 2.85 + } 2.86 + 2.87 + private static void runTest() throws Exception { 2.88 + String useTypeSpeculation = "-XX:" + (RNG.nextBoolean() ? "+" : "-") + USE_TYPE_SPECULATION; 2.89 + String typeProfileLevel = "-XX:" + TYPE_PROFILE_LEVEL + "=" + randomTypeProfileLevel(); 2.90 + ProfilingType type = randomProfileType(); 2.91 + OPTIONS[TYPE_PROFILE_INDEX] = typeProfileLevel; 2.92 + OPTIONS[USE_TYPE_SPECULATION_INDEX] = useTypeSpeculation; 2.93 + OPTIONS[PROFILING_TYPE_INDEX] = type.name(); 2.94 + ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(/* addTestVmOptions= */ true, OPTIONS); 2.95 + OutputAnalyzer outputAnalyzer = new OutputAnalyzer(processBuilder.start()); 2.96 + outputAnalyzer.shouldHaveExitValue(0); 2.97 + } 2.98 + 2.99 + private static ProfilingType randomProfileType() { 2.100 + ProfilingType[] value = ProfilingType.values(); 2.101 + return value[RNG.nextInt(value.length)]; 2.102 + } 2.103 + 2.104 + private static String randomTypeProfileLevel() { 2.105 + StringBuilder stringBuilder = new StringBuilder(); 2.106 + for (int i = 0; i < TYPE_PROFILE_LEVEL_LENGTH; ++i) { 2.107 + stringBuilder.append(RNG.nextInt(TYPE_PROFILE_LEVEL_BOUND)); 2.108 + } 2.109 + return stringBuilder.toString(); 2.110 + } 2.111 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/compiler/types/correctness/execution/Execution.java Fri Apr 11 18:46:35 2014 +0400 3.3 @@ -0,0 +1,45 @@ 3.4 +/* 3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 +package execution; 3.27 + 3.28 +import hierarchies.TypeHierarchy; 3.29 +import scenarios.Scenario; 3.30 + 3.31 +/** 3.32 + * Execution scenario represents test methods execution type. 3.33 + * @param <T> parameter type 3.34 + * @param <R> result Type 3.35 + */ 3.36 +public interface Execution<T extends TypeHierarchy.I, R> { 3.37 + /** 3.38 + * Executes the test code of the given scenario 3.39 + * See {@link scenarios.Scenario#run(T)} 3.40 + * 3.41 + * @param scenario test scenario 3.42 + */ 3.43 + void execute(Scenario<T, R> scenario); 3.44 + 3.45 + default String getName() { 3.46 + return this.getClass().getName(); 3.47 + } 3.48 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/compiler/types/correctness/execution/MethodHandleDelegate.java Fri Apr 11 18:46:35 2014 +0400 4.3 @@ -0,0 +1,105 @@ 4.4 +/* 4.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +package execution; 4.28 + 4.29 +import hierarchies.TypeHierarchy; 4.30 +import scenarios.Scenario; 4.31 + 4.32 +import java.lang.invoke.MethodHandle; 4.33 +import java.lang.invoke.MethodHandles; 4.34 +import java.lang.invoke.MethodType; 4.35 + 4.36 +/** 4.37 + * Executes test scenario using {@link MethodHandle#invoke(Object...)}. 4.38 + * Delegates execution to the given {@link Execution} by creating 4.39 + * new test scenario, see {@link Scenario} 4.40 + */ 4.41 +public class MethodHandleDelegate<T extends TypeHierarchy.I, R> implements Execution<T, R> { 4.42 + private final Execution<T, R> delegate; 4.43 + 4.44 + public MethodHandleDelegate(Execution<T, R> delegate) { 4.45 + this.delegate = delegate; 4.46 + } 4.47 + 4.48 + @Override 4.49 + public void execute(Scenario<T, R> scenario) { 4.50 + delegate.execute(new MHScenario<T, R>(scenario)); 4.51 + } 4.52 + 4.53 + @Override 4.54 + public String getName() { 4.55 + return "MethodHandleDelegate # " + delegate.getName(); 4.56 + } 4.57 + 4.58 + private static class MHScenario<T extends TypeHierarchy.I, R> extends Scenario<T, R> { 4.59 + private final Scenario<T, R> scenario; 4.60 + private static final MethodHandle METHOD_HANDLE_RUN; 4.61 + 4.62 + static { 4.63 + MethodHandles.Lookup lookup = MethodHandles.lookup(); 4.64 + MethodType methodType = MethodType.methodType(Object.class, TypeHierarchy.I.class); 4.65 + 4.66 + try { 4.67 + METHOD_HANDLE_RUN = lookup.findVirtual(Scenario.class, "run", methodType); 4.68 + } catch (NoSuchMethodException | IllegalAccessException e) { 4.69 + System.err.println("Failed to get target method run() with " + e); 4.70 + e.printStackTrace(); 4.71 + throw new RuntimeException(e); 4.72 + } 4.73 + } 4.74 + 4.75 + /** 4.76 + * Constructor 4.77 + * 4.78 + * @param scenario test scenario to be executed 4.79 + */ 4.80 + private MHScenario(Scenario<T, R> scenario) { 4.81 + super("MethodHandle::" + scenario.getName(), scenario.profilingType, scenario.hierarchy); 4.82 + this.scenario = scenario; 4.83 + } 4.84 + 4.85 + /** 4.86 + * Runs {@link Scenario#run(T)} with {@link MethodHandle#invoke(Object...)} 4.87 + * 4.88 + * @param t subject of the test 4.89 + * @return result of the underlying {@link Scenario#run(T)} invocation 4.90 + */ 4.91 + @SuppressWarnings("unchecked") 4.92 + @Override 4.93 + public R run(T t) { 4.94 + try { 4.95 + return (R) METHOD_HANDLE_RUN.invoke(scenario, t); 4.96 + } catch (Throwable thr) { 4.97 + System.err.println(scenario.getName() 4.98 + + " failed to invoke target method run() with " + thr); 4.99 + throw new RuntimeException("Invocation failed", thr); 4.100 + } 4.101 + } 4.102 + 4.103 + @Override 4.104 + public void check(R r, T t) { 4.105 + scenario.check(r, t); 4.106 + } 4.107 + } 4.108 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/compiler/types/correctness/execution/TypeConflict.java Fri Apr 11 18:46:35 2014 +0400 5.3 @@ -0,0 +1,74 @@ 5.4 +/* 5.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +package execution; 5.28 + 5.29 +import hierarchies.TypeHierarchy; 5.30 +import scenarios.Scenario; 5.31 + 5.32 +/** 5.33 + * Type profiling conflict execution scenario. The main goal is 5.34 + * to make compiler profile and compile methods with different types. 5.35 + * Scenario tests guards by passing conflicting types (incompatible 5.36 + * for the profiled data). 5.37 + */ 5.38 +public class TypeConflict<T extends TypeHierarchy.I, R> implements Execution<T, R> { 5.39 + /** Test methods execution number to make profile */ 5.40 + private final static int POLLUTION_THRESHOLD = 5000; 5.41 + /** Test methods execution number to make it profiled and compiled*/ 5.42 + private final static int PROFILE_THRESHOLD = 20000; 5.43 + 5.44 + @Override 5.45 + public void execute(Scenario<T, R> scenario) { 5.46 + T base = scenario.getProfiled(); 5.47 + T incompatible = scenario.getConflict(); 5.48 + 5.49 + // pollute profile by passing different types 5.50 + R baseResult = null; 5.51 + R incResult = null; 5.52 + for (int i = 0; i < POLLUTION_THRESHOLD; i++) { 5.53 + baseResult = methodNotToCompile(scenario, base); 5.54 + incResult = methodNotToCompile(scenario, incompatible); 5.55 + } 5.56 + scenario.check(baseResult, base); 5.57 + scenario.check(incResult, incompatible); 5.58 + 5.59 + // profile and compile 5.60 + R result = null; 5.61 + for (int i = 0; i < PROFILE_THRESHOLD; i++) { 5.62 + result = methodNotToCompile(scenario, base); 5.63 + } 5.64 + scenario.check(result, base); 5.65 + 5.66 + // pass another type to make guard work and recompile 5.67 + for (int i = 0; i < PROFILE_THRESHOLD; i++) { 5.68 + result = methodNotToCompile(scenario, incompatible); 5.69 + } 5.70 + scenario.check(result, incompatible); 5.71 + } 5.72 + 5.73 + private R methodNotToCompile(Scenario<T, R> scenario, T t) { 5.74 + return scenario.run(t); 5.75 + } 5.76 +} 5.77 +
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/compiler/types/correctness/execution/TypeProfile.java Fri Apr 11 18:46:35 2014 +0400 6.3 @@ -0,0 +1,59 @@ 6.4 +/* 6.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +package execution; 6.28 + 6.29 +import hierarchies.TypeHierarchy; 6.30 +import scenarios.Scenario; 6.31 + 6.32 +/** 6.33 + * Profile type execution scenario. Executes tester method 6.34 + * in a loop without any manipulation with types or instances. 6.35 + */ 6.36 +public class TypeProfile<T extends TypeHierarchy.I, R> implements Execution<T, R> { 6.37 + /** Number of test method execution to make it profiled and compiled */ 6.38 + private final static int PROFILE_THRESHOLD = 100000; 6.39 + 6.40 + /** 6.41 + * Makes scenario code be profiled and compiled 6.42 + * @param scenario Test scenario 6.43 + */ 6.44 + @Override 6.45 + public void execute(Scenario<T, R> scenario) { 6.46 + R result = null; 6.47 + T prof = scenario.getProfiled(); 6.48 + T confl = scenario.getConflict(); 6.49 + 6.50 + for (int i = 0; i < PROFILE_THRESHOLD; i++) { 6.51 + result = methodNotToCompile(scenario, prof); 6.52 + } 6.53 + scenario.check(result, prof); 6.54 + 6.55 + result = methodNotToCompile(scenario, confl); 6.56 + scenario.check(result, confl); 6.57 + } 6.58 + 6.59 + protected R methodNotToCompile(Scenario<T, R> scenario, T t) { 6.60 + return scenario.run(t); 6.61 + } 6.62 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/compiler/types/correctness/hierarchies/DefaultMethodInterface.java Fri Apr 11 18:46:35 2014 +0400 7.3 @@ -0,0 +1,54 @@ 7.4 +/* 7.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. 7.11 + * 7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.15 + * version 2 for more details (a copy is included in the LICENSE file that 7.16 + * accompanied this code). 7.17 + * 7.18 + * You should have received a copy of the GNU General Public License version 7.19 + * 2 along with this work; if not, write to the Free Software Foundation, 7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.21 + * 7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.23 + * or visit www.oracle.com if you need additional information or have any 7.24 + * questions. 7.25 + */ 7.26 + 7.27 +package hierarchies; 7.28 + 7.29 +public class DefaultMethodInterface { 7.30 + private DefaultMethodInterface() { 7.31 + } 7.32 + 7.33 + public static class Hierarchy 7.34 + extends TypeHierarchy<DefaultMethodInterface.A, DefaultMethodInterface.B> { 7.35 + public Hierarchy() { 7.36 + super(new DefaultMethodInterface.A(), new DefaultMethodInterface.B(), 7.37 + DefaultMethodInterface.A.class, DefaultMethodInterface.B.class); 7.38 + } 7.39 + } 7.40 + 7.41 + public static interface I2 extends TypeHierarchy.I { 7.42 + default int m() { 7.43 + return TypeHierarchy.ANSWER; 7.44 + } 7.45 + } 7.46 + 7.47 + public static class A implements I2 { 7.48 + // use default method from I2 7.49 + } 7.50 + 7.51 + public static class B extends A { 7.52 + @Override 7.53 + public int m() { 7.54 + return TypeHierarchy.YEAR; 7.55 + } 7.56 + } 7.57 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/compiler/types/correctness/hierarchies/DefaultMethodInterface2.java Fri Apr 11 18:46:35 2014 +0400 8.3 @@ -0,0 +1,47 @@ 8.4 +/* 8.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. 8.11 + * 8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.15 + * version 2 for more details (a copy is included in the LICENSE file that 8.16 + * accompanied this code). 8.17 + * 8.18 + * You should have received a copy of the GNU General Public License version 8.19 + * 2 along with this work; if not, write to the Free Software Foundation, 8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.21 + * 8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.23 + * or visit www.oracle.com if you need additional information or have any 8.24 + * questions. 8.25 + */ 8.26 + 8.27 +package hierarchies; 8.28 + 8.29 +public class DefaultMethodInterface2 { 8.30 + private DefaultMethodInterface2() { 8.31 + } 8.32 + 8.33 + public static class Hierarchy 8.34 + extends TypeHierarchy<TypeHierarchy.A, DefaultMethodInterface2.B> { 8.35 + public Hierarchy() { 8.36 + super(new TypeHierarchy.A(), new DefaultMethodInterface2.B(), 8.37 + TypeHierarchy.A.class, DefaultMethodInterface2.B.class); 8.38 + } 8.39 + } 8.40 + 8.41 + public static interface I2 extends TypeHierarchy.I { 8.42 + default int m() { 8.43 + return TypeHierarchy.ANSWER; 8.44 + } 8.45 + } 8.46 + 8.47 + public static class B implements I2 { 8.48 + // default method I2.m() 8.49 + } 8.50 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/compiler/types/correctness/hierarchies/Linear.java Fri Apr 11 18:46:35 2014 +0400 9.3 @@ -0,0 +1,43 @@ 9.4 +/* 9.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.7 + * 9.8 + * This code is free software; you can redistribute it and/or modify it 9.9 + * under the terms of the GNU General Public License version 2 only, as 9.10 + * published by the Free Software Foundation. 9.11 + * 9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9.15 + * version 2 for more details (a copy is included in the LICENSE file that 9.16 + * accompanied this code). 9.17 + * 9.18 + * You should have received a copy of the GNU General Public License version 9.19 + * 2 along with this work; if not, write to the Free Software Foundation, 9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 9.21 + * 9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 9.23 + * or visit www.oracle.com if you need additional information or have any 9.24 + * questions. 9.25 + */ 9.26 + 9.27 +package hierarchies; 9.28 + 9.29 +public class Linear { 9.30 + private Linear() { 9.31 + } 9.32 + 9.33 + public static class Hierarchy extends TypeHierarchy<TypeHierarchy.A, Linear.B> { 9.34 + public Hierarchy() { 9.35 + super(new TypeHierarchy.A(), new Linear.B(), 9.36 + TypeHierarchy.A.class, Linear.B.class); 9.37 + } 9.38 + } 9.39 + 9.40 + public static class B extends TypeHierarchy.A { 9.41 + @Override 9.42 + public int m() { 9.43 + return TypeHierarchy.YEAR; 9.44 + } 9.45 + } 9.46 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/compiler/types/correctness/hierarchies/Linear2.java Fri Apr 11 18:46:35 2014 +0400 10.3 @@ -0,0 +1,47 @@ 10.4 +/* 10.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.7 + * 10.8 + * This code is free software; you can redistribute it and/or modify it 10.9 + * under the terms of the GNU General Public License version 2 only, as 10.10 + * published by the Free Software Foundation. 10.11 + * 10.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 10.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10.15 + * version 2 for more details (a copy is included in the LICENSE file that 10.16 + * accompanied this code). 10.17 + * 10.18 + * You should have received a copy of the GNU General Public License version 10.19 + * 2 along with this work; if not, write to the Free Software Foundation, 10.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.21 + * 10.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 10.23 + * or visit www.oracle.com if you need additional information or have any 10.24 + * questions. 10.25 + */ 10.26 + 10.27 +package hierarchies; 10.28 + 10.29 +public class Linear2 { 10.30 + private Linear2() { 10.31 + } 10.32 + 10.33 + public static class Hierarchy extends TypeHierarchy<TypeHierarchy.A, Linear2.B> { 10.34 + public Hierarchy() { 10.35 + super(new A(), new Linear2.B(), 10.36 + A.class, Linear2.B.class); 10.37 + } 10.38 + } 10.39 + 10.40 + public static interface I2 { 10.41 + int m(); 10.42 + } 10.43 + 10.44 + public static class B extends TypeHierarchy.A implements Linear2.I2 { 10.45 + @Override 10.46 + public int m() { 10.47 + return TypeHierarchy.YEAR; 10.48 + } 10.49 + } 10.50 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/compiler/types/correctness/hierarchies/NullableType.java Fri Apr 11 18:46:35 2014 +0400 11.3 @@ -0,0 +1,33 @@ 11.4 +/* 11.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. 11.11 + * 11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.15 + * version 2 for more details (a copy is included in the LICENSE file that 11.16 + * accompanied this code). 11.17 + * 11.18 + * You should have received a copy of the GNU General Public License version 11.19 + * 2 along with this work; if not, write to the Free Software Foundation, 11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.21 + * 11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.23 + * or visit www.oracle.com if you need additional information or have any 11.24 + * questions. 11.25 + */ 11.26 + 11.27 +package hierarchies; 11.28 + 11.29 +public class NullableType<M extends TypeHierarchy.I, N extends TypeHierarchy.I> 11.30 + extends TypeHierarchy<M, N> { 11.31 + 11.32 + public NullableType(TypeHierarchy<M, N> delegate) { 11.33 + super(delegate.getM(), null, 11.34 + delegate.getClassM(), delegate.getClassN()); 11.35 + } 11.36 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/compiler/types/correctness/hierarchies/OneRank.java Fri Apr 11 18:46:35 2014 +0400 12.3 @@ -0,0 +1,44 @@ 12.4 +/* 12.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.23 + * or visit www.oracle.com if you need additional information or have any 12.24 + * questions. 12.25 + */ 12.26 + 12.27 +package hierarchies; 12.28 + 12.29 +public class OneRank { 12.30 + private OneRank() { 12.31 + } 12.32 + 12.33 + public static class Hierarchy extends TypeHierarchy<TypeHierarchy.A, OneRank.B> { 12.34 + public Hierarchy() { 12.35 + super(new TypeHierarchy.A(), new OneRank.B(), 12.36 + TypeHierarchy.A.class, OneRank.B.class); 12.37 + } 12.38 + } 12.39 + 12.40 + public static class B implements TypeHierarchy.I { 12.41 + @Override 12.42 + public int m() { 12.43 + return TypeHierarchy.YEAR; 12.44 + } 12.45 + } 12.46 + 12.47 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/compiler/types/correctness/hierarchies/TypeHierarchy.java Fri Apr 11 18:46:35 2014 +0400 13.3 @@ -0,0 +1,73 @@ 13.4 +/* 13.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. 13.11 + * 13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.15 + * version 2 for more details (a copy is included in the LICENSE file that 13.16 + * accompanied this code). 13.17 + * 13.18 + * You should have received a copy of the GNU General Public License version 13.19 + * 2 along with this work; if not, write to the Free Software Foundation, 13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.21 + * 13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.23 + * or visit www.oracle.com if you need additional information or have any 13.24 + * questions. 13.25 + */ 13.26 + 13.27 +package hierarchies; 13.28 + 13.29 +/** 13.30 + * Type hierarchy contains classes the type profiling and speculation are tested with 13.31 + */ 13.32 +public abstract class TypeHierarchy<M extends TypeHierarchy.I, N extends TypeHierarchy.I> { 13.33 + // Magic numbers 13.34 + public static final int ANSWER = 42; 13.35 + public static final int TEMP = 451; 13.36 + public static final int YEAR = 1984; 13.37 + 13.38 + private final M m; 13.39 + private final N n; 13.40 + private final Class<M> classM; 13.41 + private final Class<N> classN; 13.42 + 13.43 + protected TypeHierarchy(M m, N n, Class<M> classM, Class<N> classN) { 13.44 + this.m = m; 13.45 + this.n = n; 13.46 + this.classM = classM; 13.47 + this.classN = classN; 13.48 + } 13.49 + 13.50 + public final M getM() { 13.51 + return m; 13.52 + } 13.53 + 13.54 + public final N getN() { 13.55 + return n; 13.56 + } 13.57 + 13.58 + public final Class<M> getClassM() { 13.59 + return classM; 13.60 + } 13.61 + 13.62 + public final Class<N> getClassN() { 13.63 + return classN; 13.64 + } 13.65 + 13.66 + public interface I { 13.67 + int m(); 13.68 + } 13.69 + 13.70 + public static class A implements I { 13.71 + @Override 13.72 + public int m() { 13.73 + return TypeHierarchy.ANSWER; 13.74 + } 13.75 + } 13.76 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/compiler/types/correctness/scenarios/ArrayCopy.java Fri Apr 11 18:46:35 2014 +0400 14.3 @@ -0,0 +1,63 @@ 14.4 +/* 14.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +package scenarios; 14.28 + 14.29 +import hierarchies.TypeHierarchy; 14.30 + 14.31 +import java.util.Arrays; 14.32 + 14.33 +/** 14.34 + * Tests System.arraycopy() 14.35 + */ 14.36 +public class ArrayCopy extends ArrayScenario { 14.37 + public ArrayCopy(ProfilingType profilingType, 14.38 + TypeHierarchy<? extends TypeHierarchy.I, ? extends TypeHierarchy.I> hierarchy) { 14.39 + super("ArrayCopy", profilingType, hierarchy); 14.40 + } 14.41 + 14.42 + /** 14.43 + * @param obj is used to fill arrays 14.44 + * @return the same obj 14.45 + */ 14.46 + @Override 14.47 + public TypeHierarchy.I run(TypeHierarchy.I obj) { 14.48 + switch (profilingType) { 14.49 + case RETURN: 14.50 + TypeHierarchy.I t = collectReturnType(obj); 14.51 + Arrays.fill(array, t); 14.52 + System.arraycopy(array, 0, matrix[0], 0, array.length); 14.53 + return array[0]; 14.54 + case ARGUMENTS: 14.55 + field = obj; 14.56 + Arrays.fill(array, field); 14.57 + System.arraycopy(array, 0, matrix[0], 0, array.length); 14.58 + return array[0]; 14.59 + case PARAMETERS: 14.60 + Arrays.fill(array, obj); 14.61 + System.arraycopy(array, 0, matrix[0], 0, array.length); 14.62 + return array[0]; 14.63 + } 14.64 + throw new RuntimeException("Should not reach here"); 14.65 + } 14.66 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/compiler/types/correctness/scenarios/ArrayReferenceStore.java Fri Apr 11 18:46:35 2014 +0400 15.3 @@ -0,0 +1,63 @@ 15.4 +/* 15.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 + 15.27 +package scenarios; 15.28 + 15.29 +import hierarchies.TypeHierarchy; 15.30 + 15.31 +import java.util.Arrays; 15.32 + 15.33 +/** 15.34 + * Tests aastore bytecode 15.35 + */ 15.36 +public class ArrayReferenceStore extends ArrayScenario { 15.37 + public ArrayReferenceStore(ProfilingType profilingType, 15.38 + TypeHierarchy<? extends TypeHierarchy.I, ? extends TypeHierarchy.I> hierarchy) { 15.39 + super("ArrayReferenceStore", profilingType, hierarchy); 15.40 + } 15.41 + 15.42 + /** 15.43 + * @param obj is used to fill arrays 15.44 + * @return obj 15.45 + */ 15.46 + @Override 15.47 + public TypeHierarchy.I run(TypeHierarchy.I obj) { 15.48 + switch (profilingType) { 15.49 + case RETURN: 15.50 + TypeHierarchy.I t = collectReturnType(obj); 15.51 + Arrays.fill(array, t); 15.52 + matrix[0] = array; 15.53 + return matrix[0][0]; 15.54 + case ARGUMENTS: 15.55 + field = obj; 15.56 + Arrays.fill(array, field); 15.57 + matrix[0] = array; 15.58 + return matrix[0][0]; 15.59 + case PARAMETERS: 15.60 + Arrays.fill(array, obj); 15.61 + matrix[0] = array; 15.62 + return matrix[0][0]; 15.63 + } 15.64 + throw new RuntimeException("Should not reach here"); 15.65 + } 15.66 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/compiler/types/correctness/scenarios/ArrayScenario.java Fri Apr 11 18:46:35 2014 +0400 16.3 @@ -0,0 +1,68 @@ 16.4 +/* 16.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 + 16.27 +package scenarios; 16.28 + 16.29 +import com.oracle.java.testlibrary.Asserts; 16.30 +import hierarchies.TypeHierarchy; 16.31 + 16.32 +import java.lang.reflect.Array; 16.33 +import java.util.Arrays; 16.34 + 16.35 +/** 16.36 + * Base class for array scenarios 16.37 + */ 16.38 +public abstract class ArrayScenario extends Scenario<TypeHierarchy.I, TypeHierarchy.I> { 16.39 + protected final TypeHierarchy.I[] array; 16.40 + protected final TypeHierarchy.I[][] matrix; 16.41 + 16.42 + protected ArrayScenario(String name, ProfilingType profilingType, 16.43 + TypeHierarchy<? extends TypeHierarchy.I, ? extends TypeHierarchy.I> hierarchy) { 16.44 + super(name, profilingType, hierarchy); 16.45 + final int x = 20; 16.46 + final int y = 10; 16.47 + 16.48 + TypeHierarchy.I prof = hierarchy.getM(); 16.49 + TypeHierarchy.I confl = hierarchy.getN(); 16.50 + 16.51 + this.array = (TypeHierarchy.I[]) Array.newInstance(hierarchy.getClassM(), y); 16.52 + Arrays.fill(array, prof); 16.53 + 16.54 + this.matrix = (TypeHierarchy.I[][]) Array.newInstance(hierarchy.getClassM(), x, y); 16.55 + for (int i = 0; i < x; i++) { 16.56 + this.matrix[i] = this.array; 16.57 + } 16.58 + 16.59 + Asserts.assertEquals(array.length, matrix[0].length, "Invariant"); 16.60 + } 16.61 + 16.62 + @Override 16.63 + public boolean isApplicable() { 16.64 + return hierarchy.getClassM().isAssignableFrom(hierarchy.getClassN()); 16.65 + } 16.66 + 16.67 + @Override 16.68 + public void check(TypeHierarchy.I res, TypeHierarchy.I orig) { 16.69 + Asserts.assertEquals(res, orig, "Check failed"); 16.70 + } 16.71 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/compiler/types/correctness/scenarios/CheckCast.java Fri Apr 11 18:46:35 2014 +0400 17.3 @@ -0,0 +1,77 @@ 17.4 +/* 17.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.7 + * 17.8 + * This code is free software; you can redistribute it and/or modify it 17.9 + * under the terms of the GNU General Public License version 2 only, as 17.10 + * published by the Free Software Foundation. 17.11 + * 17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.15 + * version 2 for more details (a copy is included in the LICENSE file that 17.16 + * accompanied this code). 17.17 + * 17.18 + * You should have received a copy of the GNU General Public License version 17.19 + * 2 along with this work; if not, write to the Free Software Foundation, 17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.21 + * 17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 17.23 + * or visit www.oracle.com if you need additional information or have any 17.24 + * questions. 17.25 + */ 17.26 + 17.27 +package scenarios; 17.28 + 17.29 +import com.oracle.java.testlibrary.Asserts; 17.30 +import hierarchies.TypeHierarchy; 17.31 + 17.32 +import java.util.Objects; 17.33 + 17.34 +/** 17.35 + * Checkcast scenario 17.36 + * @param <T> profiling parameter 17.37 + */ 17.38 +public class CheckCast<T extends TypeHierarchy.I> extends Scenario<T, Integer> { 17.39 + public CheckCast(ProfilingType profilingType, TypeHierarchy<? extends T, ? extends T> hierarchy) { 17.40 + super("CheckCast", profilingType, hierarchy); 17.41 + } 17.42 + 17.43 + /** 17.44 + * Returns type profiling. 17.45 + * @param obj is a profiled parameter for the test 17.46 + * @return parameter casted to the type R 17.47 + */ 17.48 + @Override 17.49 + public Integer run(T obj) { 17.50 + switch (profilingType) { 17.51 + case RETURN: 17.52 + T t = collectReturnType(obj); 17.53 + if (t != null) { 17.54 + return t.m(); 17.55 + } 17.56 + return null; 17.57 + case ARGUMENTS: 17.58 + field = obj; 17.59 + if (field != null) { 17.60 + return field.m(); 17.61 + } 17.62 + return null; 17.63 + case PARAMETERS: 17.64 + if (obj != null) { 17.65 + return obj.m(); 17.66 + } 17.67 + return null; 17.68 + } 17.69 + throw new RuntimeException("Should not reach here"); 17.70 + } 17.71 + 17.72 + @Override 17.73 + public void check(Integer result, T orig) { 17.74 + if (result != null || orig != null) { 17.75 + Objects.requireNonNull(result); 17.76 + Objects.requireNonNull(orig); 17.77 + Asserts.assertEquals(result, orig.m(), "Results mismatch"); 17.78 + } 17.79 + } 17.80 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/compiler/types/correctness/scenarios/ClassIdentity.java Fri Apr 11 18:46:35 2014 +0400 18.3 @@ -0,0 +1,80 @@ 18.4 +/* 18.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.7 + * 18.8 + * This code is free software; you can redistribute it and/or modify it 18.9 + * under the terms of the GNU General Public License version 2 only, as 18.10 + * published by the Free Software Foundation. 18.11 + * 18.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 18.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18.15 + * version 2 for more details (a copy is included in the LICENSE file that 18.16 + * accompanied this code). 18.17 + * 18.18 + * You should have received a copy of the GNU General Public License version 18.19 + * 2 along with this work; if not, write to the Free Software Foundation, 18.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18.21 + * 18.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 18.23 + * or visit www.oracle.com if you need additional information or have any 18.24 + * questions. 18.25 + */ 18.26 + 18.27 +package scenarios; 18.28 + 18.29 +import com.oracle.java.testlibrary.Asserts; 18.30 +import hierarchies.TypeHierarchy; 18.31 + 18.32 +/** 18.33 + * Tests pattern: if (a.getClass() == D.class) 18.34 + */ 18.35 +public class ClassIdentity<T extends TypeHierarchy.I> extends Scenario<T, Integer> { 18.36 + public ClassIdentity(ProfilingType profilingType, 18.37 + TypeHierarchy<? extends T, ? extends T> hierarchy) { 18.38 + super("ClassIdentity", profilingType, hierarchy); 18.39 + } 18.40 + 18.41 + @Override 18.42 + public boolean isApplicable() { 18.43 + return hierarchy.getM() != null && hierarchy.getN() != null; 18.44 + } 18.45 + 18.46 + @Override 18.47 + public Integer run(T obj) { 18.48 + switch (profilingType) { 18.49 + case RETURN: 18.50 + T t = collectReturnType(obj); 18.51 + if (t.getClass() == TypeHierarchy.A.class) { 18.52 + return inlinee(t); 18.53 + } 18.54 + return TypeHierarchy.TEMP; 18.55 + case ARGUMENTS: 18.56 + field = obj; 18.57 + if (field.getClass() == TypeHierarchy.A.class) { 18.58 + return inlinee(field); 18.59 + } 18.60 + return TypeHierarchy.TEMP; 18.61 + case PARAMETERS: 18.62 + if (obj.getClass() == TypeHierarchy.A.class) { 18.63 + return inlinee(obj); 18.64 + } 18.65 + return TypeHierarchy.TEMP; 18.66 + } 18.67 + throw new RuntimeException("Should not reach here"); 18.68 + } 18.69 + 18.70 + public int inlinee(T obj) { 18.71 + return obj.m(); 18.72 + } 18.73 + 18.74 + @Override 18.75 + public void check(Integer result, T orig) { 18.76 + if (orig.getClass() == TypeHierarchy.A.class) { 18.77 + Asserts.assertEquals(result, orig.m(), 18.78 + "Results are not equal for TypeHierarchy.A.class"); 18.79 + } else { 18.80 + Asserts.assertEquals(result, TypeHierarchy.TEMP, "Result differs from expected"); 18.81 + } 18.82 + } 18.83 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/compiler/types/correctness/scenarios/ClassInstanceOf.java Fri Apr 11 18:46:35 2014 +0400 19.3 @@ -0,0 +1,74 @@ 19.4 +/* 19.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. 19.11 + * 19.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.15 + * version 2 for more details (a copy is included in the LICENSE file that 19.16 + * accompanied this code). 19.17 + * 19.18 + * You should have received a copy of the GNU General Public License version 19.19 + * 2 along with this work; if not, write to the Free Software Foundation, 19.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.21 + * 19.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.23 + * or visit www.oracle.com if you need additional information or have any 19.24 + * questions. 19.25 + */ 19.26 + 19.27 +package scenarios; 19.28 + 19.29 +import com.oracle.java.testlibrary.Asserts; 19.30 +import hierarchies.TypeHierarchy; 19.31 + 19.32 +/** 19.33 + * Tests instanceof 19.34 + */ 19.35 +public class ClassInstanceOf<T extends TypeHierarchy.I> extends Scenario<T, Integer> { 19.36 + public ClassInstanceOf(ProfilingType profilingType, 19.37 + TypeHierarchy<? extends T, ? extends T> hierarchy) { 19.38 + super("ClassInstanceOf", profilingType, hierarchy); 19.39 + } 19.40 + 19.41 + @Override 19.42 + public Integer run(T obj) { 19.43 + switch (profilingType) { 19.44 + case RETURN: 19.45 + T t = collectReturnType(obj); 19.46 + if (t instanceof TypeHierarchy.A) { 19.47 + return inlinee(t); 19.48 + } 19.49 + return TypeHierarchy.TEMP; 19.50 + case ARGUMENTS: 19.51 + field = obj; 19.52 + if (field instanceof TypeHierarchy.A) { 19.53 + return inlinee(field); 19.54 + } 19.55 + return TypeHierarchy.TEMP; 19.56 + case PARAMETERS: 19.57 + if (obj instanceof TypeHierarchy.A) { 19.58 + return inlinee(obj); 19.59 + } 19.60 + return TypeHierarchy.TEMP; 19.61 + } 19.62 + throw new RuntimeException("Should not reach here"); 19.63 + } 19.64 + 19.65 + public int inlinee(T obj) { 19.66 + return obj.m(); 19.67 + } 19.68 + 19.69 + @Override 19.70 + public void check(Integer result, T orig) { 19.71 + if (orig instanceof TypeHierarchy.A) { 19.72 + Asserts.assertEquals(result, orig.m(), "Results are not equal for TypeHierarchy.A"); 19.73 + } else { 19.74 + Asserts.assertEquals(result, TypeHierarchy.TEMP, "Result differs from expected"); 19.75 + } 19.76 + } 19.77 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/compiler/types/correctness/scenarios/ClassIsInstance.java Fri Apr 11 18:46:35 2014 +0400 20.3 @@ -0,0 +1,77 @@ 20.4 +/* 20.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, as 20.10 + * published by the Free Software Foundation. 20.11 + * 20.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.15 + * version 2 for more details (a copy is included in the LICENSE file that 20.16 + * accompanied this code). 20.17 + * 20.18 + * You should have received a copy of the GNU General Public License version 20.19 + * 2 along with this work; if not, write to the Free Software Foundation, 20.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.21 + * 20.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20.23 + * or visit www.oracle.com if you need additional information or have any 20.24 + * questions. 20.25 + */ 20.26 + 20.27 +package scenarios; 20.28 + 20.29 +import com.oracle.java.testlibrary.Asserts; 20.30 +import hierarchies.TypeHierarchy; 20.31 + 20.32 +/** 20.33 + * Tests {@link Class#isInstance(Object)} 20.34 + */ 20.35 +public class ClassIsInstance<T extends TypeHierarchy.I> extends Scenario<T, Integer> { 20.36 + private final Class<?> baseClass; 20.37 + 20.38 + public ClassIsInstance(ProfilingType profilingType, 20.39 + TypeHierarchy<? extends T, ? extends T> hierarchy) { 20.40 + super("ClassIsInstance", profilingType, hierarchy); 20.41 + this.baseClass = hierarchy.getClassM(); 20.42 + } 20.43 + 20.44 + @Override 20.45 + public Integer run(T obj) { 20.46 + switch (profilingType) { 20.47 + case RETURN: 20.48 + T t = collectReturnType(obj); 20.49 + if (baseClass.isInstance(t)) { 20.50 + return inlinee(t); 20.51 + } 20.52 + return TypeHierarchy.TEMP; 20.53 + case ARGUMENTS: 20.54 + field = obj; 20.55 + if (baseClass.isInstance(field)) { 20.56 + return inlinee(field); 20.57 + } 20.58 + return TypeHierarchy.TEMP; 20.59 + case PARAMETERS: 20.60 + if (baseClass.isInstance(obj)) { 20.61 + return inlinee(obj); 20.62 + } 20.63 + return TypeHierarchy.TEMP; 20.64 + } 20.65 + throw new RuntimeException("Should not reach here"); 20.66 + } 20.67 + 20.68 + public int inlinee(T obj) { 20.69 + return obj.m(); 20.70 + } 20.71 + 20.72 + @Override 20.73 + public void check(Integer result, T orig) { 20.74 + if (baseClass.isInstance(orig)) { 20.75 + Asserts.assertEquals(result, orig.m(), "Results are not equal for base class"); 20.76 + } else { 20.77 + Asserts.assertEquals(result, TypeHierarchy.TEMP, "Result differs from expected"); 20.78 + } 20.79 + } 20.80 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/compiler/types/correctness/scenarios/ProfilingType.java Fri Apr 11 18:46:35 2014 +0400 21.3 @@ -0,0 +1,33 @@ 21.4 +/* 21.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.7 + * 21.8 + * This code is free software; you can redistribute it and/or modify it 21.9 + * under the terms of the GNU General Public License version 2 only, as 21.10 + * published by the Free Software Foundation. 21.11 + * 21.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 21.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21.15 + * version 2 for more details (a copy is included in the LICENSE file that 21.16 + * accompanied this code). 21.17 + * 21.18 + * You should have received a copy of the GNU General Public License version 21.19 + * 2 along with this work; if not, write to the Free Software Foundation, 21.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.21 + * 21.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21.23 + * or visit www.oracle.com if you need additional information or have any 21.24 + * questions. 21.25 + */ 21.26 + 21.27 +package scenarios; 21.28 + 21.29 +public enum ProfilingType { 21.30 + /** type profiling of return values of reference types from an invoke */ 21.31 + RETURN, 21.32 + /** type profiling for reference parameters on method entries */ 21.33 + PARAMETERS, 21.34 + /** type profiling for reference arguments at an invoke */ 21.35 + ARGUMENTS, 21.36 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/compiler/types/correctness/scenarios/ReceiverAtInvokes.java Fri Apr 11 18:46:35 2014 +0400 22.3 @@ -0,0 +1,74 @@ 22.4 +/* 22.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.7 + * 22.8 + * This code is free software; you can redistribute it and/or modify it 22.9 + * under the terms of the GNU General Public License version 2 only, as 22.10 + * published by the Free Software Foundation. 22.11 + * 22.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 22.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22.15 + * version 2 for more details (a copy is included in the LICENSE file that 22.16 + * accompanied this code). 22.17 + * 22.18 + * You should have received a copy of the GNU General Public License version 22.19 + * 2 along with this work; if not, write to the Free Software Foundation, 22.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22.21 + * 22.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22.23 + * or visit www.oracle.com if you need additional information or have any 22.24 + * questions. 22.25 + */ 22.26 + 22.27 +package scenarios; 22.28 + 22.29 +import com.oracle.java.testlibrary.Asserts; 22.30 +import hierarchies.TypeHierarchy; 22.31 + 22.32 +/** 22.33 + * Receiver at invokes profiling and speculation 22.34 + * 22.35 + * @param <T> parameter to be returned 22.36 + */ 22.37 +public class ReceiverAtInvokes<T extends TypeHierarchy.I> extends Scenario<T, Integer> { 22.38 + public ReceiverAtInvokes(ProfilingType profilingType, 22.39 + TypeHierarchy<? extends T, ? extends T> hierarchy) { 22.40 + super("ReceiverAtInvokes", profilingType, hierarchy); 22.41 + } 22.42 + 22.43 + @Override 22.44 + public boolean isApplicable() { 22.45 + return hierarchy.getM() != null && hierarchy.getN() != null; 22.46 + } 22.47 + 22.48 + /** 22.49 + * Receiver profiling 22.50 + * 22.51 + * @param obj is a profiled parameter for the test 22.52 + * @return parameter casted to the type R 22.53 + */ 22.54 + @Override 22.55 + public Integer run(T obj) { 22.56 + switch (profilingType) { 22.57 + case RETURN: 22.58 + T t = collectReturnType(obj); 22.59 + return inlinee(t); 22.60 + case ARGUMENTS: 22.61 + field = obj; 22.62 + return inlinee(field); 22.63 + case PARAMETERS: 22.64 + return inlinee(obj); 22.65 + } 22.66 + throw new RuntimeException("Should not reach here"); 22.67 + } 22.68 + 22.69 + private Integer inlinee(T obj) { 22.70 + return obj.m(); // should be inlined 22.71 + } 22.72 + 22.73 + @Override 22.74 + public void check(Integer result, T orig) { 22.75 + Asserts.assertEquals(result, orig.m(), "Results mismatch"); 22.76 + } 22.77 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/test/compiler/types/correctness/scenarios/Scenario.java Fri Apr 11 18:46:35 2014 +0400 23.3 @@ -0,0 +1,108 @@ 23.4 +/* 23.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.7 + * 23.8 + * This code is free software; you can redistribute it and/or modify it 23.9 + * under the terms of the GNU General Public License version 2 only, as 23.10 + * published by the Free Software Foundation. 23.11 + * 23.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 23.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23.15 + * version 2 for more details (a copy is included in the LICENSE file that 23.16 + * accompanied this code). 23.17 + * 23.18 + * You should have received a copy of the GNU General Public License version 23.19 + * 2 along with this work; if not, write to the Free Software Foundation, 23.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23.21 + * 23.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23.23 + * or visit www.oracle.com if you need additional information or have any 23.24 + * questions. 23.25 + */ 23.26 + 23.27 +package scenarios; 23.28 + 23.29 +import hierarchies.TypeHierarchy; 23.30 + 23.31 +/** 23.32 + * Test scenario 23.33 + * 23.34 + * @param <T> parameter type 23.35 + * @param <R> result type 23.36 + */ 23.37 +public abstract class Scenario<T extends TypeHierarchy.I, R> { 23.38 + 23.39 + private final String name; 23.40 + public final ProfilingType profilingType; 23.41 + public final TypeHierarchy <? extends T, ? extends T> hierarchy; 23.42 + protected volatile T field; 23.43 + 23.44 + /** 23.45 + * Constructor 23.46 + * 23.47 + * @param name scenario name 23.48 + * @param profilingType tested profiling type 23.49 + * @param hierarchy type hierarchy 23.50 + */ 23.51 + protected Scenario(String name, ProfilingType profilingType, 23.52 + TypeHierarchy<? extends T, ? extends T> hierarchy) { 23.53 + this.profilingType = profilingType; 23.54 + this.name = name + " # " + profilingType.name(); 23.55 + this.hierarchy = hierarchy; 23.56 + } 23.57 + 23.58 + /** 23.59 + * Returns the object which should be used as a parameter 23.60 + * for the methods used for profile data 23.61 + * 23.62 + * @return profiled type object 23.63 + */ 23.64 + public T getProfiled() { 23.65 + return hierarchy.getM(); 23.66 + } 23.67 + 23.68 + /** 23.69 + * Returns the object which makes a conflict for a profiled data 23.70 + * when passed instead of {@linkplain Scenario#getProfiled} 23.71 + * 23.72 + * @return incompatible to profiled object 23.73 + */ 23.74 + public T getConflict() { 23.75 + return hierarchy.getN(); 23.76 + } 23.77 + 23.78 + /** 23.79 + * @return scenario name 23.80 + */ 23.81 + public String getName() { 23.82 + return name; 23.83 + } 23.84 + 23.85 + /** Is this scenario applicable for a hierarchy it was constructed with */ 23.86 + public boolean isApplicable() { 23.87 + return true; 23.88 + } 23.89 + 23.90 + /** 23.91 + * Runs test scenario 23.92 + * 23.93 + * @param t subject of the test 23.94 + * @return result of the test invocation 23.95 + */ 23.96 + public abstract R run(T t); 23.97 + 23.98 + /** Used for a return type profiling */ 23.99 + protected final T collectReturnType(T t) { 23.100 + return t; 23.101 + } 23.102 + 23.103 + /** 23.104 + * Checks the result for R and T 23.105 + * 23.106 + * @param r result 23.107 + * @param t original 23.108 + * @throws java.lang.RuntimeException on result mismatch 23.109 + */ 23.110 + public abstract void check(R r, T t); 23.111 +}