Index: base/android/jni_android.cc |
diff --git a/base/android/jni_android.cc b/base/android/jni_android.cc |
index 59f25e2e817dbe6ea258d16b65b7d71e5bedb9ec..c9cdf0dd16eaeab775a8bc7b296ee4bd2f4b9e51 100644 |
--- a/base/android/jni_android.cc |
+++ b/base/android/jni_android.cc |
@@ -17,6 +17,8 @@ using base::android::MethodID; |
using base::android::ScopedJavaLocalRef; |
JavaVM* g_jvm = NULL; |
+const JNIInvokeInterface* g_jvm_functions = NULL; |
joth
2013/11/25 17:08:42
Is the layout of JNIInvokeInterface guaranteed to
digit1
2013/11/25 17:34:02
Yes, since the structure is defined in <jni.h>, it
digit1
2013/11/25 17:35:53
Done.
|
+ |
// Leak the global app context, as it is used from a non-joinable worker thread |
// that may still be running at shutdown. There is no harm in doing this. |
base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky |
@@ -76,7 +78,10 @@ namespace android { |
JNIEnv* AttachCurrentThread() { |
DCHECK(g_jvm); |
JNIEnv* env = NULL; |
- jint ret = g_jvm->AttachCurrentThread(&env, NULL); |
+ // See http://crbug.com/322200 for the reasons for these CHECKs. |
+ CHECK(g_jvm); |
+ CHECK_EQ(g_jvm_functions, g_jvm->functions); |
+ jint ret = g_jvm_functions->AttachCurrentThread(g_jvm, &env, NULL); |
DCHECK_EQ(JNI_OK, ret); |
return env; |
} |
@@ -84,13 +89,18 @@ JNIEnv* AttachCurrentThread() { |
void DetachFromVM() { |
// Ignore the return value, if the thread is not attached, DetachCurrentThread |
// will fail. But it is ok as the native thread may never be attached. |
- if (g_jvm) |
+ if (g_jvm) { |
+ // See http://crbug.com/322200 for the reasons for these CHECKs. |
+ CHECK(g_jvm); |
+ CHECK_EQ(g_jvm_functions, g_jvm->functions); |
g_jvm->DetachCurrentThread(); |
+ } |
} |
void InitVM(JavaVM* vm) { |
DCHECK(!g_jvm); |
g_jvm = vm; |
+ g_jvm_functions = vm->functions; |
} |
bool IsVMInitialized() { |