# HG changeset patch # User Doug Simon # Date 1371484519 -7200 # Node ID abb9d3a2602570a43f0f778c92ec5aa94f16b35d # Parent 529570e20afffc0f5d790922b148570d36c57d8d an instanceof instruction lowers to a deoptimize-on-hint-miss snippet only if its profile indicates a miss (of a hint type) occurs an order of magnitude less than the compilation threshold diff -r 529570e20aff -r abb9d3a26025 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Mon Jun 17 14:53:37 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Mon Jun 17 17:55:19 2013 +0200 @@ -38,6 +38,7 @@ public int codeEntryAlignment; public boolean verifyOops; public boolean ciTime; + public int compileThreshold; public boolean compileTheWorld; public int compileTheWorldStartAt; public int compileTheWorldStopAt; diff -r 529570e20aff -r abb9d3a26025 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java Mon Jun 17 14:53:37 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java Mon Jun 17 17:55:19 2013 +0200 @@ -59,10 +59,23 @@ public class InstanceOfSnippets implements Snippets { /** + * Gets the minimum required probability of a profiled instanceof hitting one the profiled types + * for use of the {@linkplain #instanceofWithProfile deoptimizing} snippet. The value is + * computed to be an order of magnitude greater than the configured compilation threshold. For + * example, if a method is compiled after being interpreted 10000 times, the deoptimizing + * snippet will only be used for an instanceof if its profile indicates that less than 1 in + * 100000 executions are for an object whose type is not one of the top N profiled types (where + * {@code N == } {@link GraalOptions#InstanceOfMaxHints}). + */ + public static double hintHitProbabilityThresholdForDeoptimizingSnippet() { + return 1.0D - (1.0D / (graalRuntime().getConfig().compileThreshold * 10)); + } + + /** * A test against a set of hints derived from a profile with very close to 100% precise coverage * of seen types. This snippet deoptimizes on hint miss paths. * - * @see GraalOptions#InstanceOfFullCoverageSpeculationThreshold + * @see #hintHitProbabilityThresholdForDeoptimizingSnippet() */ @Snippet public static Object instanceofWithProfile(Object object, @VarargsParameter Word[] hints, @VarargsParameter boolean[] hintIsPositive, Object trueValue, Object falseValue, @@ -196,7 +209,8 @@ ConstantNode hub = ConstantNode.forConstant(type.klass(), runtime, instanceOf.graph()); Arguments args; - if (hintInfo.hintHitProbability >= InstanceOfFullCoverageSpeculationThreshold.getValue()) { + + if (hintInfo.hintHitProbability >= hintHitProbabilityThresholdForDeoptimizingSnippet()) { Hints hints = createHints(hintInfo, runtime, false, hub.graph()); args = new Arguments(instanceofWithProfile); args.add("object", object); @@ -222,7 +236,7 @@ args.add("trueValue", replacer.trueValue); args.add("falseValue", replacer.falseValue); args.addConst("checkNull", !object.stamp().nonNull()); - if (hintInfo.hintHitProbability >= InstanceOfFullCoverageSpeculationThreshold.getValue()) { + if (hintInfo.hintHitProbability >= hintHitProbabilityThresholdForDeoptimizingSnippet()) { args.addConst("nullSeen", hintInfo.profile.getNullSeen() != TriState.FALSE); } return args; diff -r 529570e20aff -r abb9d3a26025 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Mon Jun 17 14:53:37 2013 +0200 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Mon Jun 17 17:55:19 2013 +0200 @@ -343,12 +343,4 @@ */ @Option(help = "") public static final OptionValue InstanceOfMaxHints = new OptionValue<>(2); - - /** - * If the probability that an instanceof will hit one the profiled types (up to {@link #InstanceOfMaxHints}) - * is above this value, the compiled instanceof will deoptimize if all hints are missed. - */ - @Option(help = "") - public static final OptionValue InstanceOfFullCoverageSpeculationThreshold = new OptionValue<>(0.998); - } diff -r 529570e20aff -r abb9d3a26025 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Mon Jun 17 14:53:37 2013 +0200 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Mon Jun 17 17:55:19 2013 +0200 @@ -668,6 +668,7 @@ set_boolean("cAssertions", DEBUG_ONLY(true) NOT_DEBUG(false)); set_boolean("verifyOops", VerifyOops); set_boolean("ciTime", CITime); + set_int("compileThreshold", CompileThreshold); set_boolean("compileTheWorld", CompileTheWorld); set_int("compileTheWorldStartAt", CompileTheWorldStartAt); set_int("compileTheWorldStopAt", CompileTheWorldStopAt);