Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadFieldNode.java @ 10817:2c9332a969d6
made it possible to use enum constants in snippets
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 19 Jul 2013 17:47:35 +0200 |
parents | eef9281ec13b |
children | 4da2141fc40f |
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.java; |
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.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
26 import com.oracle.graal.graph.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
27 import com.oracle.graal.nodes.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
28 import com.oracle.graal.nodes.spi.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
29 import com.oracle.graal.nodes.type.*; |
6710
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
30 import com.oracle.graal.nodes.virtual.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 |
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 * The {@code LoadFieldNode} represents a read of a static or instance field. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 */ |
5814
d241f8b2e6f9
Adapt the coloring filter for binary dumped graphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5758
diff
changeset
|
35 @NodeInfo(nameTemplate = "LoadField#{p#field/s}") |
9755
432b8405e056
small refactoring of early read elimination (move logic into "virtualize" methods)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7660
diff
changeset
|
36 public final class LoadFieldNode extends AccessFieldNode implements Canonicalizable, Node.IterableNodeType, VirtualizableRoot { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 |
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 * Creates a new LoadFieldNode instance. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7394
diff
changeset
|
40 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 * @param object the receiver object |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 * @param field the compiler interface field |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 */ |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
44 public LoadFieldNode(ValueNode object, ResolvedJavaField field) { |
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
45 super(createStamp(field), object, field); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 |
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
|
48 private static Stamp createStamp(ResolvedJavaField field) { |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5814
diff
changeset
|
49 Kind kind = field.getKind(); |
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5814
diff
changeset
|
50 if (kind == Kind.Object && field.getType() instanceof ResolvedJavaType) { |
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5814
diff
changeset
|
51 return StampFactory.declared((ResolvedJavaType) field.getType()); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 } else { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 return StampFactory.forKind(kind); |
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 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 @Override |
4309
4a609a685fa4
changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents:
4199
diff
changeset
|
58 public ValueNode canonical(CanonicalizerTool tool) { |
5755
12e5956a8fdd
Use MetaAccessProvider instead of CodeCacheProvider wherever possible.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5572
diff
changeset
|
59 MetaAccessProvider runtime = tool.runtime(); |
10817
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
60 if (tool.canonicalizeReads()) { |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
61 ConstantNode constant = asConstant(runtime); |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
62 if (constant != null) { |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
63 return constant; |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
64 } |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
65 } |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
66 return this; |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
67 } |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
68 |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
69 /** |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
70 * Gets a constant value for this load if possible. |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
71 */ |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
72 public ConstantNode asConstant(MetaAccessProvider runtime) { |
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
73 if (runtime != null) { |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5531
diff
changeset
|
74 Constant constant = null; |
5473
c73882b7db10
runtime may be null in the canonicalizer (like target or assumptions)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5443
diff
changeset
|
75 if (isStatic()) { |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5814
diff
changeset
|
76 constant = field().readConstantValue(null); |
5473
c73882b7db10
runtime may be null in the canonicalizer (like target or assumptions)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5443
diff
changeset
|
77 } else if (object().isConstant() && !object().isNullConstant()) { |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
5814
diff
changeset
|
78 constant = field().readConstantValue(object().asConstant()); |
5473
c73882b7db10
runtime may be null in the canonicalizer (like target or assumptions)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5443
diff
changeset
|
79 } |
c73882b7db10
runtime may be null in the canonicalizer (like target or assumptions)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5443
diff
changeset
|
80 if (constant != null) { |
5572
8f9c9d372e31
small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents:
5541
diff
changeset
|
81 return ConstantNode.forConstant(constant, runtime, graph()); |
5473
c73882b7db10
runtime may be null in the canonicalizer (like target or assumptions)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5443
diff
changeset
|
82 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
83 } |
10817
2c9332a969d6
made it possible to use enum constants in snippets
Doug Simon <doug.simon@oracle.com>
parents:
9944
diff
changeset
|
84 return null; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
85 } |
6710
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
86 |
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
87 @Override |
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
88 public void virtualize(VirtualizerTool tool) { |
7394
94f032472c28
changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents:
6710
diff
changeset
|
89 State state = tool.getObjectState(object()); |
94f032472c28
changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents:
6710
diff
changeset
|
90 if (state != null && state.getState() == EscapeState.Virtual) { |
94f032472c28
changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents:
6710
diff
changeset
|
91 int fieldIndex = ((VirtualInstanceNode) state.getVirtualObject()).fieldIndex(field()); |
6710
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
92 if (fieldIndex != -1) { |
7394
94f032472c28
changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents:
6710
diff
changeset
|
93 tool.replaceWith(state.getEntry(fieldIndex)); |
6710
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
94 } |
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
95 } |
6db6881c1270
add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents:
6539
diff
changeset
|
96 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
97 } |