Ensure thread_list_lock_ is correctly locked
We were incorrectly disallowing the thread_list_lock_ on the
InstrumentThreadStack function and not holding it for long enough in
some other situations. This meant we could have hit issues where
threads die in unexpected situations.
Test: ./art/test.py --host -j50
Test: ./art/tools/run-jdwp-tests.sh --mode=host
Bug: 34414073
Bug: 62821960
Change-Id: I91f5daa59cca4aaf3a73e860f68bb01c9ec0a47f
diff --git a/runtime/openjdkjvmti/ti_method.cc b/runtime/openjdkjvmti/ti_method.cc
index ed5645a..8f72714 100644
--- a/runtime/openjdkjvmti/ti_method.cc
+++ b/runtime/openjdkjvmti/ti_method.cc
@@ -782,6 +782,7 @@
}
art::Thread* self = art::Thread::Current();
art::ScopedObjectAccess soa(self);
+ art::MutexLock mu(self, *art::Locks::thread_list_lock_);
art::Thread* target = ThreadUtil::GetNativeThread(thread, soa);
if (target == nullptr && thread == nullptr) {
return ERR(INVALID_THREAD);
@@ -790,7 +791,6 @@
return ERR(THREAD_NOT_ALIVE);
}
GetLocalVariableClosure c(self, depth, slot, type, val);
- art::MutexLock mu(self, *art::Locks::thread_list_lock_);
if (!target->RequestSynchronousCheckpoint(&c)) {
return ERR(THREAD_NOT_ALIVE);
} else {
@@ -909,6 +909,7 @@
}
art::Thread* self = art::Thread::Current();
art::ScopedObjectAccess soa(self);
+ art::MutexLock mu(self, *art::Locks::thread_list_lock_);
art::Thread* target = ThreadUtil::GetNativeThread(thread, soa);
if (target == nullptr && thread == nullptr) {
return ERR(INVALID_THREAD);
@@ -917,7 +918,6 @@
return ERR(THREAD_NOT_ALIVE);
}
SetLocalVariableClosure c(self, depth, slot, type, val);
- art::MutexLock mu(self, *art::Locks::thread_list_lock_);
if (!target->RequestSynchronousCheckpoint(&c)) {
return ERR(THREAD_NOT_ALIVE);
} else {
@@ -974,6 +974,7 @@
}
art::Thread* self = art::Thread::Current();
art::ScopedObjectAccess soa(self);
+ art::MutexLock mu(self, *art::Locks::thread_list_lock_);
art::Thread* target = ThreadUtil::GetNativeThread(thread, soa);
if (target == nullptr && thread == nullptr) {
return ERR(INVALID_THREAD);
@@ -982,7 +983,6 @@
return ERR(THREAD_NOT_ALIVE);
}
GetLocalInstanceClosure c(self, depth, data);
- art::MutexLock mu(self, *art::Locks::thread_list_lock_);
if (!target->RequestSynchronousCheckpoint(&c)) {
return ERR(THREAD_NOT_ALIVE);
} else {