Use more ArrayRefs in quicken infos

Use ArrayRef to get bound checks for debug builds.

Bug: 72608794
Bug: 63756964
Test: test-art-host-gtest

Change-Id: Ie423c969730c13b0cd936a64cbc7be07a716aa65
diff --git a/runtime/base/array_ref.h b/runtime/base/array_ref.h
index ef86512..2753c81 100644
--- a/runtime/base/array_ref.h
+++ b/runtime/base/array_ref.h
@@ -106,6 +106,12 @@
     return *this = ArrayRef(other);
   }
 
+  template <typename U>
+  static ArrayRef Cast(const ArrayRef<U>& src) {
+    return ArrayRef(reinterpret_cast<const T*>(src.data()),
+                    src.size() * sizeof(T) / sizeof(U));
+  }
+
   // Destructor.
   ~ArrayRef() = default;
 
diff --git a/runtime/quicken_info.h b/runtime/quicken_info.h
index 52eca61..32f7005 100644
--- a/runtime/quicken_info.h
+++ b/runtime/quicken_info.h
@@ -50,16 +50,17 @@
     return index % kElementsPerIndex == 0;
   }
 
-  explicit QuickenInfoOffsetTableAccessor(const uint8_t* data, uint32_t max_index)
-      : table_(reinterpret_cast<const uint32_t*>(data)),
-        num_indices_(RoundUp(max_index, kElementsPerIndex) / kElementsPerIndex) {}
+  QuickenInfoOffsetTableAccessor(const ArrayRef<const uint8_t>& data, uint32_t max_index)
+      : table_(ArrayRef<const TableType>::Cast(data).SubArray(
+          0,
+          RoundUp(max_index, kElementsPerIndex) / kElementsPerIndex)) {}
 
   size_t SizeInBytes() const {
     return NumIndices() * sizeof(table_[0]);
   }
 
   uint32_t NumIndices() const {
-    return num_indices_;
+    return table_.size();
   }
 
   // Returns the offset for the index at or before the desired index. If the offset is for an index
@@ -69,17 +70,12 @@
     return table_[index / kElementsPerIndex];
   }
 
-  const uint8_t* DataEnd() const {
-    return reinterpret_cast<const uint8_t*>(table_ + NumIndices());
-  }
-
   static uint32_t Alignment() {
     return alignof(TableType);
   }
 
  private:
-  const TableType* table_;
-  uint32_t num_indices_;
+  const ArrayRef<const TableType> table_;
 };
 
 // QuickenInfoTable is a table of 16 bit dex indices. There is one slot for every instruction that
diff --git a/runtime/vdex_file.cc b/runtime/vdex_file.cc
index 7428e98..0829c54 100644
--- a/runtime/vdex_file.cc
+++ b/runtime/vdex_file.cc
@@ -228,8 +228,7 @@
     const ArrayRef<const uint8_t>& quickening_info) const {
   // The offset a is in preheader right before the dex file.
   const uint32_t offset = GetQuickeningInfoTableOffset(source_dex_begin);
-  const uint8_t* data_ptr = quickening_info.data() + offset;
-  return QuickenInfoOffsetTableAccessor(data_ptr, num_method_ids);
+  return QuickenInfoOffsetTableAccessor(quickening_info.SubArray(offset), num_method_ids);
 }
 
 QuickenInfoOffsetTableAccessor VdexFile::GetQuickenInfoOffsetTable(