Mercurial > hg > graal-compiler
changeset 5052:7a019062451e
Merge
author | Christian Haeubl <christian.haeubl@oracle.com> |
---|---|
date | Wed, 07 Mar 2012 14:14:25 -0800 |
parents | 2ab527c53dba (diff) 6bc165b0fdcd (current diff) |
children | c53115427ff9 |
files | |
diffstat | 2 files changed, 52 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java Wed Mar 07 21:04:56 2012 +0100 +++ b/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java Wed Mar 07 14:14:25 2012 -0800 @@ -535,12 +535,12 @@ } private void genGoto() { - if (profilingInfo.getBranchTakenProbability(bci()) == 0) { - append(currentGraph.add(new DeoptimizeNode(DeoptAction.InvalidateReprofile))); - } else { - appendGoto(createTarget(currentBlock.successors.get(0), frameState)); - assert currentBlock.normalSuccessors == 1; + double probability = profilingInfo.getBranchTakenProbability(bci()); + if (probability < 0) { + probability = 1; } + appendGoto(createTarget(probability, currentBlock.successors.get(0), frameState)); + assert currentBlock.normalSuccessors == 1; } private void ifNode(ValueNode x, Condition cond, ValueNode y) { @@ -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 21:04:56 2012 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfBoxingEliminationTest.java Wed Mar 07 14:14:25 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); + } + }); } }