diff options
-rw-r--r-- | libcore/dalvik/src/main/java/dalvik/system/VMDebug.java | 24 | ||||
-rw-r--r-- | vm/Profile.h | 3 | ||||
-rw-r--r-- | vm/native/dalvik_system_VMDebug.c | 27 | ||||
-rw-r--r-- | vm/oo/Class.c | 16 |
4 files changed, 60 insertions, 10 deletions
diff --git a/libcore/dalvik/src/main/java/dalvik/system/VMDebug.java b/libcore/dalvik/src/main/java/dalvik/system/VMDebug.java index ce3e95c3e..6f64c5f94 100644 --- a/libcore/dalvik/src/main/java/dalvik/system/VMDebug.java +++ b/libcore/dalvik/src/main/java/dalvik/system/VMDebug.java @@ -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); diff --git a/vm/Profile.h b/vm/Profile.h index 7cac150e2..a294f831b 100644 --- a/vm/Profile.h +++ b/vm/Profile.h @@ -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() diff --git a/vm/native/dalvik_system_VMDebug.c b/vm/native/dalvik_system_VMDebug.c index 1d2f024f7..f2b364bab 100644 --- a/vm/native/dalvik_system_VMDebug.c +++ b/vm/native/dalvik_system_VMDebug.c @@ -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; diff --git a/vm/oo/Class.c b/vm/oo/Class.c index 0c655d4bf..0b03d94db 100644 --- a/vm/oo/Class.c +++ b/vm/oo/Class.c @@ -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: |