Turn the thread peer_ into a Object*.

Don't use a JNI global ref for the thread peer_ so that we can
support more threads than we can global refs. This fixes run-test 51.
Fix a race in thread destruction where a thread may be requested to
suspend while deleting itself.

Change-Id: Id8756a575becf80d2a0be0a213325034556927f1
diff --git a/src/debugger.cc b/src/debugger.cc
index e0e02cf..672b660 100644
--- a/src/debugger.cc
+++ b/src/debugger.cc
@@ -1497,7 +1497,7 @@
         // query all threads, so it's easier if we just don't tell them about this thread.
         return;
       }
-      Object* peer = soa_.Decode<Object*>(t->GetPeer());
+      Object* peer = t->GetPeer();
       if (IsInDesiredThreadGroup(peer)) {
         thread_ids_.push_back(gRegistry->Add(peer));
       }
@@ -1632,7 +1632,7 @@
 
 JDWP::ObjectId Dbg::GetThreadSelfId() {
   ScopedObjectAccessUnchecked soa(Thread::Current());
-  return gRegistry->Add(soa.Decode<Object*>(Thread::Current()->GetPeer()));
+  return gRegistry->Add(soa.Self()->GetPeer());
 }
 
 void Dbg::SuspendVM() {
@@ -2755,7 +2755,7 @@
 void Dbg::PostThreadStartOrStop(Thread* t, uint32_t type) {
   if (IsDebuggerActive()) {
     ScopedObjectAccessUnchecked soa(Thread::Current());
-    JDWP::ObjectId id = gRegistry->Add(soa.Decode<Object*>(t->GetPeer()));
+    JDWP::ObjectId id = gRegistry->Add(t->GetPeer());
     gJdwpState->PostThreadChange(id, type == CHUNK_TYPE("THCR"));
     // If this thread's just joined the party while we're already debugging, make sure it knows
     // to give us updates when it's running.