OSDN Git Service

Two minor JNI fixes.
authorAndy McFadden <fadden@android.com>
Thu, 17 Dec 2009 19:21:09 +0000 (11:21 -0800)
committerAndy McFadden <fadden@android.com>
Thu, 17 Dec 2009 21:11:47 +0000 (13:11 -0800)
(1) In the CheckJNI return type scanner, don't assume that the caller's
class loader is already listed as an initiating loader for the type
being returned.

(2) Make sure the PlatformAddress class is initialized before calling
one of its static methods from NewDirectByteBuffer.

vm/CheckJni.c
vm/Jni.c

index ff75770..ff0efd3 100644 (file)
@@ -85,12 +85,13 @@ static void checkCallResultCommon(const u4* args, JValue* pResult,
          *
          * Since we're returning an instance of declType, it's safe to
          * assume that it has been loaded and initialized (or, for the case
-         * of an array, generated), so we can just look for it in the
-         * loaded-classes list.
+         * of an array, generated).  However, the current class loader may
+         * not be listed as an initiating loader, so we can't just look for
+         * it in the loaded-classes list.
          */
         ClassObject* declClazz;
 
-        declClazz = dvmLookupClass(declType, method->clazz->classLoader, false);
+        declClazz = dvmFindClassNoInit(declType, method->clazz->classLoader);
         if (declClazz == NULL) {
             LOGW("JNI WARNING: method declared to return '%s' returned '%s'\n",
                 declType, objType);
index 1029cdd..7b68195 100644 (file)
--- a/vm/Jni.c
+++ b/vm/Jni.c
@@ -3545,6 +3545,11 @@ static jobject NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity)
     Object* platformAddress = NULL;
     JValue callResult;
     jobject result = NULL;
+    ClassObject* tmpClazz;
+
+    tmpClazz = gDvm.methOrgApacheHarmonyLuniPlatformPlatformAddress_on->clazz;
+    if (!dvmIsClassInitialized(tmpClazz) && !dvmInitClass(tmpClazz))
+        goto bail;
 
     /* get an instance of PlatformAddress that wraps the provided address */
     dvmCallMethod(self,
@@ -3559,10 +3564,10 @@ static jobject NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity)
     LOGV("tracking %p for address=%p\n", platformAddress, address);
 
     /* create an instance of java.nio.ReadWriteDirectByteBuffer */
-    ClassObject* clazz = gDvm.classJavaNioReadWriteDirectByteBuffer;
-    if (!dvmIsClassInitialized(clazz) && !dvmInitClass(clazz))
+    tmpClazz = gDvm.classJavaNioReadWriteDirectByteBuffer;
+    if (!dvmIsClassInitialized(tmpClazz) && !dvmInitClass(tmpClazz))
         goto bail;
-    Object* newObj = dvmAllocObject(clazz, ALLOC_DONT_TRACK);
+    Object* newObj = dvmAllocObject(tmpClazz, ALLOC_DONT_TRACK);
     if (newObj != NULL) {
         /* call the (PlatformAddress, int, int) constructor */
         result = addLocalReference(env, newObj);