Detect over-long thread suspends and time out fatally.
Bug: 5726434
Change-Id: Ib7d4429c2b195f59133bb6dc7f9072b705c53e82
diff --git a/src/thread.cc b/src/thread.cc
index 26eaf68..b828e94 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -644,10 +644,14 @@
}
void Thread::WaitUntilSuspended() {
- // TODO: dalvik dropped the waiting thread's priority after a while.
- // TODO: dalvik timed out and aborted.
+ static const useconds_t kTimeoutUs = 30 * 1000000; // 30s.
+
+ useconds_t total_delay = 0;
useconds_t delay = 0;
while (GetState() == Thread::kRunnable) {
+ if (total_delay >= kTimeoutUs) {
+ Runtime::Current()->DumpLockHolders(LOG(FATAL) << "Thread suspend timeout: " << *this << "\n");
+ }
useconds_t new_delay = delay * 2;
CHECK_GE(new_delay, delay);
delay = new_delay;
@@ -656,6 +660,7 @@
delay = 10000;
} else {
usleep(delay);
+ total_delay += delay;
}
}
}