43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, 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.replacements;
|
|
24 |
|
|
25 |
import static org.graalvm.compiler.debug.GraalError.unimplemented;
|
|
26 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED;
|
|
27 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED;
|
|
28 |
|
|
29 |
import java.util.ArrayList;
|
|
30 |
import java.util.Arrays;
|
|
31 |
import java.util.HashMap;
|
|
32 |
import java.util.List;
|
|
33 |
import java.util.Map;
|
|
34 |
|
|
35 |
import org.graalvm.compiler.bytecode.Bytecode;
|
|
36 |
import org.graalvm.compiler.bytecode.BytecodeProvider;
|
46344
|
37 |
import org.graalvm.compiler.core.common.PermanentBailoutException;
|
43972
|
38 |
import org.graalvm.compiler.core.common.cfg.CFGVerifier;
|
|
39 |
import org.graalvm.compiler.core.common.spi.ConstantFieldProvider;
|
|
40 |
import org.graalvm.compiler.core.common.type.StampFactory;
|
|
41 |
import org.graalvm.compiler.core.common.type.StampPair;
|
|
42 |
import org.graalvm.compiler.debug.Debug;
|
|
43 |
import org.graalvm.compiler.debug.DebugCloseable;
|
|
44 |
import org.graalvm.compiler.debug.GraalError;
|
|
45 |
import org.graalvm.compiler.graph.Node;
|
|
46 |
import org.graalvm.compiler.graph.NodeClass;
|
|
47 |
import org.graalvm.compiler.graph.NodeSourcePosition;
|
|
48 |
import org.graalvm.compiler.graph.spi.Canonicalizable;
|
|
49 |
import org.graalvm.compiler.java.GraphBuilderPhase;
|
|
50 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
51 |
import org.graalvm.compiler.nodes.AbstractBeginNode;
|
|
52 |
import org.graalvm.compiler.nodes.AbstractMergeNode;
|
|
53 |
import org.graalvm.compiler.nodes.CallTargetNode;
|
|
54 |
import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind;
|
46371
|
55 |
import org.graalvm.compiler.nodes.ControlSinkNode;
|
43972
|
56 |
import org.graalvm.compiler.nodes.DeoptimizeNode;
|
|
57 |
import org.graalvm.compiler.nodes.EncodedGraph;
|
|
58 |
import org.graalvm.compiler.nodes.FixedNode;
|
|
59 |
import org.graalvm.compiler.nodes.FixedWithNextNode;
|
|
60 |
import org.graalvm.compiler.nodes.FrameState;
|
|
61 |
import org.graalvm.compiler.nodes.IfNode;
|
|
62 |
import org.graalvm.compiler.nodes.Invoke;
|
|
63 |
import org.graalvm.compiler.nodes.InvokeWithExceptionNode;
|
|
64 |
import org.graalvm.compiler.nodes.MergeNode;
|
|
65 |
import org.graalvm.compiler.nodes.ParameterNode;
|
|
66 |
import org.graalvm.compiler.nodes.ReturnNode;
|
|
67 |
import org.graalvm.compiler.nodes.SimplifyingGraphDecoder;
|
|
68 |
import org.graalvm.compiler.nodes.StateSplit;
|
|
69 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
70 |
import org.graalvm.compiler.nodes.UnwindNode;
|
|
71 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
72 |
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
|
|
73 |
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
|
|
74 |
import org.graalvm.compiler.nodes.extended.IntegerSwitchNode;
|
|
75 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
|
|
76 |
import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
|
|
77 |
import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo;
|
|
78 |
import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
|
|
79 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
|
|
80 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
|
81 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver;
|
|
82 |
import org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin;
|
|
83 |
import org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin.LoopExplosionKind;
|
|
84 |
import org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin;
|
|
85 |
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
|
|
86 |
import org.graalvm.compiler.nodes.java.MonitorIdNode;
|
|
87 |
import org.graalvm.compiler.nodes.spi.StampProvider;
|
|
88 |
import org.graalvm.compiler.nodes.util.GraphUtil;
|
|
89 |
import org.graalvm.compiler.options.Option;
|
46344
|
90 |
import org.graalvm.compiler.options.OptionKey;
|
43972
|
91 |
import org.graalvm.compiler.options.OptionType;
|
46344
|
92 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
93 |
import org.graalvm.compiler.phases.common.inlining.InliningUtil;
|
|
94 |
|
|
95 |
import jdk.vm.ci.code.Architecture;
|
|
96 |
import jdk.vm.ci.code.BailoutException;
|
|
97 |
import jdk.vm.ci.code.BytecodeFrame;
|
|
98 |
import jdk.vm.ci.meta.ConstantReflectionProvider;
|
|
99 |
import jdk.vm.ci.meta.DeoptimizationAction;
|
|
100 |
import jdk.vm.ci.meta.DeoptimizationReason;
|
|
101 |
import jdk.vm.ci.meta.JavaConstant;
|
|
102 |
import jdk.vm.ci.meta.JavaKind;
|
|
103 |
import jdk.vm.ci.meta.JavaType;
|
|
104 |
import jdk.vm.ci.meta.MetaAccessProvider;
|
|
105 |
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
106 |
|
|
107 |
/**
|
|
108 |
* A graph decoder that performs partial evaluation, i.e., that performs method inlining and
|
|
109 |
* canonicalization/simplification of nodes during decoding.
|
|
110 |
*
|
|
111 |
* Inlining and loop explosion are configured via the plugin mechanism also used by the
|
|
112 |
* {@link GraphBuilderPhase}. However, not all callback methods defined in
|
|
113 |
* {@link GraphBuilderContext} are available since decoding is more limited than graph building.
|
|
114 |
*
|
|
115 |
* The standard {@link Canonicalizable#canonical node canonicalization} interface is used to
|
|
116 |
* canonicalize nodes during decoding. Additionally, {@link IfNode branches} and
|
|
117 |
* {@link IntegerSwitchNode switches} with constant conditions are simplified.
|
|
118 |
*/
|
|
119 |
public abstract class PEGraphDecoder extends SimplifyingGraphDecoder {
|
|
120 |
|
|
121 |
public static class Options {
|
|
122 |
@Option(help = "Maximum inlining depth during partial evaluation before reporting an infinite recursion")//
|
46344
|
123 |
public static final OptionKey<Integer> InliningDepthError = new OptionKey<>(1000);
|
43972
|
124 |
|
|
125 |
@Option(help = "Max number of loop explosions per method.", type = OptionType.Debug)//
|
46344
|
126 |
public static final OptionKey<Integer> MaximumLoopExplosionCount = new OptionKey<>(10000);
|
43972
|
127 |
|
|
128 |
@Option(help = "Do not bail out but throw an exception on failed loop explosion.", type = OptionType.Debug) //
|
46344
|
129 |
public static final OptionKey<Boolean> FailedLoopExplosionIsFatal = new OptionKey<>(false);
|
43972
|
130 |
}
|
|
131 |
|
|
132 |
protected class PEMethodScope extends MethodScope {
|
|
133 |
/** The state of the caller method. Only non-null during method inlining. */
|
|
134 |
protected final PEMethodScope caller;
|
|
135 |
protected final ResolvedJavaMethod method;
|
|
136 |
protected final InvokeData invokeData;
|
|
137 |
protected final int inliningDepth;
|
|
138 |
|
|
139 |
protected final ValueNode[] arguments;
|
|
140 |
|
|
141 |
protected FrameState outerState;
|
|
142 |
protected FrameState exceptionState;
|
|
143 |
protected ExceptionPlaceholderNode exceptionPlaceholderNode;
|
|
144 |
protected NodeSourcePosition callerBytecodePosition;
|
|
145 |
|
|
146 |
protected PEMethodScope(StructuredGraph targetGraph, PEMethodScope caller, LoopScope callerLoopScope, EncodedGraph encodedGraph, ResolvedJavaMethod method, InvokeData invokeData,
|
46371
|
147 |
int inliningDepth, LoopExplosionPlugin loopExplosionPlugin, ValueNode[] arguments) {
|
43972
|
148 |
super(callerLoopScope, targetGraph, encodedGraph, loopExplosionKind(method, loopExplosionPlugin));
|
|
149 |
|
|
150 |
this.caller = caller;
|
|
151 |
this.method = method;
|
|
152 |
this.invokeData = invokeData;
|
|
153 |
this.inliningDepth = inliningDepth;
|
|
154 |
this.arguments = arguments;
|
|
155 |
}
|
|
156 |
|
46371
|
157 |
@Override
|
43972
|
158 |
public boolean isInlinedMethod() {
|
|
159 |
return caller != null;
|
|
160 |
}
|
|
161 |
|
|
162 |
public NodeSourcePosition getCallerBytecodePosition() {
|
|
163 |
if (caller == null) {
|
|
164 |
return null;
|
|
165 |
}
|
|
166 |
if (callerBytecodePosition == null) {
|
|
167 |
JavaConstant constantReceiver = caller.invokeData == null ? null : caller.invokeData.constantReceiver;
|
|
168 |
NodeSourcePosition callerPosition = caller.getCallerBytecodePosition();
|
|
169 |
NodeSourcePosition invokePosition = invokeData.invoke.asNode().getNodeSourcePosition();
|
|
170 |
callerBytecodePosition = invokePosition != null ? invokePosition.addCaller(constantReceiver, callerPosition) : callerPosition;
|
|
171 |
}
|
|
172 |
return callerBytecodePosition;
|
|
173 |
}
|
|
174 |
}
|
|
175 |
|
|
176 |
protected class PENonAppendGraphBuilderContext implements GraphBuilderContext {
|
|
177 |
protected final PEMethodScope methodScope;
|
|
178 |
protected final Invoke invoke;
|
|
179 |
|
|
180 |
public PENonAppendGraphBuilderContext(PEMethodScope methodScope, Invoke invoke) {
|
|
181 |
this.methodScope = methodScope;
|
|
182 |
this.invoke = invoke;
|
|
183 |
}
|
|
184 |
|
|
185 |
@Override
|
|
186 |
public BailoutException bailout(String string) {
|
|
187 |
BailoutException bailout = new PermanentBailoutException(string);
|
|
188 |
throw GraphUtil.createBailoutException(string, bailout, GraphUtil.approxSourceStackTraceElement(methodScope.getCallerBytecodePosition()));
|
|
189 |
}
|
|
190 |
|
|
191 |
@Override
|
|
192 |
public StampProvider getStampProvider() {
|
|
193 |
return stampProvider;
|
|
194 |
}
|
|
195 |
|
|
196 |
@Override
|
|
197 |
public MetaAccessProvider getMetaAccess() {
|
|
198 |
return metaAccess;
|
|
199 |
}
|
|
200 |
|
|
201 |
@Override
|
|
202 |
public ConstantReflectionProvider getConstantReflection() {
|
|
203 |
return constantReflection;
|
|
204 |
}
|
|
205 |
|
|
206 |
@Override
|
|
207 |
public ConstantFieldProvider getConstantFieldProvider() {
|
|
208 |
return constantFieldProvider;
|
|
209 |
}
|
|
210 |
|
|
211 |
@Override
|
|
212 |
public StructuredGraph getGraph() {
|
46371
|
213 |
return graph;
|
43972
|
214 |
}
|
|
215 |
|
|
216 |
@Override
|
|
217 |
public int getDepth() {
|
|
218 |
return methodScope.inliningDepth;
|
|
219 |
}
|
|
220 |
|
|
221 |
@Override
|
|
222 |
public IntrinsicContext getIntrinsic() {
|
|
223 |
return null;
|
|
224 |
}
|
|
225 |
|
|
226 |
@Override
|
|
227 |
public <T extends ValueNode> T append(T value) {
|
|
228 |
throw unimplemented();
|
|
229 |
}
|
|
230 |
|
|
231 |
@Override
|
|
232 |
public <T extends ValueNode> T recursiveAppend(T value) {
|
|
233 |
throw unimplemented();
|
|
234 |
}
|
|
235 |
|
|
236 |
@Override
|
|
237 |
public void push(JavaKind kind, ValueNode value) {
|
|
238 |
throw unimplemented();
|
|
239 |
}
|
|
240 |
|
|
241 |
@Override
|
|
242 |
public void handleReplacedInvoke(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ValueNode[] args, boolean inlineEverything) {
|
|
243 |
throw unimplemented();
|
|
244 |
}
|
|
245 |
|
|
246 |
@Override
|
46344
|
247 |
public void handleReplacedInvoke(CallTargetNode callTarget, JavaKind resultType) {
|
|
248 |
throw unimplemented();
|
|
249 |
}
|
|
250 |
|
|
251 |
@Override
|
43972
|
252 |
public boolean intrinsify(BytecodeProvider bytecodeProvider, ResolvedJavaMethod targetMethod, ResolvedJavaMethod substitute, InvocationPlugin.Receiver receiver, ValueNode[] args) {
|
|
253 |
return false;
|
|
254 |
}
|
|
255 |
|
|
256 |
@Override
|
|
257 |
public void setStateAfter(StateSplit stateSplit) {
|
|
258 |
throw unimplemented();
|
|
259 |
}
|
|
260 |
|
|
261 |
@Override
|
|
262 |
public GraphBuilderContext getParent() {
|
|
263 |
throw unimplemented();
|
|
264 |
}
|
|
265 |
|
|
266 |
@Override
|
|
267 |
public Bytecode getCode() {
|
|
268 |
throw unimplemented();
|
|
269 |
}
|
|
270 |
|
|
271 |
@Override
|
|
272 |
public ResolvedJavaMethod getMethod() {
|
|
273 |
throw unimplemented();
|
|
274 |
}
|
|
275 |
|
|
276 |
@Override
|
|
277 |
public int bci() {
|
|
278 |
return invoke.bci();
|
|
279 |
}
|
|
280 |
|
|
281 |
@Override
|
|
282 |
public InvokeKind getInvokeKind() {
|
|
283 |
throw unimplemented();
|
|
284 |
}
|
|
285 |
|
|
286 |
@Override
|
|
287 |
public JavaType getInvokeReturnType() {
|
|
288 |
throw unimplemented();
|
|
289 |
}
|
|
290 |
}
|
|
291 |
|
|
292 |
protected class PEAppendGraphBuilderContext extends PENonAppendGraphBuilderContext {
|
|
293 |
protected FixedWithNextNode lastInstr;
|
|
294 |
protected ValueNode pushedNode;
|
46344
|
295 |
protected boolean invokeConsumed;
|
43972
|
296 |
|
|
297 |
public PEAppendGraphBuilderContext(PEMethodScope inlineScope, FixedWithNextNode lastInstr) {
|
|
298 |
super(inlineScope, inlineScope.invokeData.invoke);
|
|
299 |
this.lastInstr = lastInstr;
|
|
300 |
}
|
|
301 |
|
|
302 |
@Override
|
|
303 |
public void push(JavaKind kind, ValueNode value) {
|
|
304 |
if (pushedNode != null) {
|
|
305 |
throw unimplemented("Only one push is supported");
|
|
306 |
}
|
|
307 |
pushedNode = value;
|
|
308 |
}
|
|
309 |
|
|
310 |
@Override
|
|
311 |
public void setStateAfter(StateSplit stateSplit) {
|
|
312 |
Node stateAfter = decodeFloatingNode(methodScope.caller, methodScope.callerLoopScope, methodScope.invokeData.stateAfterOrderId);
|
|
313 |
getGraph().add(stateAfter);
|
|
314 |
FrameState fs = (FrameState) handleFloatingNodeAfterAdd(methodScope.caller, methodScope.callerLoopScope, stateAfter);
|
|
315 |
stateSplit.setStateAfter(fs);
|
|
316 |
}
|
|
317 |
|
|
318 |
@SuppressWarnings("try")
|
|
319 |
@Override
|
|
320 |
public <T extends ValueNode> T append(T v) {
|
|
321 |
if (v.graph() != null) {
|
|
322 |
return v;
|
|
323 |
}
|
|
324 |
try (DebugCloseable position = withNodeSoucePosition()) {
|
|
325 |
T added = getGraph().addOrUnique(v);
|
|
326 |
if (added == v) {
|
|
327 |
updateLastInstruction(v);
|
|
328 |
}
|
|
329 |
return added;
|
|
330 |
}
|
|
331 |
}
|
|
332 |
|
|
333 |
private DebugCloseable withNodeSoucePosition() {
|
|
334 |
if (getGraph().mayHaveNodeSourcePosition()) {
|
|
335 |
return getGraph().withNodeSourcePosition(methodScope.getCallerBytecodePosition());
|
|
336 |
}
|
|
337 |
return null;
|
|
338 |
}
|
|
339 |
|
|
340 |
@SuppressWarnings("try")
|
|
341 |
@Override
|
|
342 |
public <T extends ValueNode> T recursiveAppend(T v) {
|
|
343 |
if (v.graph() != null) {
|
|
344 |
return v;
|
|
345 |
}
|
|
346 |
try (DebugCloseable position = withNodeSoucePosition()) {
|
|
347 |
T added = getGraph().addOrUniqueWithInputs(v);
|
|
348 |
if (added == v) {
|
|
349 |
updateLastInstruction(v);
|
|
350 |
}
|
|
351 |
return added;
|
|
352 |
}
|
|
353 |
}
|
|
354 |
|
|
355 |
private <T extends ValueNode> void updateLastInstruction(T v) {
|
|
356 |
if (v instanceof FixedNode) {
|
|
357 |
FixedNode fixedNode = (FixedNode) v;
|
46344
|
358 |
if (lastInstr != null) {
|
|
359 |
lastInstr.setNext(fixedNode);
|
|
360 |
}
|
43972
|
361 |
if (fixedNode instanceof FixedWithNextNode) {
|
|
362 |
FixedWithNextNode fixedWithNextNode = (FixedWithNextNode) fixedNode;
|
|
363 |
assert fixedWithNextNode.next() == null : "cannot append instruction to instruction which isn't end";
|
|
364 |
lastInstr = fixedWithNextNode;
|
|
365 |
} else {
|
|
366 |
lastInstr = null;
|
|
367 |
}
|
|
368 |
}
|
|
369 |
}
|
46344
|
370 |
|
|
371 |
@Override
|
|
372 |
public void handleReplacedInvoke(CallTargetNode callTarget, JavaKind resultType) {
|
|
373 |
if (invokeConsumed) {
|
|
374 |
throw unimplemented("handleReplacedInvoke can be called only once");
|
|
375 |
}
|
|
376 |
invokeConsumed = true;
|
|
377 |
|
|
378 |
appendInvoke(methodScope.caller, methodScope.callerLoopScope, methodScope.invokeData, callTarget);
|
|
379 |
updateLastInstruction(invoke.asNode());
|
|
380 |
}
|
43972
|
381 |
}
|
|
382 |
|
|
383 |
@NodeInfo(cycles = CYCLES_IGNORED, size = SIZE_IGNORED)
|
|
384 |
static class ExceptionPlaceholderNode extends ValueNode {
|
|
385 |
public static final NodeClass<ExceptionPlaceholderNode> TYPE = NodeClass.create(ExceptionPlaceholderNode.class);
|
|
386 |
|
|
387 |
protected ExceptionPlaceholderNode() {
|
|
388 |
super(TYPE, StampFactory.object());
|
|
389 |
}
|
|
390 |
}
|
|
391 |
|
46344
|
392 |
protected final OptionValues options;
|
46371
|
393 |
private final LoopExplosionPlugin loopExplosionPlugin;
|
|
394 |
private final InvocationPlugins invocationPlugins;
|
|
395 |
private final InlineInvokePlugin[] inlineInvokePlugins;
|
|
396 |
private final ParameterPlugin parameterPlugin;
|
46344
|
397 |
|
46371
|
398 |
public PEGraphDecoder(Architecture architecture, StructuredGraph graph, MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection, ConstantFieldProvider constantFieldProvider,
|
|
399 |
StampProvider stampProvider, OptionValues options, LoopExplosionPlugin loopExplosionPlugin, InvocationPlugins invocationPlugins, InlineInvokePlugin[] inlineInvokePlugins,
|
|
400 |
ParameterPlugin parameterPlugin) {
|
|
401 |
super(architecture, graph, metaAccess, constantReflection, constantFieldProvider, stampProvider, true);
|
|
402 |
this.loopExplosionPlugin = loopExplosionPlugin;
|
|
403 |
this.invocationPlugins = invocationPlugins;
|
|
404 |
this.inlineInvokePlugins = inlineInvokePlugins;
|
|
405 |
this.parameterPlugin = parameterPlugin;
|
46344
|
406 |
this.options = options;
|
43972
|
407 |
}
|
|
408 |
|
|
409 |
protected static LoopExplosionKind loopExplosionKind(ResolvedJavaMethod method, LoopExplosionPlugin loopExplosionPlugin) {
|
|
410 |
if (loopExplosionPlugin == null) {
|
|
411 |
return LoopExplosionKind.NONE;
|
|
412 |
} else {
|
|
413 |
return loopExplosionPlugin.loopExplosionKind(method);
|
|
414 |
}
|
|
415 |
}
|
|
416 |
|
46371
|
417 |
public void decode(ResolvedJavaMethod method) {
|
|
418 |
PEMethodScope methodScope = new PEMethodScope(graph, null, null, lookupEncodedGraph(method, null), method, null, 0, loopExplosionPlugin, null);
|
43972
|
419 |
decode(createInitialLoopScope(methodScope, null));
|
|
420 |
cleanupGraph(methodScope);
|
|
421 |
|
46371
|
422 |
Debug.dump(Debug.VERBOSE_LEVEL, graph, "After graph cleanup");
|
|
423 |
assert graph.verify();
|
43972
|
424 |
|
|
425 |
try {
|
|
426 |
/* Check that the control flow graph can be computed, to catch problems early. */
|
46371
|
427 |
assert CFGVerifier.verify(ControlFlowGraph.compute(graph, true, true, true, true));
|
43972
|
428 |
} catch (Throwable ex) {
|
|
429 |
throw GraalError.shouldNotReachHere("Control flow graph not valid after partial evaluation");
|
|
430 |
}
|
|
431 |
}
|
|
432 |
|
|
433 |
@Override
|
|
434 |
protected void cleanupGraph(MethodScope methodScope) {
|
|
435 |
super.cleanupGraph(methodScope);
|
|
436 |
|
46371
|
437 |
for (FrameState frameState : graph.getNodes(FrameState.TYPE)) {
|
43972
|
438 |
if (frameState.bci == BytecodeFrame.UNWIND_BCI) {
|
|
439 |
/*
|
|
440 |
* handleMissingAfterExceptionFrameState is called during graph decoding from
|
|
441 |
* InliningUtil.processFrameState - but during graph decoding it does not do
|
|
442 |
* anything because the usages of the frameState are not available yet. So we need
|
|
443 |
* to call it again.
|
|
444 |
*/
|
|
445 |
InliningUtil.handleMissingAfterExceptionFrameState(frameState);
|
|
446 |
|
|
447 |
/*
|
|
448 |
* The frameState must be gone now, because it is not a valid deoptimization point.
|
|
449 |
*/
|
|
450 |
assert frameState.isDeleted();
|
|
451 |
}
|
|
452 |
}
|
|
453 |
}
|
|
454 |
|
|
455 |
@Override
|
|
456 |
protected void checkLoopExplosionIteration(MethodScope s, LoopScope loopScope) {
|
|
457 |
PEMethodScope methodScope = (PEMethodScope) s;
|
|
458 |
|
46344
|
459 |
if (loopScope.loopIteration > Options.MaximumLoopExplosionCount.getValue(options)) {
|
|
460 |
throw tooManyLoopExplosionIterations(methodScope, options);
|
43972
|
461 |
}
|
|
462 |
}
|
|
463 |
|
46344
|
464 |
private static RuntimeException tooManyLoopExplosionIterations(PEMethodScope methodScope, OptionValues options) {
|
43972
|
465 |
String message = "too many loop explosion iterations - does the explosion not terminate for method " + methodScope.method + "?";
|
46344
|
466 |
RuntimeException bailout = Options.FailedLoopExplosionIsFatal.getValue(options) ? new RuntimeException(message) : new PermanentBailoutException(message);
|
43972
|
467 |
throw GraphUtil.createBailoutException(message, bailout, GraphUtil.approxSourceStackTraceElement(methodScope.getCallerBytecodePosition()));
|
|
468 |
}
|
|
469 |
|
|
470 |
@Override
|
|
471 |
protected LoopScope handleInvoke(MethodScope s, LoopScope loopScope, InvokeData invokeData) {
|
|
472 |
PEMethodScope methodScope = (PEMethodScope) s;
|
|
473 |
|
|
474 |
/*
|
|
475 |
* Decode the call target, but do not add it to the graph yet. This avoids adding usages for
|
|
476 |
* all the arguments, which are expensive to remove again when we can inline the method.
|
|
477 |
*/
|
|
478 |
assert invokeData.invoke.callTarget() == null : "callTarget edge is ignored during decoding of Invoke";
|
|
479 |
CallTargetNode callTarget = (CallTargetNode) decodeFloatingNode(methodScope, loopScope, invokeData.callTargetOrderId);
|
|
480 |
if (callTarget instanceof MethodCallTargetNode) {
|
|
481 |
MethodCallTargetNode methodCall = (MethodCallTargetNode) callTarget;
|
|
482 |
if (methodCall.invokeKind().hasReceiver()) {
|
|
483 |
invokeData.constantReceiver = methodCall.arguments().get(0).asJavaConstant();
|
|
484 |
}
|
|
485 |
LoopScope inlineLoopScope = trySimplifyInvoke(methodScope, loopScope, invokeData, (MethodCallTargetNode) callTarget);
|
|
486 |
if (inlineLoopScope != null) {
|
|
487 |
return inlineLoopScope;
|
|
488 |
}
|
|
489 |
}
|
|
490 |
|
|
491 |
/* We know that we need an invoke, so now we can add the call target to the graph. */
|
46371
|
492 |
graph.add(callTarget);
|
43972
|
493 |
registerNode(loopScope, invokeData.callTargetOrderId, callTarget, false, false);
|
|
494 |
return super.handleInvoke(methodScope, loopScope, invokeData);
|
|
495 |
}
|
|
496 |
|
|
497 |
protected LoopScope trySimplifyInvoke(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
|
|
498 |
// attempt to devirtualize the call
|
|
499 |
ResolvedJavaMethod specialCallTarget = MethodCallTargetNode.findSpecialCallTarget(callTarget.invokeKind(), callTarget.receiver(), callTarget.targetMethod(), invokeData.contextType);
|
|
500 |
if (specialCallTarget != null) {
|
|
501 |
callTarget.setTargetMethod(specialCallTarget);
|
|
502 |
callTarget.setInvokeKind(InvokeKind.Special);
|
|
503 |
}
|
|
504 |
|
|
505 |
if (tryInvocationPlugin(methodScope, loopScope, invokeData, callTarget)) {
|
|
506 |
/*
|
|
507 |
* The invocation plugin handled the call, so decoding continues in the calling method.
|
|
508 |
*/
|
|
509 |
return loopScope;
|
|
510 |
}
|
|
511 |
LoopScope inlineLoopScope = tryInline(methodScope, loopScope, invokeData, callTarget);
|
|
512 |
if (inlineLoopScope != null) {
|
|
513 |
/*
|
|
514 |
* We can inline the call, so decoding continues in the inlined method.
|
|
515 |
*/
|
|
516 |
return inlineLoopScope;
|
|
517 |
}
|
|
518 |
|
46371
|
519 |
for (InlineInvokePlugin plugin : inlineInvokePlugins) {
|
43972
|
520 |
plugin.notifyNotInlined(new PENonAppendGraphBuilderContext(methodScope, invokeData.invoke), callTarget.targetMethod(), invokeData.invoke);
|
|
521 |
}
|
|
522 |
return null;
|
|
523 |
}
|
|
524 |
|
|
525 |
protected boolean tryInvocationPlugin(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
|
46371
|
526 |
if (invocationPlugins == null) {
|
43972
|
527 |
return false;
|
|
528 |
}
|
|
529 |
|
|
530 |
Invoke invoke = invokeData.invoke;
|
|
531 |
|
|
532 |
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
|
46371
|
533 |
InvocationPlugin invocationPlugin = invocationPlugins.lookupInvocation(targetMethod);
|
43972
|
534 |
if (invocationPlugin == null) {
|
|
535 |
return false;
|
|
536 |
}
|
|
537 |
|
|
538 |
ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
|
|
539 |
FixedWithNextNode invokePredecessor = (FixedWithNextNode) invoke.asNode().predecessor();
|
|
540 |
|
|
541 |
/*
|
|
542 |
* Remove invoke from graph so that invocation plugin can append nodes to the predecessor.
|
|
543 |
*/
|
|
544 |
invoke.asNode().replaceAtPredecessor(null);
|
|
545 |
|
46371
|
546 |
PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, null, targetMethod, invokeData, methodScope.inliningDepth + 1, loopExplosionPlugin, arguments);
|
43972
|
547 |
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, invokePredecessor);
|
|
548 |
InvocationPluginReceiver invocationPluginReceiver = new InvocationPluginReceiver(graphBuilderContext);
|
|
549 |
|
|
550 |
if (invocationPlugin.execute(graphBuilderContext, targetMethod, invocationPluginReceiver.init(targetMethod, arguments), arguments)) {
|
|
551 |
|
46344
|
552 |
if (graphBuilderContext.invokeConsumed) {
|
|
553 |
/* Nothing to do. */
|
|
554 |
} else if (graphBuilderContext.lastInstr != null) {
|
43972
|
555 |
registerNode(loopScope, invokeData.invokeOrderId, graphBuilderContext.pushedNode, true, true);
|
|
556 |
invoke.asNode().replaceAtUsages(graphBuilderContext.pushedNode);
|
|
557 |
graphBuilderContext.lastInstr.setNext(nodeAfterInvoke(methodScope, loopScope, invokeData, AbstractBeginNode.prevBegin(graphBuilderContext.lastInstr)));
|
46344
|
558 |
deleteInvoke(invoke);
|
43972
|
559 |
} else {
|
|
560 |
assert graphBuilderContext.pushedNode == null : "Why push a node when the invoke does not return anyway?";
|
|
561 |
invoke.asNode().replaceAtUsages(null);
|
46344
|
562 |
deleteInvoke(invoke);
|
43972
|
563 |
}
|
|
564 |
return true;
|
|
565 |
|
|
566 |
} else {
|
|
567 |
/* Intrinsification failed, restore original state: invoke is in Graph. */
|
|
568 |
invokePredecessor.setNext(invoke.asNode());
|
|
569 |
return false;
|
|
570 |
}
|
|
571 |
}
|
|
572 |
|
|
573 |
protected LoopScope tryInline(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
|
|
574 |
if (!callTarget.invokeKind().isDirect()) {
|
|
575 |
return null;
|
|
576 |
}
|
|
577 |
|
|
578 |
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
|
46344
|
579 |
if (targetMethod.hasNeverInlineDirective()) {
|
43972
|
580 |
return null;
|
|
581 |
}
|
|
582 |
|
|
583 |
ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
|
|
584 |
GraphBuilderContext graphBuilderContext = new PENonAppendGraphBuilderContext(methodScope, invokeData.invoke);
|
|
585 |
|
46371
|
586 |
for (InlineInvokePlugin plugin : inlineInvokePlugins) {
|
43972
|
587 |
InlineInfo inlineInfo = plugin.shouldInlineInvoke(graphBuilderContext, targetMethod, arguments);
|
|
588 |
if (inlineInfo != null) {
|
|
589 |
if (inlineInfo.getMethodToInline() == null) {
|
|
590 |
return null;
|
|
591 |
} else {
|
|
592 |
return doInline(methodScope, loopScope, invokeData, inlineInfo, arguments);
|
|
593 |
}
|
|
594 |
}
|
|
595 |
}
|
|
596 |
return null;
|
|
597 |
}
|
|
598 |
|
|
599 |
protected LoopScope doInline(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, InlineInfo inlineInfo, ValueNode[] arguments) {
|
|
600 |
ResolvedJavaMethod inlineMethod = inlineInfo.getMethodToInline();
|
|
601 |
EncodedGraph graphToInline = lookupEncodedGraph(inlineMethod, inlineInfo.getIntrinsicBytecodeProvider());
|
|
602 |
if (graphToInline == null) {
|
|
603 |
return null;
|
|
604 |
}
|
|
605 |
|
46344
|
606 |
if (methodScope.inliningDepth > Options.InliningDepthError.getValue(options)) {
|
43972
|
607 |
throw tooDeepInlining(methodScope);
|
|
608 |
}
|
|
609 |
|
46371
|
610 |
for (InlineInvokePlugin plugin : inlineInvokePlugins) {
|
43972
|
611 |
plugin.notifyBeforeInline(inlineMethod);
|
|
612 |
}
|
|
613 |
|
|
614 |
Invoke invoke = invokeData.invoke;
|
|
615 |
FixedNode invokeNode = invoke.asNode();
|
|
616 |
FixedWithNextNode predecessor = (FixedWithNextNode) invokeNode.predecessor();
|
|
617 |
invokeNode.replaceAtPredecessor(null);
|
|
618 |
|
46371
|
619 |
PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, graphToInline, inlineMethod, invokeData, methodScope.inliningDepth + 1,
|
|
620 |
loopExplosionPlugin, arguments);
|
43972
|
621 |
|
|
622 |
/*
|
|
623 |
* Do the actual inlining by returning the initial loop scope for the inlined method scope.
|
|
624 |
*/
|
|
625 |
return createInitialLoopScope(inlineScope, predecessor);
|
|
626 |
}
|
|
627 |
|
46371
|
628 |
@Override
|
|
629 |
protected void finishInlining(MethodScope is) {
|
|
630 |
PEMethodScope inlineScope = (PEMethodScope) is;
|
|
631 |
ResolvedJavaMethod inlineMethod = inlineScope.method;
|
|
632 |
PEMethodScope methodScope = inlineScope.caller;
|
|
633 |
LoopScope loopScope = inlineScope.callerLoopScope;
|
|
634 |
InvokeData invokeData = inlineScope.invokeData;
|
43972
|
635 |
Invoke invoke = invokeData.invoke;
|
|
636 |
FixedNode invokeNode = invoke.asNode();
|
|
637 |
|
|
638 |
ValueNode exceptionValue = null;
|
46371
|
639 |
int returnNodeCount = 0;
|
|
640 |
int unwindNodeCount = 0;
|
|
641 |
List<ControlSinkNode> returnAndUnwindNodes = inlineScope.returnAndUnwindNodes;
|
|
642 |
for (int i = 0; i < returnAndUnwindNodes.size(); i++) {
|
|
643 |
FixedNode fixedNode = returnAndUnwindNodes.get(i);
|
|
644 |
if (fixedNode instanceof ReturnNode) {
|
|
645 |
returnNodeCount++;
|
|
646 |
} else if (fixedNode.isAlive()) {
|
|
647 |
assert fixedNode instanceof UnwindNode;
|
|
648 |
unwindNodeCount++;
|
43972
|
649 |
}
|
|
650 |
}
|
|
651 |
|
46371
|
652 |
if (unwindNodeCount > 0) {
|
43972
|
653 |
FixedNode unwindReplacement;
|
|
654 |
if (invoke instanceof InvokeWithExceptionNode) {
|
|
655 |
/* Decoding continues for the exception handler. */
|
|
656 |
unwindReplacement = makeStubNode(methodScope, loopScope, invokeData.exceptionNextOrderId);
|
|
657 |
} else {
|
|
658 |
/* No exception handler available, so the only thing we can do is deoptimize. */
|
46371
|
659 |
unwindReplacement = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler));
|
43972
|
660 |
}
|
|
661 |
|
46371
|
662 |
if (unwindNodeCount == 1) {
|
43972
|
663 |
/* Only one UnwindNode, we can use the exception directly. */
|
46371
|
664 |
UnwindNode unwindNode = getSingleMatchingNode(returnAndUnwindNodes, returnNodeCount > 0, UnwindNode.class);
|
43972
|
665 |
exceptionValue = unwindNode.exception();
|
|
666 |
unwindNode.replaceAndDelete(unwindReplacement);
|
|
667 |
|
|
668 |
} else {
|
|
669 |
/*
|
|
670 |
* More than one UnwindNode. This can happen with the loop explosion strategy
|
|
671 |
* FULL_EXPLODE_UNTIL_RETURN, where we keep exploding after the loop and therefore
|
|
672 |
* also explode exception paths. Merge the exception in a similar way as multiple
|
|
673 |
* return values.
|
|
674 |
*/
|
46371
|
675 |
MergeNode unwindMergeNode = graph.add(new MergeNode());
|
|
676 |
exceptionValue = InliningUtil.mergeValueProducers(unwindMergeNode, getMatchingNodes(returnAndUnwindNodes, returnNodeCount > 0, UnwindNode.class, unwindNodeCount),
|
|
677 |
unwindNode -> unwindNode.exception());
|
43972
|
678 |
unwindMergeNode.setNext(unwindReplacement);
|
|
679 |
|
|
680 |
ensureExceptionStateDecoded(inlineScope);
|
|
681 |
unwindMergeNode.setStateAfter(inlineScope.exceptionState.duplicateModified(JavaKind.Object, JavaKind.Object, exceptionValue));
|
|
682 |
}
|
|
683 |
}
|
|
684 |
|
|
685 |
assert invoke.next() == null;
|
|
686 |
assert !(invoke instanceof InvokeWithExceptionNode) || ((InvokeWithExceptionNode) invoke).exceptionEdge() == null;
|
|
687 |
|
|
688 |
ValueNode returnValue;
|
46371
|
689 |
if (returnNodeCount == 0) {
|
|
690 |
returnValue = null;
|
|
691 |
} else if (returnNodeCount == 1) {
|
|
692 |
ReturnNode returnNode = getSingleMatchingNode(returnAndUnwindNodes, unwindNodeCount > 0, ReturnNode.class);
|
|
693 |
returnValue = returnNode.result();
|
|
694 |
FixedNode n = nodeAfterInvoke(methodScope, loopScope, invokeData, AbstractBeginNode.prevBegin(returnNode));
|
|
695 |
returnNode.replaceAndDelete(n);
|
43972
|
696 |
} else {
|
46371
|
697 |
AbstractMergeNode merge = graph.add(new MergeNode());
|
|
698 |
merge.setStateAfter((FrameState) ensureNodeCreated(methodScope, loopScope, invokeData.stateAfterOrderId));
|
|
699 |
returnValue = InliningUtil.mergeReturns(merge, getMatchingNodes(returnAndUnwindNodes, unwindNodeCount > 0, ReturnNode.class, returnNodeCount));
|
|
700 |
FixedNode n = nodeAfterInvoke(methodScope, loopScope, invokeData, merge);
|
|
701 |
merge.setNext(n);
|
43972
|
702 |
}
|
|
703 |
invokeNode.replaceAtUsages(returnValue);
|
|
704 |
|
|
705 |
/*
|
|
706 |
* Usage the handles that we have on the return value and the exception to update the
|
|
707 |
* orderId->Node table.
|
|
708 |
*/
|
|
709 |
registerNode(loopScope, invokeData.invokeOrderId, returnValue, true, true);
|
|
710 |
if (invoke instanceof InvokeWithExceptionNode) {
|
|
711 |
registerNode(loopScope, invokeData.exceptionOrderId, exceptionValue, true, true);
|
|
712 |
}
|
|
713 |
if (inlineScope.exceptionPlaceholderNode != null) {
|
|
714 |
inlineScope.exceptionPlaceholderNode.replaceAtUsagesAndDelete(exceptionValue);
|
|
715 |
}
|
|
716 |
deleteInvoke(invoke);
|
|
717 |
|
46371
|
718 |
for (InlineInvokePlugin plugin : inlineInvokePlugins) {
|
43972
|
719 |
plugin.notifyAfterInline(inlineMethod);
|
|
720 |
}
|
46371
|
721 |
}
|
|
722 |
|
|
723 |
@SuppressWarnings("unchecked")
|
|
724 |
private static <T> T getSingleMatchingNode(List<ControlSinkNode> returnAndUnwindNodes, boolean hasNonMatchingEntries, Class<T> clazz) {
|
|
725 |
if (!hasNonMatchingEntries) {
|
|
726 |
assert returnAndUnwindNodes.size() == 1;
|
|
727 |
return (T) returnAndUnwindNodes.get(0);
|
|
728 |
}
|
43972
|
729 |
|
46371
|
730 |
for (int i = 0; i < returnAndUnwindNodes.size(); i++) {
|
|
731 |
ControlSinkNode node = returnAndUnwindNodes.get(i);
|
|
732 |
if (clazz.isInstance(node)) {
|
|
733 |
return (T) node;
|
|
734 |
}
|
43972
|
735 |
}
|
46371
|
736 |
throw GraalError.shouldNotReachHere();
|
|
737 |
}
|
|
738 |
|
|
739 |
@SuppressWarnings("unchecked")
|
|
740 |
private static <T> List<T> getMatchingNodes(List<ControlSinkNode> returnAndUnwindNodes, boolean hasNonMatchingEntries, Class<T> clazz, int resultCount) {
|
|
741 |
if (!hasNonMatchingEntries) {
|
|
742 |
return (List<T>) returnAndUnwindNodes;
|
|
743 |
}
|
|
744 |
|
|
745 |
List<T> result = new ArrayList<>(resultCount);
|
|
746 |
for (int i = 0; i < returnAndUnwindNodes.size(); i++) {
|
|
747 |
ControlSinkNode node = returnAndUnwindNodes.get(i);
|
|
748 |
if (clazz.isInstance(node)) {
|
|
749 |
result.add((T) node);
|
|
750 |
}
|
|
751 |
}
|
|
752 |
assert result.size() == resultCount;
|
|
753 |
return result;
|
43972
|
754 |
}
|
|
755 |
|
|
756 |
private static RuntimeException tooDeepInlining(PEMethodScope methodScope) {
|
|
757 |
HashMap<ResolvedJavaMethod, Integer> methodCounts = new HashMap<>();
|
|
758 |
for (PEMethodScope cur = methodScope; cur != null; cur = cur.caller) {
|
|
759 |
Integer oldCount = methodCounts.get(cur.method);
|
|
760 |
methodCounts.put(cur.method, oldCount == null ? 1 : oldCount + 1);
|
|
761 |
}
|
|
762 |
|
|
763 |
List<Map.Entry<ResolvedJavaMethod, Integer>> methods = new ArrayList<>(methodCounts.entrySet());
|
|
764 |
methods.sort((e1, e2) -> -Integer.compare(e1.getValue(), e2.getValue()));
|
|
765 |
|
|
766 |
StringBuilder msg = new StringBuilder("Too deep inlining, probably caused by recursive inlining.").append(System.lineSeparator()).append("== Inlined methods ordered by inlining frequency:");
|
|
767 |
for (Map.Entry<ResolvedJavaMethod, Integer> entry : methods) {
|
|
768 |
msg.append(System.lineSeparator()).append(entry.getKey().format("%H.%n(%p) [")).append(entry.getValue()).append("]");
|
|
769 |
}
|
|
770 |
msg.append(System.lineSeparator()).append("== Complete stack trace of inlined methods:");
|
|
771 |
int lastBci = 0;
|
|
772 |
for (PEMethodScope cur = methodScope; cur != null; cur = cur.caller) {
|
|
773 |
msg.append(System.lineSeparator()).append(cur.method.asStackTraceElement(lastBci));
|
|
774 |
if (cur.invokeData != null) {
|
|
775 |
lastBci = cur.invokeData.invoke.bci();
|
|
776 |
} else {
|
|
777 |
lastBci = 0;
|
|
778 |
}
|
|
779 |
}
|
|
780 |
|
|
781 |
throw new PermanentBailoutException(msg.toString());
|
|
782 |
}
|
|
783 |
|
|
784 |
public FixedNode nodeAfterInvoke(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, AbstractBeginNode lastBlock) {
|
|
785 |
assert lastBlock.isAlive();
|
|
786 |
FixedNode n;
|
|
787 |
if (invokeData.invoke instanceof InvokeWithExceptionNode) {
|
|
788 |
registerNode(loopScope, invokeData.nextOrderId, lastBlock, false, false);
|
|
789 |
n = makeStubNode(methodScope, loopScope, invokeData.nextNextOrderId);
|
|
790 |
} else {
|
|
791 |
n = makeStubNode(methodScope, loopScope, invokeData.nextOrderId);
|
|
792 |
}
|
|
793 |
return n;
|
|
794 |
}
|
|
795 |
|
|
796 |
private static void deleteInvoke(Invoke invoke) {
|
|
797 |
/*
|
|
798 |
* Clean up unused nodes. We cannot just call killCFG on the invoke node because that can
|
|
799 |
* kill too much: nodes that are decoded later can use values that appear unused by now.
|
|
800 |
*/
|
|
801 |
FrameState frameState = invoke.stateAfter();
|
|
802 |
invoke.asNode().safeDelete();
|
|
803 |
assert invoke.callTarget() == null : "must not have been added to the graph yet";
|
|
804 |
if (frameState != null && frameState.hasNoUsages()) {
|
|
805 |
frameState.safeDelete();
|
|
806 |
}
|
|
807 |
}
|
|
808 |
|
|
809 |
protected abstract EncodedGraph lookupEncodedGraph(ResolvedJavaMethod method, BytecodeProvider intrinsicBytecodeProvider);
|
|
810 |
|
|
811 |
@SuppressWarnings("try")
|
|
812 |
@Override
|
|
813 |
protected void handleFixedNode(MethodScope s, LoopScope loopScope, int nodeOrderId, FixedNode node) {
|
|
814 |
PEMethodScope methodScope = (PEMethodScope) s;
|
|
815 |
if (node instanceof ForeignCallNode) {
|
|
816 |
ForeignCallNode foreignCall = (ForeignCallNode) node;
|
|
817 |
if (foreignCall.getBci() == BytecodeFrame.UNKNOWN_BCI && methodScope.invokeData != null) {
|
|
818 |
foreignCall.setBci(methodScope.invokeData.invoke.bci());
|
|
819 |
}
|
|
820 |
}
|
|
821 |
|
|
822 |
NodeSourcePosition pos = node.getNodeSourcePosition();
|
|
823 |
if (pos != null && methodScope.isInlinedMethod()) {
|
|
824 |
NodeSourcePosition newPosition = pos.addCaller(methodScope.getCallerBytecodePosition());
|
46344
|
825 |
try (DebugCloseable scope = node.graph().withNodeSourcePosition(newPosition)) {
|
43972
|
826 |
super.handleFixedNode(s, loopScope, nodeOrderId, node);
|
|
827 |
}
|
|
828 |
if (node.isAlive()) {
|
|
829 |
node.setNodeSourcePosition(newPosition);
|
|
830 |
}
|
|
831 |
} else {
|
|
832 |
super.handleFixedNode(s, loopScope, nodeOrderId, node);
|
|
833 |
}
|
|
834 |
|
|
835 |
}
|
|
836 |
|
|
837 |
@Override
|
46371
|
838 |
protected Node handleFloatingNodeBeforeAdd(MethodScope s, LoopScope loopScope, Node n) {
|
43972
|
839 |
PEMethodScope methodScope = (PEMethodScope) s;
|
|
840 |
|
46371
|
841 |
Node node = n;
|
43972
|
842 |
if (node instanceof ParameterNode) {
|
|
843 |
ParameterNode param = (ParameterNode) node;
|
46371
|
844 |
if (methodScope.isInlinedMethod()) {
|
43972
|
845 |
Node result = methodScope.arguments[param.index()];
|
|
846 |
assert result != null;
|
|
847 |
return result;
|
|
848 |
|
46371
|
849 |
} else if (parameterPlugin != null) {
|
|
850 |
assert !methodScope.isInlinedMethod();
|
43972
|
851 |
GraphBuilderContext graphBuilderContext = new PENonAppendGraphBuilderContext(methodScope, null);
|
46371
|
852 |
Node result = parameterPlugin.interceptParameter(graphBuilderContext, param.index(),
|
43972
|
853 |
StampPair.create(param.stamp(), param.uncheckedStamp()));
|
|
854 |
if (result != null) {
|
|
855 |
return result;
|
|
856 |
}
|
|
857 |
}
|
46371
|
858 |
node = param.copyWithInputs();
|
43972
|
859 |
}
|
|
860 |
|
|
861 |
return super.handleFloatingNodeBeforeAdd(methodScope, loopScope, node);
|
|
862 |
}
|
|
863 |
|
|
864 |
protected void ensureOuterStateDecoded(PEMethodScope methodScope) {
|
|
865 |
if (methodScope.outerState == null && methodScope.caller != null) {
|
|
866 |
FrameState stateAtReturn = methodScope.invokeData.invoke.stateAfter();
|
|
867 |
if (stateAtReturn == null) {
|
|
868 |
stateAtReturn = (FrameState) decodeFloatingNode(methodScope.caller, methodScope.callerLoopScope, methodScope.invokeData.stateAfterOrderId);
|
|
869 |
}
|
|
870 |
|
|
871 |
JavaKind invokeReturnKind = methodScope.invokeData.invoke.asNode().getStackKind();
|
46371
|
872 |
FrameState outerState = stateAtReturn.duplicateModified(graph, methodScope.invokeData.invoke.bci(), stateAtReturn.rethrowException(), true, invokeReturnKind, null, null);
|
43972
|
873 |
|
|
874 |
/*
|
|
875 |
* When the encoded graph has methods inlining, we can already have a proper caller
|
|
876 |
* state. If not, we set the caller state here.
|
|
877 |
*/
|
|
878 |
if (outerState.outerFrameState() == null && methodScope.caller != null) {
|
|
879 |
ensureOuterStateDecoded(methodScope.caller);
|
|
880 |
outerState.setOuterFrameState(methodScope.caller.outerState);
|
|
881 |
}
|
|
882 |
methodScope.outerState = outerState;
|
|
883 |
}
|
|
884 |
}
|
|
885 |
|
|
886 |
protected void ensureStateAfterDecoded(PEMethodScope methodScope) {
|
|
887 |
if (methodScope.invokeData.invoke.stateAfter() == null) {
|
|
888 |
methodScope.invokeData.invoke.setStateAfter((FrameState) ensureNodeCreated(methodScope.caller, methodScope.callerLoopScope, methodScope.invokeData.stateAfterOrderId));
|
|
889 |
}
|
|
890 |
}
|
|
891 |
|
|
892 |
protected void ensureExceptionStateDecoded(PEMethodScope methodScope) {
|
|
893 |
if (methodScope.exceptionState == null && methodScope.caller != null && methodScope.invokeData.invoke instanceof InvokeWithExceptionNode) {
|
|
894 |
ensureStateAfterDecoded(methodScope);
|
|
895 |
|
|
896 |
assert methodScope.exceptionPlaceholderNode == null;
|
46371
|
897 |
methodScope.exceptionPlaceholderNode = graph.add(new ExceptionPlaceholderNode());
|
43972
|
898 |
registerNode(methodScope.callerLoopScope, methodScope.invokeData.exceptionOrderId, methodScope.exceptionPlaceholderNode, false, false);
|
|
899 |
FrameState exceptionState = (FrameState) ensureNodeCreated(methodScope.caller, methodScope.callerLoopScope, methodScope.invokeData.exceptionStateOrderId);
|
|
900 |
|
|
901 |
if (exceptionState.outerFrameState() == null && methodScope.caller != null) {
|
|
902 |
ensureOuterStateDecoded(methodScope.caller);
|
|
903 |
exceptionState.setOuterFrameState(methodScope.caller.outerState);
|
|
904 |
}
|
|
905 |
methodScope.exceptionState = exceptionState;
|
|
906 |
}
|
|
907 |
}
|
|
908 |
|
|
909 |
@Override
|
|
910 |
protected Node addFloatingNode(MethodScope s, Node node) {
|
|
911 |
Node addedNode = super.addFloatingNode(s, node);
|
|
912 |
PEMethodScope methodScope = (PEMethodScope) s;
|
|
913 |
NodeSourcePosition pos = node.getNodeSourcePosition();
|
|
914 |
if (methodScope.isInlinedMethod()) {
|
|
915 |
if (pos != null) {
|
|
916 |
NodeSourcePosition bytecodePosition = methodScope.getCallerBytecodePosition();
|
|
917 |
node.setNodeSourcePosition(pos.addCaller(bytecodePosition));
|
|
918 |
}
|
|
919 |
}
|
|
920 |
return addedNode;
|
|
921 |
}
|
|
922 |
|
|
923 |
@Override
|
|
924 |
protected Node handleFloatingNodeAfterAdd(MethodScope s, LoopScope loopScope, Node node) {
|
|
925 |
PEMethodScope methodScope = (PEMethodScope) s;
|
|
926 |
|
|
927 |
if (methodScope.isInlinedMethod()) {
|
|
928 |
if (node instanceof FrameState) {
|
|
929 |
FrameState frameState = (FrameState) node;
|
|
930 |
|
|
931 |
ensureOuterStateDecoded(methodScope);
|
|
932 |
if (frameState.bci < 0) {
|
|
933 |
ensureExceptionStateDecoded(methodScope);
|
|
934 |
}
|
|
935 |
List<ValueNode> invokeArgsList = null;
|
|
936 |
if (frameState.bci == BytecodeFrame.BEFORE_BCI) {
|
|
937 |
/*
|
|
938 |
* We know that the argument list is only used in this case, so avoid the List
|
|
939 |
* allocation for "normal" bcis.
|
|
940 |
*/
|
|
941 |
invokeArgsList = Arrays.asList(methodScope.arguments);
|
|
942 |
}
|
|
943 |
return InliningUtil.processFrameState(frameState, methodScope.invokeData.invoke, methodScope.method, methodScope.exceptionState, methodScope.outerState, true, methodScope.method,
|
|
944 |
invokeArgsList);
|
|
945 |
|
|
946 |
} else if (node instanceof MonitorIdNode) {
|
|
947 |
ensureOuterStateDecoded(methodScope);
|
|
948 |
InliningUtil.processMonitorId(methodScope.outerState, (MonitorIdNode) node);
|
|
949 |
return node;
|
|
950 |
}
|
|
951 |
}
|
|
952 |
|
|
953 |
return node;
|
|
954 |
}
|
|
955 |
}
|