ObjPtr<>-ify mirror::IfTable.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 31113334
Change-Id: I77d36cc96f48ff92c1ca3b2581be7637a2ea22d7
diff --git a/runtime/cha.cc b/runtime/cha.cc
index 68e7477..a142723 100644
--- a/runtime/cha.cc
+++ b/runtime/cha.cc
@@ -608,10 +608,10 @@
     ObjPtr<mirror::IfTable> iftable = klass->GetIfTable();
     const size_t ifcount = klass->GetIfTableCount();
     for (size_t i = 0; i < ifcount; ++i) {
-      mirror::Class* interface = iftable->GetInterface(i);
+      ObjPtr<mirror::Class> interface = iftable->GetInterface(i);
       for (size_t j = 0, count = iftable->GetMethodArrayCount(i); j < count; ++j) {
         ArtMethod* interface_method = interface->GetVirtualMethod(j, image_pointer_size);
-        mirror::PointerArray* method_array = iftable->GetMethodArray(i);
+        ObjPtr<mirror::PointerArray> method_array = iftable->GetMethodArray(i);
         ArtMethod* implementation_method =
             method_array->GetElementPtrSize<ArtMethod*>(j, image_pointer_size);
         DCHECK(implementation_method != nullptr) << klass->PrettyClass();
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 58ac995..16f6383 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -6766,7 +6766,7 @@
     if (method_array_count == 0) {
       continue;
     }
-    auto* method_array = if_table->GetMethodArray(i);
+    ObjPtr<mirror::PointerArray> method_array = if_table->GetMethodArray(i);
     for (size_t j = 0; j < method_array_count; ++j) {
       ArtMethod* implementation_method =
           method_array->GetElementPtrSize<ArtMethod*>(j, image_pointer_size_);
@@ -6824,7 +6824,7 @@
       if (method_array_count == 0) {
         continue;
       }
-      auto* method_array = if_table->GetMethodArray(i);
+      ObjPtr<mirror::PointerArray> method_array = if_table->GetMethodArray(i);
       for (size_t j = 0; j < method_array_count; ++j) {
         ArtMethod* implementation_method =
             method_array->GetElementPtrSize<ArtMethod*>(j, image_pointer_size_);
@@ -7784,8 +7784,8 @@
   // Go fix up all the stale iftable pointers.
   for (size_t i = 0; i < ifcount; ++i) {
     for (size_t j = 0, count = iftable->GetMethodArrayCount(i); j < count; ++j) {
-      auto* method_array = iftable->GetMethodArray(i);
-      auto* m = method_array->GetElementPtrSize<ArtMethod*>(j, pointer_size);
+      ObjPtr<mirror::PointerArray> method_array = iftable->GetMethodArray(i);
+      ArtMethod* m = method_array->GetElementPtrSize<ArtMethod*>(j, pointer_size);
       DCHECK(m != nullptr) << klass_->PrettyClass();
       auto it = move_table_.find(m);
       if (it != move_table_.end()) {
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index b4269d3..9b5b73c 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -1228,12 +1228,13 @@
               // below.
               int32_t ifcount = klass->GetIfTableCount<kVerifyNone>();
               for (int32_t i = 0; i != ifcount; ++i) {
-                mirror::PointerArray* unpatched_ifarray =
+                ObjPtr<mirror::PointerArray> unpatched_ifarray =
                     iftable->GetMethodArrayOrNull<kVerifyNone, kWithoutReadBarrier>(i);
                 if (unpatched_ifarray != nullptr) {
                   // The iftable has not been patched, so we need to explicitly adjust the pointer.
-                  mirror::PointerArray* ifarray = forward_object(unpatched_ifarray);
-                  if (app_image_objects.InDest(ifarray) && !visited_bitmap->Set(ifarray)) {
+                  ObjPtr<mirror::PointerArray> ifarray = forward_object(unpatched_ifarray.Ptr());
+                  if (app_image_objects.InDest(ifarray.Ptr()) &&
+                      !visited_bitmap->Set(ifarray.Ptr())) {
                     patch_object_visitor.VisitPointerArray(ifarray);
                   }
                 }
diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h
index 57e8e8d..fe67a5b 100644
--- a/runtime/mirror/class-inl.h
+++ b/runtime/mirror/class-inl.h
@@ -31,7 +31,7 @@
 #include "dex/dex_file-inl.h"
 #include "dex/invoke_type.h"
 #include "dex_cache.h"
-#include "iftable.h"
+#include "iftable-inl.h"
 #include "imtable.h"
 #include "object-inl.h"
 #include "object_array.h"
diff --git a/runtime/mirror/iftable-inl.h b/runtime/mirror/iftable-inl.h
index d6191c2..225a36d 100644
--- a/runtime/mirror/iftable-inl.h
+++ b/runtime/mirror/iftable-inl.h
@@ -19,10 +19,20 @@
 
 #include "iftable.h"
 #include "obj_ptr-inl.h"
+#include "object_array-inl.h"
 
 namespace art {
 namespace mirror {
 
+template<VerifyObjectFlags kVerifyFlags,
+         ReadBarrierOption kReadBarrierOption>
+inline ObjPtr<Class> IfTable::GetInterface(int32_t i) {
+  Class* interface =
+      GetWithoutChecks<kVerifyFlags, kReadBarrierOption>((i * kMax) + kInterface)->AsClass();
+  DCHECK(interface != nullptr);
+  return interface;
+}
+
 inline void IfTable::SetInterface(int32_t i, ObjPtr<Class> interface) {
   DCHECK(interface != nullptr);
   DCHECK(interface->IsInterface());
@@ -31,6 +41,28 @@
   SetWithoutChecks<false>(idx, interface);
 }
 
+template<VerifyObjectFlags kVerifyFlags,
+         ReadBarrierOption kReadBarrierOption>
+inline ObjPtr<PointerArray> IfTable::GetMethodArrayOrNull(int32_t i) {
+  return down_cast<PointerArray*>(
+      Get<kVerifyFlags, kReadBarrierOption>((i * kMax) + kMethodArray));
+}
+
+template<VerifyObjectFlags kVerifyFlags,
+         ReadBarrierOption kReadBarrierOption>
+inline ObjPtr<PointerArray> IfTable::GetMethodArray(int32_t i) {
+  ObjPtr<PointerArray> method_array = GetMethodArrayOrNull<kVerifyFlags, kReadBarrierOption>(i);
+  DCHECK(method_array != nullptr);
+  return method_array;
+}
+
+template<VerifyObjectFlags kVerifyFlags,
+         ReadBarrierOption kReadBarrierOption>
+inline size_t IfTable::GetMethodArrayCount(int32_t i) {
+  ObjPtr<PointerArray> method_array = GetMethodArrayOrNull<kVerifyFlags, kReadBarrierOption>(i);
+  return method_array == nullptr ? 0u : method_array->GetLength<kVerifyFlags>();
+}
+
 inline void IfTable::SetMethodArray(int32_t i, ObjPtr<PointerArray> arr) {
   DCHECK(arr != nullptr);
   auto idx = i * kMax + kMethodArray;
diff --git a/runtime/mirror/iftable.h b/runtime/mirror/iftable.h
index 3d4c5a7..7391e07 100644
--- a/runtime/mirror/iftable.h
+++ b/runtime/mirror/iftable.h
@@ -27,37 +27,22 @@
  public:
   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
-  ALWAYS_INLINE Class* GetInterface(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_) {
-    Class* interface =
-        GetWithoutChecks<kVerifyFlags, kReadBarrierOption>((i * kMax) + kInterface)->AsClass();
-    DCHECK(interface != nullptr);
-    return interface;
-  }
+  ALWAYS_INLINE ObjPtr<Class> GetInterface(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_);
 
   ALWAYS_INLINE void SetInterface(int32_t i, ObjPtr<Class> interface)
       REQUIRES_SHARED(Locks::mutator_lock_);
 
   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
-  PointerArray* GetMethodArrayOrNull(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_) {
-    return down_cast<PointerArray*>(
-        Get<kVerifyFlags, kReadBarrierOption>((i * kMax) + kMethodArray));
-  }
+  ObjPtr<PointerArray> GetMethodArrayOrNull(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_);
 
   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
-  PointerArray* GetMethodArray(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_) {
-    PointerArray* method_array = GetMethodArrayOrNull<kVerifyFlags, kReadBarrierOption>(i);
-    DCHECK(method_array != nullptr);
-    return method_array;
-  }
+  ObjPtr<PointerArray> GetMethodArray(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_);
 
   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
-  size_t GetMethodArrayCount(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_) {
-    PointerArray* method_array = GetMethodArrayOrNull<kVerifyFlags, kReadBarrierOption>(i);
-    return method_array == nullptr ? 0u : method_array->GetLength<kVerifyFlags>();
-  }
+  size_t GetMethodArrayCount(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_);
 
   void SetMethodArray(int32_t i, ObjPtr<PointerArray> arr) REQUIRES_SHARED(Locks::mutator_lock_);
 
diff --git a/runtime/mirror/object_array-inl.h b/runtime/mirror/object_array-inl.h
index 054a2bb..d318887 100644
--- a/runtime/mirror/object_array-inl.h
+++ b/runtime/mirror/object_array-inl.h
@@ -27,6 +27,7 @@
 #include "class.h"
 #include "obj_ptr-inl.h"
 #include "object-inl.h"
+#include "read_barrier-inl.h"
 #include "runtime.h"
 #include "thread-current-inl.h"
 #include "write_barrier-inl.h"