# HG changeset patch # User Doug Simon # Date 1335971340 -7200 # Node ID 20c14eb462388673b444a8549d11f0b7e2315da7 # Parent 77809963c5cc30e75348e0aa2bc2e5d91b319b14 added GraalOptions.CheckcastMinHintHitProbability to better guide use of hints for checkcasts diff -r 77809963c5cc -r 20c14eb46238 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Wed May 02 16:32:00 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Wed May 02 17:09:00 2012 +0200 @@ -230,7 +230,19 @@ */ public static boolean CheckcastCounters = false; + /** + * If the probability that a checkcast will hit one the profiled types (up to {@link #CheckcastMaxHints}) + * is below this value, the checkcast will be compiled without hints. + */ + public static double CheckcastMinHintHitProbability = 0.5; + + /** + * The maximum number of hint types that will be used when compiling a checkcast for which + * profiling information is available. Note that {@link #CheckcastMinHintHitProbability} + * also influences whether hints are used. + */ public static int CheckcastMaxHints = 2; + public static int InstanceOfMaxHints = 1; static { diff -r 77809963c5cc -r 20c14eb46238 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotXirGenerator.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotXirGenerator.java Wed May 02 16:32:00 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotXirGenerator.java Wed May 02 17:09:00 2012 +0200 @@ -464,12 +464,12 @@ }; enum CheckcastCounter { - hintsHit("hit one of the hint types"), - hintsMissed("missed all of the hint types"), + hintsHit("hit a hint type"), + hintsMissed("missed the hint types"), exact("tested type is (statically) final"), - noHints_class("profile information is not available for tested class"), - noHints_iface("profile information is not available for tested interface"), - noHints_unknown("tested type is not a compile-time constant"), + noHints_class("profile information is not used (test type is a class)"), + noHints_iface("profile information is not used (test type is an interface)"), + noHints_unknown("test type is not a compile-time constant"), isNull("object tested is null"), exception("type test failed with a ClassCastException"); diff -r 77809963c5cc -r 20c14eb46238 graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Wed May 02 16:32:00 2012 +0200 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Wed May 02 17:09:00 2012 +0200 @@ -603,18 +603,23 @@ if (typeProfile != null) { double notRecordedTypes = typeProfile.getNotRecordedProbability(); ProfiledType[] ptypes = typeProfile.getTypes(); - - if (notRecordedTypes == 0 && ptypes != null && ptypes.length > 0 && ptypes.length <= maxHints) { - //if (notRecordedTypes < 0.1d && ptypes != null && ptypes.length > 0) { + if (notRecordedTypes < GraalOptions.CheckcastMinHintHitProbability && ptypes != null && ptypes.length > 0) { RiResolvedType[] hints = new RiResolvedType[ptypes.length]; int hintCount = 0; + double totalHintProbability = 0.0d; for (ProfiledType ptype : ptypes) { RiResolvedType hint = ptype.type; if (hint.isSubtypeOf(type)) { hints[hintCount++] = hint; + totalHintProbability += ptype.probability; } } - return Arrays.copyOf(hints, Math.min(maxHints, hintCount)); + if (totalHintProbability >= GraalOptions.CheckcastMinHintHitProbability) { + if (hints.length == hintCount && hintCount <= maxHints) { + return hints; + } + return Arrays.copyOf(hints, Math.min(maxHints, hintCount)); + } } } return EMPTY_TYPE_ARRAY;