Add GcRoot to clean up and enforce read barriers.

Introduce a value-type wrapper around Object* for GC roots so that 1)
we won't have to directly add the read barrier code in many places and
2) we can avoid accidentally bypassing/missing read barriers on GC
roots (the GcRoot interface ensures that the read barrier is executed
on a read).

The jdwp test passed.

Bug: 12687968
Change-Id: Ib167c7c325b3c7e3900133578815f04d219972a1
diff --git a/runtime/runtime.h b/runtime/runtime.h
index c8e462e..a85c2e4 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -27,6 +27,7 @@
 #include <vector>
 
 #include "compiler_callbacks.h"
+#include "gc_root.h"
 #include "instrumentation.h"
 #include "instruction_set.h"
 #include "jobject_comparator.h"
@@ -282,11 +283,11 @@
   mirror::ArtMethod* GetResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
   bool HasResolutionMethod() const {
-    return resolution_method_ != nullptr;
+    return !resolution_method_.IsNull();
   }
 
   void SetResolutionMethod(mirror::ArtMethod* method) {
-    resolution_method_ = method;
+    resolution_method_ = GcRoot<mirror::ArtMethod>(method);
   }
 
   mirror::ArtMethod* CreateResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -295,11 +296,11 @@
   mirror::ArtMethod* GetImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
   bool HasImtConflictMethod() const {
-    return imt_conflict_method_ != nullptr;
+    return !imt_conflict_method_.IsNull();
   }
 
   void SetImtConflictMethod(mirror::ArtMethod* method) {
-    imt_conflict_method_ = method;
+    imt_conflict_method_ = GcRoot<mirror::ArtMethod>(method);
   }
 
   mirror::ArtMethod* CreateImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -309,11 +310,11 @@
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
   bool HasDefaultImt() const {
-    return default_imt_ != nullptr;
+    return !default_imt_.IsNull();
   }
 
   void SetDefaultImt(mirror::ObjectArray<mirror::ArtMethod>* imt) {
-    default_imt_ = imt;
+    default_imt_ = GcRoot<mirror::ObjectArray<mirror::ArtMethod>>(imt);
   }
 
   mirror::ObjectArray<mirror::ArtMethod>* CreateDefaultImt(ClassLinker* cl)
@@ -328,7 +329,7 @@
   };
 
   bool HasCalleeSaveMethod(CalleeSaveType type) const {
-    return callee_save_methods_[type] != NULL;
+    return !callee_save_methods_[type].IsNull();
   }
 
   mirror::ArtMethod* GetCalleeSaveMethod(CalleeSaveType type)
@@ -488,11 +489,11 @@
   static constexpr int kProfileForground = 0;
   static constexpr int kProfileBackgrouud = 1;
 
-  mirror::ArtMethod* callee_save_methods_[kLastCalleeSaveType];
-  mirror::Throwable* pre_allocated_OutOfMemoryError_;
-  mirror::ArtMethod* resolution_method_;
-  mirror::ArtMethod* imt_conflict_method_;
-  mirror::ObjectArray<mirror::ArtMethod>* default_imt_;
+  GcRoot<mirror::ArtMethod> callee_save_methods_[kLastCalleeSaveType];
+  GcRoot<mirror::Throwable> pre_allocated_OutOfMemoryError_;
+  GcRoot<mirror::ArtMethod> resolution_method_;
+  GcRoot<mirror::ArtMethod> imt_conflict_method_;
+  GcRoot<mirror::ObjectArray<mirror::ArtMethod>> default_imt_;
 
   InstructionSet instruction_set_;
   QuickMethodFrameInfo callee_save_method_frame_infos_[kLastCalleeSaveType];