annotate test/compiler/types/correctness/CorrectnessTest.java @ 18408:2c3666f44855

Truffle: initial commit of object API implementation
author Andreas Woess <andreas.woess@jku.at>
date Tue, 18 Nov 2014 23:19:43 +0100
parents 534fbe3d90f0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17881
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
1 /*
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
4 *
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
7 * published by the Free Software Foundation.
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
8 *
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
13 * accompanied this code).
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
14 *
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
18 *
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
21 * questions.
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
22 */
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
23
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
24 /*
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
25 * @test CorrectnessTest
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
26 * @bug 8038418
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
27 * @library /testlibrary /testlibrary/whitebox
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
28 * @compile execution/TypeConflict.java execution/TypeProfile.java
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
29 * execution/MethodHandleDelegate.java
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
30 * @build CorrectnessTest
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
31 * @run main ClassFileInstaller sun.hotspot.WhiteBox
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
32 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
33 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
34 * -XX:TypeProfileLevel=222 -XX:+UseTypeSpeculation
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
35 * -XX:CompileCommand=exclude,execution/*::methodNotToCompile
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
36 * -XX:CompileCommand=dontinline,scenarios/Scenario::collectReturnType
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
37 * CorrectnessTest RETURN
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
38 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
39 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
40 * -XX:TypeProfileLevel=222 -XX:+UseTypeSpeculation
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
41 * -XX:CompileCommand=exclude,execution/*::methodNotToCompile
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
42 * -XX:CompileCommand=dontinline,scenarios/Scenario::collectReturnType
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
43 * CorrectnessTest PARAMETERS
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
44 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
45 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
46 * -XX:TypeProfileLevel=222 -XX:+UseTypeSpeculation
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
47 * -XX:CompileCommand=exclude,execution/*::methodNotToCompile
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
48 * -XX:CompileCommand=dontinline,scenarios/Scenario::collectReturnType
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
49 * CorrectnessTest ARGUMENTS
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
50 * @summary Tests correctness of type usage with type profiling and speculations
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
51 */
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
52
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
53 import com.oracle.java.testlibrary.Asserts;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
54 import com.oracle.java.testlibrary.Platform;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
55 import execution.Execution;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
56 import execution.MethodHandleDelegate;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
57 import execution.TypeConflict;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
58 import execution.TypeProfile;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
59 import hierarchies.*;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
60 import scenarios.*;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
61 import sun.hotspot.WhiteBox;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
62
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
63 import java.lang.reflect.Constructor;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
64 import java.lang.reflect.Method;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
65 import java.util.ArrayList;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
66 import java.util.List;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
67 import java.util.function.BiFunction;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
68
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
69 public class CorrectnessTest {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
70 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
71
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
72 public static void main(String[] args) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
73 if (!Platform.isServer()) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
74 System.out.println("ALL TESTS SKIPPED");
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
75 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
76 Asserts.assertGTE(args.length, 1);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
77 ProfilingType profilingType = ProfilingType.valueOf(args[0]);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
78 if (runTests(profilingType)) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
79 System.out.println("ALL TESTS PASSED");
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
80 } else {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
81 throw new RuntimeException("SOME TESTS FAILED");
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
82 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
83 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
84
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
85 @SuppressWarnings("unchecked")
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
86 public static boolean runTests(ProfilingType profilingType) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
87 boolean result = true;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
88
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
89 List<Execution> executionList = new ArrayList<>();
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
90 executionList.add(new TypeConflict());
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
91 executionList.add(new TypeProfile());
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
92 for (int i = 0, n = executionList.size(); i < n; i++) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
93 executionList.add(new MethodHandleDelegate(executionList.get(i)));
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
94 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
95
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
96 List<TypeHierarchy> hierarchyList = new ArrayList<>();
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
97 hierarchyList.add(new DefaultMethodInterface.Hierarchy());
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
98 hierarchyList.add(new DefaultMethodInterface2.Hierarchy());
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
99 hierarchyList.add(new Linear.Hierarchy());
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
100 hierarchyList.add(new Linear2.Hierarchy());
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
101 hierarchyList.add(new OneRank.Hierarchy());
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
102 for (int i = 0, n = hierarchyList.size(); i < n; i++) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
103 hierarchyList.add(new NullableType(hierarchyList.get(i)));
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
104 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
105
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
106 List<BiFunction<ProfilingType, TypeHierarchy, Scenario<?, ?>>> testCasesConstructors
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
107 = new ArrayList<>();
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
108 testCasesConstructors.add(ArrayCopy::new);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
109 testCasesConstructors.add(ArrayReferenceStore::new);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
110 testCasesConstructors.add(ClassIdentity::new);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
111 testCasesConstructors.add(ClassInstanceOf::new);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
112 testCasesConstructors.add(ClassIsInstance::new);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
113 testCasesConstructors.add(ReceiverAtInvokes::new);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
114 testCasesConstructors.add(CheckCast::new);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
115
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
116 for (TypeHierarchy hierarchy : hierarchyList) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
117 for (BiFunction<ProfilingType, TypeHierarchy, Scenario<?, ?>> constructor : testCasesConstructors) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
118 for (Execution execution : executionList) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
119 Scenario<?, ?> scenario = constructor.apply(profilingType, hierarchy);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
120 if (scenario.isApplicable()) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
121 result &= executeTest(hierarchy, execution, scenario);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
122 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
123 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
124 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
125 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
126 return result;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
127 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
128
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
129 /**
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
130 * Executes test case
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
131 *
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
132 * @param hierarchy type hierarchy for the test
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
133 * @param execution execution scenario
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
134 * @param scenario test scenario executed with given Execution
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
135 */
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
136 private static boolean executeTest(TypeHierarchy hierarchy, Execution execution, Scenario<?, ?> scenario) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
137 boolean testCaseResult = false;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
138 String testName = hierarchy.getClass().getName() + " :: " + scenario.getName() + " @ " + execution.getName();
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
139 clearAllMethodsState(scenario.getClass());
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
140 try {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
141 execution.execute(scenario);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
142 testCaseResult = true;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
143 } catch (Exception e) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
144 System.err.println(testName + " failed with exception " + e);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
145 e.printStackTrace();
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
146 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
147 System.out.println((testCaseResult ? "PASSED: " : "FAILED: ") + testName);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
148 return testCaseResult;
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
149 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
150
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
151 private static void clearAllMethodsState(Class aClass) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
152 while (aClass != null) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
153 for (Method m : aClass.getDeclaredMethods()) {
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
154 WHITE_BOX.clearMethodState(m);
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
155 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
156 aClass = aClass.getSuperclass();
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
157 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
158 }
534fbe3d90f0 8038418: New tests development for type profiling and speculation
iignatyev
parents:
diff changeset
159 }