Fix crash in VirtualMachine.AllThreads JDWP command
When collecting all the started threads, we may encounter a thread in the
process of being started from Java code (Thread.start) in the threads list. The
crash occurs when we attempt to access the java.lang.Thread peer (calling
Thread::GetPeer) but the JNI global reference to it (Thread::jpeer) has not
been destroyed yet (which is verified with a check). This only happens when the
thread is starting up.
We now check the thread finished starting up before accessing the Java peer.
This also prevents from returning non-started threads in the reply.
Bug: 16660101
(cherry picked from commit a22d115711b5158cfc67b4f260a5b40f3ab303ca)
Change-Id: Ib61dbd0b01f63bfdda708d3c93eac58284bbe236
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index fa1a1a8..1cddb8b 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -2095,6 +2095,11 @@
// query all threads, so it's easier if we just don't tell them about this thread.
return;
}
+ if (t->IsStillStarting()) {
+ // This thread is being started (and has been registered in the thread list). However, it is
+ // not completely started yet so we must ignore it.
+ return;
+ }
mirror::Object* peer = t->GetPeer();
if (IsInDesiredThreadGroup(peer)) {
thread_ids_.push_back(gRegistry->Add(peer));