Correctly perform read-barriers on cross-thread reg access
For debug workloads we will sometimes read stack registers on other
threads. This generally only happens when the target thread is
suspended due to a running GC and the debugger thread tries to access
stack registers from a compiled method. This could lead to a missed
read-barrier and a From-Space reference being returned. To fix this we
manually perform a read-barrier after pulling the reference out of the
compiled stack.
Test: ./test.py --host
Test: ./art/tools/run-libjdwp-tests.sh --mode=host
Test: ./test.py --host --all-compiler --all-gc -t 1966
Bug: 141590021
Change-Id: I5540c03bfdaecddbc1329ff6c7c58c6f18d6a090
diff --git a/openjdkjvmti/ti_method.cc b/openjdkjvmti/ti_method.cc
index defcd54..d36e2c9 100644
--- a/openjdkjvmti/ti_method.cc
+++ b/openjdkjvmti/ti_method.cc
@@ -65,6 +65,7 @@
#include "nativehelper/scoped_local_ref.h"
#include "oat_file.h"
#include "obj_ptr.h"
+#include "runtime.h"
#include "runtime_callbacks.h"
#include "scoped_thread_state_change-inl.h"
#include "scoped_thread_state_change.h"
@@ -890,11 +891,8 @@
&ptr_val)) {
return ERR(OPAQUE_FRAME);
}
- art::JNIEnvExt* jni = art::Thread::Current()->GetJniEnv();
art::ObjPtr<art::mirror::Object> obj(reinterpret_cast<art::mirror::Object*>(ptr_val));
- ScopedLocalRef<jobject> local(
- jni, obj.IsNull() ? nullptr : jni->AddLocalReference<jobject>(obj));
- obj_val_ = jni->NewGlobalRef(local.get());
+ obj_val_ = art::Runtime::Current()->GetJavaVM()->AddGlobalRef(art::Thread::Current(), obj);
break;
}
case art::Primitive::kPrimInt: