Prep DDMS stuff in InitRefs

Find some methods and field offsets.

Also removed a duplicate entry.

Change-Id: I4c23af6cfe6e7d4f5e8767c5a9a30d3b441ad425
diff --git a/vm/Ddm.c b/vm/Ddm.c
index 528072e..07367bb 100644
--- a/vm/Ddm.c
+++ b/vm/Ddm.c
@@ -48,46 +48,6 @@
     assert(dataLen >= 0);
 
     /*
-     * Prep DdmServer.  We could throw this in gDvm.
-     */
-    ClassObject* ddmServerClass;
-    Method* dispatch;
-
-    ddmServerClass =
-        dvmFindClass("Lorg/apache/harmony/dalvik/ddmc/DdmServer;", NULL);
-    if (ddmServerClass == NULL) {
-        LOGW("Unable to find org.apache.harmony.dalvik.ddmc.DdmServer\n");
-        goto bail;
-    }
-    dispatch = dvmFindDirectMethodByDescriptor(ddmServerClass, "dispatch",
-                    "(I[BII)Lorg/apache/harmony/dalvik/ddmc/Chunk;");
-    if (dispatch == NULL) {
-        LOGW("Unable to find DdmServer.dispatch\n");
-        goto bail;
-    }
-
-    /*
-     * Prep Chunk.
-     */
-    int chunkTypeOff, chunkDataOff, chunkOffsetOff, chunkLengthOff;
-    ClassObject* chunkClass;
-    chunkClass = dvmFindClass("Lorg/apache/harmony/dalvik/ddmc/Chunk;", NULL);
-    if (chunkClass == NULL) {
-        LOGW("Unable to find org.apache.harmony.dalvik.ddmc.Chunk\n");
-        goto bail;
-    }
-    chunkTypeOff = dvmFindFieldOffset(chunkClass, "type", "I");
-    chunkDataOff = dvmFindFieldOffset(chunkClass, "data", "[B");
-    chunkOffsetOff = dvmFindFieldOffset(chunkClass, "offset", "I");
-    chunkLengthOff = dvmFindFieldOffset(chunkClass, "length", "I");
-    if (chunkTypeOff < 0 || chunkDataOff < 0 ||
-        chunkOffsetOff < 0 || chunkLengthOff < 0)
-    {
-        LOGW("Unable to find all chunk fields\n");
-        goto bail;
-    }
-
-    /*
      * The chunk handlers are written in the Java programming language, so
      * we need to convert the buffer to a byte array.
      */
@@ -115,8 +75,8 @@
      * Call the handler.
      */
     JValue callRes;
