OSDN Git Service

Add class init stats to alloc counters (API change).
authorAndy McFadden <fadden@android.com>
Tue, 23 Feb 2010 01:07:23 +0000 (17:07 -0800)
committerAndy McFadden <fadden@android.com>
Wed, 24 Feb 2010 00:55:50 +0000 (16:55 -0800)
Add calls to retrieve class initialization stats via the allocation
count mechanism.

Also: deprecate a method that is never used, and a redundantly declared
default filename that begins with "/sdcard".

For bug 2461549.

libcore/dalvik/src/main/java/dalvik/system/VMDebug.java
vm/Profile.h
vm/native/dalvik_system_VMDebug.c
vm/oo/Class.c

index ce3e95c..6f64c5f 100644 (file)
@@ -34,6 +34,8 @@ import java.io.IOException;
 public final class VMDebug {
     /**
      * Specifies the default method trace data file name.
+     *
+     * @deprecated only used in one place, which is unused and deprecated
      */
     static public final String DEFAULT_METHOD_TRACE_FILE_NAME = "/sdcard/dmtrace.trace";
 
@@ -44,11 +46,13 @@ public final class VMDebug {
     public static final int TRACE_COUNT_ALLOCS = 1;
 
     /* constants for getAllocCount */
-    private static final int KIND_ALLOCATED_OBJECTS = 1<<0;
-    private static final int KIND_ALLOCATED_BYTES   = 1<<1;
-    private static final int KIND_FREED_OBJECTS     = 1<<2;
-    private static final int KIND_FREED_BYTES       = 1<<3;
-    private static final int KIND_GC_INVOCATIONS    = 1<<4;
+    private static final int KIND_ALLOCATED_OBJECTS     = 1<<0;
+    private static final int KIND_ALLOCATED_BYTES       = 1<<1;
+    private static final int KIND_FREED_OBJECTS         = 1<<2;
+    private static final int KIND_FREED_BYTES           = 1<<3;
+    private static final int KIND_GC_INVOCATIONS        = 1<<4;
+    private static final int KIND_CLASS_INIT_COUNT      = 1<<5;
+    private static final int KIND_CLASS_INIT_TIME       = 1<<6;
     private static final int KIND_EXT_ALLOCATED_OBJECTS = 1<<12;
     private static final int KIND_EXT_ALLOCATED_BYTES   = 1<<13;
     private static final int KIND_EXT_FREED_OBJECTS     = 1<<14;
@@ -64,6 +68,10 @@ public final class VMDebug {
         KIND_FREED_BYTES;
     public static final int KIND_GLOBAL_GC_INVOCATIONS =
         KIND_GC_INVOCATIONS;
+    public static final int KIND_GLOBAL_CLASS_INIT_COUNT =
+        KIND_CLASS_INIT_COUNT;
+    public static final int KIND_GLOBAL_CLASS_INIT_TIME =
+        KIND_CLASS_INIT_TIME;
     public static final int KIND_GLOBAL_EXT_ALLOCATED_OBJECTS =
         KIND_EXT_ALLOCATED_OBJECTS;
     public static final int KIND_GLOBAL_EXT_ALLOCATED_BYTES =
@@ -83,6 +91,10 @@ public final class VMDebug {
         KIND_FREED_BYTES << 16;
     public static final int KIND_THREAD_GC_INVOCATIONS =
         KIND_GC_INVOCATIONS << 16;
+    public static final int KIND_THREAD_CLASS_INIT_COUNT =
+        KIND_CLASS_INIT_COUNT << 16;
+    public static final int KIND_THREAD_CLASS_INIT_TIME =
+        KIND_CLASS_INIT_TIME << 16;
     public static final int KIND_THREAD_EXT_ALLOCATED_OBJECTS =
         KIND_EXT_ALLOCATED_OBJECTS << 16;
     public static final int KIND_THREAD_EXT_ALLOCATED_BYTES =
@@ -131,6 +143,8 @@ public final class VMDebug {
     /**
      * Start method tracing with default name, size, and with <code>0</code>
      * flags.
+     *
+     * @deprecated not used, not needed
      */
     public static void startMethodTracing() {
         startMethodTracing(DEFAULT_METHOD_TRACE_FILE_NAME, 0, 0);
index 7cac150..a294f83 100644 (file)
@@ -80,6 +80,9 @@ typedef struct AllocProfState {
 
     int     gcCount;            // #of times an allocation triggered a GC
 
+    int     classInitCount;     // #of initialized classes
+    u8      classInitTime;      // cumulative time spent in class init (nsec)
+
 #if PROFILE_EXTERNAL_ALLOCATIONS
     int     externalAllocCount; // #of calls to dvmTrackExternalAllocation()
     int     externalAllocSize;  // #of bytes passed to ...ExternalAllocation()
index 1d2f024..f2b364b 100644 (file)
@@ -108,11 +108,13 @@ static void Dalvik_dalvik_system_VMDebug_getVmFeatureList(const u4* args,
 /* These must match the values in dalvik.system.VMDebug.
  */
 enum {
-    KIND_ALLOCATED_OBJECTS = 1<<0,
-    KIND_ALLOCATED_BYTES   = 1<<1,
-    KIND_FREED_OBJECTS     = 1<<2,
-    KIND_FREED_BYTES       = 1<<3,
-    KIND_GC_INVOCATIONS    = 1<<4,
+    KIND_ALLOCATED_OBJECTS      = 1<<0,
+    KIND_ALLOCATED_BYTES        = 1<<1,
+    KIND_FREED_OBJECTS          = 1<<2,
+    KIND_FREED_BYTES            = 1<<3,
+    KIND_GC_INVOCATIONS         = 1<<4,
+    KIND_CLASS_INIT_COUNT       = 1<<5,
+    KIND_CLASS_INIT_TIME        = 1<<6,
 #if PROFILE_EXTERNAL_ALLOCATIONS
     KIND_EXT_ALLOCATED_OBJECTS = 1<<12,
     KIND_EXT_ALLOCATED_BYTES   = 1<<13,
@@ -125,6 +127,8 @@ enum {
     KIND_GLOBAL_FREED_OBJECTS       = KIND_FREED_OBJECTS,
     KIND_GLOBAL_FREED_BYTES         = KIND_FREED_BYTES,
     KIND_GLOBAL_GC_INVOCATIONS      = KIND_GC_INVOCATIONS,
+    KIND_GLOBAL_CLASS_INIT_COUNT    = KIND_CLASS_INIT_COUNT,
+    KIND_GLOBAL_CLASS_INIT_TIME     = KIND_CLASS_INIT_TIME,
 #if PROFILE_EXTERNAL_ALLOCATIONS
     KIND_GLOBAL_EXT_ALLOCATED_OBJECTS = KIND_EXT_ALLOCATED_OBJECTS,
     KIND_GLOBAL_EXT_ALLOCATED_BYTES = KIND_EXT_ALLOCATED_BYTES,
@@ -170,6 +174,12 @@ static void clearAllocProfStateFields(AllocProfState *allocProf,
     if (kinds & KIND_GC_INVOCATIONS) {
         allocProf->gcCount = 0;
     }
+    if (kinds & KIND_CLASS_INIT_COUNT) {
+        allocProf->classInitCount = 0;
+    }
+    if (kinds & KIND_CLASS_INIT_TIME) {
+        allocProf->classInitTime = 0;
+    }
 #if PROFILE_EXTERNAL_ALLOCATIONS
     if (kinds & KIND_EXT_ALLOCATED_OBJECTS) {
         allocProf->externalAllocCount = 0;
@@ -254,6 +264,13 @@ static void Dalvik_dalvik_system_VMDebug_getAllocCount(const u4* args,
     case KIND_GC_INVOCATIONS:
         pResult->i = allocProf->gcCount;
         break;
+    case KIND_CLASS_INIT_COUNT:
+        pResult->i = allocProf->classInitCount;
+        break;
+    case KIND_CLASS_INIT_TIME:
+        /* convert nsec to usec, reduce to 32 bits */
+        pResult->i = (int) (allocProf->classInitTime / 1000);
+        break;
 #if PROFILE_EXTERNAL_ALLOCATIONS
     case KIND_EXT_ALLOCATED_OBJECTS:
         pResult->i = allocProf->externalAllocCount;
index 0c655d4..0b03d94 100644 (file)
@@ -4394,6 +4394,11 @@ noverify:
         return false;
     }
 
+    u8 startWhen = 0;
+    if (gDvm.allocProf.enabled) {
+        startWhen = dvmGetRelativeTimeNsec();
+    }
+
     /*
      * We're ready to go, and have exclusive access to the class.
      *
@@ -4485,6 +4490,17 @@ noverify:
         dvmLockObject(self, (Object*) clazz);
         clazz->status = CLASS_INITIALIZED;
         LOGVV("Initialized class: %s\n", clazz->descriptor);
+
+        /*
+         * Update alloc counters.  TODO: guard with mutex.
+         */
+        if (gDvm.allocProf.enabled && startWhen != 0) {
+            u8 initDuration = dvmGetRelativeTimeNsec() - startWhen;
+            gDvm.allocProf.classInitTime += initDuration;
+            self->allocProf.classInitTime += initDuration;
+            gDvm.allocProf.classInitCount++;
+            self->allocProf.classInitCount++;
+        }
     }
 
 bail_notify: