# HG changeset patch # User Erik Eckstein # Date 1395824911 -3600 # Node ID 3e1e832871283537b6da321c4cb845dd465ff61c # Parent 3128becfec959c16fe31409f358b75744b4861c7 add assertion to detect infinite recursion in snippet inlining diff -r 3128becfec95 -r 3e1e83287128 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Wed Mar 26 10:06:25 2014 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Wed Mar 26 10:08:31 2014 +0100 @@ -343,7 +343,7 @@ public StructuredGraph makeGraph(final SnippetInliningPolicy policy) { try (Scope s = Debug.scope("BuildSnippetGraph", method)) { - StructuredGraph graph = parseGraph(method, policy); + StructuredGraph graph = parseGraph(method, policy, 0); // Cannot have a finalized version of a graph in the cache graph = graph.copy(); @@ -383,12 +383,14 @@ new DeadCodeEliminationPhase().apply(graph); } - private StructuredGraph parseGraph(final ResolvedJavaMethod methodToParse, final SnippetInliningPolicy policy) { + private static final int MAX_GRAPH_INLINING_DEPTH = 100; // more than enough + + private StructuredGraph parseGraph(final ResolvedJavaMethod methodToParse, final SnippetInliningPolicy policy, int inliningDepth) { StructuredGraph graph = graphCache.get(methodToParse); if (graph == null) { StructuredGraph newGraph = null; try (Scope s = Debug.scope("ParseGraph", methodToParse)) { - newGraph = buildGraph(methodToParse, policy == null ? inliningPolicy(methodToParse) : policy); + newGraph = buildGraph(methodToParse, policy == null ? inliningPolicy(methodToParse) : policy, inliningDepth); } catch (Throwable e) { throw Debug.handle(e); } @@ -452,7 +454,8 @@ } } - private StructuredGraph buildGraph(final ResolvedJavaMethod methodToParse, final SnippetInliningPolicy policy) { + private StructuredGraph buildGraph(final ResolvedJavaMethod methodToParse, final SnippetInliningPolicy policy, int inliningDepth) { + assert inliningDepth < MAX_GRAPH_INLINING_DEPTH : "inlining limit exceeded"; assert isInlinableSnippet(methodToParse) : methodToParse; final StructuredGraph graph = buildInitialGraph(methodToParse); try (Scope s = Debug.scope("buildGraph", graph)) { @@ -484,7 +487,7 @@ " while preparing replacement " + format("%H.%n(%p)", method) + ". Placing \"//JaCoCo Exclude\" anywhere in " + methodToParse.getDeclaringClass().getSourceFileName() + " should fix this."); } - targetGraph = parseGraph(callee, policy); + targetGraph = parseGraph(callee, policy, inliningDepth + 1); } Object beforeInlineData = beforeInline(callTarget, targetGraph); InliningUtil.inline(callTarget.invoke(), targetGraph, true);