Mercurial > hg > graal-compiler
comparison graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java @ 10069:abb9d3a26025
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
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 17 Jun 2013 17:55:19 +0200 |
parents | 0b30da13d86b |
children | e04f128d719c |
comparison
equal
deleted
inserted
replaced
10068:529570e20aff | 10069:abb9d3a26025 |
---|---|
57 * Cliff Click and John Rose. | 57 * Cliff Click and John Rose. |
58 */ | 58 */ |
59 public class InstanceOfSnippets implements Snippets { | 59 public class InstanceOfSnippets implements Snippets { |
60 | 60 |
61 /** | 61 /** |
62 * Gets the minimum required probability of a profiled instanceof hitting one the profiled types | |
63 * for use of the {@linkplain #instanceofWithProfile deoptimizing} snippet. The value is | |
64 * computed to be an order of magnitude greater than the configured compilation threshold. For | |
65 * example, if a method is compiled after being interpreted 10000 times, the deoptimizing | |
66 * snippet will only be used for an instanceof if its profile indicates that less than 1 in | |
67 * 100000 executions are for an object whose type is not one of the top N profiled types (where | |
68 * {@code N == } {@link GraalOptions#InstanceOfMaxHints}). | |
69 */ | |
70 public static double hintHitProbabilityThresholdForDeoptimizingSnippet() { | |
71 return 1.0D - (1.0D / (graalRuntime().getConfig().compileThreshold * 10)); | |
72 } | |
73 | |
74 /** | |
62 * A test against a set of hints derived from a profile with very close to 100% precise coverage | 75 * A test against a set of hints derived from a profile with very close to 100% precise coverage |
63 * of seen types. This snippet deoptimizes on hint miss paths. | 76 * of seen types. This snippet deoptimizes on hint miss paths. |
64 * | 77 * |
65 * @see GraalOptions#InstanceOfFullCoverageSpeculationThreshold | 78 * @see #hintHitProbabilityThresholdForDeoptimizingSnippet() |
66 */ | 79 */ |
67 @Snippet | 80 @Snippet |
68 public static Object instanceofWithProfile(Object object, @VarargsParameter Word[] hints, @VarargsParameter boolean[] hintIsPositive, Object trueValue, Object falseValue, | 81 public static Object instanceofWithProfile(Object object, @VarargsParameter Word[] hints, @VarargsParameter boolean[] hintIsPositive, Object trueValue, Object falseValue, |
69 @ConstantParameter boolean checkNull, @ConstantParameter boolean nullSeen) { | 82 @ConstantParameter boolean checkNull, @ConstantParameter boolean nullSeen) { |
70 if (probability(NOT_FREQUENT_PROBABILITY, checkNull && object == null)) { | 83 if (probability(NOT_FREQUENT_PROBABILITY, checkNull && object == null)) { |
194 TypeCheckHints hintInfo = new TypeCheckHints(instanceOf.type(), instanceOf.profile(), tool.assumptions(), InstanceOfMinHintHitProbability.getValue(), InstanceOfMaxHints.getValue()); | 207 TypeCheckHints hintInfo = new TypeCheckHints(instanceOf.type(), instanceOf.profile(), tool.assumptions(), InstanceOfMinHintHitProbability.getValue(), InstanceOfMaxHints.getValue()); |
195 final HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) instanceOf.type(); | 208 final HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) instanceOf.type(); |
196 ConstantNode hub = ConstantNode.forConstant(type.klass(), runtime, instanceOf.graph()); | 209 ConstantNode hub = ConstantNode.forConstant(type.klass(), runtime, instanceOf.graph()); |
197 | 210 |
198 Arguments args; | 211 Arguments args; |
199 if (hintInfo.hintHitProbability >= InstanceOfFullCoverageSpeculationThreshold.getValue()) { | 212 |
213 if (hintInfo.hintHitProbability >= hintHitProbabilityThresholdForDeoptimizingSnippet()) { | |
200 Hints hints = createHints(hintInfo, runtime, false, hub.graph()); | 214 Hints hints = createHints(hintInfo, runtime, false, hub.graph()); |
201 args = new Arguments(instanceofWithProfile); | 215 args = new Arguments(instanceofWithProfile); |
202 args.add("object", object); | 216 args.add("object", object); |
203 args.addVarargs("hints", Word.class, StampFactory.forKind(wordKind()), hints.hubs); | 217 args.addVarargs("hints", Word.class, StampFactory.forKind(wordKind()), hints.hubs); |
204 args.addVarargs("hintIsPositive", boolean.class, StampFactory.forKind(Kind.Boolean), hints.isPositive); | 218 args.addVarargs("hintIsPositive", boolean.class, StampFactory.forKind(Kind.Boolean), hints.isPositive); |
220 args.addVarargs("hintIsPositive", boolean.class, StampFactory.forKind(Kind.Boolean), hints.isPositive); | 234 args.addVarargs("hintIsPositive", boolean.class, StampFactory.forKind(Kind.Boolean), hints.isPositive); |
221 } | 235 } |
222 args.add("trueValue", replacer.trueValue); | 236 args.add("trueValue", replacer.trueValue); |
223 args.add("falseValue", replacer.falseValue); | 237 args.add("falseValue", replacer.falseValue); |
224 args.addConst("checkNull", !object.stamp().nonNull()); | 238 args.addConst("checkNull", !object.stamp().nonNull()); |
225 if (hintInfo.hintHitProbability >= InstanceOfFullCoverageSpeculationThreshold.getValue()) { | 239 if (hintInfo.hintHitProbability >= hintHitProbabilityThresholdForDeoptimizingSnippet()) { |
226 args.addConst("nullSeen", hintInfo.profile.getNullSeen() != TriState.FALSE); | 240 args.addConst("nullSeen", hintInfo.profile.getNullSeen() != TriState.FALSE); |
227 } | 241 } |
228 return args; | 242 return args; |
229 | 243 |
230 } else { | 244 } else { |