Bug 963242 - Only save JNI env in TLS when first attaching; r=kats
authorJim Chen <nchen@mozilla.com>
Tue, 28 Jan 2014 18:32:28 -0600
changeset 181691 45db690af8c63188c448bd3a9648e13aa1d6f8c8
parent 181690 92dfed2592ae21d8e7d9d230f431261edfe4aac1
child 181692 ba1d3a43ab927868f54dc44872bb71b92ebd85b3
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs963242
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 963242 - Only save JNI env in TLS when first attaching; r=kats
widget/android/AndroidBridge.cpp
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -272,18 +272,21 @@ extern "C" {
     __attribute__ ((visibility("default")))
     JNIEnv * GetJNIForThread()
     {
         JNIEnv *jEnv = static_cast<JNIEnv*>(PR_GetThreadPrivate(sJavaEnvThreadIndex));
         if (jEnv) {
             return jEnv;
         }
         JavaVM *jVm  = mozilla::AndroidBridge::GetVM();
-        if (!jVm->GetEnv(reinterpret_cast<void**>(&jEnv), JNI_VERSION_1_2) ||
-            !jVm->AttachCurrentThread(&jEnv, nullptr)) {
+        if (!jVm->GetEnv(reinterpret_cast<void**>(&jEnv), JNI_VERSION_1_2)) {
+            MOZ_ASSERT(jEnv);
+            return jEnv;
+        }
+        if (!jVm->AttachCurrentThread(&jEnv, nullptr)) {
             MOZ_ASSERT(jEnv);
             PR_SetThreadPrivate(sJavaEnvThreadIndex, jEnv);
             return jEnv;
         }
         MOZ_CRASH();
         return nullptr; // unreachable
     }
 }