summaryrefslogtreecommitdiffstats
path: root/vm/Thread.c
diff options
context:
space:
mode:
authorAndy McFadden <fadden@android.com>2009-05-04 13:29:30 -0700
committerAndy McFadden <fadden@android.com>2009-05-04 13:29:30 -0700
commita1a7a349843bf3bd730c3eb3bff529188f835d50 (patch)
tree1991d581217f2154d5ca9f52f37dd0ff770a540b /vm/Thread.c
parent9ab2fb67e66129337d22afe490e73619dff6a0dc (diff)
downloadandroid_dalvik-a1a7a349843bf3bd730c3eb3bff529188f835d50.tar.gz
android_dalvik-a1a7a349843bf3bd730c3eb3bff529188f835d50.tar.bz2
android_dalvik-a1a7a349843bf3bd730c3eb3bff529188f835d50.zip
Moved the context class loader init down a bit to ensure proper init.
Since we're executing interpreted code it's best if we set the context class loader as late as possible in this function. I also updated a few comments while I was in there.
Diffstat (limited to 'vm/Thread.c')
-rw-r--r--vm/Thread.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/vm/Thread.c b/vm/Thread.c
index b2753f000..acfc7a9df 100644
--- a/vm/Thread.c
+++ b/vm/Thread.c
@@ -627,6 +627,7 @@ bool dvmPrepMainForJni(JNIEnv* pEnv)
/*
* Finish preparing the main thread, allocating some objects to represent
* it. As part of doing so, we finish initializing Thread and ThreadGroup.
+ * This will execute some interpreted code (e.g. class initializers).
*/
bool dvmPrepMainThread(void)
{
@@ -691,22 +692,6 @@ 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);
@@ -730,7 +715,8 @@ bool dvmPrepMainThread(void)
/*
* Stuff the VMThread back into the Thread. From this point on, other
- * Threads will see that this Thread is running.
+ * Threads will see that this Thread is running (at least, they would,
+ * if there were any).
*/
dvmSetFieldObject(threadObj, gDvm.offJavaLangThread_vmThread,
vmThreadObj);
@@ -738,6 +724,24 @@ bool dvmPrepMainThread(void)
thread->threadObj = threadObj;
/*
+ * Set the context class loader. This invokes a ClassLoader method,
+ * which could conceivably call Thread.currentThread(), so we want the
+ * Thread to be fully configured before we do this.
+ */
+ 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);
+
+ /*
* Finish our thread prep.
*/