changeset 5343:20c14eb46238

added GraalOptions.CheckcastMinHintHitProbability to better guide use of hints for checkcasts
author Doug Simon <doug.simon@oracle.com>
date Wed, 02 May 2012 17:09:00 +0200
parents 77809963c5cc
children f47c770756e6
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotXirGenerator.java graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java
diffstat 3 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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 {
--- 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");
 
--- 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;