diff options
Diffstat (limited to 'openjdkjvmti/ti_threadgroup.cc')
-rw-r--r-- | openjdkjvmti/ti_threadgroup.cc | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/openjdkjvmti/ti_threadgroup.cc b/openjdkjvmti/ti_threadgroup.cc index 120024e8b2..bfe6b51791 100644 --- a/openjdkjvmti/ti_threadgroup.cc +++ b/openjdkjvmti/ti_threadgroup.cc @@ -171,18 +171,26 @@ static void GetThreads(art::Handle<art::mirror::Object> thread_group, CHECK(thread_group != nullptr); art::MutexLock mu(art::Thread::Current(), *art::Locks::thread_list_lock_); - for (art::Thread* t : art::Runtime::Current()->GetThreadList()->GetList()) { - if (t->IsStillStarting()) { - continue; - } - art::ObjPtr<art::mirror::Object> peer = t->GetPeerFromOtherThread(); - if (peer == nullptr) { - continue; - } - if (IsInDesiredThreadGroup(thread_group, peer)) { + std::list<art::Thread*> thread_list = art::Runtime::Current()->GetThreadList()->GetList(); + // We have to be careful with threads exiting while we build this list. + std::vector<art::ThreadExitFlag> tefs(thread_list.size()); + auto i = tefs.begin(); + for (art::Thread* thd : thread_list) { + thd->NotifyOnThreadExit(&*i++); + } + DCHECK(i == tefs.end()); + + i = tefs.begin(); + for (art::Thread* t : thread_list) { + art::ThreadExitFlag* tef = &*i++; + art::ObjPtr<art::mirror::Object> peer = t->LockedGetPeerFromOtherThread(tef); + if (peer != nullptr && !tef->HasExited() && !t->IsStillStarting() && + IsInDesiredThreadGroup(thread_group, peer)) { thread_peers->push_back(peer); } + t->UnregisterThreadExitFlag(tef); } + DCHECK(i == tefs.end()); } static void GetChildThreadGroups(art::Handle<art::mirror::Object> thread_group, |