Global lock levels.

Introduce the notion of the mutators/GC being a shared-exclusive (aka
reader-writer) lock. Introduce globally ordered locks, analysable by
annotalysis, statically at compile time. Add locking attributes to
methods.

More subtly, remove the heap_lock_ and split between various locks that
are held for smaller periods (where work doesn't get blocked). Remove
buggy Dalvik style thread transitions. Make GC use CMS in all cases when
concurrent is enabled. Fix bug where suspend counts rather than debug
suspend counts were sent to JDWP. Move the PathClassLoader to
WellKnownClasses. In debugger refactor calls to send request and
possibly suspend. Break apart different VmWait thread states. Move
identity hash code to a shared method.

Change-Id: Icdbfc3ce3fcccd14341860ac7305d8e97b51f5c6
diff --git a/src/indirect_reference_table.cc b/src/indirect_reference_table.cc
index 81b87ef..958531d 100644
--- a/src/indirect_reference_table.cc
+++ b/src/indirect_reference_table.cc
@@ -18,6 +18,7 @@
 #include "jni_internal.h"
 #include "reference_table.h"
 #include "runtime.h"
+#include "scoped_thread_state_change.h"
 #include "thread.h"
 #include "utils.h"
 
@@ -91,7 +92,7 @@
     if (topIndex == max_entries_) {
       LOG(FATAL) << "JNI ERROR (app bug): " << kind_ << " table overflow "
                  << "(max=" << max_entries_ << ")\n"
-                 << Dumpable<IndirectReferenceTable>(*this);
+                 << MutatorLockedDumpable<IndirectReferenceTable>(*this);
     }
 
     size_t newSize = alloc_entries_ * 2;
@@ -101,13 +102,14 @@
     DCHECK_GT(newSize, alloc_entries_);
 
     table_ = reinterpret_cast<const Object**>(realloc(table_, newSize * sizeof(const Object*)));
-    slot_data_ = reinterpret_cast<IndirectRefSlot*>(realloc(slot_data_, newSize * sizeof(IndirectRefSlot)));
+    slot_data_ = reinterpret_cast<IndirectRefSlot*>(realloc(slot_data_,
+                                                            newSize * sizeof(IndirectRefSlot)));
     if (table_ == NULL || slot_data_ == NULL) {
       LOG(FATAL) << "JNI ERROR (app bug): unable to expand "
                  << kind_ << " table (from "
                  << alloc_entries_ << " to " << newSize
                  << ", max=" << max_entries_ << ")\n"
-                 << Dumpable<IndirectReferenceTable>(*this);
+                 << MutatorLockedDumpable<IndirectReferenceTable>(*this);
     }
 
     // Clear the newly-allocated slot_data_ elements.
@@ -150,9 +152,10 @@
 }
 
 void IndirectReferenceTable::AssertEmpty() {
-  if (begin() != end()) {
+  if (UNLIKELY(begin() != end())) {
+    ScopedObjectAccess soa(Thread::Current());
     LOG(FATAL) << "Internal Error: non-empty local reference table\n"
-               << Dumpable<IndirectReferenceTable>(*this);
+               << MutatorLockedDumpable<IndirectReferenceTable>(*this);
   }
 }