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/instrumentation.cc b/runtime/instrumentation.cc
index 8e375cf..16be077 100644
--- a/runtime/instrumentation.cc
+++ b/runtime/instrumentation.cc
@@ -25,6 +25,7 @@
 #include "debugger.h"
 #include "dex_file-inl.h"
 #include "entrypoints/quick/quick_alloc_entrypoints.h"
+#include "gc_root-inl.h"
 #include "interpreter/interpreter.h"
 #include "mirror/art_method-inl.h"
 #include "mirror/class-inl.h"
@@ -628,7 +629,7 @@
   }
   // Not found. Add it.
   int32_t hash_code = method->IdentityHashCode();
-  deoptimized_methods_.insert(std::make_pair(hash_code, method));
+  deoptimized_methods_.insert(std::make_pair(hash_code, GcRoot<mirror::ArtMethod>(method)));
   return true;
 }
 
@@ -636,8 +637,7 @@
   int32_t hash_code = method->IdentityHashCode();
   auto range = deoptimized_methods_.equal_range(hash_code);
   for (auto it = range.first; it != range.second; ++it) {
-    mirror::ArtMethod** root = &it->second;
-    mirror::ArtMethod* m = ReadBarrier::BarrierForRoot<mirror::ArtMethod>(root);
+    mirror::ArtMethod* m = it->second.Read();
     if (m == method) {
       // Found.
       return true;
@@ -653,16 +653,14 @@
     // Empty.
     return nullptr;
   }
-  mirror::ArtMethod** root = &it->second;
-  return ReadBarrier::BarrierForRoot<mirror::ArtMethod>(root);
+  return it->second.Read();
 }
 
 bool Instrumentation::RemoveDeoptimizedMethod(mirror::ArtMethod* method) {
   int32_t hash_code = method->IdentityHashCode();
   auto range = deoptimized_methods_.equal_range(hash_code);
   for (auto it = range.first; it != range.second; ++it) {
-    mirror::ArtMethod** root = &it->second;
-    mirror::ArtMethod* m = ReadBarrier::BarrierForRoot<mirror::ArtMethod>(root);
+    mirror::ArtMethod* m = it->second.Read();
     if (m == method) {
       // Found. Erase and return.
       deoptimized_methods_.erase(it);
@@ -1024,8 +1022,7 @@
     return;
   }
   for (auto pair : deoptimized_methods_) {
-    mirror::ArtMethod** root = &pair.second;
-    callback(reinterpret_cast<mirror::Object**>(root), arg, 0, kRootVMInternal);
+    pair.second.VisitRoot(callback, arg, 0, kRootVMInternal);
   }
 }