annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LoadMethodNode.java @ 16258:3a463b85b195

fix for LoadMethodNode
author Lukas Stadler <lukas.stadler@oracle.com>
date Thu, 26 Jun 2014 17:29:37 +0200
parents 24c30ecf930f
children 5d468add216f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
16258
3a463b85b195 fix for LoadMethodNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16219
diff changeset
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.nodes.extended;
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import com.oracle.graal.api.meta.*;
15261
882f4cb7cfcf Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 12045
diff changeset
26 import com.oracle.graal.compiler.common.type.*;
16183
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
27 import com.oracle.graal.graph.*;
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
28 import com.oracle.graal.graph.spi.*;
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.nodes.*;
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.nodes.spi.*;
16183
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
31 import com.oracle.graal.nodes.type.*;
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 /**
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 * Loads a method from the virtual method table of a given hub.
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 */
16183
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
36 public final class LoadMethodNode extends FixedWithNextNode implements Lowerable, Canonicalizable {
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 @Input private ValueNode hub;
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 private final ResolvedJavaMethod method;
15725
ef6b8d1898e6 Add resolved receiver type to ResolvedJavaMethod.isInVirtualMethodTable in order to be able to do vtable-calls for miranda and default methods
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15311
diff changeset
40 private final ResolvedJavaType receiverType;
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 public ValueNode getHub() {
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 return hub;
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 }
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45
15725
ef6b8d1898e6 Add resolved receiver type to ResolvedJavaMethod.isInVirtualMethodTable in order to be able to do vtable-calls for miranda and default methods
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15311
diff changeset
46 public LoadMethodNode(ResolvedJavaMethod method, ResolvedJavaType receiverType, ValueNode hub, Kind kind) {
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 super(kind == Kind.Object ? StampFactory.objectNonNull() : StampFactory.forKind(kind));
15725
ef6b8d1898e6 Add resolved receiver type to ResolvedJavaMethod.isInVirtualMethodTable in order to be able to do vtable-calls for miranda and default methods
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15311
diff changeset
48 this.receiverType = receiverType;
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 this.hub = hub;
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 this.method = method;
15311
820c6d353358 added ModifiersProvider as superinterface for ResolvedJava[Method|Field|Type] and implemented all checks against modifiers as default methods
Doug Simon <doug.simon@oracle.com>
parents: 15261
diff changeset
51 assert !method.isAbstract() : "Cannot load abstract method from a hub";
820c6d353358 added ModifiersProvider as superinterface for ResolvedJava[Method|Field|Type] and implemented all checks against modifiers as default methods
Doug Simon <doug.simon@oracle.com>
parents: 15261
diff changeset
52 assert !method.isStatic() : "Cannot load a static method from a hub";
15725
ef6b8d1898e6 Add resolved receiver type to ResolvedJavaMethod.isInVirtualMethodTable in order to be able to do vtable-calls for miranda and default methods
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15311
diff changeset
53 assert method.isInVirtualMethodTable(receiverType);
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 }
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 @Override
11579
ae619d70bf4b Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9610
diff changeset
57 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
58 tool.getLowerer().lower(this, tool);
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 }
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60
16183
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
61 @Override
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
62 public Node canonical(CanonicalizerTool tool) {
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
63 if (hub instanceof LoadHubNode) {
16219
24c30ecf930f rename object() to getValue() in LoadHubNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16183
diff changeset
64 ValueNode object = ((LoadHubNode) hub).getValue();
16183
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
65 ResolvedJavaType type = StampTool.typeOrNull(object);
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
66 if (StampTool.isExactType(object)) {
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
67 return resolveExactMethod(tool, type);
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
68 }
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
69 if (type != null && tool.assumptions().useOptimisticAssumptions()) {
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
70 ResolvedJavaMethod resolvedMethod = type.findUniqueConcreteMethod(method);
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
71 if (resolvedMethod != null && !type.isInterface() && method.getDeclaringClass().isAssignableFrom(type)) {
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
72 tool.assumptions().recordConcreteMethod(method, type, resolvedMethod);
16258
3a463b85b195 fix for LoadMethodNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16219
diff changeset
73 return ConstantNode.forConstant(resolvedMethod.getEncoding(), tool.getMetaAccess());
16183
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
74 }
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
75 }
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
76 }
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
77 if (hub.isConstant()) {
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
78 return resolveExactMethod(tool, tool.getConstantReflection().asJavaType(hub.asConstant()));
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
79 }
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
80
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
81 return this;
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
82 }
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
83
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
84 /**
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
85 * Find the method which would be loaded.
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
86 *
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
87 * @param tool
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
88 * @param type the exact type of object being loaded from
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
89 * @return the method which would be invoked for {@code type} or null if it doesn't implement
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
90 * the method
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
91 */
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
92 private Node resolveExactMethod(CanonicalizerTool tool, ResolvedJavaType type) {
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
93 ResolvedJavaMethod newMethod = type.resolveMethod(method, type);
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
94 if (newMethod == null) {
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
95 /*
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
96 * This really represent a misuse of LoadMethod since we're loading from a class which
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
97 * isn't known to implement the original method but for now at least fold it away.
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
98 */
16258
3a463b85b195 fix for LoadMethodNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16219
diff changeset
99 return ConstantNode.forConstant(Constant.NULL_OBJECT, null);
16183
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
100 } else {
16258
3a463b85b195 fix for LoadMethodNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16219
diff changeset
101 return ConstantNode.forConstant(newMethod.getEncoding(), tool.getMetaAccess());
16183
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
102 }
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
103 }
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15725
diff changeset
104
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105 public ResolvedJavaMethod getMethod() {
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 return method;
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 }
15725
ef6b8d1898e6 Add resolved receiver type to ResolvedJavaMethod.isInVirtualMethodTable in order to be able to do vtable-calls for miranda and default methods
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15311
diff changeset
108
ef6b8d1898e6 Add resolved receiver type to ResolvedJavaMethod.isInVirtualMethodTable in order to be able to do vtable-calls for miranda and default methods
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15311
diff changeset
109 public ResolvedJavaType getReceiverType() {
ef6b8d1898e6 Add resolved receiver type to ResolvedJavaMethod.isInVirtualMethodTable in order to be able to do vtable-calls for miranda and default methods
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15311
diff changeset
110 return receiverType;
ef6b8d1898e6 Add resolved receiver type to ResolvedJavaMethod.isInVirtualMethodTable in order to be able to do vtable-calls for miranda and default methods
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15311
diff changeset
111 }
9377
0f4041cc6be1 First draft of node for loading a method from the vtable of a hub.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
112 }