Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/GetClassNode.java @ 21678:7355942cb270
Improve lowering of the type check node.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Wed, 03 Jun 2015 01:10:18 +0200 |
parents | 48c1ebd24120 |
children |
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; |
21678
7355942cb270
Improve lowering of the type check node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21556
diff
changeset
|
51 assert ((ObjectStamp) object.stamp()).nonNull(); |
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
|
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 |
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 @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
|
55 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
|
56 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
|
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 |
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 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
|
60 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
|
61 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
|
62 |
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 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
|
64 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
|
65 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
|
66 } 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
|
67 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
|
68 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
|
69 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
|
70 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
|
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 |
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 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
|
75 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
|
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 } |
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 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
|
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 |
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 @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
|
82 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
|
83 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
|
84 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
|
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 |
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 @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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
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 } |
987b4c42aef9
add GetClassNode and use it in a non-HotSpot specific InvocationPlugin for Object.getClass()
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
95 } |