Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1149)

Unified Diff: base/android/jni_android.cc

Issue 86013003: android: Add CHECK() calls to better understand memory corruption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add common for g_jvm_functions Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/jni_android.cc
diff --git a/base/android/jni_android.cc b/base/android/jni_android.cc
index 59f25e2e817dbe6ea258d16b65b7d71e5bedb9ec..0ec6f9a64e871239a298acf193a0e389ae850933 100644
--- a/base/android/jni_android.cc
+++ b/base/android/jni_android.cc
@@ -17,6 +17,10 @@ using base::android::MethodID;
using base::android::ScopedJavaLocalRef;
JavaVM* g_jvm = NULL;
+
+// NOTE: This variable is only used for debugging http://crbug.com/322200
+const JNIInvokeInterface* g_jvm_functions = NULL;
+
// 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 +80,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 +91,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() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698