Wire up work_around_app_jni_bugs.
This removes the cached value from struct JNIEnv. YAGNI.
Change-Id: Iad1a9182e86d7bf533af14000b99bb0340d6af9b
diff --git a/src/check_jni.cc b/src/check_jni.cc
index 4b17ad8..94f4cbd 100644
--- a/src/check_jni.cc
+++ b/src/check_jni.cc
@@ -691,7 +691,7 @@
if (env_ != threadEnv) {
LOG(ERROR) << "JNI ERROR: thread " << *self << " using JNIEnv* from thread " << *env_->self;
// If we're keeping broken code limping along, we need to suppress the abort...
- if (!env_->work_around_app_jni_bugs) {
+ if (!vm_->work_around_app_jni_bugs) {
JniAbort();
return;
}
diff --git a/src/dalvik_system_VMRuntime.cc b/src/dalvik_system_VMRuntime.cc
index de5252d..3a1eac0 100644
--- a/src/dalvik_system_VMRuntime.cc
+++ b/src/dalvik_system_VMRuntime.cc
@@ -112,13 +112,12 @@
void VMRuntime_setTargetSdkVersion(JNIEnv* env, jobject, jint targetSdkVersion) {
// This is the target SDK version of the app we're about to run.
- // Note that this value may be CUR_DEVELOPMENT (10000).
- // Note that this value may be 0, meaning "current".
+ // Note that targetSdkVersion may be CUR_DEVELOPMENT (10000).
+ // Note that targetSdkVersion may be 0, meaning "current".
if (targetSdkVersion > 0 && targetSdkVersion <= 13 /* honeycomb-mr2 */) {
// TODO: running with CheckJNI should override this and force you to obey the strictest rules.
LOG(INFO) << "Turning on JNI app bug workarounds for target SDK version " << targetSdkVersion << "...";
- UNIMPLEMENTED(WARNING) << "can we get this as a command-line argument?";
- //gDvmJni.work_around_app_jni_bugs = true;
+ Runtime::Current()->GetJavaVM()->work_around_app_jni_bugs = true;
}
}
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 95acf99..8362895 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -94,7 +94,7 @@
}
#endif
- if (env->work_around_app_jni_bugs) {
+ if (env->vm->work_around_app_jni_bugs) {
// Hand out direct pointers to support broken old apps.
return reinterpret_cast<T>(obj);
}
@@ -2347,7 +2347,7 @@
return JNILocalRefType;
}
- if (!ts.Env()->work_around_app_jni_bugs) {
+ if (!ts.Vm()->work_around_app_jni_bugs) {
return JNIInvalidRefType;
}
@@ -2608,7 +2608,6 @@
local_ref_cookie(IRT_FIRST_SEGMENT),
locals(kLocalsInitial, kLocalsMax, kLocal),
check_jni(false),
- work_around_app_jni_bugs(vm->work_around_app_jni_bugs),
critical(false),
monitors("monitors", kMonitorsInitial, kMonitorsMax) {
functions = unchecked_functions = &gNativeInterface;
@@ -2750,7 +2749,7 @@
check_jni(false),
force_copy(false), // TODO: add a way to enable this
trace(options->jni_trace_),
- work_around_app_jni_bugs(false), // TODO: add a way to enable this
+ work_around_app_jni_bugs(false),
pins_lock("JNI pin table lock"),
pin_table("pin table", kPinTableInitial, kPinTableMax),
globals_lock("JNI global reference table lock"),
diff --git a/src/jni_internal.h b/src/jni_internal.h
index dacc310..e02d01d 100644
--- a/src/jni_internal.h
+++ b/src/jni_internal.h
@@ -158,7 +158,6 @@
// Frequently-accessed fields cached from JavaVM.
bool check_jni;
- bool work_around_app_jni_bugs;
// How many nested "critical" JNI calls are we in?
int critical;
diff --git a/src/scoped_jni_thread_state.h b/src/scoped_jni_thread_state.h
index 0da03d6..b312c5a 100644
--- a/src/scoped_jni_thread_state.h
+++ b/src/scoped_jni_thread_state.h
@@ -38,7 +38,7 @@
static Thread* ThreadForEnv(JNIEnv* env) {
JNIEnvExt* full_env(reinterpret_cast<JNIEnvExt*>(env));
Thread* env_self = full_env->self;
- Thread* self = full_env->work_around_app_jni_bugs ? Thread::Current() : env_self;
+ Thread* self = full_env->vm->work_around_app_jni_bugs ? Thread::Current() : env_self;
if (self != env_self) {
LOG(ERROR) << "JNI ERROR: JNIEnv for " << *env_self
<< " used on " << *self;
diff --git a/src/thread.cc b/src/thread.cc
index 6bee2c8..a0179d8 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -957,7 +957,7 @@
// Check if this is a local reference in the SIRT
if (SirtContains(obj)) {
result = *reinterpret_cast<Object**>(obj); // Read from SIRT
- } else if (jni_env_->work_around_app_jni_bugs) {
+ } else if (Runtime::Current()->GetJavaVM()->work_around_app_jni_bugs) {
// Assume an invalid local reference is actually a direct pointer.
result = reinterpret_cast<Object*>(obj);
} else {