-    dvmCallMethod(self, dispatch, NULL, &callRes, type, dataArray, offset,
-        length);
+    dvmCallMethod(self, gDvm.methDalvikDdmcServer_dispatch, NULL, &callRes,
+        type, dataArray, offset, length);
     if (dvmCheckException(self)) {
         LOGI("Exception thrown by dispatcher for 0x%08x\n", type);
         dvmLogExceptionStackTrace();
@@ -144,10 +104,11 @@
      *
      * So we're pretty much stuck with copying data around multiple times.
      */
-    type = dvmGetFieldInt(chunk, chunkTypeOff);
-    replyData = (ArrayObject*) dvmGetFieldObject(chunk, chunkDataOff);
-    offset = dvmGetFieldInt(chunk, chunkOffsetOff);
-    length = dvmGetFieldInt(chunk, chunkLengthOff);
+    type = dvmGetFieldInt(chunk, gDvm.offDalvikDdmcChunk_type);
+    replyData =
+        (ArrayObject*) dvmGetFieldObject(chunk, gDvm.offDalvikDdmcChunk_data);
+    offset = dvmGetFieldInt(chunk, gDvm.offDalvikDdmcChunk_offset);
+    length = dvmGetFieldInt(chunk, gDvm.offDalvikDdmcChunk_length);
 
     LOGV("DDM reply: type=0x%08x data=%p offset=%d length=%d\n",
         type, replyData, offset, length);
@@ -192,21 +153,6 @@
  */
 static void broadcast(int event)
 {
-    ClassObject* ddmServerClass;
-    Method* bcast;
-
-    ddmServerClass =
-        dvmFindClass("Lorg/apache/harmony/dalvik/ddmc/DdmServer;", NULL);
-    if (ddmServerClass == NULL) {
-        LOGW("Unable to find org.apache.harmony.dalvik.ddmc.DdmServer\n");
-        goto bail;
-    }
-    bcast = dvmFindDirectMethodByDescriptor(ddmServerClass, "broadcast", "(I)V");
-    if (bcast == NULL) {
-        LOGW("Unable to find DdmServer.broadcast\n");
-        goto bail;
-    }
-
     Thread* self = dvmThreadSelf();
 
     if (self->status != THREAD_RUNNING) {
@@ -215,7 +161,8 @@
     }
 
     JValue unused;
-    dvmCallMethod(self, bcast, NULL, &unused, event);
+    dvmCallMethod(self, gDvm.methDalvikDdmcServer_broadcast, NULL, &unused,
+        event);
     if (dvmCheckException(self)) {
         LOGI("Exception thrown by broadcast(%d)\n", event);
         dvmLogExceptionStackTrace();
diff --git a/vm/Globals.h b/vm/Globals.h
index 9d697ce..9e37aac 100644
--- a/vm/Globals.h
+++ b/vm/Globals.h
@@ -401,6 +401,16 @@
     int         offJavaNioBuffer_capacity;
     int         offJavaNioBuffer_effectiveDirectAddress;
 
+    /* direct method pointers - org.apache.harmony.dalvik.ddmc.DdmServer */
+    Method*     methDalvikDdmcServer_dispatch;
+    Method*     methDalvikDdmcServer_broadcast;
+
+    /* field offsets - org.apache.harmony.dalvik.ddmc.Chunk */
+    int         offDalvikDdmcChunk_type;
+    int         offDalvikDdmcChunk_data;
+    int         offDalvikDdmcChunk_offset;
+    int         offDalvikDdmcChunk_length;
+
     /*
      * Thread list.  This always has at least one element in it (main),
      * and main is always the first entry.
diff --git a/vm/InitRefs.c b/vm/InitRefs.c
index 4855697..f7fc4da 100644
--- a/vm/InitRefs.c
+++ b/vm/InitRefs.c
@@ -264,6 +264,14 @@
         const char* type;
     };
 
+    static struct FieldInfo infoDdmcChunk[] = {
+        { &gDvm.offDalvikDdmcChunk_type,   "type",   "I" },
+        { &gDvm.offDalvikDdmcChunk_data,   "data",   "[B" },
+        { &gDvm.offDalvikDdmcChunk_offset, "offset", "I" },
+        { &gDvm.offDalvikDdmcChunk_length, "length", "I" },
+        { NULL, NULL, NULL }
+    };
+
     static struct FieldInfo infoFileDescriptor[] = {
         { &gDvm.offJavaIoFileDescriptor_descriptor, "descriptor", "I" },
         { NULL, NULL, NULL }
@@ -341,18 +349,19 @@
     };
 
     static struct { const char* name; const struct FieldInfo* fields; } classes[] = {
-        { "Ljava/io/FileDescriptor;",             infoFileDescriptor },
-        { "Ljava/lang/String;",                   infoString },
-        { "Ljava/lang/Thread;",                   infoThread },
-        { "Ljava/lang/ThreadGroup;",              infoThreadGroup },
-        { "Ljava/lang/Throwable;",                infoThrowable },
-        { "Ljava/lang/VMThread;",                 infoVMThread },
-        { "Ljava/lang/reflect/AccessibleObject;", infoAccessibleObject },
-        { "Ljava/lang/reflect/Constructor;",      infoConstructor },
-        { "Ljava/lang/reflect/Field;",            infoField },
-        { "Ljava/lang/reflect/Method;",           infoMethod },
-        { "Ljava/lang/reflect/Proxy;",            infoProxy },
-        { "Ljava/nio/Buffer;",                    infoBuffer },
+        { "Lorg/apache/harmony/dalvik/ddmc/Chunk;", infoDdmcChunk },
+        { "Ljava/io/FileDescriptor;",               infoFileDescriptor },
+        { "Ljava/lang/String;",                     infoString },
+        { "Ljava/lang/Thread;",                     infoThread },
+        { "Ljava/lang/ThreadGroup;",                infoThreadGroup },
+        { "Ljava/lang/Throwable;",                  infoThrowable },
+        { "Ljava/lang/VMThread;",                   infoVMThread },
+        { "Ljava/lang/reflect/AccessibleObject;",   infoAccessibleObject },
+        { "Ljava/lang/reflect/Constructor;",        infoConstructor },
+        { "Ljava/lang/reflect/Field;",              infoField },
+        { "Ljava/lang/reflect/Method;",             infoMethod },
+        { "Ljava/lang/reflect/Proxy;",              infoProxy },
+        { "Ljava/nio/Buffer;",                      infoBuffer },
         { NULL, NULL }
     };
 
@@ -451,11 +460,14 @@
           "Lorg/apache/harmony/lang/annotation/AnnotationFactory;", "createAnnotation",
           "(Ljava/lang/Class;[Lorg/apache/harmony/lang/annotation/AnnotationMember;)"
           "Ljava/lang/annotation/Annotation;" },
-        { &gDvm.methodTraceClassPrepMethod, "Ldalvik/system/VMDebug;", "startClassPrep", "()V" },
         { &gDvm.methDalvikSystemNativeStart_main, "Ldalvik/system/NativeStart;", "main", "([Ljava/lang/String;)V" },
         { &gDvm.methDalvikSystemNativeStart_run, "Ldalvik/system/NativeStart;", "run", "()V" },
         { &gDvm.methJavaLangRefFinalizerReferenceAdd,
           "Ljava/lang/ref/FinalizerReference;", "add", "(Ljava/lang/Object;)V" },
+        { &gDvm.methDalvikDdmcServer_dispatch,
+          "Lorg/apache/harmony/dalvik/ddmc/DdmServer;", "dispatch", "(I[BII)Lorg/apache/harmony/dalvik/ddmc/Chunk;" },
+        { &gDvm.methDalvikDdmcServer_broadcast,
+          "Lorg/apache/harmony/dalvik/ddmc/DdmServer;", "broadcast", "(I)V" },
         { NULL, NULL, NULL, NULL }
     };