# HG changeset patch # User Christian Haeubl # Date 1331142488 28800 # Node ID 4d6e5ddf70e55b0dd31e776779f114650cd4d388 # Parent f3d2447db2d9999b65dae6278b3294fb73e7e5de added option to print the profiling information better log output for the inlining decisions diff -r f3d2447db2d9 -r 4d6e5ddf70e5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java Tue Mar 06 11:11:27 2012 -0800 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java Wed Mar 07 09:48:08 2012 -0800 @@ -129,6 +129,7 @@ // Other printing settings public static boolean PrintQueue = ____; public static boolean PrintCompilation = ____; + public static boolean PrintProfilingInformation = ____; public static boolean PrintXirTemplates = ____; public static boolean PrintIRWithLIR = ____; public static boolean PrintAssembly = ____; diff -r f3d2447db2d9 -r 4d6e5ddf70e5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Tue Mar 06 11:11:27 2012 -0800 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Wed Mar 07 09:48:08 2012 -0800 @@ -33,6 +33,7 @@ import com.oracle.max.graal.compiler.util.InliningUtil.InliningCallback; import com.oracle.max.graal.cri.*; import com.oracle.max.graal.debug.*; +import com.oracle.max.graal.debug.internal.*; import com.oracle.max.graal.graph.*; import com.oracle.max.graal.nodes.*; @@ -245,14 +246,13 @@ private static class WeightBasedInliningPolicy implements InliningPolicy { @Override public boolean isWorthInlining(StructuredGraph callerGraph, InlineInfo info) { - if (GraalOptions.SmallCompiledCodeSize >= 0 && info.compiledCodeSize() > GraalOptions.SmallCompiledCodeSize) { - Debug.log("not inlining (CompiledCodeSize too large %d): %s", info.compiledCodeSize(), info); + if (!checkCompiledCodeSize(info)) { return false; } double penalty = Math.pow(GraalOptions.InliningSizePenaltyExp, callerGraph.getNodeCount() / (double) GraalOptions.MaximumDesiredSize) / GraalOptions.InliningSizePenaltyExp; if (info.weight > GraalOptions.MaximumInlineWeight / (1 + penalty * GraalOptions.InliningSizePenalty)) { - Debug.log("not inlining (cut off by weight %e): ", info.weight); + Debug.log("not inlining (cut off by weight %e): %s", info.weight, info); return false; } @@ -265,13 +265,7 @@ @Override public boolean isWorthInlining(StructuredGraph callerGraph, InlineInfo info) { double maxSize = Math.max(GraalOptions.MaximumTrivialSize, Math.pow(GraalOptions.NestedInliningSizeRatio, info.level) * GraalOptions.MaximumInlineSize); - if (info.weight <= maxSize) { - Debug.log("inlining (size %f): %s", info.weight, info); - return true; - } else { - Debug.log("not inlining (too large %f): %s", info.weight, info); - return false; - } + return decideSizeBasedInlining(info, maxSize); } } @@ -279,8 +273,7 @@ @Override public boolean isWorthInlining(StructuredGraph callerGraph, InlineInfo info) { assert GraalOptions.ProbabilityAnalysis; - if (GraalOptions.SmallCompiledCodeSize >= 0 && info.compiledCodeSize() > GraalOptions.SmallCompiledCodeSize) { - Debug.log("not inlining (CompiledCodeSize too large %d): %s", info.compiledCodeSize(), info); + if (!checkCompiledCodeSize(info)) { return false; } @@ -288,13 +281,7 @@ double maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level) * GraalOptions.MaximumInlineSize * inlineWeight; maxSize = Math.max(GraalOptions.MaximumTrivialSize, maxSize); - if (info.weight <= maxSize) { - Debug.log("inlining (size %f <= %f): %s", info.weight, maxSize, info); - return true; - } else { - Debug.log("not inlining (too large %f > %f): %s", info.weight, maxSize, info); - return false; - } + return decideSizeBasedInlining(info, maxSize); } } @@ -302,8 +289,7 @@ @Override public boolean isWorthInlining(StructuredGraph callerGraph, InlineInfo info) { assert GraalOptions.ProbabilityAnalysis; - if (GraalOptions.SmallCompiledCodeSize >= 0 && info.compiledCodeSize() > GraalOptions.SmallCompiledCodeSize) { - Debug.log("not inlining (CompiledCodeSize too large %d): %s", info.compiledCodeSize(), info); + if (!checkCompiledCodeSize(info)) { return false; } @@ -312,13 +298,7 @@ maxSize = maxSize + maxSize * inlineBoost; maxSize = Math.min(GraalOptions.MaximumGreedyInlineSize, Math.max(GraalOptions.MaximumTrivialSize, maxSize)); - if (info.weight <= maxSize) { - Debug.log("inlining (size %f <= %f): %s", info.weight, maxSize, info); - return true; - } else { - Debug.log("not inlining (too large %f > %f): %s", info.weight, maxSize, info); - return false; - } + return decideSizeBasedInlining(info, maxSize); } } @@ -326,8 +306,7 @@ @Override public boolean isWorthInlining(StructuredGraph callerGraph, InlineInfo info) { assert GraalOptions.ProbabilityAnalysis; - if (GraalOptions.SmallCompiledCodeSize >= 0 && info.compiledCodeSize() > GraalOptions.SmallCompiledCodeSize) { - Debug.log("not inlining (CompiledCodeSize too large %d): %s", info.compiledCodeSize(), info); + if (!checkCompiledCodeSize(info)) { return false; } @@ -345,16 +324,28 @@ maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level) * maxSize * inlineRatio; maxSize = Math.max(maxSize, GraalOptions.MaximumTrivialSize); - if (info.weight <= maxSize) { - Debug.log("inlining (size %f <= %f): %s", info.weight, maxSize, info); - return true; - } else { - Debug.log("not inlining (too large %f > %f): %s", info.weight, maxSize, info); - return false; - } + return decideSizeBasedInlining(info, maxSize); } } + private static boolean decideSizeBasedInlining(InlineInfo info, double maxSize) { + boolean success = info.weight <= maxSize; + if (DebugScope.getInstance().isLogEnabled()) { + String formatterString = success ? "inlining invoke at %s@%d (size %f <= %f): %s" : "not inlining invoke at %s@%d (too large %f > %f): %s"; + Debug.log(formatterString, CiUtil.format("%H.%n(%p):%r", info.invoke.stateAfter().method()), info.invoke.bci(), info.weight, maxSize, info); + } + return success; + } + + private static boolean checkCompiledCodeSize(InlineInfo info) { + if (GraalOptions.SmallCompiledCodeSize >= 0 && info.compiledCodeSize() > GraalOptions.SmallCompiledCodeSize) { + Debug.log("not inlining invoke at %s@%d (CompiledCodeSize %d > %d): %s", CiUtil.format("%H.%n(%p):%r", info.invoke.stateAfter().method()), info.invoke.bci(), info.compiledCodeSize(), GraalOptions.SmallCompiledCodeSize, info); + return false; + } + return true; + } + + private interface WeightComputationPolicy { double computeWeight(RiResolvedMethod caller, RiResolvedMethod method, Invoke invoke, boolean preferredInvoke); } diff -r f3d2447db2d9 -r 4d6e5ddf70e5 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 Tue Mar 06 11:11:27 2012 -0800 +++ b/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java Wed Mar 07 09:48:08 2012 -0800 @@ -155,6 +155,10 @@ log.println("Compiling " + method); } + if (GraalOptions.PrintProfilingInformation) { + method.dumpProfile(); + } + // compute the block map, setup exception handlers and get the entrypoint(s) BciBlockMapping blockMap = createBlockMap(); this.canTrapBitSet = blockMap.canTrap; @@ -602,17 +606,21 @@ } private void genGoto() { - appendGoto(createTarget(currentBlock.successors.get(0), frameState)); - assert currentBlock.normalSuccessors == 1; + if (profilingInfo.getBranchTakenProbability(bci()) == 0) { + append(currentGraph.add(new DeoptimizeNode(DeoptAction.InvalidateReprofile))); + } else { + appendGoto(createTarget(currentBlock.successors.get(0), frameState)); + assert currentBlock.normalSuccessors == 1; + } } private void ifNode(ValueNode x, Condition cond, ValueNode y) { assert !x.isDeleted() && !y.isDeleted(); - double probability = profilingInfo.getBranchTakenProbability(bci()); - if (probability < 0) { - assert probability == -1 : "invalid probability"; + double takenProbability = profilingInfo.getBranchTakenProbability(bci()); + if (takenProbability < 0) { + assert takenProbability == -1 : "invalid probability"; Debug.log("missing probability in %s at bci %d", method, bci()); - probability = 0.5; + takenProbability = 0.5; } CompareNode condition = currentGraph.unique(new CompareNode(x, cond, y)); @@ -621,7 +629,7 @@ if (trueSuccessor == falseSuccessor) { appendGoto(trueSuccessor); } else { - append(currentGraph.add(new IfNode(condition, trueSuccessor, falseSuccessor, probability))); + append(currentGraph.add(new IfNode(condition, trueSuccessor, falseSuccessor, takenProbability))); } assert currentBlock.normalSuccessors == 2 : currentBlock.normalSuccessors;