OSDN Git Service

merge in klp-release history after reset to klp-dev
[android-x86/dalvik.git] / vm / Native.cpp
index ee64e78..a12c4e0 100644 (file)
@@ -97,8 +97,8 @@ void dvmResolveNativeMethod(const u4* args, JValue* pResult,
             free(desc);
         }
         if (dvmIsSynchronizedMethod(method)) {
-            LOGE("ERROR: internal-native can't be declared 'synchronized'");
-            LOGE("Failing on %s.%s", method->clazz->descriptor, method->name);
+            ALOGE("ERROR: internal-native can't be declared 'synchronized'");
+            ALOGE("Failing on %s.%s", method->clazz->descriptor, method->name);
             dvmAbort();     // harsh, but this is VM-internal problem
         }
         DalvikBridgeFunc dfunc = (DalvikBridgeFunc) infunc;
@@ -116,14 +116,14 @@ void dvmResolveNativeMethod(const u4* args, JValue* pResult,
         return;
     }
 
-    IF_LOGW() {
+    IF_ALOGW() {
         char* desc = dexProtoCopyMethodDescriptor(&method->prototype);
-        LOGW("No implementation found for native %s.%s %s",
+        ALOGW("No implementation found for native %s.%s:%s",
             clazz->descriptor, method->name, desc);
         free(desc);
     }
 
-    dvmThrowUnsatisfiedLinkError(method->name);
+    dvmThrowUnsatisfiedLinkError("Native method not found", method);
 }
 
 
@@ -184,7 +184,7 @@ static int hashcmpSharedLib(const void* ventry, const void* vnewEntry)
     const SharedLib* pLib = (const SharedLib*) ventry;
     const SharedLib* pNewLib = (const SharedLib*) vnewEntry;
 
-    LOGD("--- comparing %p '%s' %p '%s'",
+    ALOGD("--- comparing %p '%s' %p '%s'",
         pLib, pLib->pathName, pNewLib, pNewLib->pathName);
     return strcmp(pLib->pathName, pNewLib->pathName);
 }
@@ -269,7 +269,7 @@ static bool checkOnLoadResult(SharedLib* pEntry)
          * Check this so we don't end up waiting for ourselves.  We need
          * to return "true" so the caller can continue.
          */
-        LOGI("threadid=%d: recursive native library load attempt (%s)",
+        ALOGI("threadid=%d: recursive native library load attempt (%s)",
             self->threadId, pEntry->pathName);
         return true;
     }
@@ -279,7 +279,7 @@ static bool checkOnLoadResult(SharedLib* pEntry)
 
     dvmLockMutex(&pEntry->onLoadLock);
     while (pEntry->onLoadResult == kOnLoadPending) {
-        LOGD("threadid=%d: waiting for %s OnLoad status",
+        ALOGD("threadid=%d: waiting for %s OnLoad status",
             self->threadId, pEntry->pathName);
         ThreadStatus oldStatus = dvmChangeStatus(self, THREAD_VMWAIT);
         pthread_cond_wait(&pEntry->onLoadCond, &pEntry->onLoadLock);
@@ -327,7 +327,7 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
     verbose = verbose && !!strncmp(pathName, "/vendor", sizeof("/vendor")-1);
 
     if (verbose)
-        LOGD("Trying to load lib %s %p", pathName, classLoader);
+        ALOGD("Trying to load lib %s %p", pathName, classLoader);
 
     *detail = NULL;
 
@@ -338,12 +338,12 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
     pEntry = findSharedLibEntry(pathName);
     if (pEntry != NULL) {
         if (pEntry->classLoader != classLoader) {
-            LOGW("Shared lib '%s' already opened by CL %p; can't open in %p",
+            ALOGW("Shared lib '%s' already opened by CL %p; can't open in %p",
                 pathName, pEntry->classLoader, classLoader);
             return false;
         }
         if (verbose) {
-            LOGD("Shared lib '%s' already loaded in same CL %p",
+            ALOGD("Shared lib '%s' already loaded in same CL %p",
                 pathName, classLoader);
         }
         if (!checkOnLoadResult(pEntry))
@@ -385,6 +385,7 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
 
     if (handle == NULL) {
         *detail = strdup(dlerror());
+        ALOGE("dlopen(\"%s\") failed: %s", pathName, *detail);
         return false;
     }
 
@@ -402,22 +403,22 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
     SharedLib* pActualEntry = addSharedLibEntry(pNewEntry);
 
     if (pNewEntry != pActualEntry) {
-        LOGI("WOW: we lost a race to add a shared lib (%s CL=%p)",
+        ALOGI("WOW: we lost a race to add a shared lib (%s CL=%p)",
             pathName, classLoader);
         freeSharedLibEntry(pNewEntry);
         return checkOnLoadResult(pActualEntry);
     } else {
         if (verbose)
-            LOGD("Added shared lib %s %p", pathName, classLoader);
+            ALOGD("Added shared lib %s %p", pathName, classLoader);
 
-        bool result = true;
+        bool result = false;
         void* vonLoad;
         int version;
 
         vonLoad = dlsym(handle, "JNI_OnLoad");
         if (vonLoad == NULL) {
-            LOGD("No JNI_OnLoad found in %s %p, skipping init",
-                pathName, classLoader);
+            ALOGD("No JNI_OnLoad found in %s %p, skipping init", pathName, classLoader);
+            result = true;
         } else {
             /*
              * Call JNI_OnLoad.  We have to override the current class
@@ -431,17 +432,18 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
             self->classLoaderOverride = classLoader;
             oldStatus = dvmChangeStatus(self, THREAD_NATIVE);
             if (gDvm.verboseJni) {
-                LOGI("[Calling JNI_OnLoad for \"%s\"]", pathName);
+                ALOGI("[Calling JNI_OnLoad for \"%s\"]", pathName);
             }
             version = (*func)(gDvmJni.jniVm, NULL);
             dvmChangeStatus(self, oldStatus);
             self->classLoaderOverride = prevOverride;
 
-            if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4 &&
-                version != JNI_VERSION_1_6)
-            {
-                LOGW("JNI_OnLoad returned bad version (%d) in %s %p",
-                    version, pathName, classLoader);
+            if (version == JNI_ERR) {
+                *detail = strdup(StringPrintf("JNI_ERR returned from JNI_OnLoad in \"%s\"",
+                                              pathName).c_str());
+            } else if (dvmIsBadJniVersion(version)) {
+                *detail = strdup(StringPrintf("Bad JNI version returned from JNI_OnLoad in \"%s\": %d",
+                                              pathName, version).c_str());
                 /*
                  * It's unwise to call dlclose() here, but we can mark it
                  * as bad and ensure that future load attempts will fail.
@@ -451,11 +453,12 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
                  * newly-registered native method calls.  We could try to
                  * unregister them, but that doesn't seem worthwhile.
                  */
-                result = false;
             } else {
-                if (gDvm.verboseJni) {
-                    LOGI("[Returned from JNI_OnLoad for \"%s\"]", pathName);
-                }
+                result = true;
+            }
+            if (gDvm.verboseJni) {
+                ALOGI("[Returned %s from JNI_OnLoad for \"%s\"]",
+                      (result ? "successfully" : "failure"), pathName);
             }
         }
 
@@ -526,7 +529,7 @@ static void unregisterJNINativeMethods(Method* methods, size_t count)
          * anything.
          */
 
-        LOGD("Unregistering JNI method %s.%s:%s",
+        ALOGD("Unregistering JNI method %s.%s:%s",
             meth->clazz->descriptor, meth->name, meth->shorty);
         dvmSetNativeFunc(meth, dvmResolveNativeMethod, NULL);
     }
@@ -583,7 +586,7 @@ static char* createJniNameString(const char* classDescriptor,
  */
 static char* mangleString(const char* str, int len)
 {
-    //LOGI("mangling '%s' %d", str, len);
+    //ALOGI("mangling '%s' %d", str, len);
 
     assert(str[len] == '\0');
 
@@ -753,7 +756,7 @@ bail:
 static void* lookupSharedLibMethod(const Method* method)
 {
     if (gDvm.nativeLibs == NULL) {
-        LOGE("Unexpected init state: nativeLibs not ready");
+        ALOGE("Unexpected init state: nativeLibs not ready");
         dvmAbort();
     }
     return (void*) dvmHashForeach(gDvm.nativeLibs, findMethodInLib,