Partially ObjPtr<>-ify HandleScope.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing --interpreter
Bug: 31113334
Change-Id: I560683b5345bda9df4b22903d032b593d6c2dd4f
diff --git a/runtime/handle_scope-inl.h b/runtime/handle_scope-inl.h
index 765ed7d..6d8a05d 100644
--- a/runtime/handle_scope-inl.h
+++ b/runtime/handle_scope-inl.h
@@ -22,6 +22,7 @@
 #include "base/mutex.h"
 #include "handle.h"
 #include "handle_wrapper.h"
+#include "mirror/object_reference-inl.h"
 #include "obj_ptr-inl.h"
 #include "thread-current-inl.h"
 #include "verify_object.h"
@@ -30,7 +31,7 @@
 
 template<size_t kNumReferences>
 inline FixedSizeHandleScope<kNumReferences>::FixedSizeHandleScope(BaseHandleScope* link,
-                                                                  mirror::Object* fill_value)
+                                                                  ObjPtr<mirror::Object> fill_value)
     : HandleScope(link, kNumReferences) {
   if (kDebugLocking) {
     Locks::mutator_lock_->AssertSharedHeld(Thread::Current());
@@ -43,7 +44,8 @@
 }
 
 template<size_t kNumReferences>
-inline StackHandleScope<kNumReferences>::StackHandleScope(Thread* self, mirror::Object* fill_value)
+inline StackHandleScope<kNumReferences>::StackHandleScope(Thread* self,
+                                                          ObjPtr<mirror::Object> fill_value)
     : FixedSizeHandleScope<kNumReferences>(self->GetTopHandleScope(), fill_value),
       self_(self) {
   DCHECK_EQ(self, Thread::Current());
@@ -72,7 +74,7 @@
   return header_size + data_size;
 }
 
-inline mirror::Object* HandleScope::GetReference(size_t i) const {
+inline ObjPtr<mirror::Object> HandleScope::GetReference(size_t i) const {
   DCHECK_LT(i, NumberOfReferences());
   if (kDebugLocking) {
     Locks::mutator_lock_->AssertSharedHeld(Thread::Current());
@@ -90,7 +92,7 @@
   return MutableHandle<mirror::Object>(&GetReferences()[i]);
 }
 
-inline void HandleScope::SetReference(size_t i, mirror::Object* object) {
+inline void HandleScope::SetReference(size_t i, ObjPtr<mirror::Object> object) {
   if (kDebugLocking) {
     Locks::mutator_lock_->AssertSharedHeld(Thread::Current());
   }
@@ -118,16 +120,16 @@
 
 template<size_t kNumReferences> template<class T>
 inline MutableHandle<T> FixedSizeHandleScope<kNumReferences>::NewHandle(T* object) {
-  SetReference(pos_, object);
-  MutableHandle<T> h(GetHandle<T>(pos_));
-  pos_++;
-  return h;
+  return NewHandle(ObjPtr<T>(object));
 }
 
 template<size_t kNumReferences> template<class MirrorType>
 inline MutableHandle<MirrorType> FixedSizeHandleScope<kNumReferences>::NewHandle(
     ObjPtr<MirrorType> object) {
-  return NewHandle(object.Ptr());
+  SetReference(pos_, object);
+  MutableHandle<MirrorType> h(GetHandle<MirrorType>(pos_));
+  ++pos_;
+  return h;
 }
 
 template<size_t kNumReferences> template<class T>
@@ -142,7 +144,8 @@
 }
 
 template<size_t kNumReferences>
-inline void FixedSizeHandleScope<kNumReferences>::SetReference(size_t i, mirror::Object* object) {
+inline void FixedSizeHandleScope<kNumReferences>::SetReference(size_t i,
+                                                               ObjPtr<mirror::Object> object) {
   if (kDebugLocking) {
     Locks::mutator_lock_->AssertSharedHeld(Thread::Current());
   }
@@ -194,16 +197,16 @@
 }
 
 template<class T>
-MutableHandle<T> VariableSizedHandleScope::NewHandle(T* object) {
-  if (current_scope_->RemainingSlots() == 0) {
-    current_scope_ = new LocalScopeType(current_scope_);
-  }
-  return current_scope_->NewHandle(object);
+inline MutableHandle<T> VariableSizedHandleScope::NewHandle(T* object) {
+  return NewHandle(ObjPtr<T>(object));
 }
 
 template<class MirrorType>
 inline MutableHandle<MirrorType> VariableSizedHandleScope::NewHandle(ObjPtr<MirrorType> ptr) {
-  return NewHandle(ptr.Ptr());
+  if (current_scope_->RemainingSlots() == 0) {
+    current_scope_ = new LocalScopeType(current_scope_);
+  }
+  return current_scope_->NewHandle(ptr);
 }
 
 inline VariableSizedHandleScope::VariableSizedHandleScope(Thread* const self)