Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeCastNode.java @ 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
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 15 Aug 2014 11:34:38 +0200 |
parents | 5d468add216f |
children | 06c15e88d383 |
rev | line source |
---|---|
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
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.extended; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5443
diff
changeset
|
25 import com.oracle.graal.api.meta.*; |
15198
2c0cfbf454b5
Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15073
diff
changeset
|
26 import com.oracle.graal.compiler.common.type.*; |
11752
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
27 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
|
28 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:
16811
diff
changeset
|
29 import com.oracle.graal.nodeinfo.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
30 import com.oracle.graal.nodes.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
31 import com.oracle.graal.nodes.spi.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
32 import com.oracle.graal.nodes.type.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 /** |
11752
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
35 * The {@code UnsafeCastNode} produces the same value as its input, but with a different type. It |
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
36 * allows unsafe casts "sideways" in the type hierarchy. It does not allow to "drop" type |
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
37 * information, i.e., an unsafe cast is removed if the input object has a more precise or equal type |
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
38 * than the type this nodes casts to. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 */ |
16811
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
15447
diff
changeset
|
40 @NodeInfo |
12405
139b84d713bc
Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11881
diff
changeset
|
41 public class UnsafeCastNode extends FloatingGuardedNode implements LIRLowerable, Virtualizable, GuardingNode, IterableNodeType, Canonicalizable, ValueProxy { |
11752
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
42 |
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
43 @Input private ValueNode object; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
45 public UnsafeCastNode(ValueNode object, Stamp stamp) { |
11752
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
46 super(stamp); |
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
47 this.object = object; |
10040
6b34d50d3d24
Remove PiNode.anchor, use the guard field of FloatingGuardedNode instead
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9786
diff
changeset
|
48 } |
6b34d50d3d24
Remove PiNode.anchor, use the guard field of FloatingGuardedNode instead
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9786
diff
changeset
|
49 |
8536
2978a819763b
CheckCastSnippets: anchor UnsafeCast with subclass tests
Bernhard Urban <bernhard.urban@jku.at>
parents:
8472
diff
changeset
|
50 public UnsafeCastNode(ValueNode object, Stamp stamp, ValueNode anchor) { |
11752
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
51 super(stamp, (GuardingNode) anchor); |
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
52 this.object = object; |
8536
2978a819763b
CheckCastSnippets: anchor UnsafeCast with subclass tests
Bernhard Urban <bernhard.urban@jku.at>
parents:
8472
diff
changeset
|
53 } |
2978a819763b
CheckCastSnippets: anchor UnsafeCast with subclass tests
Bernhard Urban <bernhard.urban@jku.at>
parents:
8472
diff
changeset
|
54 |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
55 public UnsafeCastNode(ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) { |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
56 this(object, toType.getKind() == Kind.Object ? StampFactory.object(toType, exactType, nonNull || StampTool.isObjectNonNull(object.stamp())) : StampFactory.forKind(toType.getKind())); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 @Override |
15009
e49f62425090
introduce non-ValueNode Proxy interface
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14950
diff
changeset
|
60 public ValueNode getOriginalNode() { |
11752
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
61 return object; |
7337
c1a5c3bc5656
more accurate inferStamp for UnsafeCastNode and CheckCastNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7296
diff
changeset
|
62 } |
c1a5c3bc5656
more accurate inferStamp for UnsafeCastNode and CheckCastNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7296
diff
changeset
|
63 |
c1a5c3bc5656
more accurate inferStamp for UnsafeCastNode and CheckCastNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7296
diff
changeset
|
64 @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:
11752
diff
changeset
|
65 public Node canonical(CanonicalizerTool tool) { |
14633
da2431cc1506
Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents:
13501
diff
changeset
|
66 assert getKind() == Kind.Object && object.getKind() == Kind.Object; |
15447
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
67 |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
68 ObjectStamp my = (ObjectStamp) stamp(); |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
69 ObjectStamp other = (ObjectStamp) object.stamp(); |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
70 |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
71 if (my.type() == null || other.type() == null) { |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
72 return this; |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
73 } |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
74 if (my.isExactType() && !other.isExactType()) { |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
75 return this; |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
76 } |
15447
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
77 if (my.nonNull() && !other.nonNull()) { |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
78 return this; |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
79 } |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
80 if (!my.type().isAssignableFrom(other.type())) { |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
81 return this; |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
82 } |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
83 /* |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
84 * The unsafe cast does not add any new type information, so it can be removed. Note that |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
85 * this means that the unsafe cast cannot be used to "drop" type information (in which case |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
86 * it must not be canonicalized in any case). |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
87 */ |
951647e16782
Backed out changeset: d44e138f7020
Andreas Woess <andreas.woess@jku.at>
parents:
15260
diff
changeset
|
88 return object; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
89 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
90 |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
91 @Override |
12405
139b84d713bc
Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11881
diff
changeset
|
92 public void virtualize(VirtualizerTool tool) { |
139b84d713bc
Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11881
diff
changeset
|
93 State state = tool.getObjectState(object); |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
94 if (state != null && state.getState() == EscapeState.Virtual && StampTool.typeOrNull(this) != null && StampTool.typeOrNull(this).isAssignableFrom(state.getVirtualObject().type())) { |
12405
139b84d713bc
Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11881
diff
changeset
|
95 tool.replaceWithVirtual(state.getVirtualObject()); |
139b84d713bc
Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11881
diff
changeset
|
96 } |
139b84d713bc
Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11881
diff
changeset
|
97 } |
139b84d713bc
Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11881
diff
changeset
|
98 |
139b84d713bc
Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11881
diff
changeset
|
99 @Override |
14950
d5a1206e1923
NodeLIRBuilderTool: fix typo in interface name.
Josef Eisl <josef.eisl@jku.at>
parents:
14888
diff
changeset
|
100 public void generate(NodeLIRBuilderTool generator) { |
14633
da2431cc1506
Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents:
13501
diff
changeset
|
101 assert getKind() == Kind.Object && object.getKind() == Kind.Object; |
11752
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
102 /* |
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
103 * The LIR only cares about the kind of an operand, not the actual type of an object. So we |
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
104 * do not have to introduce a new operand. |
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
105 */ |
7e7edb86fb43
Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
11322
diff
changeset
|
106 generator.setResult(this, generator.operand(object)); |
8472
f71fec3fadae
made method substitutions for Thread be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
107 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
108 } |