Fix a heap lock/thread list lock deadlock.

We had an uncaught OOME whose uncaught exception handler -- running
with the thread lock held -- was trying to cause a GC while some
other thread had the heap lock and was waiting for the thread list
lock.

Change-Id: I22177129562268837127d9edcc63ef5e93054bdf
diff --git a/src/thread_list.cc b/src/thread_list.cc
index 7b6d3ba..77ee31a 100644
--- a/src/thread_list.cc
+++ b/src/thread_list.cc
@@ -43,6 +43,10 @@
   return find(list_.begin(), list_.end(), thread) != list_.end();
 }
 
+uint32_t ThreadList::GetLockOwner() {
+  return thread_list_lock_.GetOwner();
+}
+
 void ThreadList::Dump(std::ostream& os) {
   MutexLock mu(thread_list_lock_);
   os << "DALVIK THREADS (" << list_.size() << "):\n";
@@ -267,6 +271,10 @@
     LOG(INFO) << "ThreadList::Unregister() " << *self;
   }
 
+  // This may need to call user-supplied managed code. Make sure we do this before we start tearing
+  // down the Thread* and removing it from the thread list (or start taking any locks).
+  self->HandleUncaughtExceptions();
+
   MutexLock mu(thread_list_lock_);
 
   // Remove this thread from the list.