OSDN Git Service

Set the main thread's context class loader to the system class loader.
authorAndy McFadden <fadden@android.com>
Mon, 4 May 2009 19:52:57 +0000 (12:52 -0700)
committerAndy McFadden <fadden@android.com>
Mon, 4 May 2009 19:52:57 +0000 (12:52 -0700)
vm/Thread.c

index 680755c..b2753f0 100644 (file)
@@ -691,6 +691,22 @@ bool dvmPrepMainThread(void)
     }
 
     /*
+     * Set the context class loader.
+     */
+    Object* systemLoader = dvmGetSystemClassLoader();
+    if (systemLoader == NULL) {
+        LOGW("WARNING: system class loader is NULL (setting main ctxt)\n");
+        /* keep going */
+    }
+    int ctxtClassLoaderOffset = dvmFindFieldOffset(gDvm.classJavaLangThread,
+        "contextClassLoader", "Ljava/lang/ClassLoader;");
+    if (ctxtClassLoaderOffset < 0) {
+        LOGE("Unable to find contextClassLoader field in Thread\n");
+        return false;
+    }
+    dvmSetFieldObject(threadObj, ctxtClassLoaderOffset, systemLoader);
+
+    /*
      * Allocate and construct a VMThread.
      */
     vmThreadObj = dvmAllocObject(gDvm.classJavaLangVMThread, ALLOC_DEFAULT);