Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/GetClassNode.java @ 21556:48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 27 May 2015 00:36:16 +0200 |
parents | 987b4c42aef9 |
children | 7355942cb270 |
rev | line source |
---|---|
20135
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.nodes.extended; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 import com.oracle.graal.compiler.common.type.*; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 import com.oracle.graal.graph.*; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.graal.graph.spi.*; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.nodeinfo.*; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.graal.nodes.*; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.nodes.calc.*; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.nodes.spi.*; |
21556
48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
20135
diff
changeset
|
32 import com.oracle.jvmci.meta.Assumptions.AssumptionResult; |
48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
20135
diff
changeset
|
33 import com.oracle.jvmci.meta.*; |
20135
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 /** |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 * Loads an object's class (i.e., this node can be created for {@code object.getClass()}). |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 */ |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 @NodeInfo |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 public final class GetClassNode extends FloatingNode implements Lowerable, Canonicalizable, Virtualizable { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 public static final NodeClass<GetClassNode> TYPE = NodeClass.create(GetClassNode.class); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 @Input ValueNode object; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
43 |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 public ValueNode getObject() { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 return object; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 public GetClassNode(Stamp stamp, ValueNode object) { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 super(TYPE, stamp); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 this.object = object; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 @Override |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 public void lower(LoweringTool tool) { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 tool.getLowerer().lower(this, tool); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 public static ValueNode tryFold(MetaAccessProvider metaAccess, ValueNode object) { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 if (metaAccess != null && object != null && object.stamp() instanceof ObjectStamp) { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 ObjectStamp objectStamp = (ObjectStamp) object.stamp(); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
62 ResolvedJavaType exactType = null; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 if (objectStamp.isExactType()) { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 exactType = objectStamp.type(); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 } else if (objectStamp.type() != null && object.graph().getAssumptions() != null) { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 AssumptionResult<ResolvedJavaType> leafConcreteSubtype = objectStamp.type().findLeafConcreteSubtype(); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 if (leafConcreteSubtype != null) { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 exactType = leafConcreteSubtype.getResult(); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 object.graph().getAssumptions().record(leafConcreteSubtype); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 if (exactType != null) { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 return ConstantNode.forConstant(exactType.getJavaClass(), metaAccess); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 return null; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 @Override |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 public ValueNode canonical(CanonicalizerTool tool) { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 ValueNode folded = tryFold(tool.getMetaAccess(), getObject()); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 return folded == null ? this : folded; |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 @Override |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 public void virtualize(VirtualizerTool tool) { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 State state = tool.getObjectState(object); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 if (state != null) { |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
90 Constant javaClass = state.getVirtualObject().type().getJavaClass(); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
91 tool.replaceWithValue(ConstantNode.forConstant(stamp(), javaClass, tool.getMetaAccessProvider(), graph())); |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 } |