43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
|
|
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 org.graalvm.compiler.nodes;
|
|
24 |
|
46509
|
25 |
import jdk.vm.ci.meta.JavaKind;
|
46551
|
26 |
|
43972
|
27 |
import org.graalvm.compiler.core.common.type.Stamp;
|
|
28 |
import org.graalvm.compiler.graph.Node;
|
|
29 |
import org.graalvm.compiler.graph.NodeClass;
|
|
30 |
import org.graalvm.compiler.nodeinfo.InputType;
|
46393
|
31 |
import org.graalvm.compiler.nodeinfo.NodeCycles;
|
43972
|
32 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
46393
|
33 |
import org.graalvm.compiler.nodeinfo.NodeSize;
|
43972
|
34 |
import org.graalvm.compiler.nodeinfo.Verbosity;
|
|
35 |
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
|
|
36 |
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
|
|
37 |
import org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint;
|
|
38 |
import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
|
|
39 |
import org.graalvm.compiler.nodes.spi.LIRLowerable;
|
|
40 |
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
|
41 |
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
|
|
42 |
import org.graalvm.compiler.nodes.spi.UncheckedInterfaceProvider;
|
|
43 |
import org.graalvm.compiler.nodes.util.GraphUtil;
|
49873
|
44 |
import jdk.internal.vm.compiler.word.LocationIdentity;
|
43972
|
45 |
|
46509
|
46 |
import java.util.Map;
|
|
47 |
|
|
48 |
import static org.graalvm.compiler.nodeinfo.InputType.Extension;
|
|
49 |
import static org.graalvm.compiler.nodeinfo.InputType.Memory;
|
|
50 |
import static org.graalvm.compiler.nodeinfo.InputType.State;
|
|
51 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_2;
|
|
52 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_64;
|
|
53 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_8;
|
|
54 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_UNKNOWN;
|
|
55 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_2;
|
|
56 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_64;
|
|
57 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_8;
|
|
58 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_UNKNOWN;
|
43972
|
59 |
|
|
60 |
/**
|
|
61 |
* The {@code InvokeNode} represents all kinds of method calls.
|
|
62 |
*/
|
|
63 |
// @formatter:off
|
|
64 |
@NodeInfo(nameTemplate = "Invoke#{p#targetMethod/s}",
|
|
65 |
allowedUsageTypes = {Memory},
|
|
66 |
cycles = CYCLES_UNKNOWN,
|
|
67 |
cyclesRationale = "We cannot estimate the runtime cost of a call, it is a blackhole." +
|
|
68 |
"However, we can estimate, dyanmically, the cost of the call operation itself based on the type of the call.",
|
|
69 |
size = SIZE_UNKNOWN,
|
|
70 |
sizeRationale = "We can only dyanmically, based on the type of the call (special, static, virtual, interface) decide" +
|
|
71 |
"how much code is generated for the call.")
|
|
72 |
// @formatter:on
|
|
73 |
public final class InvokeNode extends AbstractMemoryCheckpoint implements Invoke, LIRLowerable, MemoryCheckpoint.Single, UncheckedInterfaceProvider {
|
|
74 |
public static final NodeClass<InvokeNode> TYPE = NodeClass.create(InvokeNode.class);
|
|
75 |
|
|
76 |
@OptionalInput ValueNode classInit;
|
|
77 |
@Input(Extension) CallTargetNode callTarget;
|
|
78 |
@OptionalInput(State) FrameState stateDuring;
|
|
79 |
protected final int bci;
|
|
80 |
protected boolean polymorphic;
|
|
81 |
protected boolean useForInlining;
|
|
82 |
|
|
83 |
public InvokeNode(CallTargetNode callTarget, int bci) {
|
|
84 |
this(callTarget, bci, callTarget.returnStamp().getTrustedStamp());
|
|
85 |
}
|
|
86 |
|
|
87 |
public InvokeNode(CallTargetNode callTarget, int bci, Stamp stamp) {
|
|
88 |
super(TYPE, stamp);
|
|
89 |
this.callTarget = callTarget;
|
|
90 |
this.bci = bci;
|
|
91 |
this.polymorphic = false;
|
|
92 |
this.useForInlining = true;
|
|
93 |
}
|
|
94 |
|
|
95 |
@Override
|
49451
|
96 |
protected void afterClone(Node other) {
|
|
97 |
updateInliningLogAfterClone(other);
|
|
98 |
}
|
|
99 |
|
|
100 |
@Override
|
|
101 |
public FixedNode asFixedNode() {
|
|
102 |
return this;
|
|
103 |
}
|
|
104 |
|
|
105 |
@Override
|
43972
|
106 |
public CallTargetNode callTarget() {
|
|
107 |
return callTarget;
|
|
108 |
}
|
|
109 |
|
|
110 |
void setCallTarget(CallTargetNode callTarget) {
|
|
111 |
updateUsages(this.callTarget, callTarget);
|
|
112 |
this.callTarget = callTarget;
|
|
113 |
}
|
|
114 |
|
|
115 |
@Override
|
|
116 |
public boolean isPolymorphic() {
|
|
117 |
return polymorphic;
|
|
118 |
}
|
|
119 |
|
|
120 |
@Override
|
|
121 |
public void setPolymorphic(boolean value) {
|
|
122 |
this.polymorphic = value;
|
|
123 |
}
|
|
124 |
|
|
125 |
@Override
|
|
126 |
public boolean useForInlining() {
|
|
127 |
return useForInlining;
|
|
128 |
}
|
|
129 |
|
|
130 |
@Override
|
|
131 |
public void setUseForInlining(boolean value) {
|
|
132 |
this.useForInlining = value;
|
|
133 |
}
|
|
134 |
|
|
135 |
@Override
|
|
136 |
public boolean isAllowedUsageType(InputType type) {
|
|
137 |
if (!super.isAllowedUsageType(type)) {
|
|
138 |
if (getStackKind() != JavaKind.Void) {
|
|
139 |
if (callTarget instanceof MethodCallTargetNode && ((MethodCallTargetNode) callTarget).targetMethod().getAnnotation(NodeIntrinsic.class) != null) {
|
|
140 |
return true;
|
|
141 |
}
|
|
142 |
}
|
|
143 |
return false;
|
|
144 |
}
|
|
145 |
return true;
|
|
146 |
}
|
|
147 |
|
|
148 |
@Override
|
|
149 |
public Map<Object, Object> getDebugProperties(Map<Object, Object> map) {
|
|
150 |
Map<Object, Object> debugProperties = super.getDebugProperties(map);
|
|
151 |
if (callTarget != null) {
|
|
152 |
debugProperties.put("targetMethod", callTarget.targetName());
|
|
153 |
}
|
|
154 |
return debugProperties;
|
|
155 |
}
|
|
156 |
|
|
157 |
@Override
|
|
158 |
public LocationIdentity getLocationIdentity() {
|
|
159 |
return LocationIdentity.any();
|
|
160 |
}
|
|
161 |
|
|
162 |
@Override
|
|
163 |
public void lower(LoweringTool tool) {
|
|
164 |
tool.getLowerer().lower(this, tool);
|
|
165 |
}
|
|
166 |
|
|
167 |
@Override
|
|
168 |
public void generate(NodeLIRBuilderTool gen) {
|
|
169 |
gen.emitInvoke(this);
|
|
170 |
}
|
|
171 |
|
|
172 |
@Override
|
|
173 |
public String toString(Verbosity verbosity) {
|
|
174 |
if (verbosity == Verbosity.Long) {
|
|
175 |
return super.toString(Verbosity.Short) + "(bci=" + bci() + ")";
|
|
176 |
} else if (verbosity == Verbosity.Name) {
|
|
177 |
return "Invoke#" + (callTarget == null ? "null" : callTarget().targetName());
|
|
178 |
} else {
|
|
179 |
return super.toString(verbosity);
|
|
180 |
}
|
|
181 |
}
|
|
182 |
|
|
183 |
@Override
|
|
184 |
public int bci() {
|
|
185 |
return bci;
|
|
186 |
}
|
|
187 |
|
|
188 |
@Override
|
|
189 |
public void intrinsify(Node node) {
|
|
190 |
assert !(node instanceof ValueNode) || node.isAllowedUsageType(InputType.Value) == isAllowedUsageType(InputType.Value) : "replacing " + this + " with " + node;
|
|
191 |
CallTargetNode call = callTarget;
|
|
192 |
FrameState currentStateAfter = stateAfter();
|
|
193 |
if (node instanceof StateSplit) {
|
|
194 |
StateSplit stateSplit = (StateSplit) node;
|
|
195 |
stateSplit.setStateAfter(currentStateAfter);
|
|
196 |
}
|
|
197 |
if (node instanceof ForeignCallNode) {
|
|
198 |
ForeignCallNode foreign = (ForeignCallNode) node;
|
|
199 |
foreign.setBci(bci());
|
|
200 |
}
|
|
201 |
if (node instanceof FixedWithNextNode) {
|
|
202 |
graph().replaceFixedWithFixed(this, (FixedWithNextNode) node);
|
|
203 |
} else if (node instanceof ControlSinkNode) {
|
|
204 |
this.replaceAtPredecessor(node);
|
|
205 |
this.replaceAtUsages(null);
|
|
206 |
GraphUtil.killCFG(this);
|
|
207 |
return;
|
|
208 |
} else {
|
|
209 |
graph().replaceFixed(this, node);
|
|
210 |
}
|
|
211 |
GraphUtil.killWithUnusedFloatingInputs(call);
|
|
212 |
if (currentStateAfter.hasNoUsages()) {
|
|
213 |
GraphUtil.killWithUnusedFloatingInputs(currentStateAfter);
|
|
214 |
}
|
|
215 |
}
|
|
216 |
|
|
217 |
@Override
|
|
218 |
public boolean canDeoptimize() {
|
|
219 |
return true;
|
|
220 |
}
|
|
221 |
|
|
222 |
@Override
|
|
223 |
public FrameState stateDuring() {
|
|
224 |
return stateDuring;
|
|
225 |
}
|
|
226 |
|
|
227 |
@Override
|
|
228 |
public void setStateDuring(FrameState stateDuring) {
|
|
229 |
updateUsages(this.stateDuring, stateDuring);
|
|
230 |
this.stateDuring = stateDuring;
|
|
231 |
}
|
|
232 |
|
|
233 |
@Override
|
|
234 |
public Stamp uncheckedStamp() {
|
|
235 |
return this.callTarget.returnStamp().getUncheckedStamp();
|
|
236 |
}
|
|
237 |
|
|
238 |
@Override
|
|
239 |
public void setClassInit(ValueNode classInit) {
|
|
240 |
this.classInit = classInit;
|
|
241 |
updateUsages(null, classInit);
|
|
242 |
}
|
|
243 |
|
|
244 |
@Override
|
|
245 |
public ValueNode classInit() {
|
|
246 |
return classInit;
|
|
247 |
}
|
46393
|
248 |
|
|
249 |
@Override
|
|
250 |
public NodeCycles estimatedNodeCycles() {
|
|
251 |
switch (callTarget().invokeKind()) {
|
|
252 |
case Interface:
|
|
253 |
return CYCLES_64;
|
|
254 |
case Special:
|
|
255 |
case Static:
|
|
256 |
return CYCLES_2;
|
|
257 |
case Virtual:
|
|
258 |
return CYCLES_8;
|
|
259 |
default:
|
|
260 |
return CYCLES_UNKNOWN;
|
|
261 |
}
|
|
262 |
}
|
|
263 |
|
|
264 |
@Override
|
|
265 |
public NodeSize estimatedNodeSize() {
|
|
266 |
switch (callTarget().invokeKind()) {
|
|
267 |
case Interface:
|
|
268 |
return SIZE_64;
|
|
269 |
case Special:
|
|
270 |
case Static:
|
|
271 |
return SIZE_2;
|
|
272 |
case Virtual:
|
|
273 |
return SIZE_8;
|
|
274 |
default:
|
|
275 |
return SIZE_UNKNOWN;
|
|
276 |
}
|
|
277 |
}
|
43972
|
278 |
}
|