# HG changeset patch # User Christian Haeubl # Date 1331158443 28800 # Node ID 2ab527c53dba7f870de4d7a9f141ce5c6c0f10ab # Parent 9f4224ae490f6c002afee0c6ab79d05fed1abb7c another fix for goto's deopt case diff -r 9f4224ae490f -r 2ab527c53dba graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java --- 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); diff -r 9f4224ae490f -r 2ab527c53dba graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfBoxingEliminationTest.java --- 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 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 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); + } + }); } }