Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java @ 17154:7716c6993546
Stamp: interface types can not be trusted except after explicit runtime checks
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Thu, 18 Sep 2014 17:41:19 +0200 |
parents | ceb34d2d124e |
children | ffb974bef674 |
rev | line source |
---|---|
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
16252
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
2 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
23 package com.oracle.graal.nodes.java; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
11839
0e2cceed1caf
Temporarily move encodeDeoptActionAndReason to MetaAccessProvider
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11798
diff
changeset
|
25 import static com.oracle.graal.api.meta.DeoptimizationAction.*; |
10693
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
26 import static com.oracle.graal.api.meta.DeoptimizationReason.*; |
10788
ac3cb56f47a0
made use of symbolic constants for branch probabilities
Doug Simon <doug.simon@oracle.com>
parents:
10786
diff
changeset
|
27 import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; |
10693
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
28 |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5504
diff
changeset
|
29 import com.oracle.graal.api.meta.*; |
10786
745322b36359
added a field to LogicBinaryNode capturing the probability that the evaluation of the logic node is short-circuited (i.e. only the left input is evaluated)
Doug Simon <doug.simon@oracle.com>
parents:
10762
diff
changeset
|
30 import com.oracle.graal.api.meta.ProfilingInfo.TriState; |
15198
2c0cfbf454b5
Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15009
diff
changeset
|
31 import com.oracle.graal.compiler.common.type.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
32 import com.oracle.graal.graph.*; |
11881
da9db8331658
moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11880
diff
changeset
|
33 import com.oracle.graal.graph.spi.*; |
16841
cbd42807a31f
moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents:
16822
diff
changeset
|
34 import com.oracle.graal.nodeinfo.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
35 import com.oracle.graal.nodes.*; |
10693
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
36 import com.oracle.graal.nodes.calc.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
37 import com.oracle.graal.nodes.spi.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
38 import com.oracle.graal.nodes.type.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 /** |
6648
7bf5a6c42db7
factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents:
6462
diff
changeset
|
41 * Implements a type check against a compile-time known type. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 */ |
16822
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16422
diff
changeset
|
43 @NodeInfo |
16252
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
44 public class CheckCastNode extends FixedWithNextNode implements Canonicalizable, Simplifiable, Lowerable, Virtualizable, ValueProxy { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 |
17135
ceb34d2d124e
Make fields and constructors protected to allow subclasses in different packages
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16919
diff
changeset
|
46 @Input protected ValueNode object; |
6648
7bf5a6c42db7
factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents:
6462
diff
changeset
|
47 private final ResolvedJavaType type; |
5541
b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
48 private final JavaTypeProfile profile; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 /** |
9478
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
51 * Determines the exception thrown by this node if the check fails: {@link ClassCastException} |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
52 * if false; {@link ArrayStoreException} if true. |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
53 */ |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
54 private final boolean forStoreCheck; |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
55 |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
56 /** |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 * Creates a new CheckCast instruction. |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14160
diff
changeset
|
58 * |
6648
7bf5a6c42db7
factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents:
6462
diff
changeset
|
59 * @param type the type being cast to |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 * @param object the instruction producing the object |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 */ |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
62 public static CheckCastNode create(ResolvedJavaType type, ValueNode object, JavaTypeProfile profile, boolean forStoreCheck) { |
16919
0fe4732e5181
made use of generated Node classes predicated on value of graal.useGeneratedNodes system property (default is false)
Doug Simon <doug.simon@oracle.com>
parents:
16897
diff
changeset
|
63 return USE_GENERATED_NODES ? new CheckCastNodeGen(type, object, profile, forStoreCheck) : new CheckCastNode(type, object, profile, forStoreCheck); |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
64 } |
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
65 |
17135
ceb34d2d124e
Make fields and constructors protected to allow subclasses in different packages
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16919
diff
changeset
|
66 protected CheckCastNode(ResolvedJavaType type, ValueNode object, JavaTypeProfile profile, boolean forStoreCheck) { |
17154
7716c6993546
Stamp: interface types can not be trusted except after explicit runtime checks
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
17135
diff
changeset
|
67 super(StampFactory.declared(type, false, true)); |
6648
7bf5a6c42db7
factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents:
6462
diff
changeset
|
68 assert type != null; |
7bf5a6c42db7
factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents:
6462
diff
changeset
|
69 this.type = type; |
5370 | 70 this.object = object; |
71 this.profile = profile; | |
9478
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
72 this.forStoreCheck = forStoreCheck; |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
73 } |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
74 |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
75 public boolean isForStoreCheck() { |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
76 return forStoreCheck; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
78 |
10693
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
79 /** |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
80 * Lowers a {@link CheckCastNode} to a {@link GuardingPiNode}. That is: |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14160
diff
changeset
|
81 * |
10693
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
82 * <pre> |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
83 * 1: A a = ... |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
84 * 2: B b = (B) a; |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
85 * </pre> |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14160
diff
changeset
|
86 * |
10693
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
87 * is lowered to: |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14160
diff
changeset
|
88 * |
10693
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
89 * <pre> |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
90 * 1: A a = ... |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
91 * 2: B b = guardingPi(a == null || a instanceof B, a, stamp(B)) |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
92 * </pre> |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14160
diff
changeset
|
93 * |
10693
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
94 * or if a is known to be non-null: |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14160
diff
changeset
|
95 * |
10693
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
96 * <pre> |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
97 * 1: A a = ... |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
98 * 2: B b = guardingPi(a instanceof B, a, stamp(B, non-null)) |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
99 * </pre> |
15002
06e50d290784
isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14160
diff
changeset
|
100 * |
12384
28d80a9260cd
During CheckCast lowering, if null was never seen and a guard is created for the null case, the instanceof should be done on a non-null value.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11881
diff
changeset
|
101 * Note: we use {@link Graph#addWithoutUnique} as opposed to {@link Graph#unique} for the new |
10693
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
102 * {@link InstanceOfNode} to maintain the invariant checked by |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
103 * {@code LoweringPhase.checkUsagesAreScheduled()}. |
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
104 */ |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
105 @Override |
11579
ae619d70bf4b
Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
106 public void lower(LoweringTool tool) { |
17154
7716c6993546
Stamp: interface types can not be trusted except after explicit runtime checks
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
17135
diff
changeset
|
107 Stamp stamp = StampFactory.declared(type, false, true); |
11265 | 108 if (stamp() instanceof ObjectStamp && object().stamp() instanceof ObjectStamp) { |
109 stamp = ((ObjectStamp) object().stamp()).castTo((ObjectStamp) stamp); | |
110 } | |
11226
422b0e9b9aed
removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
10918
diff
changeset
|
111 ValueNode condition; |
16422
7f20dee1be60
ensure instanceof and null check stay dependent
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16252
diff
changeset
|
112 ValueNode theValue = object; |
11387
9088d13767f3
Keep a kind in the illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11265
diff
changeset
|
113 if (stamp instanceof IllegalStamp) { |
11226
422b0e9b9aed
removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
10918
diff
changeset
|
114 // This is a check cast that will always fail |
422b0e9b9aed
removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
10918
diff
changeset
|
115 condition = LogicConstantNode.contradiction(graph()); |
17154
7716c6993546
Stamp: interface types can not be trusted except after explicit runtime checks
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
17135
diff
changeset
|
116 stamp = StampFactory.declared(type, false, true); |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
117 } else if (StampTool.isObjectNonNull(object)) { |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
118 condition = graph().addWithoutUnique(InstanceOfNode.create(type, object, profile)); |
11226
422b0e9b9aed
removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
10918
diff
changeset
|
119 } else { |
422b0e9b9aed
removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
10918
diff
changeset
|
120 if (profile != null && profile.getNullSeen() == TriState.FALSE) { |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
121 FixedGuardNode nullCheck = graph().add(FixedGuardNode.create(graph().unique(IsNullNode.create(object)), UnreachedCode, InvalidateReprofile, true)); |
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
122 PiNode nullGuarded = graph().unique(PiNode.create(object, object().stamp().join(StampFactory.objectNonNull()), nullCheck)); |
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
123 InstanceOfNode typeTest = graph().addWithoutUnique(InstanceOfNode.create(type, nullGuarded, profile)); |
12384
28d80a9260cd
During CheckCast lowering, if null was never seen and a guard is created for the null case, the instanceof should be done on a non-null value.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11881
diff
changeset
|
124 graph().addBeforeFixed(this, nullCheck); |
10729
2a4ad6ab345e
disabled new lowering of checkcast until performance regression is fixed
Doug Simon <doug.simon@oracle.com>
parents:
10712
diff
changeset
|
125 condition = typeTest; |
16422
7f20dee1be60
ensure instanceof and null check stay dependent
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16252
diff
changeset
|
126 /* |
7f20dee1be60
ensure instanceof and null check stay dependent
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16252
diff
changeset
|
127 * The PiNode is injecting an extra guard into the type so make sure it's used in |
7f20dee1be60
ensure instanceof and null check stay dependent
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16252
diff
changeset
|
128 * the GuardingPi, otherwise we can lose the null guard if the InstanceOf is |
7f20dee1be60
ensure instanceof and null check stay dependent
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16252
diff
changeset
|
129 * optimized away. |
7f20dee1be60
ensure instanceof and null check stay dependent
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16252
diff
changeset
|
130 */ |
7f20dee1be60
ensure instanceof and null check stay dependent
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16252
diff
changeset
|
131 theValue = nullGuarded; |
11226
422b0e9b9aed
removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
10918
diff
changeset
|
132 stamp = stamp.join(StampFactory.objectNonNull()); |
12384
28d80a9260cd
During CheckCast lowering, if null was never seen and a guard is created for the null case, the instanceof should be done on a non-null value.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11881
diff
changeset
|
133 nullCheck.lower(tool); |
10729
2a4ad6ab345e
disabled new lowering of checkcast until performance regression is fixed
Doug Simon <doug.simon@oracle.com>
parents:
10712
diff
changeset
|
134 } else { |
11226
422b0e9b9aed
removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
10918
diff
changeset
|
135 // TODO (ds) replace with probability of null-seen when available |
422b0e9b9aed
removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
10918
diff
changeset
|
136 double shortCircuitProbability = NOT_FREQUENT_PROBABILITY; |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
137 InstanceOfNode typeTest = graph().addWithoutUnique(InstanceOfNode.create(type, object, profile)); |
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
138 condition = LogicNode.or(graph().unique(IsNullNode.create(object)), typeTest, shortCircuitProbability); |
10729
2a4ad6ab345e
disabled new lowering of checkcast until performance regression is fixed
Doug Simon <doug.simon@oracle.com>
parents:
10712
diff
changeset
|
139 } |
10693
f8adf47cc05e
checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents:
9786
diff
changeset
|
140 } |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
141 GuardingPiNode checkedObject = graph().add(GuardingPiNode.create(theValue, condition, false, forStoreCheck ? ArrayStoreException : ClassCastException, InvalidateReprofile, stamp)); |
11226
422b0e9b9aed
removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
10918
diff
changeset
|
142 graph().replaceFixedWithFixed(this, checkedObject); |
11798
2fbb9fd55dde
made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents:
11652
diff
changeset
|
143 checkedObject.lower(tool); |
5379
c862951e769d
moved checkcast lowering into LoweringPhase and added -G:HIRLowerCheckcast option to enable it (disabled by default) as it is not yet stable
Doug Simon <doug.simon@oracle.com>
parents:
5372
diff
changeset
|
144 } |
c862951e769d
moved checkcast lowering into LoweringPhase and added -G:HIRLowerCheckcast option to enable it (disabled by default) as it is not yet stable
Doug Simon <doug.simon@oracle.com>
parents:
5372
diff
changeset
|
145 |
c862951e769d
moved checkcast lowering into LoweringPhase and added -G:HIRLowerCheckcast option to enable it (disabled by default) as it is not yet stable
Doug Simon <doug.simon@oracle.com>
parents:
5372
diff
changeset
|
146 @Override |
5831
ed08c40d67de
Add a alwaysNull property to ObjectStamp (Phi(null, a! A) get a "a A" stamp and not just "a -")
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5720
diff
changeset
|
147 public boolean inferStamp() { |
15754
45285c8eccbd
Never use the current node's stamp in ValueNode.inferStamp overrides.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
148 if (object().stamp() instanceof ObjectStamp) { |
17154
7716c6993546
Stamp: interface types can not be trusted except after explicit runtime checks
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
17135
diff
changeset
|
149 ObjectStamp castStamp = (ObjectStamp) StampFactory.declared(type, false, true); |
15754
45285c8eccbd
Never use the current node's stamp in ValueNode.inferStamp overrides.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
150 return updateStamp(((ObjectStamp) object().stamp()).castTo(castStamp)); |
11265 | 151 } |
152 return false; | |
5831
ed08c40d67de
Add a alwaysNull property to ObjectStamp (Phi(null, a! A) get a "a A" stamp and not just "a -")
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5720
diff
changeset
|
153 } |
ed08c40d67de
Add a alwaysNull property to ObjectStamp (Phi(null, a! A) get a "a A" stamp and not just "a -")
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5720
diff
changeset
|
154 |
ed08c40d67de
Add a alwaysNull property to ObjectStamp (Phi(null, a! A) get a "a A" stamp and not just "a -")
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5720
diff
changeset
|
155 @Override |
11880
9a747d8e0d0f
broadened types in Canonicalizable interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11839
diff
changeset
|
156 public Node canonical(CanonicalizerTool tool) { |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
157 ResolvedJavaType objectType = StampTool.typeOrNull(object()); |
9478
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
158 if (objectType != null && type.isAssignableFrom(objectType)) { |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
159 // we don't have to check for null types here because they will also pass the |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
160 // checkcast. |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
161 return object(); |
fb22b4d5f475
Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9251
diff
changeset
|
162 } |
9543
f8a5f7f7d0bd
CheckCastNode: eliminate the other way around
Bernhard Urban <bernhard.urban@jku.at>
parents:
9494
diff
changeset
|
163 |
16252
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
164 if (StampTool.isObjectAlwaysNull(object())) { |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
165 return object(); |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
166 } |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
167 |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
168 if (tool.assumptions() != null && tool.assumptions().useOptimisticAssumptions()) { |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
169 ResolvedJavaType exactType = type.findUniqueConcreteSubtype(); |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
170 if (exactType != null && !exactType.equals(type)) { |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
171 // Propagate more precise type information to usages of the checkcast. |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
172 tool.assumptions().recordConcreteSubtype(type, exactType); |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
173 return CheckCastNode.create(exactType, object, profile, forStoreCheck); |
16252
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
174 } |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
175 } |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
176 |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
177 return this; |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
178 } |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
179 |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
180 @Override |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
181 public void simplify(SimplifierTool tool) { |
10918
3736fb3dcc56
checkcastnode: fix comment and scope in unittest
Bernhard Urban <bernhard.urban@jku.at>
parents:
10877
diff
changeset
|
182 // if the previous node is also a checkcast, with a less precise and compatible type, |
3736fb3dcc56
checkcastnode: fix comment and scope in unittest
Bernhard Urban <bernhard.urban@jku.at>
parents:
10877
diff
changeset
|
183 // replace both with one checkcast checking the more specific type. |
9543
f8a5f7f7d0bd
CheckCastNode: eliminate the other way around
Bernhard Urban <bernhard.urban@jku.at>
parents:
9494
diff
changeset
|
184 if (predecessor() instanceof CheckCastNode) { |
f8a5f7f7d0bd
CheckCastNode: eliminate the other way around
Bernhard Urban <bernhard.urban@jku.at>
parents:
9494
diff
changeset
|
185 CheckCastNode ccn = (CheckCastNode) predecessor(); |
f8a5f7f7d0bd
CheckCastNode: eliminate the other way around
Bernhard Urban <bernhard.urban@jku.at>
parents:
9494
diff
changeset
|
186 if (ccn != null && ccn.type != null && ccn == object && ccn.forStoreCheck == forStoreCheck && ccn.type.isAssignableFrom(type)) { |
9602
19c5a07c7843
Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9543
diff
changeset
|
187 StructuredGraph graph = ccn.graph(); |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
188 CheckCastNode newccn = graph.add(CheckCastNode.create(type, ccn.object, ccn.profile, ccn.forStoreCheck)); |
9543
f8a5f7f7d0bd
CheckCastNode: eliminate the other way around
Bernhard Urban <bernhard.urban@jku.at>
parents:
9494
diff
changeset
|
189 graph.replaceFixedWithFixed(ccn, newccn); |
16252
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
190 replaceAtUsages(newccn); |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15831
diff
changeset
|
191 graph.removeFixed(this); |
5417
791eb4f85b29
Use exact type for check cast canonicalization if available
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5379
diff
changeset
|
192 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
193 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
194 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
195 |
5370 | 196 public ValueNode object() { |
197 return object; | |
198 } | |
199 | |
200 /** | |
6648
7bf5a6c42db7
factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents:
6462
diff
changeset
|
201 * Gets the type being cast to. |
5370 | 202 */ |
6648
7bf5a6c42db7
factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents:
6462
diff
changeset
|
203 public ResolvedJavaType type() { |
7bf5a6c42db7
factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents:
6462
diff
changeset
|
204 return type; |
5370 | 205 } |
206 | |
5541
b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
207 public JavaTypeProfile profile() { |
5370 | 208 return profile; |
209 } | |
6710
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6648
diff
changeset
|
210 |
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6648
diff
changeset
|
211 @Override |
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6648
diff
changeset
|
212 public void virtualize(VirtualizerTool tool) { |
7394
94f032472c28
changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents:
7337
diff
changeset
|
213 State state = tool.getObjectState(object); |
94f032472c28
changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents:
7337
diff
changeset
|
214 if (state != null && state.getState() == EscapeState.Virtual) { |
8961
1b5eeb50e690
PEA: fix virtualization of CheckCastNode (check type)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
215 if (type.isAssignableFrom(state.getVirtualObject().type())) { |
1b5eeb50e690
PEA: fix virtualization of CheckCastNode (check type)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
216 tool.replaceWithVirtual(state.getVirtualObject()); |
1b5eeb50e690
PEA: fix virtualization of CheckCastNode (check type)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
217 } |
6710
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6648
diff
changeset
|
218 } |
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6648
diff
changeset
|
219 } |
10762
c483912aaf70
add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents:
10730
diff
changeset
|
220 |
c483912aaf70
add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents:
10730
diff
changeset
|
221 @Override |
15009
e49f62425090
introduce non-ValueNode Proxy interface
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15002
diff
changeset
|
222 public ValueNode getOriginalNode() { |
10762
c483912aaf70
add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents:
10730
diff
changeset
|
223 return object; |
c483912aaf70
add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents:
10730
diff
changeset
|
224 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
225 } |