Skip to content

Commit

Permalink
[GR-9427] Limit recursive inlining when parsing invokedynamic instruc…
Browse files Browse the repository at this point in the history
…tions.

PullRequest: graal/1351
  • Loading branch information
dougxc committed Apr 18, 2018
2 parents d1c5d7e + 33f1c0e commit 2f1b863
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
package org.graalvm.compiler.replacements;

import static org.graalvm.compiler.core.common.GraalOptions.MaximumRecursiveInlining;

import org.graalvm.compiler.core.common.type.StampPair;
import org.graalvm.compiler.graph.NodeInputList;
import org.graalvm.compiler.nodes.CallTargetNode;
Expand All @@ -46,6 +48,16 @@ public MethodHandlePlugin(MethodHandleAccessProvider methodHandleAccess, boolean
this.safeForDeoptimization = safeForDeoptimization;
}

private static int countRecursiveInlining(GraphBuilderContext b, ResolvedJavaMethod method) {
int count = 0;
for (GraphBuilderContext c = b.getParent(); c != null; c = c.getParent()) {
if (method.equals(c.getMethod())) {
count++;
}
}
return count;
}

@Override
public boolean handleInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
IntrinsicMethod intrinsicMethod = methodHandleAccess.lookupMethodHandleIntrinsic(method);
Expand Down Expand Up @@ -83,11 +95,19 @@ public <T extends ValueNode> T add(T node) {
// As such, it needs to recursively inline everything.
inlineEverything = args.length != argumentsList.size();
}
if (inlineEverything && !callTarget.targetMethod().hasBytecodes()) {
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
if (inlineEverything && !targetMethod.hasBytecodes()) {
// we need to force-inline but we can not, leave the invoke as-is
return false;
}
b.handleReplacedInvoke(invoke.getInvokeKind(), callTarget.targetMethod(), argumentsList.toArray(new ValueNode[argumentsList.size()]), inlineEverything);

int recursionDepth = countRecursiveInlining(b, targetMethod);
int maxRecursionDepth = MaximumRecursiveInlining.getValue(b.getOptions());
if (recursionDepth > maxRecursionDepth) {
return false;
}

b.handleReplacedInvoke(invoke.getInvokeKind(), targetMethod, argumentsList.toArray(new ValueNode[argumentsList.size()]), inlineEverything);
}
return true;
}
Expand Down

0 comments on commit 2f1b863

Please sign in to comment.