changeset 10707:a643c88d164f

Add scopes to capture the graphs in ReplacementsImpl
author Gilles Duboscq <duboscq@ssw.jku.at>
date Thu, 11 Jul 2013 14:45:31 +0200
parents 8d961f93725c
children 41e9c8845826
files graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java
diffstat 1 files changed, 51 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- 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;
         }
     }