Print mutexes held in Thread::Dump.

Should help finding and fixing thread suspend timeout issues.

Bug: 15328839
Change-Id: I30a10529cec0716c7571a0318e9f66be54734fd8
diff --git a/runtime/thread.cc b/runtime/thread.cc
index f89fada..3bfdc3f 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -824,6 +824,26 @@
     os << "  | stack=" << reinterpret_cast<void*>(thread->tlsPtr_.stack_begin) << "-"
         << reinterpret_cast<void*>(thread->tlsPtr_.stack_end) << " stackSize="
         << PrettySize(thread->tlsPtr_.stack_size) << "\n";
+    // Dump the held mutexes.
+    os << "  | held mutexes=";
+    for (size_t i = 0; i < kLockLevelCount; ++i) {
+      if (i != kMonitorLock) {
+        BaseMutex* mutex = thread->GetHeldMutex(static_cast<LockLevel>(i));
+        if (mutex != nullptr) {
+          os << " \"" << mutex->GetName() << "\"";
+          if (mutex->IsReaderWriterMutex()) {
+            ReaderWriterMutex* rw_mutex = down_cast<ReaderWriterMutex*>(mutex);
+            if (rw_mutex->IsExclusiveHeld(thread)) {
+              os << "(exclusive held)";
+            } else {
+              CHECK(rw_mutex->IsSharedHeld(thread));
+              os << "(shared held)";
+            }
+          }
+        }
+      }
+    }
+    os << "\n";
   }
 }