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
Change-Id: I9e445e5da3a6951143d6c3c9a0d4f136398fde2f
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index bc13379..7710885 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -2087,6 +2087,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));