annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java @ 16252:a762ddb12b43

change some node types from Canonicalizable to Simplifiable
author Lukas Stadler <lukas.stadler@oracle.com>
date Thu, 26 Jun 2014 16:27:36 +0200
parents 1ddee372bf62
children 7f20dee1be60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
34 import com.oracle.graal.nodes.*;
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
35 import com.oracle.graal.nodes.calc.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
36 import com.oracle.graal.nodes.spi.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
37 import com.oracle.graal.nodes.type.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 /**
6648
7bf5a6c42db7 factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents: 6462
diff changeset
40 * 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
41 */
16252
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
42 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
43
5370
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
44 @Input private ValueNode object;
6648
7bf5a6c42db7 factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents: 6462
diff changeset
45 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
46 private final JavaTypeProfile profile;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 /**
9478
fb22b4d5f475 Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9251
diff changeset
49 * 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
50 * 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
51 */
fb22b4d5f475 Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9251
diff changeset
52 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
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 /**
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 * Creates a new CheckCast instruction.
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14160
diff changeset
56 *
6648
7bf5a6c42db7 factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents: 6462
diff changeset
57 * @param type the type being cast to
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 * @param object the instruction producing the object
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 */
9478
fb22b4d5f475 Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9251
diff changeset
60 public CheckCastNode(ResolvedJavaType type, ValueNode object, JavaTypeProfile profile, boolean forStoreCheck) {
6648
7bf5a6c42db7 factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents: 6462
diff changeset
61 super(StampFactory.declared(type));
7bf5a6c42db7 factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents: 6462
diff changeset
62 assert type != null;
7bf5a6c42db7 factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents: 6462
diff changeset
63 this.type = type;
5370
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
64 this.object = object;
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
65 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
66 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
67 }
fb22b4d5f475 Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9251
diff changeset
68
fb22b4d5f475 Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9251
diff changeset
69 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
70 return forStoreCheck;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
73 /**
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
74 * 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
75 *
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
76 * <pre>
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
77 * 1: A a = ...
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
78 * 2: B b = (B) a;
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
79 * </pre>
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14160
diff changeset
80 *
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
81 * is lowered to:
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14160
diff changeset
82 *
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
83 * <pre>
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
84 * 1: A a = ...
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
85 * 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
86 * </pre>
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14160
diff changeset
87 *
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
88 * or if a is known to be non-null:
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14160
diff changeset
89 *
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
90 * <pre>
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
91 * 1: A a = ...
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
92 * 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
93 * </pre>
15002
06e50d290784 isAllowedUsageType on Nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14160
diff changeset
94 *
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
95 * 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
96 * {@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
97 * {@code LoweringPhase.checkUsagesAreScheduled()}.
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
98 */
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 @Override
11579
ae619d70bf4b Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11387
diff changeset
100 public void lower(LoweringTool tool) {
11265
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11226
diff changeset
101 Stamp stamp = StampFactory.declared(type);
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11226
diff changeset
102 if (stamp() instanceof ObjectStamp && object().stamp() instanceof ObjectStamp) {
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11226
diff changeset
103 stamp = ((ObjectStamp) object().stamp()).castTo((ObjectStamp) stamp);
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11226
diff changeset
104 }
11226
422b0e9b9aed removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 10918
diff changeset
105 ValueNode condition;
11387
9088d13767f3 Keep a kind in the illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11265
diff changeset
106 if (stamp instanceof IllegalStamp) {
11226
422b0e9b9aed removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 10918
diff changeset
107 // This is a check cast that will always fail
422b0e9b9aed removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 10918
diff changeset
108 condition = LogicConstantNode.contradiction(graph());
422b0e9b9aed removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 10918
diff changeset
109 stamp = StampFactory.declared(type);
15260
61363577a184 Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents: 15198
diff changeset
110 } else if (StampTool.isObjectNonNull(object)) {
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
111 condition = graph().addWithoutUnique(new InstanceOfNode(type, object, profile));
11226
422b0e9b9aed removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 10918
diff changeset
112 } else {
422b0e9b9aed removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 10918
diff changeset
113 if (profile != null && profile.getNullSeen() == TriState.FALSE) {
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
114 FixedGuardNode nullCheck = graph().add(new FixedGuardNode(graph().unique(new IsNullNode(object)), UnreachedCode, InvalidateReprofile, true));
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
115 PiNode nullGuarded = graph().unique(new PiNode(object, object().stamp().join(StampFactory.objectNonNull()), nullCheck));
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
116 InstanceOfNode typeTest = graph().addWithoutUnique(new InstanceOfNode(type, nullGuarded, profile));
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
117 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
118 condition = typeTest;
11226
422b0e9b9aed removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 10918
diff changeset
119 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
120 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
121 } else {
11226
422b0e9b9aed removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 10918
diff changeset
122 // 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
123 double shortCircuitProbability = NOT_FREQUENT_PROBABILITY;
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 InstanceOfNode typeTest = graph().addWithoutUnique(new InstanceOfNode(type, object, profile));
11582
9e12e51fe7b2 Add helper methods with negations for inputs in LogicNode. Use helper method in CheckCastNode lowering
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11579
diff changeset
125 condition = LogicNode.or(graph().unique(new IsNullNode(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
126 }
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 9786
diff changeset
127 }
11226
422b0e9b9aed removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 10918
diff changeset
128 GuardingPiNode checkedObject = graph().add(new GuardingPiNode(object, condition, false, forStoreCheck ? ArrayStoreException : ClassCastException, InvalidateReprofile, stamp));
422b0e9b9aed removed obsolete checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 10918
diff changeset
129 graph().replaceFixedWithFixed(this, checkedObject);
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11652
diff changeset
130 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
131 }
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
132
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
133 @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
134 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
135 if (object().stamp() instanceof ObjectStamp) {
45285c8eccbd Never use the current node's stamp in ValueNode.inferStamp overrides.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15260
diff changeset
136 ObjectStamp castStamp = (ObjectStamp) StampFactory.declared(type);
45285c8eccbd Never use the current node's stamp in ValueNode.inferStamp overrides.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15260
diff changeset
137 return updateStamp(((ObjectStamp) object().stamp()).castTo(castStamp));
11265
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11226
diff changeset
138 }
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11226
diff changeset
139 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
140 }
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
141
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
142 @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
143 public Node canonical(CanonicalizerTool tool) {
15260
61363577a184 Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents: 15198
diff changeset
144 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
145 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
146 // 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
147 // checkcast.
fb22b4d5f475 Allow distinction between ClassCastException and ArrayStoreException. Add more canonicalizations for check casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9251
diff changeset
148 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
149 }
9543
f8a5f7f7d0bd CheckCastNode: eliminate the other way around
Bernhard Urban <bernhard.urban@jku.at>
parents: 9494
diff changeset
150
16252
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
151 if (StampTool.isObjectAlwaysNull(object())) {
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
152 return object();
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
153 }
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
154
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
155 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
156 ResolvedJavaType exactType = type.findUniqueConcreteSubtype();
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
157 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
158 // 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
159 tool.assumptions().recordConcreteSubtype(type, exactType);
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
160 return new CheckCastNode(exactType, object, profile, forStoreCheck);
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
161 }
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
162 }
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
163
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
164 return this;
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
165 }
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 @Override
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
168 public void simplify(SimplifierTool tool) {
10918
3736fb3dcc56 checkcastnode: fix comment and scope in unittest
Bernhard Urban <bernhard.urban@jku.at>
parents: 10877
diff changeset
169 // 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
170 // 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
171 if (predecessor() instanceof CheckCastNode) {
f8a5f7f7d0bd CheckCastNode: eliminate the other way around
Bernhard Urban <bernhard.urban@jku.at>
parents: 9494
diff changeset
172 CheckCastNode ccn = (CheckCastNode) predecessor();
f8a5f7f7d0bd CheckCastNode: eliminate the other way around
Bernhard Urban <bernhard.urban@jku.at>
parents: 9494
diff changeset
173 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
174 StructuredGraph graph = ccn.graph();
9543
f8a5f7f7d0bd CheckCastNode: eliminate the other way around
Bernhard Urban <bernhard.urban@jku.at>
parents: 9494
diff changeset
175 CheckCastNode newccn = graph.add(new CheckCastNode(type, ccn.object, ccn.profile, ccn.forStoreCheck));
f8a5f7f7d0bd CheckCastNode: eliminate the other way around
Bernhard Urban <bernhard.urban@jku.at>
parents: 9494
diff changeset
176 graph.replaceFixedWithFixed(ccn, newccn);
16252
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
177 replaceAtUsages(newccn);
a762ddb12b43 change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15831
diff changeset
178 graph.removeFixed(this);
5417
791eb4f85b29 Use exact type for check cast canonicalization if available
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5379
diff changeset
179 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182
5370
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
183 public ValueNode object() {
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
184 return object;
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
185 }
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
186
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
187 /**
6648
7bf5a6c42db7 factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents: 6462
diff changeset
188 * Gets the type being cast to.
5370
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
189 */
6648
7bf5a6c42db7 factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents: 6462
diff changeset
190 public ResolvedJavaType type() {
7bf5a6c42db7 factored CheckCastDynamicNode out of CheckCastNode
Doug Simon <doug.simon@oracle.com>
parents: 6462
diff changeset
191 return type;
5370
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
192 }
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
193
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
194 public JavaTypeProfile profile() {
5370
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
195 return profile;
5229911d3970 removed TypeCheckNode
Doug Simon <doug.simon@oracle.com>
parents: 5369
diff changeset
196 }
6710
6db6881c1270 add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents: 6648
diff changeset
197
6db6881c1270 add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents: 6648
diff changeset
198 @Override
6db6881c1270 add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents: 6648
diff changeset
199 public void virtualize(VirtualizerTool tool) {
7394
94f032472c28 changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents: 7337
diff changeset
200 State state = tool.getObjectState(object);
94f032472c28 changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents: 7337
diff changeset
201 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
202 if (type.isAssignableFrom(state.getVirtualObject().type())) {
1b5eeb50e690 PEA: fix virtualization of CheckCastNode (check type)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
203 tool.replaceWithVirtual(state.getVirtualObject());
1b5eeb50e690 PEA: fix virtualization of CheckCastNode (check type)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
204 }
6710
6db6881c1270 add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents: 6648
diff changeset
205 }
6db6881c1270 add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents: 6648
diff changeset
206 }
10762
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 10730
diff changeset
207
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 10730
diff changeset
208 @Override
15009
e49f62425090 introduce non-ValueNode Proxy interface
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15002
diff changeset
209 public ValueNode getOriginalNode() {
10762
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 10730
diff changeset
210 return object;
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 10730
diff changeset
211 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212 }