Mercurial > hg > truffle
annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MethodHandleNode.java @ 21522:28cbfacd0518
Merge
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Thu, 28 May 2015 17:44:05 +0200 |
parents | graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MethodHandleNode.java@5ea03a00828a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MethodHandleNode.java@331da25c2dda |
children | 47bebae7454f |
rev | line source |
---|---|
9691 | 1 /* |
19396
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 */ | |
21396
331da25c2dda
Make support for method handles VM independent
Christian Wimmer <christian.wimmer@oracle.com>
parents:
20089
diff
changeset
|
23 package com.oracle.graal.replacements.nodes; |
9691 | 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.*; |
19795
3362ba500371
Connect required Assumptions with answer to CHA query
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19526
diff
changeset
|
29 import com.oracle.graal.api.meta.Assumptions.AssumptionResult; |
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
|
30 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
|
31 import com.oracle.graal.compiler.common.*; |
15261
882f4cb7cfcf
Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15260
diff
changeset
|
32 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
|
33 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
|
34 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:
16822
diff
changeset
|
35 import com.oracle.graal.nodeinfo.*; |
14022
2b5b3fcd65ba
Separate singleton stamp for the void type.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
36 import com.oracle.graal.nodes.*; |
16563
1e63cb55f61d
Move InvokeKind from MethodCallTargetNode to CallTargetNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16329
diff
changeset
|
37 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
|
38 import com.oracle.graal.nodes.java.*; |
11265 | 39 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
|
40 import com.oracle.graal.nodes.util.*; |
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 */ |
16822
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 { |
19526
8fc336a04d77
Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19403
diff
changeset
|
47 public static final NodeClass<MethodHandleNode> TYPE = NodeClass.create(MethodHandleNode.class); |
9691 | 48 |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
49 protected final IntrinsicMethod intrinsicMethod; |
9691 | 50 |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
51 public MethodHandleNode(IntrinsicMethod intrinsicMethod, InvokeKind invokeKind, ResolvedJavaMethod targetMethod, int bci, JavaType returnType, ValueNode... arguments) { |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
52 super(TYPE, invokeKind, targetMethod, bci, returnType, arguments); |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
53 this.intrinsicMethod = intrinsicMethod; |
9691 | 54 } |
55 | |
56 /** | |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
57 * Attempts to transform application of an intrinsifiable {@link MethodHandle} method into an |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
58 * invocation on another method with possibly transformed arguments. |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
59 * |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
60 * @param assumptions object for recording any speculations made during the transformation |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
61 * @param methodHandleAccess objects for accessing the implementation internals of a |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
62 * {@link MethodHandle} |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
63 * @param intrinsicMethod denotes the intrinsifiable {@link MethodHandle} method being processed |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
64 * @param bci the BCI of the original {@link MethodHandle} call |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
65 * @param returnType return type of the original {@link MethodHandle} call |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
66 * @param arguments arguments to the original {@link MethodHandle} call |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
67 * @return a more direct invocation derived from the {@link MethodHandle} call or null |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
68 */ |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
69 public static InvokeNode tryResolveTargetInvoke(Assumptions assumptions, MethodHandleAccessProvider methodHandleAccess, IntrinsicMethod intrinsicMethod, ResolvedJavaMethod original, int bci, |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
70 JavaType returnType, ValueNode... arguments) { |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
71 switch (intrinsicMethod) { |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
72 case INVOKE_BASIC: |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
73 return getInvokeBasicTarget(assumptions, intrinsicMethod, methodHandleAccess, original, bci, returnType, arguments); |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
74 case LINK_TO_STATIC: |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
75 case LINK_TO_SPECIAL: |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
76 case LINK_TO_VIRTUAL: |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
77 case LINK_TO_INTERFACE: |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
78 return getLinkToTarget(assumptions, intrinsicMethod, methodHandleAccess, original, bci, returnType, arguments); |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
79 default: |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
80 throw GraalInternalError.shouldNotReachHere(); |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
81 } |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
82 } |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
83 |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
84 @Override |
16252
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15481
diff
changeset
|
85 public void simplify(SimplifierTool tool) { |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
86 MethodHandleAccessProvider methodHandleAccess = tool.getConstantReflection().getMethodHandleAccess(); |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
87 ValueNode[] argumentsArray = arguments.toArray(new ValueNode[arguments.size()]); |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
88 InvokeNode invoke = tryResolveTargetInvoke(graph().getAssumptions(), methodHandleAccess, intrinsicMethod, targetMethod, bci, returnType, argumentsArray); |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
89 if (invoke != null) { |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
90 assert invoke.graph() == null; |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
91 invoke = graph().addOrUniqueWithInputs(invoke); |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
92 invoke.setStateAfter(stateAfter()); |
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
|
93 FixedNode currentNext = next(); |
16252
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15481
diff
changeset
|
94 replaceAtUsages(invoke); |
a762ddb12b43
change some node types from Canonicalizable to Simplifiable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15481
diff
changeset
|
95 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
|
96 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
|
97 } |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
98 } |
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 /** |
9691 | 101 * 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
|
102 * |
9691 | 103 * @return the receiver argument node |
104 */ | |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
105 private static ValueNode getReceiver(ValueNode[] arguments) { |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
106 return arguments[0]; |
9691 | 107 } |
108 | |
109 /** | |
110 * 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
|
111 * |
9691 | 112 * @return the MemberName argument node (which is the last argument) |
113 */ | |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
114 private static ValueNode getMemberName(ValueNode[] arguments) { |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
115 return arguments[arguments.length - 1]; |
9691 | 116 } |
117 | |
118 /** | |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
119 * 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
|
120 * 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
|
121 * |
9691 | 122 * @return invoke node for the {@link java.lang.invoke.MethodHandle} target |
123 */ | |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
124 private static InvokeNode getInvokeBasicTarget(Assumptions assumptions, IntrinsicMethod intrinsicMethod, MethodHandleAccessProvider methodHandleAccess, ResolvedJavaMethod original, int bci, |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
125 JavaType returnType, ValueNode[] arguments) { |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
126 ValueNode methodHandleNode = getReceiver(arguments); |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
127 if (methodHandleNode.isConstant()) { |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
128 return getTargetInvokeNode(assumptions, intrinsicMethod, bci, returnType, arguments, methodHandleAccess.resolveInvokeBasicTarget(methodHandleNode.asJavaConstant(), true), original); |
9691 | 129 } |
130 return null; | |
131 } | |
132 | |
133 /** | |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
134 * 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
|
135 * {@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
|
136 * {@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
|
137 * 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
|
138 * |
9691 | 139 * @return invoke node for the member name target |
140 */ | |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
141 private static InvokeNode getLinkToTarget(Assumptions assumptions, IntrinsicMethod intrinsicMethod, MethodHandleAccessProvider methodHandleAccess, ResolvedJavaMethod original, int bci, |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
142 JavaType returnType, ValueNode[] arguments) { |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
143 ValueNode memberNameNode = getMemberName(arguments); |
15481
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()) { |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
145 return getTargetInvokeNode(assumptions, intrinsicMethod, bci, returnType, arguments, methodHandleAccess.resolveLinkToTarget(memberNameNode.asJavaConstant()), original); |
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 */ |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
157 private static InvokeNode getTargetInvokeNode(Assumptions assumptions, IntrinsicMethod intrinsicMethod, int bci, JavaType returnType, ValueNode[] arguments, ResolvedJavaMethod target, |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
158 ResolvedJavaMethod original) { |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
159 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
|
160 return null; |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
161 } |
9691 | 162 |
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
|
163 // In lambda forms we erase signature types to avoid resolving issues |
9691 | 164 // involving class loaders. When we optimize a method handle invoke |
165 // to a direct call we must cast the receiver and arguments to its | |
166 // actual types. | |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
167 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
|
168 final boolean isStatic = target.isStatic(); |
9691 | 169 final int receiverSkip = isStatic ? 0 : 1; |
170 | |
171 // Cast receiver to its type. | |
172 if (!isStatic) { | |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
173 JavaType receiverType = target.getDeclaringClass(); |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
174 maybeCastArgument(arguments, 0, receiverType); |
9691 | 175 } |
176 | |
177 // Cast reference arguments to its type. | |
178 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
|
179 JavaType parameterType = signature.getParameterType(index, target.getDeclaringClass()); |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
180 maybeCastArgument(arguments, receiverSkip + index, parameterType); |
9691 | 181 } |
182 | |
19891
aa66d0a6f9dc
MethodHandleNode: record unique concrete method assumptions
Andreas Woess <andreas.woess@oracle.com>
parents:
19795
diff
changeset
|
183 if (target.canBeStaticallyBound()) { |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
184 return createTargetInvokeNode(intrinsicMethod, target, original, bci, returnType, arguments); |
19891
aa66d0a6f9dc
MethodHandleNode: record unique concrete method assumptions
Andreas Woess <andreas.woess@oracle.com>
parents:
19795
diff
changeset
|
185 } |
aa66d0a6f9dc
MethodHandleNode: record unique concrete method assumptions
Andreas Woess <andreas.woess@oracle.com>
parents:
19795
diff
changeset
|
186 |
9691 | 187 // 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
|
188 if (intrinsicMethod == IntrinsicMethod.LINK_TO_VIRTUAL || intrinsicMethod == IntrinsicMethod.LINK_TO_INTERFACE) { |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
189 ValueNode receiver = getReceiver(arguments); |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
190 ResolvedJavaType receiverType = StampTool.typeOrNull(receiver.stamp()); |
9691 | 191 if (receiverType != null) { |
19795
3362ba500371
Connect required Assumptions with answer to CHA query
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19526
diff
changeset
|
192 AssumptionResult<ResolvedJavaMethod> concreteMethod = receiverType.findUniqueConcreteMethod(target); |
9691 | 193 if (concreteMethod != null) { |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
194 assumptions.record(concreteMethod); |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
195 return createTargetInvokeNode(intrinsicMethod, concreteMethod.getResult(), original, bci, returnType, arguments); |
9691 | 196 } |
197 } | |
19891
aa66d0a6f9dc
MethodHandleNode: record unique concrete method assumptions
Andreas Woess <andreas.woess@oracle.com>
parents:
19795
diff
changeset
|
198 } else { |
aa66d0a6f9dc
MethodHandleNode: record unique concrete method assumptions
Andreas Woess <andreas.woess@oracle.com>
parents:
19795
diff
changeset
|
199 AssumptionResult<ResolvedJavaMethod> concreteMethod = target.getDeclaringClass().findUniqueConcreteMethod(target); |
aa66d0a6f9dc
MethodHandleNode: record unique concrete method assumptions
Andreas Woess <andreas.woess@oracle.com>
parents:
19795
diff
changeset
|
200 if (concreteMethod != null) { |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
201 assumptions.record(concreteMethod); |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
202 return createTargetInvokeNode(intrinsicMethod, concreteMethod.getResult(), original, bci, returnType, arguments); |
19891
aa66d0a6f9dc
MethodHandleNode: record unique concrete method assumptions
Andreas Woess <andreas.woess@oracle.com>
parents:
19795
diff
changeset
|
203 } |
9691 | 204 } |
205 | |
206 return null; | |
207 } | |
208 | |
209 /** | |
210 * Inserts a node to cast the argument at index to the given type if the given type is more | |
211 * concrete than the argument type. | |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
212 * |
9691 | 213 * @param index of the argument to be cast |
214 * @param type the type the argument should be cast to | |
215 */ | |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
216 private static void maybeCastArgument(ValueNode[] arguments, int index, JavaType type) { |
9691 | 217 if (type instanceof ResolvedJavaType) { |
218 ResolvedJavaType targetType = (ResolvedJavaType) type; | |
219 if (!targetType.isPrimitive()) { | |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
220 ValueNode argument = arguments[index]; |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
221 ResolvedJavaType argumentType = StampTool.typeOrNull(argument.stamp()); |
9691 | 222 if (argumentType == null || (argumentType.isAssignableFrom(targetType) && !argumentType.equals(targetType))) { |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
223 PiNode piNode = new PiNode(argument, StampFactory.declared(targetType)); |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
224 arguments[index] = piNode; |
9691 | 225 } |
226 } | |
227 } | |
228 } | |
229 | |
230 /** | |
231 * Creates an {@link InvokeNode} for the given target method. The {@link CallTargetNode} passed | |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
232 * to the InvokeNode is in fact a {@link ResolvedMethodHandleCallTargetNode}. |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
233 * |
9691 | 234 * @return invoke node for the member name target |
235 */ | |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
236 private static InvokeNode createTargetInvokeNode(IntrinsicMethod intrinsicMethod, ResolvedJavaMethod target, ResolvedJavaMethod original, int bci, JavaType returnType, ValueNode[] arguments) { |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
237 InvokeKind targetInvokeKind = target.isStatic() ? InvokeKind.Static : InvokeKind.Special; |
18566
b650870fe2fe
Backed out changeset: 3fb1231699de
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
18551
diff
changeset
|
238 JavaType targetReturnType = target.getSignature().getReturnType(null); |
9691 | 239 |
240 // MethodHandleLinkTo* nodes have a trailing MemberName argument which | |
241 // needs to be popped. | |
242 ValueNode[] targetArguments; | |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
243 switch (intrinsicMethod) { |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
244 case INVOKE_BASIC: |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
245 targetArguments = arguments; |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
246 break; |
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_STATIC: |
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_SPECIAL: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
249 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
|
250 case LINK_TO_INTERFACE: |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
251 targetArguments = Arrays.copyOfRange(arguments, 0, arguments.length - 1); |
15481
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
252 break; |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
253 default: |
09d721bcffe2
Introduce API for lookup of VM-internals of method handles
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
254 throw GraalInternalError.shouldNotReachHere(); |
9691 | 255 } |
256 | |
20089
5ea03a00828a
allow direct call derived from constant MethodHandle if JDK version >= 1.8.0_60
Doug Simon <doug.simon@oracle.com>
parents:
20045
diff
changeset
|
257 MethodCallTargetNode callTarget = ResolvedMethodHandleCallTargetNode.create(targetInvokeKind, target, targetArguments, targetReturnType, original, arguments, returnType); |
9691 | 258 |
9784
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
259 // 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
|
260 // 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
|
261 // 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
|
262 // 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
|
263 // (usually java.lang.Object). |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
264 if (returnType.getKind() == Kind.Void) { |
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
265 return new InvokeNode(callTarget, bci, StampFactory.forVoid()); |
9784
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
266 } else { |
20045
8470e81631f8
converted all @MacroSubstitution uses to InvocationPlugins
Doug Simon <doug.simon@oracle.com>
parents:
19891
diff
changeset
|
267 return new InvokeNode(callTarget, bci); |
9784
747b2517feae
use invoker's stamp if target's return stamp is of different type
twisti
parents:
9715
diff
changeset
|
268 } |
9691 | 269 } |
270 } |