Implement ObjectReference.MonitorInfo.

Change-Id: Iefc276939b9e569f4ea4d7a5af9a28276a3fb632
diff --git a/src/native/dalvik_system_VMStack.cc b/src/native/dalvik_system_VMStack.cc
index 8ce022d..cd28b5d 100644
--- a/src/native/dalvik_system_VMStack.cc
+++ b/src/native/dalvik_system_VMStack.cc
@@ -24,7 +24,6 @@
 namespace art {
 
 static jobject GetThreadStack(JNIEnv* env, jobject peer) {
-  bool timeout;
   {
     ScopedObjectAccess soa(env);
     if (soa.Decode<Object*>(peer) == soa.Self()->GetPeer()) {
@@ -32,7 +31,8 @@
     }
   }
   // Suspend thread to build stack trace.
-  Thread* thread = Thread::SuspendForDebugger(peer, true, &timeout);
+  bool timed_out;
+  Thread* thread = Thread::SuspendForDebugger(peer, true, &timed_out);
   if (thread != NULL) {
     jobject trace;
     {
@@ -43,7 +43,7 @@
     Runtime::Current()->GetThreadList()->Resume(thread, true);
     return trace;
   } else {
-    if (timeout) {
+    if (timed_out) {
       LOG(ERROR) << "Trying to get thread's stack failed as the thread failed to suspend within a "
           "generous timeout.";
     }
diff --git a/src/native/java_lang_Thread.cc b/src/native/java_lang_Thread.cc
index 8db217e..473369e 100644
--- a/src/native/java_lang_Thread.cc
+++ b/src/native/java_lang_Thread.cc
@@ -119,15 +119,15 @@
   // Suspend thread to avoid it from killing itself while we set its name. We don't just hold the
   // thread list lock to avoid this, as setting the thread name causes mutator to lock/unlock
   // in the DDMS send code.
-  bool timeout;
-  Thread* thread = Thread::SuspendForDebugger(peer, true, &timeout);
+  bool timed_out;
+  Thread* thread = Thread::SuspendForDebugger(peer, true, &timed_out);
   if (thread != NULL) {
     {
       ScopedObjectAccess soa(env);
       thread->SetThreadName(name.c_str());
     }
     Runtime::Current()->GetThreadList()->Resume(thread, true);
-  } else if (timeout) {
+  } else if (timed_out) {
     LOG(ERROR) << "Trying to set thread name to '" << name.c_str() << "' failed as the thread "
         "failed to suspend within a generous timeout.";
   }
diff --git a/src/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc b/src/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
index a6588b4..5ba2994 100644
--- a/src/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
+++ b/src/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
@@ -39,48 +39,27 @@
   return Dbg::IsAllocTrackingEnabled();
 }
 
-static jobject FindThreadByThinLockId(JNIEnv* env, uint32_t thin_lock_id) {
-  struct ThreadFinder {
-    explicit ThreadFinder(uint32_t thin_lock_id) : thin_lock_id(thin_lock_id), thread(NULL) {
-    }
-
-    static void Callback(Thread* t, void* context) {
-      ThreadFinder* finder = reinterpret_cast<ThreadFinder*>(context);
-      if (t->GetThinLockId() == finder->thin_lock_id) {
-        finder->thread = t;
-      }
-    }
-
-    uint32_t thin_lock_id;
-    Thread* thread;
-  };
-  ThreadFinder finder(thin_lock_id);
-  {
-    Thread* self = static_cast<JNIEnvExt*>(env)->self;
-    MutexLock mu(self, *Locks::thread_list_lock_);
-    Runtime::Current()->GetThreadList()->ForEach(ThreadFinder::Callback, &finder);
-  }
-  if (finder.thread != NULL) {
-    ScopedObjectAccess soa(env);
-    return soa.AddLocalReference<jobject>(finder.thread->GetPeer());
-  } else {
-    return NULL;
-  }
-}
-
 /*
  * Get a stack trace as an array of StackTraceElement objects.  Returns
  * NULL on failure, e.g. if the threadId couldn't be found.
  */
 static jobjectArray DdmVmInternal_getStackTraceById(JNIEnv* env, jclass, jint thin_lock_id) {
-  ScopedLocalRef<jobject> peer(env,
-                               FindThreadByThinLockId(env, static_cast<uint32_t>(thin_lock_id)));
+  ScopedLocalRef<jobject> peer(env, NULL);
+  {
+    Thread* t = Runtime::Current()->GetThreadList()->FindThreadByThinLockId(thin_lock_id);
+    if (t == NULL) {
+      return NULL;
+    }
+    ScopedObjectAccess soa(env);
+    peer.reset(soa.AddLocalReference<jobject>(t->GetPeer()));
+  }
   if (peer.get() == NULL) {
     return NULL;
   }
-  bool timeout;
+
   // Suspend thread to build stack trace.
-  Thread* thread = Thread::SuspendForDebugger(peer.get(), true, &timeout);
+  bool timed_out;
+  Thread* thread = Thread::SuspendForDebugger(peer.get(), true, &timed_out);
   if (thread != NULL) {
     jobject trace;
     {
@@ -91,7 +70,7 @@
     Runtime::Current()->GetThreadList()->Resume(thread, true);
     return Thread::InternalStackTraceToStackTraceElementArray(env, trace);
   } else {
-    if (timeout) {
+    if (timed_out) {
       LOG(ERROR) << "Trying to get thread's stack by id failed as the thread failed to suspend "
           "within a generous timeout.";
     }