Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MethodHandleNode.java @ 19529:8fc336a04d77
Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 20 Feb 2015 22:22:55 +0100 |
parents | 61d3cb8e1280 |
children | 3362ba500371 |
rev | line source |
---|---|
9691 | 1 /* |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18998
diff
changeset
|
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
9691 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.graal.hotspot.replacements; | |
24 | |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
25 import java.lang.invoke.*; |
14022
2b5b3fcd65ba
Separate singleton stamp for the void type.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
26 import java.util.*; |
9691 | 27 |
14022
2b5b3fcd65ba
Separate singleton stamp for the void type.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
28 import com.oracle.graal.api.meta.*; |
18258
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
29 import com.oracle.graal.api.meta.MethodHandleAccessProvider.IntrinsicMethod; |
15193
96bb07a5d667
Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
30 import com.oracle.graal.compiler.common.*; |
15261
882f4cb7cfcf
Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15260
diff
changeset
|
31 import com.oracle.graal.compiler.common.type.*; |
14022
2b5b3fcd65ba
Separate singleton stamp for the void type.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
32 import com.oracle.graal.graph.*; |
11881
da9db8331658
moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11265
diff
changeset
|
33 import com.oracle.graal.graph.spi.*; |
16841
cbd42807a31f
moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents:
16811
diff
changeset
|
34 import com.oracle.graal.nodeinfo.*; |
14022
2b5b3fcd65ba
Separate singleton stamp for the void type.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
35 import com.oracle.graal.nodes.*; |
16563
1e63cb55f61d
Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16329
diff
changeset
|
36 import com.oracle.graal.nodes.CallTargetNode.InvokeKind; |
14022
2b5b3fcd65ba
Separate singleton stamp for the void type.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
37 import com.oracle.graal.nodes.java.*; |
11265 | 38 import com.oracle.graal.nodes.type.*; |
16252
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15481
diff
changeset
|
39 import com.oracle.graal.nodes.util.*; |
14022
2b5b3fcd65ba
Separate singleton stamp for the void type.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
40 import com.oracle.graal.replacements.nodes.*; |
9691 | 41 |
42 /** | |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
43 * Node for invocation methods defined on the class {@link MethodHandle}. |
9691 | 44 */ |
16811
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16563
diff
changeset
|
45 @NodeInfo |
18998
ec0733b5a90a
Allow final modifier on node subclasses and start adding the modifier to leaf classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
46 public final class MethodHandleNode extends MacroStateSplitNode implements Simplifiable { |
19529
8fc336a04d77
Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19410
diff
changeset
|
47 public static final NodeClass<MethodHandleNode> TYPE = NodeClass.create(MethodHandleNode.class); |
9691 | 48 |
49 // Replacement method data | |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
50 protected ResolvedJavaMethod replacementTargetMethod; |
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
51 protected JavaType replacementReturnType; |
16897
f90dcdbbb75e
switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents:
16895
diff
changeset
|
52 @Input NodeInputList<ValueNode> replacementArguments; |
9691 | 53 |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18571
diff
changeset
|
54 public MethodHandleNode(Invoke invoke) { |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18998
diff
changeset
|
55 super(TYPE, invoke); |
18571
b650870fe2fe
Backed out changeset: 3fb1231699de
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
18562
diff
changeset
|
56 MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget(); |
9691 | 57 // See if we need to save some replacement method data. |
58 if (callTarget instanceof SelfReplacingMethodCallTargetNode) { | |
59 SelfReplacingMethodCallTargetNode selfReplacingMethodCallTargetNode = (SelfReplacingMethodCallTargetNode) callTarget; | |
60 replacementTargetMethod = selfReplacingMethodCallTargetNode.replacementTargetMethod(); | |
61 replacementReturnType = selfReplacingMethodCallTargetNode.replacementReturnType(); | |
62 replacementArguments = selfReplacingMethodCallTargetNode.replacementArguments(); | |
63 } else { | |
64 // NodeInputList can't be null. | |
65 replacementArguments = new NodeInputList<>(this); | |
66 } | |
67 } | |
68 | |
69 /** | |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
70 * Returns the method handle method intrinsic identifier for the provided method, or |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
71 * {@code null} if the method is not a method that can be handled by this class. |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
72 */ |
18258
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
73 public static IntrinsicMethod lookupMethodHandleIntrinsic(ResolvedJavaMethod method, MethodHandleAccessProvider methodHandleAccess) { |
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
74 return methodHandleAccess.lookupMethodHandleIntrinsic(method); |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
75 } |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
76 |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
77 @Override |
16252
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15481
diff
changeset
|
78 public void simplify(SimplifierTool tool) { |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
79 InvokeNode invoke; |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18258
diff
changeset
|
80 IntrinsicMethod intrinsicMethod = lookupMethodHandleIntrinsic(targetMethod, tool.getConstantReflection().getMethodHandleAccess()); |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
81 switch (intrinsicMethod) { |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
82 case INVOKE_BASIC: |
18258
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
83 invoke = getInvokeBasicTarget(tool, intrinsicMethod); |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
84 break; |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
85 case LINK_TO_STATIC: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
86 case LINK_TO_SPECIAL: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
87 case LINK_TO_VIRTUAL: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
88 case LINK_TO_INTERFACE: |
18258
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
89 invoke = getLinkToTarget(tool, intrinsicMethod); |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
90 break; |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
91 default: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
92 throw GraalInternalError.shouldNotReachHere(); |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
93 } |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
94 if (invoke != null) { |
16897
f90dcdbbb75e
switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents:
16895
diff
changeset
|
95 FixedNode currentNext = next(); |
16252
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15481
diff
changeset
|
96 replaceAtUsages(invoke); |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15481
diff
changeset
|
97 GraphUtil.removeFixedWithUnusedInputs(this); |
16897
f90dcdbbb75e
switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents:
16895
diff
changeset
|
98 graph().addBeforeFixed(currentNext, invoke); |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
99 } |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
100 } |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
101 |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
102 /** |
9691 | 103 * Get the receiver of a MethodHandle.invokeBasic call. |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
104 * |
9691 | 105 * @return the receiver argument node |
106 */ | |
107 private ValueNode getReceiver() { | |
108 return arguments.first(); | |
109 } | |
110 | |
111 /** | |
112 * Get the MemberName argument of a MethodHandle.linkTo* call. | |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
113 * |
9691 | 114 * @return the MemberName argument node (which is the last argument) |
115 */ | |
116 private ValueNode getMemberName() { | |
117 return arguments.last(); | |
118 } | |
119 | |
120 /** | |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
121 * Used for the MethodHandle.invokeBasic method (the {@link IntrinsicMethod#INVOKE_BASIC } |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
122 * method) to get the target {@link InvokeNode} if the method handle receiver is constant. |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
123 * |
9691 | 124 * @return invoke node for the {@link java.lang.invoke.MethodHandle} target |
125 */ | |
18258
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
126 protected InvokeNode getInvokeBasicTarget(SimplifierTool tool, IntrinsicMethod intrinsicMethod) { |
9691 | 127 ValueNode methodHandleNode = getReceiver(); |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
128 if (methodHandleNode.isConstant()) { |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18258
diff
changeset
|
129 return getTargetInvokeNode(tool.getConstantReflection().getMethodHandleAccess().resolveInvokeBasicTarget(methodHandleNode.asJavaConstant(), false), intrinsicMethod); |
9691 | 130 } |
131 return null; | |
132 } | |
133 | |
134 /** | |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
135 * Used for the MethodHandle.linkTo* methods (the {@link IntrinsicMethod#LINK_TO_STATIC}, |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
136 * {@link IntrinsicMethod#LINK_TO_SPECIAL}, {@link IntrinsicMethod#LINK_TO_VIRTUAL}, and |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
137 * {@link IntrinsicMethod#LINK_TO_INTERFACE} methods) to get the target {@link InvokeNode} if |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
138 * the member name argument is constant. |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
139 * |
9691 | 140 * @return invoke node for the member name target |
141 */ | |
18258
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
142 protected InvokeNode getLinkToTarget(SimplifierTool tool, IntrinsicMethod intrinsicMethod) { |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
143 ValueNode memberNameNode = getMemberName(); |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
144 if (memberNameNode.isConstant()) { |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18258
diff
changeset
|
145 return getTargetInvokeNode(tool.getConstantReflection().getMethodHandleAccess().resolveLinkToTarget(memberNameNode.asJavaConstant()), intrinsicMethod); |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
146 } |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
147 return null; |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
148 } |
9691 | 149 |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
150 /** |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
151 * Helper function to get the {@link InvokeNode} for the targetMethod of a |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
152 * java.lang.invoke.MemberName. |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
153 * |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
154 * @param target the target, already loaded from the member name node |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
155 * @return invoke node for the member name target |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
156 */ |
18258
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
157 private InvokeNode getTargetInvokeNode(ResolvedJavaMethod target, IntrinsicMethod intrinsicMethod) { |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
158 if (target == null) { |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
159 return null; |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
160 } |
9691 | 161 |
13656
cd14eb248cec
get holder class from metaspace method when resolving MemberName target method; not necessarily the same as MemberName.clazz
Andreas Woess <andreas.woess@jku.at>
parents:
11881
diff
changeset
|
162 // In lambda forms we erase signature types to avoid resolving issues |
9691 | 163 // involving class loaders. When we optimize a method handle invoke |
164 // to a direct call we must cast the receiver and arguments to its | |
165 // actual types. | |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
166 Signature signature = target.getSignature(); |
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
167 final boolean isStatic = target.isStatic(); |
9691 | 168 final int receiverSkip = isStatic ? 0 : 1; |
169 | |
170 // Cast receiver to its type. | |
171 if (!isStatic) { | |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
172 JavaType receiverType = target.getDeclaringClass(); |
9691 | 173 maybeCastArgument(0, receiverType); |
174 } | |
175 | |
176 // Cast reference arguments to its type. | |
177 for (int index = 0; index < signature.getParameterCount(false); index++) { | |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
178 JavaType parameterType = signature.getParameterType(index, target.getDeclaringClass()); |
9691 | 179 maybeCastArgument(receiverSkip + index, parameterType); |
180 } | |
181 | |
182 // Try to get the most accurate receiver type | |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
183 if (intrinsicMethod == IntrinsicMethod.LINK_TO_VIRTUAL || intrinsicMethod == IntrinsicMethod.LINK_TO_INTERFACE) { |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
184 ResolvedJavaType receiverType = StampTool.typeOrNull(getReceiver().stamp()); |
9691 | 185 if (receiverType != null) { |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
186 ResolvedJavaMethod concreteMethod = receiverType.findUniqueConcreteMethod(target); |
9691 | 187 if (concreteMethod != null) { |
18258
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
188 return createTargetInvokeNode(concreteMethod, intrinsicMethod); |
9691 | 189 } |
190 } | |
191 } | |
192 | |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
193 if (target.canBeStaticallyBound()) { |
18258
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
194 return createTargetInvokeNode(target, intrinsicMethod); |
9691 | 195 } |
196 | |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
197 ResolvedJavaMethod concreteMethod = target.getDeclaringClass().findUniqueConcreteMethod(target); |
9691 | 198 if (concreteMethod != null) { |
18258
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
199 return createTargetInvokeNode(concreteMethod, intrinsicMethod); |
9691 | 200 } |
201 | |
202 return null; | |
203 } | |
204 | |
205 /** | |
206 * Inserts a node to cast the argument at index to the given type if the given type is more | |
207 * concrete than the argument type. | |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
208 * |
9691 | 209 * @param index of the argument to be cast |
210 * @param type the type the argument should be cast to | |
211 */ | |
212 private void maybeCastArgument(int index, JavaType type) { | |
213 if (type instanceof ResolvedJavaType) { | |
214 ResolvedJavaType targetType = (ResolvedJavaType) type; | |
215 if (!targetType.isPrimitive()) { | |
216 ValueNode argument = arguments.get(index); | |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
217 ResolvedJavaType argumentType = StampTool.typeOrNull(argument.stamp()); |
9691 | 218 if (argumentType == null || (argumentType.isAssignableFrom(targetType) && !argumentType.equals(targetType))) { |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18571
diff
changeset
|
219 PiNode piNode = graph().unique(new PiNode(argument, StampFactory.declared(targetType))); |
9691 | 220 arguments.set(index, piNode); |
221 } | |
222 } | |
223 } | |
224 } | |
225 | |
226 /** | |
227 * Creates an {@link InvokeNode} for the given target method. The {@link CallTargetNode} passed | |
228 * to the InvokeNode is in fact a {@link SelfReplacingMethodCallTargetNode}. | |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
229 * |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
230 * @param target the method to be called |
9691 | 231 * @return invoke node for the member name target |
232 */ | |
18258
6faee2dcebbf
moved MethodHandleAccessProvider to graal.api.meta and made it retrievable from MetaAccessProvider so that it does not need to be accessed via a global in MethodHandleNode (which is problematic for remote/replay compilation) (GRAAL-874)
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
233 private InvokeNode createTargetInvokeNode(ResolvedJavaMethod target, IntrinsicMethod intrinsicMethod) { |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
234 InvokeKind targetInvokeKind = target.isStatic() ? InvokeKind.Static : InvokeKind.Special; |
18571
b650870fe2fe
Backed out changeset: 3fb1231699de
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
18562
diff
changeset
|
235 JavaType targetReturnType = target.getSignature().getReturnType(null); |
9691 | 236 |
237 // MethodHandleLinkTo* nodes have a trailing MemberName argument which | |
238 // needs to be popped. | |
239 ValueNode[] originalArguments = arguments.toArray(new ValueNode[arguments.size()]); | |
240 ValueNode[] targetArguments; | |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
241 switch (intrinsicMethod) { |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
242 case INVOKE_BASIC: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
243 targetArguments = originalArguments; |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
244 break; |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
245 case LINK_TO_STATIC: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
246 case LINK_TO_SPECIAL: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
247 case LINK_TO_VIRTUAL: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
248 case LINK_TO_INTERFACE: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
249 targetArguments = Arrays.copyOfRange(originalArguments, 0, arguments.size() - 1); |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
250 break; |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
251 default: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
252 throw GraalInternalError.shouldNotReachHere(); |
9691 | 253 } |
254 | |
255 // If there is already replacement information, use that instead. | |
18571
b650870fe2fe
Backed out changeset: 3fb1231699de
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
18562
diff
changeset
|
256 MethodCallTargetNode callTarget; |
9691 | 257 if (replacementTargetMethod == null) { |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18571
diff
changeset
|
258 callTarget = new SelfReplacingMethodCallTargetNode(targetInvokeKind, target, targetArguments, targetReturnType, getTargetMethod(), originalArguments, getReturnType()); |
9691 | 259 } else { |
260 ValueNode[] args = replacementArguments.toArray(new ValueNode[replacementArguments.size()]); | |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18571
diff
changeset
|
261 callTarget = new SelfReplacingMethodCallTargetNode(targetInvokeKind, target, targetArguments, targetReturnType, replacementTargetMethod, args, replacementReturnType); |
9691 | 262 } |
9784
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
263 graph().add(callTarget); |
9691 | 264 |
9784
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
265 // The call target can have a different return type than the invoker, |
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
266 // e.g. the target returns an Object but the invoker void. In this case |
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
267 // we need to use the stamp of the invoker. Note: always using the |
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
268 // invoker's stamp would be wrong because it's a less concrete type |
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
269 // (usually java.lang.Object). |
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
270 InvokeNode invoke; |
14022
2b5b3fcd65ba
Separate singleton stamp for the void type.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
271 if (stamp() == StampFactory.forVoid()) { |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18571
diff
changeset
|
272 invoke = new InvokeNode(callTarget, getBci(), stamp()); |
9784
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
273 } else { |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18571
diff
changeset
|
274 invoke = new InvokeNode(callTarget, getBci()); |
9784
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
275 } |
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
276 graph().add(invoke); |
9691 | 277 invoke.setStateAfter(stateAfter()); |
278 return invoke; | |
279 } | |
280 | |
281 } |