annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeLoadNode.java @ 15039:631ca3972292

Allow Unsafe operations on Java to use precise LocationIdentity and improve address formation
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Wed, 09 Apr 2014 10:33:44 -0700
parents 27c04ee36dcb
children 882f4cb7cfcf
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 /*
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
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
25 import static com.oracle.graal.graph.UnsafeAccess.*;
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
26
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5504
diff changeset
27 import com.oracle.graal.api.meta.*;
15001
27c04ee36dcb input types
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14633
diff changeset
28 import com.oracle.graal.graph.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
29 import com.oracle.graal.nodes.*;
7091
08fe3a509cf1 Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7090
diff changeset
30 import com.oracle.graal.nodes.java.*;
5060
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 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7394
diff changeset
35 * Load of a value from a location specified as an offset relative to an object. No null check is
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7394
diff changeset
36 * performed before the load.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 */
10647
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10646
diff changeset
38 public class UnsafeLoadNode extends UnsafeAccessNode implements Lowerable, Virtualizable {
15001
27c04ee36dcb input types
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14633
diff changeset
39 @Input(InputType.Condition) private LogicNode guardingCondition;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40
12548
e1f40574c309 Unsafe{Load,Store}Node: users must provide an LocationIdentity explicitly. Provide more specific LocationIdentity in UnsafeArraySnippets (instead of ANY_LOCATION)
Bernhard Urban <bernhard.urban@jku.at>
parents: 12445
diff changeset
41 public UnsafeLoadNode(ValueNode object, ValueNode offset, Kind accessKind, LocationIdentity locationIdentity) {
e1f40574c309 Unsafe{Load,Store}Node: users must provide an LocationIdentity explicitly. Provide more specific LocationIdentity in UnsafeArraySnippets (instead of ANY_LOCATION)
Bernhard Urban <bernhard.urban@jku.at>
parents: 12445
diff changeset
42 this(object, offset, accessKind, locationIdentity, null);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44
11943
0fa39f034839 Allow floating unsafe loads.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11923
diff changeset
45 public UnsafeLoadNode(ValueNode object, ValueNode offset, Kind accessKind, LocationIdentity locationIdentity, LogicNode condition) {
11923
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
46 super(StampFactory.forKind(accessKind.getStackKind()), object, offset, accessKind, locationIdentity);
11943
0fa39f034839 Allow floating unsafe loads.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11923
diff changeset
47 this.guardingCondition = condition;
0fa39f034839 Allow floating unsafe loads.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11923
diff changeset
48 }
0fa39f034839 Allow floating unsafe loads.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11923
diff changeset
49
0fa39f034839 Allow floating unsafe loads.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11923
diff changeset
50 public LogicNode getGuardingCondition() {
0fa39f034839 Allow floating unsafe loads.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11923
diff changeset
51 return guardingCondition;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 @Override
11579
ae619d70bf4b Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10647
diff changeset
55 public void lower(LoweringTool tool) {
12045
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
56 tool.getLowerer().lower(this, tool);
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
7049
ccade022ec83 virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents: 6716
diff changeset
59 @Override
ccade022ec83 virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents: 6716
diff changeset
60 public void virtualize(VirtualizerTool tool) {
7394
94f032472c28 changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents: 7275
diff changeset
61 State state = tool.getObjectState(object());
94f032472c28 changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents: 7275
diff changeset
62 if (state != null && state.getState() == EscapeState.Virtual) {
11923
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
63 ValueNode offsetValue = tool.getReplacedValue(offset());
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
64 if (offsetValue.isConstant()) {
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
65 long offset = offsetValue.asConstant().asLong();
7394
94f032472c28 changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents: 7275
diff changeset
66 int entryIndex = state.getVirtualObject().entryIndexForOffset(offset);
12405
139b84d713bc Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12045
diff changeset
67 if (entryIndex != -1) {
139b84d713bc Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12045
diff changeset
68 ValueNode entry = state.getEntry(entryIndex);
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 12548
diff changeset
69 if (entry.getKind() == getKind() || state.getVirtualObject().entryKind(entryIndex) == accessKind()) {
12405
139b84d713bc Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12045
diff changeset
70 tool.replaceWith(entry);
139b84d713bc Truffle API adjustments: Simplify frame handling. Introduce cast for MaterializedFrame objects.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12045
diff changeset
71 }
7049
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 }
ccade022ec83 virtualization of unsafeload and unsafestore
Lukas Stadler <lukas.stadler@jku.at>
parents: 6716
diff changeset
76
7091
08fe3a509cf1 Canoncialize UnsafeLoad/Store
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7090
diff changeset
77 @Override
10647
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10646
diff changeset
78 protected ValueNode cloneAsFieldAccess(ResolvedJavaField field) {
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10646
diff changeset
79 return this.graph().add(new LoadFieldNode(object(), field));
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10646
diff changeset
80 }
2ea604c4c6ec Factor and improve unsafe load/store canonicalization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10646
diff changeset
81
15039
631ca3972292 Allow Unsafe operations on Java to use precise LocationIdentity and improve address formation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15001
diff changeset
82 @Override
631ca3972292 Allow Unsafe operations on Java to use precise LocationIdentity and improve address formation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15001
diff changeset
83 protected ValueNode cloneAsArrayAccess(ValueNode location, LocationIdentity identity) {
631ca3972292 Allow Unsafe operations on Java to use precise LocationIdentity and improve address formation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15001
diff changeset
84 return this.graph().add(new UnsafeLoadNode(object(), location, accessKind(), identity));
631ca3972292 Allow Unsafe operations on Java to use precise LocationIdentity and improve address formation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15001
diff changeset
85 }
631ca3972292 Allow Unsafe operations on Java to use precise LocationIdentity and improve address formation
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15001
diff changeset
86
12548
e1f40574c309 Unsafe{Load,Store}Node: users must provide an LocationIdentity explicitly. Provide more specific LocationIdentity in UnsafeArraySnippets (instead of ANY_LOCATION)
Bernhard Urban <bernhard.urban@jku.at>
parents: 12445
diff changeset
87 @SuppressWarnings({"unchecked", "unused"})
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 @NodeIntrinsic
12548
e1f40574c309 Unsafe{Load,Store}Node: users must provide an LocationIdentity explicitly. Provide more specific LocationIdentity in UnsafeArraySnippets (instead of ANY_LOCATION)
Bernhard Urban <bernhard.urban@jku.at>
parents: 12445
diff changeset
89 public static <T> T load(Object object, long offset, @ConstantNodeParameter Kind kind, @ConstantNodeParameter LocationIdentity locationIdentity) {
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
90 if (kind == Kind.Boolean) {
11923
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
91 return (T) (Boolean) unsafe.getBoolean(object, offset);
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
92 }
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
93 if (kind == Kind.Byte) {
11923
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
94 return (T) (Byte) unsafe.getByte(object, offset);
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
95 }
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
96 if (kind == Kind.Short) {
11923
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
97 return (T) (Short) unsafe.getShort(object, offset);
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
98 }
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
99 if (kind == Kind.Char) {
11923
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
100 return (T) (Character) unsafe.getChar(object, offset);
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
101 }
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
102 if (kind == Kind.Int) {
11923
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
103 return (T) (Integer) unsafe.getInt(object, offset);
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
104 }
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
105 if (kind == Kind.Float) {
11923
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
106 return (T) (Float) unsafe.getFloat(object, offset);
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
107 }
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
108 if (kind == Kind.Long) {
11923
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
109 return (T) (Long) unsafe.getLong(object, offset);
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
110 }
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
111 if (kind == Kind.Double) {
11923
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
112 return (T) (Double) unsafe.getDouble(object, offset);
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
113 }
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
114 assert kind == Kind.Object;
11923
88fb9cba8751 Simplify handling of unsafe store and unsafe load.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11579
diff changeset
115 return (T) unsafe.getObject(object, offset);
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
116 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117 }