summaryrefslogtreecommitdiffstats
path: root/runtime/thread_list.cc
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2014-11-11 23:08:07 -0800
committerIan Rogers <irogers@google.com>2014-11-12 15:29:12 -0800
commit4ad5cd3e7d519484559ef778d96fb3f0be8919fa (patch)
tree9870938a0552b4fe472d9994a55a3bf761fc69d5 /runtime/thread_list.cc
parent741e287b60136db49ecf8da72f2b5ca48b0a39bd (diff)
downloadart-4ad5cd3e7d519484559ef778d96fb3f0be8919fa.zip
art-4ad5cd3e7d519484559ef778d96fb3f0be8919fa.tar.gz
art-4ad5cd3e7d519484559ef778d96fb3f0be8919fa.tar.bz2
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
Diffstat (limited to 'runtime/thread_list.cc')
-rw-r--r--runtime/thread_list.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc
index 675ce9a..5ff90d6 100644
--- a/runtime/thread_list.cc
+++ b/runtime/thread_list.cc
@@ -530,6 +530,12 @@ Thread* ThreadList::SuspendThreadByPeer(jobject peer, bool request_suspension,
{
MutexLock suspend_count_mu(self, *Locks::thread_suspend_count_lock_);
if (request_suspension) {
+ if (self->GetSuspendCount() > 0) {
+ // We hold the suspend count lock but another thread is trying to suspend us. Its not
+ // safe to try to suspend another thread in case we get a cycle. Start the loop again
+ // which will allow this thread to be suspended.
+ continue;
+ }
thread->ModifySuspendCount(self, +1, debug_suspension);
request_suspension = false;
did_suspend_request = true;
@@ -608,6 +614,12 @@ Thread* ThreadList::SuspendThreadByThreadId(uint32_t thread_id, bool debug_suspe
{
MutexLock suspend_count_mu(self, *Locks::thread_suspend_count_lock_);
if (suspended_thread == nullptr) {
+ if (self->GetSuspendCount() > 0) {
+ // We hold the suspend count lock but another thread is trying to suspend us. Its not
+ // safe to try to suspend another thread in case we get a cycle. Start the loop again
+ // which will allow this thread to be suspended.
+ continue;
+ }
thread->ModifySuspendCount(self, +1, debug_suspension);
suspended_thread = thread;
} else {