Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeLoadNode.java @ 7091:08fe3a509cf1
Canoncialize UnsafeLoad/Store
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Thu, 29 Nov 2012 13:31:48 +0100 |
parents | 05ce1defa4f9 |
children | 4f220c85044d |
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) 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:
5504
diff
changeset
|
25 import com.oracle.graal.api.meta.*; |
7091
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
26 import com.oracle.graal.graph.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
27 import com.oracle.graal.nodes.*; |
7091
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
28 import com.oracle.graal.nodes.java.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
29 import com.oracle.graal.nodes.spi.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
30 import com.oracle.graal.nodes.type.*; |
7049
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
31 import com.oracle.graal.nodes.virtual.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 |
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 * Load of a value from a location specified as an offset relative to an object. |
6716
536dbb4dd212
removed null check from UnsafeLoadNode, UnsafeStoreNode, ReadNode and WriteNode as it violates the sun.misc.Unsafe API
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
35 * No null check is performed before the load. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 */ |
7091
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
37 public class UnsafeLoadNode extends UnsafeAccessNode implements Lowerable, Virtualizable, Canonicalizable { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 |
7090
05ce1defa4f9
Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7049
diff
changeset
|
39 public UnsafeLoadNode(ValueNode object, int displacement, ValueNode offset, boolean nonNull) { |
05ce1defa4f9
Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7049
diff
changeset
|
40 this(nonNull ? StampFactory.objectNonNull() : StampFactory.object(), object, displacement, offset, Kind.Object); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 |
7090
05ce1defa4f9
Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7049
diff
changeset
|
43 public UnsafeLoadNode(ValueNode object, int displacement, ValueNode offset, Kind accessKind) { |
05ce1defa4f9
Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7049
diff
changeset
|
44 this(StampFactory.forKind(accessKind.getStackKind()), object, displacement, offset, accessKind); |
5464
1d00c9a1f733
support @NodeIntrinsic based creation of a UnsafeLoadNode with a stamp indicating non-nullness
Doug Simon <doug.simon@oracle.com>
parents:
5362
diff
changeset
|
45 } |
1d00c9a1f733
support @NodeIntrinsic based creation of a UnsafeLoadNode with a stamp indicating non-nullness
Doug Simon <doug.simon@oracle.com>
parents:
5362
diff
changeset
|
46 |
7090
05ce1defa4f9
Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7049
diff
changeset
|
47 public UnsafeLoadNode(Stamp stamp, ValueNode object, int displacement, ValueNode offset, Kind accessKind) { |
05ce1defa4f9
Common out some parts of UnsafeLoad/Store in UnsafeAccess
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7049
diff
changeset
|
48 super(stamp, object, displacement, offset, accessKind); |
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 |
5718
10341299528c
renamings: ExtendedRiRuntime -> GraalCodeCacheProvider, CiLoweringTool -> LoweringTool, RiGraphCache -> GraphCache
Doug Simon <doug.simon@oracle.com>
parents:
5540
diff
changeset
|
52 public void lower(LoweringTool tool) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 tool.getRuntime().lower(this, tool); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 |
7049
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
56 @Override |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
57 public void virtualize(VirtualizerTool tool) { |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
58 VirtualObjectNode virtual = tool.getVirtualState(object()); |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
59 if (virtual != null) { |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
60 ValueNode indexValue = tool.getReplacedValue(offset()); |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
61 if (indexValue.isConstant()) { |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
62 int fieldIndex = virtual.fieldIndexForOffset(indexValue.asConstant().asLong()); |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
63 if (fieldIndex != -1) { |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
64 ValueNode result = tool.getVirtualEntry(virtual, fieldIndex); |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
65 VirtualObjectNode virtualResult = tool.getVirtualState(result); |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
66 if (virtualResult != null) { |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
67 tool.replaceWithVirtual(virtualResult); |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
68 } else { |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
69 tool.replaceWithValue(result); |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
70 } |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
71 } |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
72 } |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
73 } |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
74 } |
ccade022ec83
virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents:
6716
diff
changeset
|
75 |
7091
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
76 @Override |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
77 public ValueNode canonical(CanonicalizerTool tool) { |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
78 if (offset().isConstant()) { |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
79 long constantOffset = offset().asConstant().asLong(); |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
80 if (constantOffset != 0) { |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
81 int intDisplacement = (int) (constantOffset + displacement()); |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
82 if (constantOffset == intDisplacement) { |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
83 Graph graph = this.graph(); |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
84 return graph.add(new UnsafeLoadNode(this.stamp(), object(), intDisplacement, graph.unique(ConstantNode.forInt(0, graph)), accessKind())); |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
85 } |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
86 } else if (object().stamp() instanceof ObjectStamp) { // TODO (gd) remove that once UnsafeAccess only have an object base |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
87 ObjectStamp receiverStamp = object().objectStamp(); |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
88 if (receiverStamp.nonNull()) { |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
89 ResolvedJavaType receiverType = receiverStamp.type(); |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
90 ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(displacement()); |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
91 if (field != null) { |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
92 return this.graph().add(new LoadFieldNode(object(), field, StructuredGraph.INVALID_GRAPH_ID)); |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
93 } |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
94 } |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
95 } |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
96 } |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
97 return this; |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
98 } |
08fe3a509cf1
Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7090
diff
changeset
|
99 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
100 @NodeIntrinsic |
6458
fb66841a0994
made all @NodeIntrinsic annotated methods be native (this is a requirement now enforced during snippet intrinsification)
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
101 public static native <T> T load(Object object, @ConstantNodeParameter int displacement, long offset, @ConstantNodeParameter Kind kind); |
5464
1d00c9a1f733
support @NodeIntrinsic based creation of a UnsafeLoadNode with a stamp indicating non-nullness
Doug Simon <doug.simon@oracle.com>
parents:
5362
diff
changeset
|
102 |
1d00c9a1f733
support @NodeIntrinsic based creation of a UnsafeLoadNode with a stamp indicating non-nullness
Doug Simon <doug.simon@oracle.com>
parents:
5362
diff
changeset
|
103 @NodeIntrinsic |
6458
fb66841a0994
made all @NodeIntrinsic annotated methods be native (this is a requirement now enforced during snippet intrinsification)
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
104 public static native Object loadObject(Object object, @ConstantNodeParameter int displacement, long offset, @ConstantNodeParameter boolean nonNull); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
105 } |