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/image_test.cc b/src/image_test.cc
index f9c2d1c..9c947c1 100644
--- a/src/image_test.cc
+++ b/src/image_test.cc
@@ -32,19 +32,21 @@
 
 TEST_F(ImageTest, WriteRead) {
   ScratchFile tmp_oat;
-  std::vector<const DexFile*> dex_files;
-  dex_files.push_back(java_lang_dex_file_);
-  bool success_oat = OatWriter::Create(tmp_oat.GetFile(), NULL, dex_files, 0, "", *compiler_.get());
-  ASSERT_TRUE(success_oat);
+  {
+    ScopedObjectAccess soa(Thread::Current());
+    std::vector<const DexFile*> dex_files;
+    dex_files.push_back(java_lang_dex_file_);
+    bool success_oat = OatWriter::Create(tmp_oat.GetFile(), NULL, dex_files, 0, "", *compiler_.get());
+    ASSERT_TRUE(success_oat);
 
-  // Force all system classes into memory
-  for (size_t i = 0; i < java_lang_dex_file_->NumClassDefs(); ++i) {
-    const DexFile::ClassDef& class_def = java_lang_dex_file_->GetClassDef(i);
-    const char* descriptor = java_lang_dex_file_->GetClassDescriptor(class_def);
-    Class* klass = class_linker_->FindSystemClass(descriptor);
-    EXPECT_TRUE(klass != NULL) << descriptor;
+    // Force all system classes into memory
+    for (size_t i = 0; i < java_lang_dex_file_->NumClassDefs(); ++i) {
+      const DexFile::ClassDef& class_def = java_lang_dex_file_->GetClassDef(i);
+      const char* descriptor = java_lang_dex_file_->GetClassDescriptor(class_def);
+      Class* klass = class_linker_->FindSystemClass(descriptor);
+      EXPECT_TRUE(klass != NULL) << descriptor;
+    }
   }
-
   ImageWriter writer(NULL);
   ScratchFile tmp_image;
   const uintptr_t requested_image_base = 0x60000000;
@@ -81,7 +83,15 @@
   image.append(tmp_image.GetFilename());
   options.push_back(std::make_pair(image.c_str(), reinterpret_cast<void*>(NULL)));
 
-  runtime_.reset(Runtime::Create(options, false));
+  if (!Runtime::Create(options, false)) {
+    LOG(FATAL) << "Failed to create runtime";
+    return;
+  }
+  runtime_.reset(Runtime::Current());
+  // Runtime::Create acquired the mutator_lock_ that is normally given away when we Runtime::Start,
+  // give it away now and then switch to a more managable ScopedObjectAccess.
+  Thread::Current()->TransitionFromRunnableToSuspended(kNative);
+  ScopedObjectAccess soa(Thread::Current());
   ASSERT_TRUE(runtime_.get() != NULL);
   class_linker_ = runtime_->GetClassLinker();