Only log an error if an unattached thread is unregistered.
Turn a fatal check into a diagnostic error. It looks like this issue arises
when a runtime shutsdown without properly being started.
Bug: 17011539
Change-Id: I2983c8332e83769e9480e8f30a46ca3b80a2e90e
(cherry picked from commit e2bcf579b0bc2f53db68c38755d69543198c7b00)
diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc
index 2dbfb3e..08e66ea 100644
--- a/runtime/thread_list.cc
+++ b/runtime/thread_list.cc
@@ -872,14 +872,21 @@
// thread_suspend_count_lock_ so that the unregistering thread cannot be suspended.
// Note: deliberately not using MutexLock that could hold a stale self pointer.
Locks::thread_list_lock_->ExclusiveLock(self);
- CHECK(Contains(self));
- Locks::thread_suspend_count_lock_->ExclusiveLock(self);
- bool removed = false;
- if (!self->IsSuspended()) {
- list_.remove(self);
- removed = true;
+ bool removed = true;
+ if (!Contains(self)) {
+ std::ostringstream os;
+ DumpNativeStack(os, GetTid(), " native: ", nullptr);
+ LOG(ERROR) << "Request to unregister unattached thread\n" << os.str();
+ } else {
+ Locks::thread_suspend_count_lock_->ExclusiveLock(self);
+ if (!self->IsSuspended()) {
+ list_.remove(self);
+ } else {
+ // We failed to remove the thread due to a suspend request, loop and try again.
+ removed = false;
+ }
+ Locks::thread_suspend_count_lock_->ExclusiveUnlock(self);
}
- Locks::thread_suspend_count_lock_->ExclusiveUnlock(self);
Locks::thread_list_lock_->ExclusiveUnlock(self);
if (removed) {
delete self;