Use ArtMethod::GetDex{File,Cache}() more.

Do not go through the declaring class when it can cause
a DexFile or DexCache mismatch for obsolete methods.

Also fix similar potential mismatch in hiddenapi.

This is a follow-up to
    https://android-review.googlesource.com/834082 ,
    https://android-review.googlesource.com/836008 .

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 119830111
Change-Id: I3fdf1aa1bc7bab816d5d8034b107506a32438b77
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index abfdd55..882291f 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -70,7 +70,7 @@
   } else {
     ObjPtr<mirror::Class> declaring_class = GetDeclaringClass();
     DCHECK(declaring_class->IsInterface());
-    ArtMethod* ret = declaring_class->FindInterfaceMethod(declaring_class->GetDexCache(),
+    ArtMethod* ret = declaring_class->FindInterfaceMethod(GetDexCache(),
                                                           GetDexMethodIndex(),
                                                           pointer_size);
     DCHECK(ret != nullptr);
@@ -79,10 +79,11 @@
 }
 
 ArtMethod* ArtMethod::GetNonObsoleteMethod() {
-  DCHECK_EQ(kRuntimePointerSize, Runtime::Current()->GetClassLinker()->GetImagePointerSize());
   if (LIKELY(!IsObsolete())) {
     return this;
-  } else if (IsDirect()) {
+  }
+  DCHECK_EQ(kRuntimePointerSize, Runtime::Current()->GetClassLinker()->GetImagePointerSize());
+  if (IsDirect()) {
     return &GetDeclaringClass()->GetDirectMethodsSlice(kRuntimePointerSize)[GetMethodIndex()];
   } else {
     return GetDeclaringClass()->GetVTableEntry(GetMethodIndex(), kRuntimePointerSize);
@@ -504,10 +505,10 @@
                          << method->PrettyMethod();
   }
   DCHECK_EQ(oat_method_index,
-            GetOatMethodIndexFromMethodIndex(*declaring_class->GetDexCache()->GetDexFile(),
+            GetOatMethodIndexFromMethodIndex(declaring_class->GetDexFile(),
                                              method->GetDeclaringClass()->GetDexClassDefIndex(),
                                              method->GetDexMethodIndex()));
-  OatFile::OatClass oat_class = OatFile::FindOatClass(*declaring_class->GetDexCache()->GetDexFile(),
+  OatFile::OatClass oat_class = OatFile::FindOatClass(declaring_class->GetDexFile(),
                                                       declaring_class->GetDexClassDefIndex(),
                                                       found);
   if (!(*found)) {
@@ -543,7 +544,7 @@
 }
 
 ArrayRef<const uint8_t> ArtMethod::GetQuickenedInfo() {
-  const DexFile& dex_file = GetDeclaringClass()->GetDexFile();
+  const DexFile& dex_file = *GetDexFile();
   const OatDexFile* oat_dex_file = dex_file.GetOatDexFile();
   if (oat_dex_file == nullptr || (oat_dex_file->GetOatFile() == nullptr)) {
     return ArrayRef<const uint8_t>();