Add Handle/HandleScope and delete SirtRef.

Delete SirtRef and replaced it with Handle. Handles are value types
which wrap around StackReference*.

Renamed StackIndirectReferenceTable to HandleScope.

Added a scoped handle wrapper which wraps around an Object** and
restores it in its destructor.

Renamed Handle::get -> Get.

Bug: 8473721

Change-Id: Idbfebd4f35af629f0f43931b7c5184b334822c7a
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index ff63782..15b69f3 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -28,7 +28,7 @@
 #include "object_array-inl.h"
 #include "object_utils.h"
 #include "runtime.h"
-#include "sirt_ref.h"
+#include "handle_scope-inl.h"
 #include "thread.h"
 #include "throwable.h"
 #include "utils.h"
@@ -77,20 +77,13 @@
         << "Attempt to set as erroneous an already erroneous class " << PrettyClass(this);
 
     // Stash current exception.
-    SirtRef<mirror::Object> old_throw_this_object(self, NULL);
-    SirtRef<mirror::ArtMethod> old_throw_method(self, NULL);
-    SirtRef<mirror::Throwable> old_exception(self, NULL);
-    uint32_t old_throw_dex_pc;
-    {
-      ThrowLocation old_throw_location;
-      mirror::Throwable* old_exception_obj = self->GetException(&old_throw_location);
-      old_throw_this_object.reset(old_throw_location.GetThis());
-      old_throw_method.reset(old_throw_location.GetMethod());
-      old_exception.reset(old_exception_obj);
-      old_throw_dex_pc = old_throw_location.GetDexPc();
-      self->ClearException();
-    }
-    CHECK(old_exception.get() != NULL);
+    StackHandleScope<3> hs(self);
+    ThrowLocation old_throw_location;
+    Handle<mirror::Throwable> old_exception(hs.NewHandle(self->GetException(&old_throw_location)));
+    CHECK(old_exception.Get() != nullptr);
+    Handle<mirror::Object> old_throw_this_object(hs.NewHandle(old_throw_location.GetThis()));
+    Handle<mirror::ArtMethod> old_throw_method(hs.NewHandle(old_throw_location.GetMethod()));
+    uint32_t old_throw_dex_pc = old_throw_location.GetDexPc();
 
     // clear exception to call FindSystemClass
     self->ClearException();
@@ -107,10 +100,10 @@
     }
 
     // Restore exception.
-    ThrowLocation gc_safe_throw_location(old_throw_this_object.get(), old_throw_method.get(),
+    ThrowLocation gc_safe_throw_location(old_throw_this_object.Get(), old_throw_method.Get(),
                                          old_throw_dex_pc);
 
-    self->SetException(gc_safe_throw_location, old_exception.get());
+    self->SetException(gc_safe_throw_location, old_exception.Get());
   }
   CHECK(sizeof(Status) == sizeof(uint32_t)) << PrettyClass(this);
   if (Runtime::Current()->IsActiveTransaction()) {
@@ -149,7 +142,8 @@
     return name;
   }
   Thread* self = Thread::Current();
-  SirtRef<mirror::Class> sirt_c(self, this);
+  StackHandleScope<1> hs(self);
+  Handle<mirror::Class> handle_c(hs.NewHandle(this));
   std::string descriptor(ClassHelper(this).GetDescriptor());
   if ((descriptor[0] != 'L') && (descriptor[0] != '[')) {
     // The descriptor indicates that this is the class for
@@ -179,7 +173,7 @@
     std::replace(descriptor.begin(), descriptor.end(), '/', '.');
     name = String::AllocFromModifiedUtf8(self, descriptor.c_str());
   }
-  sirt_c->SetName(name);
+  handle_c->SetName(name);
   return name;
 }