Modify the behavior of thread suspend shootouts.
The thread doing the suspension doesn't attempt to suspend the other thread
unless it knows another thread isn't trying to suspend it. Use the suspend
count, and its lock, for this purpose.
Re-enable ThreadStress test.
Bug: 15446488
Change-Id: Idd34410c7b89d8abd6973e5699a15ca699472c78
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index 584743b..e2f6085 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -2408,9 +2408,7 @@
if (peer.get() == nullptr) {
return JDWP::ERR_THREAD_NOT_ALIVE;
}
- // Suspend thread to build stack trace. Take suspend thread lock to avoid races with threads
- // trying to suspend this one.
- MutexLock mu(self, *Locks::thread_list_suspend_thread_lock_);
+ // Suspend thread to build stack trace.
bool timed_out;
ThreadList* thread_list = Runtime::Current()->GetThreadList();
Thread* thread = thread_list->SuspendThreadByPeer(peer.get(), request_suspension, true,
@@ -3322,13 +3320,9 @@
soa.Self()->TransitionFromRunnableToSuspended(kWaitingForDebuggerSuspension);
jobject thread_peer = Dbg::GetObjectRegistry()->GetJObject(thread_id);
bool timed_out;
- Thread* suspended_thread;
- {
- // Take suspend thread lock to avoid races with threads trying to suspend this one.
- MutexLock mu(soa.Self(), *Locks::thread_list_suspend_thread_lock_);
- ThreadList* thread_list = Runtime::Current()->GetThreadList();
- suspended_thread = thread_list->SuspendThreadByPeer(thread_peer, true, true, &timed_out);
- }
+ ThreadList* thread_list = Runtime::Current()->GetThreadList();
+ Thread* suspended_thread = thread_list->SuspendThreadByPeer(thread_peer, true, true,
+ &timed_out);
CHECK_EQ(soa.Self()->TransitionFromSuspendedToRunnable(), kWaitingForDebuggerSuspension);
if (suspended_thread == nullptr) {
// Thread terminated from under us while suspending.