Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeCastNode.java @ 10040:6b34d50d3d24
Remove PiNode.anchor, use the guard field of FloatingGuardedNode instead
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Fri, 14 Jun 2013 11:16:41 +0200 |
parents | 6c1f7b853d35 |
children | ef6915cf1e59 |
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.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
26 import com.oracle.graal.nodes.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
27 import com.oracle.graal.nodes.spi.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
28 import com.oracle.graal.nodes.type.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 * The {@code UnsafeCastNode} produces the same value as its input, but with a different type. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 */ |
8650
251b1c84e668
UnsafeCastNode: make it an subclass of PiNode
Bernhard Urban <bernhard.urban@jku.at>
parents:
8604
diff
changeset
|
33 public class UnsafeCastNode extends PiNode implements Canonicalizable, LIRLowerable { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
35 public UnsafeCastNode(ValueNode object, Stamp stamp) { |
8650
251b1c84e668
UnsafeCastNode: make it an subclass of PiNode
Bernhard Urban <bernhard.urban@jku.at>
parents:
8604
diff
changeset
|
36 super(object, stamp); |
5683
0ca242de9383
improved type stamp for value flowing out of a lowered NEW bytecode instruction
Doug Simon <doug.simon@oracle.com>
parents:
5666
diff
changeset
|
37 } |
0ca242de9383
improved type stamp for value flowing out of a lowered NEW bytecode instruction
Doug Simon <doug.simon@oracle.com>
parents:
5666
diff
changeset
|
38 |
10040
6b34d50d3d24
Remove PiNode.anchor, use the guard field of FloatingGuardedNode instead
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9786
diff
changeset
|
39 public UnsafeCastNode(ValueNode object, Stamp stamp, GuardingNode anchor) { |
6b34d50d3d24
Remove PiNode.anchor, use the guard field of FloatingGuardedNode instead
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9786
diff
changeset
|
40 super(object, stamp, anchor); |
6b34d50d3d24
Remove PiNode.anchor, use the guard field of FloatingGuardedNode instead
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9786
diff
changeset
|
41 } |
6b34d50d3d24
Remove PiNode.anchor, use the guard field of FloatingGuardedNode instead
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9786
diff
changeset
|
42 |
8536
2978a819763b
CheckCastSnippets: anchor UnsafeCast with subclass tests
Bernhard Urban <bernhard.urban@jku.at>
parents:
8472
diff
changeset
|
43 public UnsafeCastNode(ValueNode object, Stamp stamp, ValueNode anchor) { |
10040
6b34d50d3d24
Remove PiNode.anchor, use the guard field of FloatingGuardedNode instead
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9786
diff
changeset
|
44 this(object, stamp, (GuardingNode) anchor); |
8536
2978a819763b
CheckCastSnippets: anchor UnsafeCast with subclass tests
Bernhard Urban <bernhard.urban@jku.at>
parents:
8472
diff
changeset
|
45 } |
2978a819763b
CheckCastSnippets: anchor UnsafeCast with subclass tests
Bernhard Urban <bernhard.urban@jku.at>
parents:
8472
diff
changeset
|
46 |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
47 public UnsafeCastNode(ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) { |
7098
e23980f4a890
Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7097
diff
changeset
|
48 this(object, toType.getKind() == Kind.Object ? StampFactory.object(toType, exactType, nonNull || object.stamp().nonNull()) : StampFactory.forKind(toType.getKind())); |
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 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 @Override |
7337
c1a5c3bc5656
more accurate inferStamp for UnsafeCastNode and CheckCastNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7296
diff
changeset
|
52 public boolean inferStamp() { |
c1a5c3bc5656
more accurate inferStamp for UnsafeCastNode and CheckCastNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7296
diff
changeset
|
53 if (kind() != Kind.Object || object().kind() != Kind.Object) { |
c1a5c3bc5656
more accurate inferStamp for UnsafeCastNode and CheckCastNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7296
diff
changeset
|
54 return false; |
c1a5c3bc5656
more accurate inferStamp for UnsafeCastNode and CheckCastNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7296
diff
changeset
|
55 } |
8198
f54b2344ef3c
workaround for UnsafeCastNode.tryInferStamp when the stamp is StampFactory.forNodeIntrinsic (contributed by Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
7883
diff
changeset
|
56 if (stamp() == StampFactory.forNodeIntrinsic()) { |
f54b2344ef3c
workaround for UnsafeCastNode.tryInferStamp when the stamp is StampFactory.forNodeIntrinsic (contributed by Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
7883
diff
changeset
|
57 return false; |
f54b2344ef3c
workaround for UnsafeCastNode.tryInferStamp when the stamp is StampFactory.forNodeIntrinsic (contributed by Mick Jordan)
Doug Simon <doug.simon@oracle.com>
parents:
7883
diff
changeset
|
58 } |
7337
c1a5c3bc5656
more accurate inferStamp for UnsafeCastNode and CheckCastNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7296
diff
changeset
|
59 return updateStamp(stamp().join(object().stamp())); |
c1a5c3bc5656
more accurate inferStamp for UnsafeCastNode and CheckCastNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7296
diff
changeset
|
60 } |
c1a5c3bc5656
more accurate inferStamp for UnsafeCastNode and CheckCastNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7296
diff
changeset
|
61 |
c1a5c3bc5656
more accurate inferStamp for UnsafeCastNode and CheckCastNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7296
diff
changeset
|
62 @Override |
4309
4a609a685fa4
changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents:
4199
diff
changeset
|
63 public ValueNode canonical(CanonicalizerTool tool) { |
8650
251b1c84e668
UnsafeCastNode: make it an subclass of PiNode
Bernhard Urban <bernhard.urban@jku.at>
parents:
8604
diff
changeset
|
64 if (kind() != object().kind()) { |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
65 return this; |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
66 } |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
67 |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
68 if (kind() == Kind.Object) { |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
69 ObjectStamp my = objectStamp(); |
8650
251b1c84e668
UnsafeCastNode: make it an subclass of PiNode
Bernhard Urban <bernhard.urban@jku.at>
parents:
8604
diff
changeset
|
70 ObjectStamp other = object().objectStamp(); |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
71 |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
72 if (my.type() == null || other.type() == null) { |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
73 return this; |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
74 } |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
75 if (my.isExactType() && !other.isExactType()) { |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
76 return this; |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
77 } |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
78 if (my.nonNull() && !other.nonNull()) { |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
79 return this; |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
80 } |
7296
8d9c7a109967
Fix elimination of unnecessary UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
81 if (!my.type().isAssignableFrom(other.type())) { |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
82 return this; |
5683
0ca242de9383
improved type stamp for value flowing out of a lowered NEW bytecode instruction
Doug Simon <doug.simon@oracle.com>
parents:
5666
diff
changeset
|
83 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
84 } |
8650
251b1c84e668
UnsafeCastNode: make it an subclass of PiNode
Bernhard Urban <bernhard.urban@jku.at>
parents:
8604
diff
changeset
|
85 return object(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
86 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
87 |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
88 @Override |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
89 public void generate(LIRGeneratorTool generator) { |
8650
251b1c84e668
UnsafeCastNode: make it an subclass of PiNode
Bernhard Urban <bernhard.urban@jku.at>
parents:
8604
diff
changeset
|
90 if (kind() != object().kind()) { |
9423
3426008293e7
Move getSizeInBytes method to Architecture class.
Roland Schatz <roland.schatz@oracle.com>
parents:
9296
diff
changeset
|
91 assert generator.target().arch.getSizeInBytes(kind()) == generator.target().arch.getSizeInBytes(object().kind()) : "unsafe cast cannot be used to change the size of a value"; |
9296
1342574c4f7d
Move targets can only be AllocatableValues.
Roland Schatz <roland.schatz@oracle.com>
parents:
8650
diff
changeset
|
92 AllocatableValue result = generator.newVariable(kind()); |
8650
251b1c84e668
UnsafeCastNode: make it an subclass of PiNode
Bernhard Urban <bernhard.urban@jku.at>
parents:
8604
diff
changeset
|
93 generator.emitMove(result, generator.operand(object())); |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
94 generator.setResult(this, result); |
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
95 } else { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7337
diff
changeset
|
96 // The LIR only cares about the kind of an operand, not the actual type of an object. So |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7337
diff
changeset
|
97 // we do not have to |
7031
2e577202843c
Better implementation of UnsafeCastNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
98 // introduce a new operand when the kind is the same. |
8650
251b1c84e668
UnsafeCastNode: make it an subclass of PiNode
Bernhard Urban <bernhard.urban@jku.at>
parents:
8604
diff
changeset
|
99 generator.setResult(this, generator.operand(object())); |
5563
6a2671066204
added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
5541
diff
changeset
|
100 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
101 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
102 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
103 @NodeIntrinsic |
8604
1f83d8994b7a
unsafeCast: remove anchor node in NewObjectSnippets
Bernhard Urban <bernhard.urban@jku.at>
parents:
8599
diff
changeset
|
104 public static native <T> T unsafeCast(Object object, @ConstantNodeParameter Stamp stamp); |
1f83d8994b7a
unsafeCast: remove anchor node in NewObjectSnippets
Bernhard Urban <bernhard.urban@jku.at>
parents:
8599
diff
changeset
|
105 |
1f83d8994b7a
unsafeCast: remove anchor node in NewObjectSnippets
Bernhard Urban <bernhard.urban@jku.at>
parents:
8599
diff
changeset
|
106 @NodeIntrinsic |
10040
6b34d50d3d24
Remove PiNode.anchor, use the guard field of FloatingGuardedNode instead
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9786
diff
changeset
|
107 public static native <T> T unsafeCast(Object object, @ConstantNodeParameter Stamp stamp, GuardingNode anchor); |
8536
2978a819763b
CheckCastSnippets: anchor UnsafeCast with subclass tests
Bernhard Urban <bernhard.urban@jku.at>
parents:
8472
diff
changeset
|
108 |
8472
f71fec3fadae
made method substitutions for Thread be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
109 @SuppressWarnings("unused") |
5683
0ca242de9383
improved type stamp for value flowing out of a lowered NEW bytecode instruction
Doug Simon <doug.simon@oracle.com>
parents:
5666
diff
changeset
|
110 @NodeIntrinsic |
8472
f71fec3fadae
made method substitutions for Thread be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
111 public static <T> T unsafeCast(Object object, @ConstantNodeParameter Class<T> toType, @ConstantNodeParameter boolean exactType, @ConstantNodeParameter boolean nonNull) { |
f71fec3fadae
made method substitutions for Thread be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
112 return toType.cast(object); |
f71fec3fadae
made method substitutions for Thread be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
113 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
114 } |