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/native/dalvik_system_VMStack.cc b/src/native/dalvik_system_VMStack.cc
index 5ef512a..0e6e675 100644
--- a/src/native/dalvik_system_VMStack.cc
+++ b/src/native/dalvik_system_VMStack.cc
@@ -25,10 +25,11 @@
 
 static jobject GetThreadStack(JNIEnv* env, jobject peer) {
   bool timeout;
-  Thread* self = Thread::Current();
-  if (env->IsSameObject(peer, self->GetPeer())) {
+  {
     ScopedObjectAccess soa(env);
-    return self->CreateInternalStackTrace(soa);
+    if (soa.Decode<Object*>(peer) == soa.Self()->GetPeer()) {
+      return soa.Self()->CreateInternalStackTrace(soa);
+    }
   }
   // Suspend thread to build stack trace.
   Thread* thread = Thread::SuspendForDebugger(peer, true, &timeout);