# HG changeset patch # User Christian Haeubl # Date 1331143353 28800 # Node ID d0d0dfbebd03d125a630ff8bb4372a9e8fecb206 # Parent e5d42eccfb29e4afcebf44d17546ad5e312b2fc2# Parent 44d746dc51bff61d9726d7ab7cf4f571a6aab72f Merge diff -r 44d746dc51bf -r d0d0dfbebd03 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:55:44 2012 -0800 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java Wed Mar 07 10:02:33 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 44d746dc51bf -r d0d0dfbebd03 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:55:44 2012 -0800 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Wed Mar 07 10:02:33 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 44d746dc51bf -r d0d0dfbebd03 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodData.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodData.java Tue Mar 06 11:55:44 2012 -0800 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodData.java Wed Mar 07 10:02:33 2012 -0800 @@ -302,7 +302,7 @@ @Override public double getBranchTakenProbability(HotSpotMethodData data, int position) { - return 1; + return getExecutionCount(data, position) != 0 ? 1 : 0; } @Override diff -r 44d746dc51bf -r d0d0dfbebd03 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodResolvedImpl.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodResolvedImpl.java Tue Mar 06 11:55:44 2012 -0800 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotMethodResolvedImpl.java Wed Mar 07 10:02:33 2012 -0800 @@ -238,6 +238,7 @@ return ((HotSpotTypeResolvedImpl) holder()).constantPool(); } + @Override public void dumpProfile() { TTY.println("profile info for %s", this); TTY.println("canBeStaticallyBound: " + canBeStaticallyBound()); diff -r 44d746dc51bf -r d0d0dfbebd03 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:55:44 2012 -0800 +++ b/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java Wed Mar 07 10:02:33 2012 -0800 @@ -152,6 +152,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; @@ -531,8 +535,12 @@ } 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) { @@ -549,7 +557,7 @@ if (probability < 0) { assert probability == -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)); diff -r 44d746dc51bf -r d0d0dfbebd03 src/cpu/x86/vm/c1_globals_x86.hpp --- a/src/cpu/x86/vm/c1_globals_x86.hpp Tue Mar 06 11:55:44 2012 -0800 +++ b/src/cpu/x86/vm/c1_globals_x86.hpp Wed Mar 07 10:02:33 2012 -0800 @@ -37,27 +37,41 @@ define_pd_global(bool, ResizeTLAB, true ); define_pd_global(bool, InlineIntrinsics, true ); define_pd_global(bool, PreferInterpreterNativeStubs, false); -define_pd_global(bool, ProfileTraps, true ); // changed for GRAAL -define_pd_global(bool, UseOnStackReplacement, true ); define_pd_global(bool, TieredCompilation, false); -define_pd_global(intx, CompileThreshold, 4500 ); // changed for GRAAL define_pd_global(intx, BackEdgeThreshold, 100000); define_pd_global(intx, OnStackReplacePercentage, 933 ); define_pd_global(intx, FreqInlineSize, 325 ); define_pd_global(intx, NewSizeThreadIncrease, 4*K ); -define_pd_global(intx, InitialCodeCacheSize, 4*M); // changed for GRAAL -define_pd_global(intx, ReservedCodeCacheSize, 48*M ); // changed for GRAAL -define_pd_global(bool, ProfileInterpreter, true ); // changed for GRAAL -define_pd_global(intx, CodeCacheExpansionSize, 64*K ); // changed for GRAAL -define_pd_global(uintx,CodeCacheMinBlockLength, 4); // changed for GRAAL define_pd_global(uintx,PermSize, 12*M ); define_pd_global(uintx,MaxPermSize, 64*M ); define_pd_global(bool, NeverActAsServerClassMachine, true ); define_pd_global(uint64_t,MaxRAM, 1ULL*G); define_pd_global(bool, CICompileOSR, true ); -define_pd_global(intx, TypeProfileWidth, 8 ); // changed for GRAAL + +#ifdef GRAAL +define_pd_global(bool, ProfileTraps, true ); +define_pd_global(bool, UseOnStackReplacement, false); +define_pd_global(intx, CompileThreshold, 4500 ); +define_pd_global(intx, InitialCodeCacheSize, 4*M ); +define_pd_global(intx, ReservedCodeCacheSize, 48*M ); +define_pd_global(bool, ProfileInterpreter, true ); +define_pd_global(intx, CodeCacheExpansionSize, 64*K ); +define_pd_global(uintx,CodeCacheMinBlockLength, 4); +define_pd_global(intx, TypeProfileWidth, 8); +#else +define_pd_global(bool, ProfileTraps, false); +define_pd_global(bool, UseOnStackReplacement, true ); +define_pd_global(intx, CompileThreshold, 1500 ); +define_pd_global(intx, InitialCodeCacheSize, 160*K); +define_pd_global(intx, ReservedCodeCacheSize, 32*M ); +define_pd_global(bool, ProfileInterpreter, false); +define_pd_global(intx, CodeCacheExpansionSize, 32*K ); +define_pd_global(uintx,CodeCacheMinBlockLength, 1); +define_pd_global(intx, TypeProfileWidth, 0); +#endif // GRAAL #endif // !TIERED + define_pd_global(bool, RoundFPResults, true ); define_pd_global(bool, LIRFillDelaySlots, false); diff -r 44d746dc51bf -r d0d0dfbebd03 src/cpu/x86/vm/templateInterpreter_x86_64.cpp --- a/src/cpu/x86/vm/templateInterpreter_x86_64.cpp Tue Mar 06 11:55:44 2012 -0800 +++ b/src/cpu/x86/vm/templateInterpreter_x86_64.cpp Wed Mar 07 10:02:33 2012 -0800 @@ -346,7 +346,7 @@ // Test to see if we should create a method data oop __ cmp32(rcx, ExternalAddress((address)&InvocationCounter::InterpreterProfileLimit)); __ jcc(Assembler::less, *profile_method_continue); - + // if no method data exists, go to profile_method __ test_method_data_pointer(rax, *profile_method); } diff -r 44d746dc51bf -r d0d0dfbebd03 src/share/vm/code/nmethod.cpp --- a/src/share/vm/code/nmethod.cpp Tue Mar 06 11:55:44 2012 -0800 +++ b/src/share/vm/code/nmethod.cpp Wed Mar 07 10:02:33 2012 -0800 @@ -1178,7 +1178,9 @@ } void nmethod::inc_decompile_count() { +#ifndef GRAAL if (!is_compiled_by_c2()) return; +#endif // Could be gated by ProfileTraps, but do not bother... methodOop m = method(); if (m == NULL) return; diff -r 44d746dc51bf -r d0d0dfbebd03 src/share/vm/oops/methodDataOop.cpp --- a/src/share/vm/oops/methodDataOop.cpp Tue Mar 06 11:55:44 2012 -0800 +++ b/src/share/vm/oops/methodDataOop.cpp Wed Mar 07 10:02:33 2012 -0800 @@ -861,6 +861,19 @@ return CompilationPolicy::policy()->is_mature(_method); } +void methodDataOopDesc::inc_decompile_count() { + _nof_decompiles += 1; + if (decompile_count() > (uint)PerMethodRecompilationCutoff) { +#ifdef GRAAL + // TODO (ch) enable this in the fastdebug build only once we are more stable + ResourceMark m; + tty->print_cr("WARN: endless recompilation of %s. Method was set to not compilable.", method()->name_and_sig_as_C_string()); + //ShouldNotReachHere(); +#endif + method()->set_not_compilable(CompLevel_full_optimization); + } +} + // Translate a bci to its corresponding data index (di). address methodDataOopDesc::bci_to_dp(int bci) { ResourceMark rm; diff -r 44d746dc51bf -r d0d0dfbebd03 src/share/vm/oops/methodDataOop.hpp --- a/src/share/vm/oops/methodDataOop.hpp Tue Mar 06 11:55:44 2012 -0800 +++ b/src/share/vm/oops/methodDataOop.hpp Wed Mar 07 10:02:33 2012 -0800 @@ -1507,12 +1507,7 @@ uint decompile_count() const { return _nof_decompiles; } - void inc_decompile_count() { - _nof_decompiles += 1; - if (decompile_count() > (uint)PerMethodRecompilationCutoff) { - method()->set_not_compilable(CompLevel_full_optimization); - } - } + void inc_decompile_count(); // Support for code generation static ByteSize data_offset() { diff -r 44d746dc51bf -r d0d0dfbebd03 src/share/vm/runtime/deoptimization.cpp --- a/src/share/vm/runtime/deoptimization.cpp Tue Mar 06 11:55:44 2012 -0800 +++ b/src/share/vm/runtime/deoptimization.cpp Wed Mar 07 10:02:33 2012 -0800 @@ -164,7 +164,7 @@ // that can confuse an asynchronous stack walker. This counter is // decremented at the end of unpack_frames(). if (TraceDeoptimization) { - tty->print("Deoptimization "); + tty->print_cr("Deoptimizing thread " INTPTR_FORMAT, thread); } thread->inc_in_deopt_handler();