changeset 5051:2ab527c53dba

another fix for goto's deopt case
author Christian Haeubl <christian.haeubl@oracle.com>
date Wed, 07 Mar 2012 14:14:03 -0800
parents 9f4224ae490f
children 7a019062451e
files graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfBoxingEliminationTest.java
diffstat 2 files changed, 48 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java	Wed Mar 07 11:36:53 2012 -0800
+++ b/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java	Wed Mar 07 14:14:03 2012 -0800
@@ -539,7 +539,7 @@
         if (probability < 0) {
             probability = 1;
         }
-        appendGoto(createBlockTarget(probability, currentBlock.successors.get(0), frameState));
+        appendGoto(createTarget(probability, currentBlock.successors.get(0), frameState));
         assert currentBlock.normalSuccessors == 1;
     }
 
@@ -1196,6 +1196,20 @@
         return x;
     }
 
+    private FixedNode createTarget(double probability, Block block, FrameStateBuilder stateAfter) {
+        assert probability >= 0 && probability <= 1;
+        if (probability == 0 && config.useBranchPrediction()) {
+            BeginNode begin = currentGraph.add(new BeginNode());
+            DeoptimizeNode deopt = currentGraph.add(new DeoptimizeNode(DeoptAction.InvalidateReprofile));
+            begin.setNext(deopt);
+            // Note: We are not allowed to set the stateAfter of the begin node, because we have to deoptimize to
+            // a bci _before_ the actual if, so that the interpreter can update the profiling information.
+            return begin;
+        } else {
+            return createTarget(block, stateAfter);
+        }
+    }
+
     private FixedNode createTarget(Block block, FrameStateBuilder stateAfter) {
         assert block != null && stateAfter != null;
         assert !block.isExceptionEntry || stateAfter.stackSize() == 1;
@@ -1263,17 +1277,7 @@
      * deoptimizes immediately.
      */
     private BeginNode createBlockTarget(double probability, Block block, FrameStateBuilder stateAfter) {
-        assert probability >= 0 && probability <= 1;
-        if (probability == 0 && config.useBranchPrediction()) {
-            BeginNode begin = currentGraph.add(new BeginNode());
-            DeoptimizeNode deopt = currentGraph.add(new DeoptimizeNode(DeoptAction.InvalidateReprofile));
-            begin.setNext(deopt);
-            // Note: We are not allowed to set the stateAfter of the begin node, because we have to deoptimize to
-            // a bci _before_ the actual if, so that the interpreter can update the profiling information.
-            return begin;
-        }
-
-        FixedNode target = createTarget(block, stateAfter);
+        FixedNode target = createTarget(probability, block, stateAfter);
         assert !(target instanceof BeginNode);
         BeginNode begin = currentGraph.add(new BeginNode());
         begin.setNext(target);
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfBoxingEliminationTest.java	Wed Mar 07 11:36:53 2012 -0800
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfBoxingEliminationTest.java	Wed Mar 07 14:14:03 2012 -0800
@@ -69,31 +69,37 @@
         return result;
     }
 
-    private void test(String snippet) {
-        StructuredGraph graph = parse(snippet);
-        BoxingMethodPool pool = new BoxingMethodPool(runtime());
-        IdentifyBoxingPhase identifyBoxingPhase = new IdentifyBoxingPhase(pool);
-        PhasePlan phasePlan = getDefaultPhasePlan();
-        phasePlan.addPhase(PhasePosition.AFTER_PARSING, identifyBoxingPhase);
-        phasePlan.addPhase(PhasePosition.AFTER_PARSING, new PhiStampPhase());
-        identifyBoxingPhase.apply(graph);
-        Collection<Invoke> hints = new ArrayList<>();
-        for (Invoke invoke : graph.getInvokes()) {
-            hints.add(invoke);
-        }
-        new InliningPhase(null, runtime(), hints, null, phasePlan).apply(graph);
-        new CanonicalizerPhase(null, runtime(), null).apply(graph);
-        new PhiStampPhase().apply(graph);
-        new CanonicalizerPhase(null, runtime(), null).apply(graph);
-        Debug.dump(graph, "Graph");
-        new BoxingEliminationPhase().apply(graph);
-        Debug.dump(graph, "Graph");
-        new ExpandBoxingNodesPhase(pool).apply(graph);
-        new CanonicalizerPhase(null, runtime(), null).apply(graph);
-        new DeadCodeEliminationPhase().apply(graph);
-        StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET);
-        new CanonicalizerPhase(null, runtime(), null).apply(referenceGraph);
-        new DeadCodeEliminationPhase().apply(referenceGraph);
-        assertEquals(referenceGraph, graph);
+    private void test(final String snippet) {
+        Debug.scope("IfBoxingEliminationTest", new DebugDumpScope(snippet), new Runnable() {
+            @Override
+            public void run() {
+                StructuredGraph graph = parse(snippet);
+                BoxingMethodPool pool = new BoxingMethodPool(runtime());
+                IdentifyBoxingPhase identifyBoxingPhase = new IdentifyBoxingPhase(pool);
+                PhasePlan phasePlan = getDefaultPhasePlan();
+                phasePlan.addPhase(PhasePosition.AFTER_PARSING, identifyBoxingPhase);
+                phasePlan.addPhase(PhasePosition.AFTER_PARSING, new PhiStampPhase());
+                identifyBoxingPhase.apply(graph);
+                Collection<Invoke> hints = new ArrayList<>();
+                for (Invoke invoke : graph.getInvokes()) {
+                    hints.add(invoke);
+                }
+                new InliningPhase(null, runtime(), hints, null, phasePlan).apply(graph);
+                new CanonicalizerPhase(null, runtime(), null).apply(graph);
+                new PhiStampPhase().apply(graph);
+                new CanonicalizerPhase(null, runtime(), null).apply(graph);
+                Debug.dump(graph, "Graph");
+                new BoxingEliminationPhase().apply(graph);
+                Debug.dump(graph, "Graph");
+                new ExpandBoxingNodesPhase(pool).apply(graph);
+                new CanonicalizerPhase(null, runtime(), null).apply(graph);
+                new DeadCodeEliminationPhase().apply(graph);
+                StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET);
+                new CanonicalizerPhase(null, runtime(), null).apply(referenceGraph);
+                new DeadCodeEliminationPhase().apply(referenceGraph);
+
+                assertEquals(referenceGraph, graph);
+            }
+        });
     }
 }