changeset 5772:2f7a03583a32

added counters for code paths through the new object snippets generalized -G:+CheckcastCounters option to -G:+SnippetCounters
author Doug Simon <doug.simon@oracle.com>
date Thu, 05 Jul 2012 17:52:32 +0200
parents 613a3ddb9a71
children 772118da9f68
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotXirGenerator.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetCounter.java
diffstat 5 files changed, 36 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java	Thu Jul 05 16:24:18 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java	Thu Jul 05 17:52:32 2012 +0200
@@ -231,9 +231,9 @@
     public static boolean PrintFlags                           = false;
 
     /**
-     * Counts the various paths taken through a compiled checkcast.
+     * Counts the various paths taken through snippets.
      */
-    public static boolean CheckcastCounters = false;
+    public static boolean SnippetCounters = false;
 
     /**
      * If the probability that a checkcast will hit one the profiled types (up to {@link #CheckcastMaxHints})
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotXirGenerator.java	Thu Jul 05 16:24:18 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotXirGenerator.java	Thu Jul 05 17:52:32 2012 +0200
@@ -498,7 +498,7 @@
         protected XirTemplate create(CiXirAssembler asm, long flags, int hintCount) {
             asm.restart(Kind.Void);
             boolean exact = is(EXACT_HINTS, flags);
-            XirParameter counters = GraalOptions.CheckcastCounters ? asm.createConstantInputParameter("counters", Kind.Object) : null;
+            XirParameter counters = GraalOptions.SnippetCounters ? asm.createConstantInputParameter("counters", Kind.Object) : null;
             XirParameter object = asm.createInputParameter("object", Kind.Object);
             final XirOperand hub = exact ? null : asm.createConstantInputParameter("hub", Kind.Object);
 
@@ -807,7 +807,7 @@
 
     @Override
     public XirSnippet genCheckCast(XirSite site, XirArgument receiver, XirArgument hub, ResolvedJavaType type, JavaTypeProfile profile) {
-        final boolean useCounters = GraalOptions.CheckcastCounters;
+        final boolean useCounters = GraalOptions.SnippetCounters;
         TypeCheckHints hints = new TypeCheckHints(type, profile, site.assumptions(), GraalOptions.CheckcastMinHintHitProbability, GraalOptions.CheckcastMaxHints);
         int hintsLength = hints.types.length;
         if (hintsLength == 0) {
@@ -1042,7 +1042,7 @@
     }
 
     public static void printCounters(PrintStream out) {
-        if (GraalOptions.CheckcastCounters) {
+        if (GraalOptions.SnippetCounters) {
             printCheckcastCounters(out);
         }
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java	Thu Jul 05 16:24:18 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java	Thu Jul 05 17:52:32 2012 +0200
@@ -305,7 +305,7 @@
         }
     }
 
-    private static final SnippetCounter.Group counters = GraalOptions.CheckcastCounters ? new SnippetCounter.Group("Checkcast") : null;
+    private static final SnippetCounter.Group counters = GraalOptions.SnippetCounters ? new SnippetCounter.Group("Checkcast") : null;
     private static final SnippetCounter hintsHit = new SnippetCounter(counters, "hintsHit", "hit a hint type");
     private static final SnippetCounter exactHit = new SnippetCounter(counters, "exactHit", "exact type test succeeded");
     private static final SnippetCounter exactMiss = new SnippetCounter(counters, "exactMiss", "exact type test failed");
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java	Thu Jul 05 16:24:18 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java	Thu Jul 05 17:52:32 2012 +0200
@@ -33,6 +33,7 @@
 
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
+import com.oracle.graal.compiler.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.hotspot.*;
@@ -75,6 +76,7 @@
                     @ConstantParameter("size") int size) {
 
         if (memory == Word.zero()) {
+            new_stub.inc();
             return NewInstanceStubCall.call(hub);
         }
         formatObject(hub, size, memory, initialMarkWord);
@@ -106,8 +108,18 @@
 
     private static Object initializeArray(Word memory, Object hub, int length, int size, Word initialMarkWord, int headerSize, boolean isObjectArray) {
         if (memory == Word.zero()) {
+            if (isObjectArray) {
+                anewarray_stub.inc();
+            } else {
+                newarray_stub.inc();
+            }
             return NewArrayStubCall.call(isObjectArray, hub, length);
         }
+        if (isObjectArray) {
+            anewarray_loopInit.inc();
+        } else {
+            newarray_loopInit.inc();
+        }
         formatArray(hub, size, length, headerSize, memory, initialMarkWord);
         Object instance = memory.toObject();
         return castFromHub(verifyOop(instance), hub);
@@ -171,11 +183,13 @@
         storeObject(memory, 0, markOffset(), headerPrototype);
         storeObject(memory, 0, hubOffset(), hub);
         if (size <= MAX_UNROLLED_OBJECT_ZEROING_SIZE) {
+            new_seqInit.inc();
             explodeLoop();
             for (int offset = 2 * wordSize(); offset < size; offset += wordSize()) {
                 storeWord(memory, 0, offset, Word.zero());
             }
         } else {
+            new_loopInit.inc();
             for (int offset = 2 * wordSize(); offset < size; offset += wordSize()) {
                 storeWord(memory, 0, offset, Word.zero());
             }
@@ -380,4 +394,17 @@
     private static int arrayLengthOffset() {
         return HotSpotGraalRuntime.getInstance().getConfig().arrayLengthOffset;
     }
+
+    private static final SnippetCounter.Group countersNew = GraalOptions.SnippetCounters ? new SnippetCounter.Group("NewInstance") : null;
+    private static final SnippetCounter new_seqInit = new SnippetCounter(countersNew, "tlabSeqInit", "TLAB alloc with unrolled zeroing");
+    private static final SnippetCounter new_loopInit = new SnippetCounter(countersNew, "tlabLoopInit", "TLAB alloc with zeroing in a loop");
+    private static final SnippetCounter new_stub = new SnippetCounter(countersNew, "stub", "alloc and zeroing via stub");
+
+    private static final SnippetCounter.Group countersNewPrimitiveArray = GraalOptions.SnippetCounters ? new SnippetCounter.Group("NewPrimitiveArray") : null;
+    private static final SnippetCounter newarray_loopInit = new SnippetCounter(countersNewPrimitiveArray, "tlabLoopInit", "TLAB alloc with zeroing in a loop");
+    private static final SnippetCounter newarray_stub = new SnippetCounter(countersNewPrimitiveArray, "stub", "alloc and zeroing via stub");
+
+    private static final SnippetCounter.Group countersNewObjectArray = GraalOptions.SnippetCounters ? new SnippetCounter.Group("NewObjectArray") : null;
+    private static final SnippetCounter anewarray_loopInit = new SnippetCounter(countersNewObjectArray, "tlabLoopInit", "TLAB alloc with zeroing in a loop");
+    private static final SnippetCounter anewarray_stub = new SnippetCounter(countersNewObjectArray, "stub", "alloc and zeroing via stub");
 }
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetCounter.java	Thu Jul 05 16:24:18 2012 +0200
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetCounter.java	Thu Jul 05 17:52:32 2012 +0200
@@ -54,15 +54,17 @@
             Collections.sort(counters);
 
             long total = 0;
+            int maxNameLen = 0;
             for (SnippetCounter c : counters) {
                 total += c.value;
+                maxNameLen = Math.max(c.name.length(), maxNameLen);
             }
 
             StringBuilder buf = new StringBuilder(String.format("Counters: %s%n", name));
 
             for (SnippetCounter c : counters) {
                 double percent = total == 0D ? 0D : ((double) (c.value * 100)) / total;
-                buf.append(String.format("%16s: %5.2f%%%10d  // %s%n", c.name, percent, c.value, c.description));
+                buf.append(String.format("  %" + maxNameLen + "s: %5.2f%%%10d  // %s%n", c.name, percent, c.value, c.description));
             }
             return buf.toString();
         }