Revert "Don't call GetPeerFromOtherThread with thread_list_lock_ held"

This reverts commit 2c4bfa20cfd4ea556a5a94f942ced5d2ccfe1c06.

Reason for revert: b/313347640

Change-Id: I055f1a868c9fe6a74278670e075c2e2aa3e82d2b
diff --git a/openjdkjvmti/ti_object.cc b/openjdkjvmti/ti_object.cc
index 24ccbaf..f37df86 100644
--- a/openjdkjvmti/ti_object.cc
+++ b/openjdkjvmti/ti_object.cc
@@ -105,15 +105,13 @@
       notify_wait.push_back(jni->AddLocalReference<jthread>(thd->GetPeerFromOtherThread()));
       wait.push_back(jni->AddLocalReference<jthread>(thd->GetPeerFromOtherThread()));
     }
-    // Scan all threads to see which are waiting on this particular monitor.
-    std::list<art::Thread*> thread_list;
     {
+      // Scan all threads to see which are waiting on this particular monitor.
       art::MutexLock tll(self, *art::Locks::thread_list_lock_);
-      thread_list = art::Runtime::Current()->GetThreadList()->GetList();
-    }
-    for (art::Thread* thd : thread_list) {
-      if (thd != info.owner_ && target.Ptr() == thd->GetMonitorEnterObject()) {
-        wait.push_back(jni->AddLocalReference<jthread>(thd->GetPeerFromOtherThread()));
+      for (art::Thread* thd : art::Runtime::Current()->GetThreadList()->GetList()) {
+        if (thd != info.owner_ && target.Ptr() == thd->GetMonitorEnterObject()) {
+          wait.push_back(jni->AddLocalReference<jthread>(thd->GetPeerFromOtherThread()));
+        }
       }
     }
   }
diff --git a/openjdkjvmti/ti_thread.cc b/openjdkjvmti/ti_thread.cc
index 33cc754..13eebbf 100644
--- a/openjdkjvmti/ti_thread.cc
+++ b/openjdkjvmti/ti_thread.cc
@@ -265,13 +265,12 @@
 
   art::Thread* self = art::Thread::Current();
   art::ScopedObjectAccess soa(self);
+  art::MutexLock mu(self, *art::Locks::thread_list_lock_);
+
   art::Thread* target;
   jvmtiError err = ERR(INTERNAL);
-  {
-    art::MutexLock mu(self, *art::Locks::thread_list_lock_);
-    if (!GetNativeThread(thread, soa, &target, &err)) {
-      return err;
-    }
+  if (!GetNativeThread(thread, soa, &target, &err)) {
+    return err;
   }
 
   JvmtiUniquePtr<char[]> name_uptr;
@@ -638,11 +637,10 @@
   art::Thread* current = art::Thread::Current();
 
   art::ScopedObjectAccess soa(current);
-  std::list<art::Thread*> thread_list;
-  {
-    art::MutexLock mu(current, *art::Locks::thread_list_lock_);
-    thread_list = art::Runtime::Current()->GetThreadList()->GetList();
-  }
+
+  art::MutexLock mu(current, *art::Locks::thread_list_lock_);
+  std::list<art::Thread*> thread_list = art::Runtime::Current()->GetThreadList()->GetList();
+
   std::vector<art::ObjPtr<art::mirror::Object>> peers;
 
   for (art::Thread* thread : thread_list) {
diff --git a/openjdkjvmti/ti_threadgroup.cc b/openjdkjvmti/ti_threadgroup.cc
index f6f0e21..120024e 100644
--- a/openjdkjvmti/ti_threadgroup.cc
+++ b/openjdkjvmti/ti_threadgroup.cc
@@ -169,12 +169,9 @@
                        std::vector<art::ObjPtr<art::mirror::Object>>* thread_peers)
     REQUIRES_SHARED(art::Locks::mutator_lock_) REQUIRES(!art::Locks::thread_list_lock_) {
   CHECK(thread_group != nullptr);
-  std::list<art::Thread*> thread_list;
-  {
-    art::MutexLock mu(art::Thread::Current(), *art::Locks::thread_list_lock_);
-    thread_list = art::Runtime::Current()->GetThreadList()->GetList();
-  }
-  for (art::Thread* t : thread_list) {
+
+  art::MutexLock mu(art::Thread::Current(), *art::Locks::thread_list_lock_);
+  for (art::Thread* t : art::Runtime::Current()->GetThreadList()->GetList()) {
     if (t->IsStillStarting()) {
       continue;
     }
diff --git a/runtime/thread.h b/runtime/thread.h
index 88e3d45..e1503ae 100644
--- a/runtime/thread.h
+++ b/runtime/thread.h
@@ -521,8 +521,7 @@
   // This function will force a flip for the other thread if necessary.
   // Since we hold a shared mutator lock, a new flip function cannot be concurrently
   // installed
-  mirror::Object* GetPeerFromOtherThread() REQUIRES_SHARED(Locks::mutator_lock_)
-      REQUIRES(!Locks::thread_list_lock_);
+  mirror::Object* GetPeerFromOtherThread() REQUIRES_SHARED(Locks::mutator_lock_);
 
   bool HasPeer() const {
     return tlsPtr_.jpeer != nullptr || tlsPtr_.opeer != nullptr;