# HG changeset patch # User Gilles Duboscq # Date 1373546731 -7200 # Node ID a643c88d164f6e7e314d01cd6ab323a275bceeb8 # Parent 8d961f93725ccaf58afe1d608a39d800b4783073 Add scopes to capture the graphs in ReplacementsImpl diff -r 8d961f93725c -r a643c88d164f 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 Tue Jul 09 18:17:55 2013 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Thu Jul 11 14:45:31 2013 +0200 @@ -316,16 +316,21 @@ */ protected StructuredGraph buildInitialGraph(final ResolvedJavaMethod methodToParse) { final StructuredGraph graph = new StructuredGraph(methodToParse); - GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(); - GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, config, OptimisticOptimizations.NONE); - graphBuilder.apply(graph); + Debug.scope("buildInitialGraph", graph, new Runnable() { + + @Override + public void run() { + GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(); + GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, config, OptimisticOptimizations.NONE); + graphBuilder.apply(graph); - new WordTypeVerificationPhase(runtime, target.wordKind).apply(graph); - if (OptCanonicalizer.getValue()) { - new WordTypeRewriterPhase(runtime, target.wordKind).apply(graph); - new CanonicalizerPhase.Instance(runtime, assumptions, true).apply(graph); - } - + new WordTypeVerificationPhase(runtime, target.wordKind).apply(graph); + if (OptCanonicalizer.getValue()) { + new WordTypeRewriterPhase(runtime, target.wordKind).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions, true).apply(graph); + } + } + }); return graph; } @@ -359,46 +364,51 @@ private StructuredGraph buildGraph(final ResolvedJavaMethod methodToParse, final SnippetInliningPolicy policy) { assert !Modifier.isAbstract(methodToParse.getModifiers()) && !Modifier.isNative(methodToParse.getModifiers()) : methodToParse; final StructuredGraph graph = buildInitialGraph(methodToParse); - - for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.class)) { - ResolvedJavaMethod callee = callTarget.targetMethod(); - if (callee == method) { - final StructuredGraph originalGraph = new StructuredGraph(original); - new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getSnippetDefault(), OptimisticOptimizations.NONE).apply(originalGraph); - InliningUtil.inline(callTarget.invoke(), originalGraph, true); + Debug.scope("buildGraph", graph, new Runnable() { - Debug.dump(graph, "after inlining %s", callee); - afterInline(graph, originalGraph); - substituteCallsOriginal = true; - } else { - StructuredGraph intrinsicGraph = InliningUtil.getIntrinsicGraph(ReplacementsImpl.this, callee); - if ((callTarget.invokeKind() == InvokeKind.Static || callTarget.invokeKind() == InvokeKind.Special) && - (policy.shouldInline(callee, methodToParse) || (intrinsicGraph != null && policy.shouldUseReplacement(callee, methodToParse)))) { - StructuredGraph targetGraph; - if (intrinsicGraph != null && policy.shouldUseReplacement(callee, methodToParse)) { - targetGraph = intrinsicGraph; + @Override + public void run() { + for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.class)) { + ResolvedJavaMethod callee = callTarget.targetMethod(); + if (callee == method) { + final StructuredGraph originalGraph = new StructuredGraph(original); + new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getSnippetDefault(), OptimisticOptimizations.NONE).apply(originalGraph); + InliningUtil.inline(callTarget.invoke(), originalGraph, true); + + Debug.dump(graph, "after inlining %s", callee); + afterInline(graph, originalGraph); + substituteCallsOriginal = true; } else { - if (callee.getName().startsWith("$jacoco")) { - throw new GraalInternalError("Parsing call to JaCoCo instrumentation method " + format("%H.%n(%p)", callee) + " from " + format("%H.%n(%p)", methodToParse) + - " while preparing replacement " + format("%H.%n(%p)", method) + ". Placing \"//JaCoCo Exclude\" anywhere in " + - methodToParse.getDeclaringClass().getSourceFileName() + " should fix this."); + StructuredGraph intrinsicGraph = InliningUtil.getIntrinsicGraph(ReplacementsImpl.this, callee); + if ((callTarget.invokeKind() == InvokeKind.Static || callTarget.invokeKind() == InvokeKind.Special) && + (policy.shouldInline(callee, methodToParse) || (intrinsicGraph != null && policy.shouldUseReplacement(callee, methodToParse)))) { + StructuredGraph targetGraph; + if (intrinsicGraph != null && policy.shouldUseReplacement(callee, methodToParse)) { + targetGraph = intrinsicGraph; + } else { + if (callee.getName().startsWith("$jacoco")) { + throw new GraalInternalError("Parsing call to JaCoCo instrumentation method " + format("%H.%n(%p)", callee) + " from " + format("%H.%n(%p)", methodToParse) + + " while preparing replacement " + format("%H.%n(%p)", method) + ". Placing \"//JaCoCo Exclude\" anywhere in " + + methodToParse.getDeclaringClass().getSourceFileName() + " should fix this."); + } + targetGraph = parseGraph(callee, policy); + } + InliningUtil.inline(callTarget.invoke(), targetGraph, true); + Debug.dump(graph, "after inlining %s", callee); + afterInline(graph, targetGraph); } - targetGraph = parseGraph(callee, policy); } - InliningUtil.inline(callTarget.invoke(), targetGraph, true); - Debug.dump(graph, "after inlining %s", callee); - afterInline(graph, targetGraph); } - } - } - afterInlining(graph); + afterInlining(graph); - for (LoopEndNode end : graph.getNodes(LoopEndNode.class)) { - end.disableSafepoint(); - } + for (LoopEndNode end : graph.getNodes(LoopEndNode.class)) { + end.disableSafepoint(); + } - new DeadCodeEliminationPhase().apply(graph); + new DeadCodeEliminationPhase().apply(graph); + } + }); return graph; } }