author | thartmann |
Fri, 12 Dec 2014 09:37:38 +0100 | |
changeset 28190 | 5a6b07edeb21 |
parent 27450 | 603dbcf4f547 |
child 29678 | dd2f3932c21e |
permissions | -rw-r--r-- |
27450
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
1 |
/* |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
4 |
* |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
8 |
* |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
13 |
* accompanied this code). |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
14 |
* |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
18 |
* |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
21 |
* questions. |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
22 |
*/ |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
23 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
24 |
/* |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
25 |
* @test NullCheckDroppingsTest |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
26 |
* @bug 8054492 |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
27 |
* @summary "Casting can result in redundant null checks in generated code" |
28190
5a6b07edeb21
8066433: Move Whitebox test library to top level repository
thartmann
parents:
27450
diff
changeset
|
28 |
* @library /testlibrary /../../test/lib /testlibrary/com/oracle/java/testlibrary |
27450
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
29 |
* @build NullCheckDroppingsTest |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
30 |
* @run main ClassFileInstaller sun.hotspot.WhiteBox |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
31 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
32 |
* @run main ClassFileInstaller com.oracle.java.testlibrary.Platform |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
33 |
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
34 |
* -Xmixed -XX:-BackgroundCompilation -XX:-TieredCompilation -XX:CompileThreshold=1000 |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
35 |
* -XX:CompileCommand=exclude,NullCheckDroppingsTest::runTest NullCheckDroppingsTest |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
36 |
*/ |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
37 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
38 |
import sun.hotspot.WhiteBox; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
39 |
import sun.hotspot.code.NMethod; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
40 |
import com.oracle.java.testlibrary.Platform; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
41 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
42 |
import java.lang.reflect.Method; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
43 |
import java.lang.invoke.MethodHandle; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
44 |
import java.lang.invoke.MethodHandles; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
45 |
import java.lang.invoke.MethodType; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
46 |
import java.util.function.BiFunction; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
47 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
48 |
public class NullCheckDroppingsTest { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
49 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
50 |
private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
51 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
52 |
static final BiFunction<Class, Object, Object> fCast = (c, o) -> c.cast(o); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
53 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
54 |
static final MethodHandle SET_SSINK; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
55 |
static final MethodHandle MH_CAST; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
56 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
57 |
static { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
58 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
59 |
SET_SSINK = MethodHandles.lookup().findSetter(NullCheckDroppingsTest.class, "ssink", String.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
60 |
MH_CAST = MethodHandles.lookup().findVirtual(Class.class, |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
61 |
"cast", |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
62 |
MethodType.methodType(Object.class, Object.class)); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
63 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
64 |
catch (Exception e) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
65 |
throw new Error(e); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
66 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
67 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
68 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
69 |
static volatile String svalue = "A"; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
70 |
static volatile String snull = null; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
71 |
static volatile Integer iobj = new Integer(0); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
72 |
static volatile int[] arr = new int[2]; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
73 |
static volatile Class objClass = String.class; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
74 |
static volatile Class nullClass = null; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
75 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
76 |
String ssink; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
77 |
Integer isink; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
78 |
int[] asink; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
79 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
80 |
public static void main(String[] args) throws Exception { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
81 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
82 |
// Only test C2 in Server VM |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
83 |
if (!Platform.isServer()) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
84 |
return; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
85 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
86 |
// Make sure background compilation is disabled |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
87 |
if (WHITE_BOX.getBooleanVMFlag("BackgroundCompilation")) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
88 |
throw new AssertionError("Background compilation enabled"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
89 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
90 |
// Make sure Tiered compilation is disabled |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
91 |
if (WHITE_BOX.getBooleanVMFlag("TieredCompilation")) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
92 |
throw new AssertionError("Tiered compilation enabled"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
93 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
94 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
95 |
Method methodClassCast = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCast", String.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
96 |
Method methodMHCast = NullCheckDroppingsTest.class.getDeclaredMethod("testMHCast", String.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
97 |
Method methodMHSetter = NullCheckDroppingsTest.class.getDeclaredMethod("testMHSetter", String.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
98 |
Method methodFunction = NullCheckDroppingsTest.class.getDeclaredMethod("testFunction", String.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
99 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
100 |
NullCheckDroppingsTest t = new NullCheckDroppingsTest(); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
101 |
t.runTest(methodClassCast, false); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
102 |
t.runTest(methodMHCast, false); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
103 |
t.runTest(methodMHSetter, false); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
104 |
t.runTest(methodFunction, false); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
105 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
106 |
// Edge cases |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
107 |
Method methodClassCastNull = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCastNull", String.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
108 |
Method methodNullClassCast = NullCheckDroppingsTest.class.getDeclaredMethod("testNullClassCast", String.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
109 |
Method methodClassCastObj = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCastObj", Object.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
110 |
Method methodObjClassCast = NullCheckDroppingsTest.class.getDeclaredMethod("testObjClassCast", String.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
111 |
Method methodVarClassCast = NullCheckDroppingsTest.class.getDeclaredMethod("testVarClassCast", String.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
112 |
Method methodClassCastInt = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCastInt", Object.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
113 |
Method methodIntClassCast = NullCheckDroppingsTest.class.getDeclaredMethod("testIntClassCast", Object.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
114 |
Method methodClassCastint = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCastint", Object.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
115 |
Method methodintClassCast = NullCheckDroppingsTest.class.getDeclaredMethod("testintClassCast", Object.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
116 |
Method methodClassCastPrim = NullCheckDroppingsTest.class.getDeclaredMethod("testClassCastPrim", Object.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
117 |
Method methodPrimClassCast = NullCheckDroppingsTest.class.getDeclaredMethod("testPrimClassCast", Object.class); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
118 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
119 |
t.runTest(methodClassCastNull, false); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
120 |
t.runTest(methodNullClassCast, false); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
121 |
t.runTest(methodClassCastObj, false); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
122 |
t.runTest(methodObjClassCast, true); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
123 |
t.runTest(methodVarClassCast, true); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
124 |
t.runTest(methodClassCastInt, false); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
125 |
t.runTest(methodIntClassCast, true); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
126 |
t.runTest(methodClassCastint, false); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
127 |
t.runTest(methodintClassCast, false); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
128 |
t.runTest(methodClassCastPrim, false); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
129 |
t.runTest(methodPrimClassCast, true); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
130 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
131 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
132 |
void testClassCast(String s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
133 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
134 |
ssink = String.class.cast(s); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
135 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
136 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
137 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
138 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
139 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
140 |
void testClassCastNull(String s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
141 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
142 |
ssink = String.class.cast(null); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
143 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
144 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
145 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
146 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
147 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
148 |
void testNullClassCast(String s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
149 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
150 |
ssink = (String)nullClass.cast(s); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
151 |
throw new AssertionError("NullPointerException is not thrown"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
152 |
} catch (NullPointerException t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
153 |
// Ignore NullPointerException |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
154 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
155 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
156 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
157 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
158 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
159 |
void testClassCastObj(Object s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
160 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
161 |
ssink = String.class.cast(s); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
162 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
163 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
164 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
165 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
166 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
167 |
void testObjClassCast(String s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
168 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
169 |
ssink = (String)objClass.cast(s); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
170 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
171 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
172 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
173 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
174 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
175 |
void testVarClassCast(String s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
176 |
Class cl = (s == null) ? null : String.class; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
177 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
178 |
ssink = (String)cl.cast(svalue); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
179 |
if (s == null) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
180 |
throw new AssertionError("NullPointerException is not thrown"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
181 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
182 |
} catch (NullPointerException t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
183 |
// Ignore NullPointerException |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
184 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
185 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
186 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
187 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
188 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
189 |
void testClassCastInt(Object s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
190 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
191 |
ssink = String.class.cast(iobj); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
192 |
throw new AssertionError("ClassCastException is not thrown"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
193 |
} catch (ClassCastException t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
194 |
// Ignore ClassCastException: Cannot cast java.lang.Integer to java.lang.String |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
195 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
196 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
197 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
198 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
199 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
200 |
void testIntClassCast(Object s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
201 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
202 |
isink = Integer.class.cast(s); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
203 |
if (s != null) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
204 |
throw new AssertionError("ClassCastException is not thrown"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
205 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
206 |
} catch (ClassCastException t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
207 |
// Ignore ClassCastException: Cannot cast java.lang.String to java.lang.Integer |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
208 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
209 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
210 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
211 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
212 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
213 |
void testClassCastint(Object s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
214 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
215 |
ssink = String.class.cast(45); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
216 |
throw new AssertionError("ClassCastException is not thrown"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
217 |
} catch (ClassCastException t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
218 |
// Ignore ClassCastException: Cannot cast java.lang.Integer to java.lang.String |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
219 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
220 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
221 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
222 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
223 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
224 |
void testintClassCast(Object s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
225 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
226 |
isink = int.class.cast(s); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
227 |
if (s != null) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
228 |
throw new AssertionError("ClassCastException is not thrown"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
229 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
230 |
} catch (ClassCastException t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
231 |
// Ignore ClassCastException: Cannot cast java.lang.String to java.lang.Integer |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
232 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
233 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
234 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
235 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
236 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
237 |
void testClassCastPrim(Object s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
238 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
239 |
ssink = String.class.cast(arr); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
240 |
throw new AssertionError("ClassCastException is not thrown"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
241 |
} catch (ClassCastException t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
242 |
// Ignore ClassCastException: Cannot cast [I to java.lang.String |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
243 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
244 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
245 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
246 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
247 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
248 |
void testPrimClassCast(Object s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
249 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
250 |
asink = int[].class.cast(s); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
251 |
if (s != null) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
252 |
throw new AssertionError("ClassCastException is not thrown"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
253 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
254 |
} catch (ClassCastException t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
255 |
// Ignore ClassCastException: Cannot cast java.lang.String to [I |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
256 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
257 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
258 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
259 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
260 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
261 |
void testMHCast(String s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
262 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
263 |
ssink = (String) (Object) MH_CAST.invokeExact(String.class, (Object) s); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
264 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
265 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
266 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
267 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
268 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
269 |
void testMHSetter(String s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
270 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
271 |
SET_SSINK.invokeExact(this, s); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
272 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
273 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
274 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
275 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
276 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
277 |
void testFunction(String s) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
278 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
279 |
ssink = (String) fCast.apply(String.class, s); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
280 |
} catch (Throwable t) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
281 |
throw new Error(t); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
282 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
283 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
284 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
285 |
void runTest(Method method, boolean deopt) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
286 |
if (method == null) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
287 |
throw new AssertionError("method was not found"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
288 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
289 |
// Ensure method is compiled |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
290 |
WHITE_BOX.testSetDontInlineMethod(method, true); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
291 |
for (int i = 0; i < 3000; i++) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
292 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
293 |
method.invoke(this, svalue); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
294 |
} catch (Exception e) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
295 |
throw new Error("Unexpected exception: ", e); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
296 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
297 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
298 |
NMethod nm = getNMethod(method); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
299 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
300 |
// Passing null should cause a de-optimization |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
301 |
// if method is compiled with a null-check. |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
302 |
try { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
303 |
method.invoke(this, snull); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
304 |
} catch (Exception e) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
305 |
throw new Error("Unexpected exception: ", e); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
306 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
307 |
checkDeoptimization(method, nm, deopt); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
308 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
309 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
310 |
static NMethod getNMethod(Method test) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
311 |
// Because background compilation is disabled, method should now be compiled |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
312 |
if (!WHITE_BOX.isMethodCompiled(test)) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
313 |
throw new AssertionError(test + " not compiled"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
314 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
315 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
316 |
NMethod nm = NMethod.get(test, false); // not OSR nmethod |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
317 |
if (nm == null) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
318 |
throw new AssertionError(test + " missing nmethod?"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
319 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
320 |
if (nm.comp_level != 4) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
321 |
throw new AssertionError(test + " compiled by not C2: " + nm); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
322 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
323 |
return nm; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
324 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
325 |
|
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
326 |
static void checkDeoptimization(Method method, NMethod nmOrig, boolean deopt) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
327 |
// Check deoptimization event (intrinsic Class.cast() works). |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
328 |
if (WHITE_BOX.isMethodCompiled(method) == deopt) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
329 |
throw new AssertionError(method + " was" + (deopt ? " not" : "") + " deoptimized"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
330 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
331 |
if (deopt) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
332 |
return; |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
333 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
334 |
// Ensure no recompilation when no deoptimization is expected. |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
335 |
NMethod nm = NMethod.get(method, false); // not OSR nmethod |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
336 |
if (nm == null) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
337 |
throw new AssertionError(method + " missing nmethod?"); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
338 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
339 |
if (nm.comp_level != 4) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
340 |
throw new AssertionError(method + " compiled by not C2: " + nm); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
341 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
342 |
if (nm.compile_id != nmOrig.compile_id) { |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
343 |
throw new AssertionError(method + " was recompiled: old nmethod=" + nmOrig + ", new nmethod=" + nm); |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
344 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
345 |
} |
603dbcf4f547
8054492: Casting can result in redundant null checks in generated code
kvn
parents:
diff
changeset
|
346 |
} |