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/native/dalvik_system_VMStack.cc b/src/native/dalvik_system_VMStack.cc
index 12fa8db..3284c97 100644
--- a/src/native/dalvik_system_VMStack.cc
+++ b/src/native/dalvik_system_VMStack.cc
@@ -18,19 +18,34 @@
 #include "jni_internal.h"
 #include "nth_caller_visitor.h"
 #include "object.h"
-#include "scoped_heap_lock.h"
-#include "scoped_jni_thread_state.h"
-#include "scoped_thread_list_lock.h"
+#include "scoped_thread_state_change.h"
 #include "thread_list.h"
 
 namespace art {
 
-static jobject GetThreadStack(JNIEnv* env, jobject javaThread) {
-  ScopedJniThreadState ts(env);
-  ScopedHeapLock heap_lock;
-  ScopedThreadListLock thread_list_lock;
-  Thread* thread = Thread::FromManagedThread(ts, javaThread);
-  return (thread != NULL) ? GetThreadStack(ts, thread) : NULL;
+static jobject GetThreadStack(JNIEnv* env, jobject peer) {
+  bool timeout;
+  {
+    ScopedObjectAccess soa(env);
+    Thread* self = Thread::Current();
+    if (soa.Decode<Object*>(peer) == self->GetPeer()) {
+      return self->CreateInternalStackTrace(soa);
+    }
+  }
+  // Suspend thread to build stack trace.
+  Thread* thread = Thread::SuspendForDebugger(peer, true, &timeout);
+  if (thread != NULL) {
+    jobject trace;
+    {
+      ScopedObjectAccess soa(env);
+      trace = thread->CreateInternalStackTrace(soa);
+    }
+    // Restart suspended thread.
+    Runtime::Current()->GetThreadList()->Resume(thread, true);
+    return trace;
+  } else {
+    return NULL;
+  }
 }
 
 static jint VMStack_fillStackTraceElements(JNIEnv* env, jclass, jobject javaThread, jobjectArray javaSteArray) {
@@ -45,10 +60,10 @@
 
 // Returns the defining class loader of the caller's caller.
 static jobject VMStack_getCallingClassLoader(JNIEnv* env, jclass) {
-  ScopedJniThreadState ts(env);
-  NthCallerVisitor visitor(ts.Self()->GetManagedStack(), ts.Self()->GetTraceStack(), 2);
+  ScopedObjectAccess soa(env);
+  NthCallerVisitor visitor(soa.Self()->GetManagedStack(), soa.Self()->GetTraceStack(), 2);
   visitor.WalkStack();
-  return ts.AddLocalReference<jobject>(visitor.caller->GetDeclaringClass()->GetClassLoader());
+  return soa.AddLocalReference<jobject>(visitor.caller->GetDeclaringClass()->GetClassLoader());
 }
 
 static jobject VMStack_getClosestUserClassLoader(JNIEnv* env, jclass, jobject javaBootstrap, jobject javaSystem) {
@@ -74,21 +89,21 @@
     Object* system;
     Object* class_loader;
   };
-  ScopedJniThreadState ts(env);
-  Object* bootstrap = ts.Decode<Object*>(javaBootstrap);
-  Object* system = ts.Decode<Object*>(javaSystem);
-  ClosestUserClassLoaderVisitor visitor(ts.Self()->GetManagedStack(), ts.Self()->GetTraceStack(),
+  ScopedObjectAccess soa(env);
+  Object* bootstrap = soa.Decode<Object*>(javaBootstrap);
+  Object* system = soa.Decode<Object*>(javaSystem);
+  ClosestUserClassLoaderVisitor visitor(soa.Self()->GetManagedStack(), soa.Self()->GetTraceStack(),
                                         bootstrap, system);
   visitor.WalkStack();
-  return ts.AddLocalReference<jobject>(visitor.class_loader);
+  return soa.AddLocalReference<jobject>(visitor.class_loader);
 }
 
 // Returns the class of the caller's caller's caller.
 static jclass VMStack_getStackClass2(JNIEnv* env, jclass) {
-  ScopedJniThreadState ts(env);
-  NthCallerVisitor visitor(ts.Self()->GetManagedStack(), ts.Self()->GetTraceStack(), 3);
+  ScopedObjectAccess soa(env);
+  NthCallerVisitor visitor(soa.Self()->GetManagedStack(), soa.Self()->GetTraceStack(), 3);
   visitor.WalkStack();
-  return ts.AddLocalReference<jclass>(visitor.caller->GetDeclaringClass());
+  return soa.AddLocalReference<jclass>(visitor.caller->GetDeclaringClass());
 }
 
 static jobjectArray VMStack_getThreadStackTrace(JNIEnv* env, jclass, jobject javaThread) {