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/dex_cache.h b/src/dex_cache.h
index f604701..b3c5ce6 100644
--- a/src/dex_cache.h
+++ b/src/dex_cache.h
@@ -38,11 +38,12 @@
             ObjectArray<Class>* types,
             ObjectArray<Method>* methods,
             ObjectArray<Field>* fields,
-            ObjectArray<StaticStorageBase>* initialized_static_storage);
+            ObjectArray<StaticStorageBase>* initialized_static_storage)
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
 
-  void Fixup(Method* trampoline);
+  void Fixup(Method* trampoline) SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
 
-  String* GetLocation() const {
+  String* GetLocation() const SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return Get(kLocation)->AsString();
   }
 
@@ -61,43 +62,49 @@
                         kResolvedMethods * sizeof(Object*));
   }
 
-  size_t NumStrings() const {
+  size_t NumStrings() const SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return GetStrings()->GetLength();
   }
 
-  size_t NumResolvedTypes() const {
+  size_t NumResolvedTypes() const SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return GetResolvedTypes()->GetLength();
   }
 
-  size_t NumResolvedMethods() const {
+  size_t NumResolvedMethods() const SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return GetResolvedMethods()->GetLength();
   }
 
-  size_t NumResolvedFields() const {
+  size_t NumResolvedFields() const SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return GetResolvedFields()->GetLength();
   }
 
-  size_t NumInitializedStaticStorage() const {
+  size_t NumInitializedStaticStorage() const
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return GetInitializedStaticStorage()->GetLength();
   }
 
-  String* GetResolvedString(uint32_t string_idx) const {
+  String* GetResolvedString(uint32_t string_idx) const
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return GetStrings()->Get(string_idx);
   }
 
-  void SetResolvedString(uint32_t string_idx, String* resolved) {
+  void SetResolvedString(uint32_t string_idx, String* resolved)
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     GetStrings()->Set(string_idx, resolved);
   }
 
-  Class* GetResolvedType(uint32_t type_idx) const {
+  Class* GetResolvedType(uint32_t type_idx) const
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return GetResolvedTypes()->Get(type_idx);
   }
 
-  void SetResolvedType(uint32_t type_idx, Class* resolved) {
+  void SetResolvedType(uint32_t type_idx, Class* resolved)
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     GetResolvedTypes()->Set(type_idx, resolved);
   }
 
-  Method* GetResolvedMethod(uint32_t method_idx) const {
+  Method* GetResolvedMethod(uint32_t method_idx) const
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     Method* method = GetResolvedMethods()->Get(method_idx);
     // Hide resolution trampoline methods from the caller
     if (method != NULL && method->GetDexMethodIndex() == DexFile::kDexNoIndex16) {
@@ -108,31 +115,39 @@
     }
   }
 
-  void SetResolvedMethod(uint32_t method_idx, Method* resolved) {
+  void SetResolvedMethod(uint32_t method_idx, Method* resolved)
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     GetResolvedMethods()->Set(method_idx, resolved);
   }
 
-  Field* GetResolvedField(uint32_t field_idx) const {
+  Field* GetResolvedField(uint32_t field_idx) const
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return GetResolvedFields()->Get(field_idx);
   }
 
-  void SetResolvedField(uint32_t field_idx, Field* resolved) {
+  void SetResolvedField(uint32_t field_idx, Field* resolved)
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     GetResolvedFields()->Set(field_idx, resolved);
   }
 
-  ObjectArray<String>* GetStrings() const {
+  ObjectArray<String>* GetStrings() const
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return static_cast<ObjectArray<String>*>(GetNonNull(kStrings));
   }
-  ObjectArray<Class>* GetResolvedTypes() const {
+  ObjectArray<Class>* GetResolvedTypes() const
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return static_cast<ObjectArray<Class>*>(GetNonNull(kResolvedTypes));
   }
-  ObjectArray<Method>* GetResolvedMethods() const {
+  ObjectArray<Method>* GetResolvedMethods() const
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return static_cast<ObjectArray<Method>*>(GetNonNull(kResolvedMethods));
   }
-  ObjectArray<Field>* GetResolvedFields() const {
+  ObjectArray<Field>* GetResolvedFields() const
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return static_cast<ObjectArray<Field>*>(GetNonNull(kResolvedFields));
   }
-  ObjectArray<StaticStorageBase>* GetInitializedStaticStorage() const {
+  ObjectArray<StaticStorageBase>* GetInitializedStaticStorage() const
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     return static_cast<ObjectArray<StaticStorageBase>*>(GetNonNull(kInitializedStaticStorage));
   }
 
@@ -151,7 +166,8 @@
     kMax                      = 6,
   };
 
-  Object* GetNonNull(ArrayIndex array_index) const {
+  Object* GetNonNull(ArrayIndex array_index) const
+      SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
     Object* obj = Get(array_index);
     DCHECK(obj != NULL);
     return obj;