Use ArtMethod::GetDexFile() instead of using declaring class.

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

Test: m test-art-host-gtest
Test: testrunner.py --host
Bug: 119830111
Change-Id: I5bd55b0293ef176385a7e9d8b296be6b470cfcc4
diff --git a/runtime/common_throws.cc b/runtime/common_throws.cc
index 7a08cb3..0dc0723 100644
--- a/runtime/common_throws.cc
+++ b/runtime/common_throws.cc
@@ -436,20 +436,15 @@
   ThrowException("Ljava/lang/NullPointerException;", nullptr, msg.str().c_str());
 }
 
-void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx,
-                                              InvokeType type) {
-  ObjPtr<mirror::DexCache> dex_cache =
-      Thread::Current()->GetCurrentMethod(nullptr)->GetDeclaringClass()->GetDexCache();
-  const DexFile& dex_file = *dex_cache->GetDexFile();
+void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx, InvokeType type) {
+  const DexFile& dex_file = *Thread::Current()->GetCurrentMethod(nullptr)->GetDexFile();
   ThrowNullPointerExceptionForMethodAccessImpl(method_idx, dex_file, type);
 }
 
-void ThrowNullPointerExceptionForMethodAccess(ArtMethod* method,
-                                              InvokeType type) {
-  ObjPtr<mirror::DexCache> dex_cache = method->GetDeclaringClass()->GetDexCache();
-  const DexFile& dex_file = *dex_cache->GetDexFile();
+void ThrowNullPointerExceptionForMethodAccess(ArtMethod* method, InvokeType type) {
   ThrowNullPointerExceptionForMethodAccessImpl(method->GetDexMethodIndex(),
-                                               dex_file, type);
+                                               *method->GetDexFile(),
+                                               type);
 }
 
 static bool IsValidReadBarrierImplicitCheck(uintptr_t addr) {
@@ -577,7 +572,7 @@
   CHECK_LT(throw_dex_pc, accessor.InsnsSizeInCodeUnits());
   const Instruction& instr = accessor.InstructionAt(throw_dex_pc);
   if (check_address && !IsValidImplicitCheck(addr, instr)) {
-    const DexFile* dex_file = method->GetDeclaringClass()->GetDexCache()->GetDexFile();
+    const DexFile* dex_file = method->GetDexFile();
     LOG(FATAL) << "Invalid address for an implicit NullPointerException check: "
                << "0x" << std::hex << addr << std::dec
                << ", at "
@@ -717,8 +712,7 @@
       break;
     }
     default: {
-      const DexFile* dex_file =
-          method->GetDeclaringClass()->GetDexCache()->GetDexFile();
+      const DexFile* dex_file = method->GetDexFile();
       LOG(FATAL) << "NullPointerException at an unexpected instruction: "
                  << instr.DumpString(dex_file)
                  << " in "
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index 1472490..c7fa109 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -2515,7 +2515,7 @@
   ArtMethod* caller_method = QuickArgumentVisitor::GetCallingMethod(sp);
   ArtMethod* method = FindMethodFast<type, access_check>(method_idx, this_object, caller_method);
   if (UNLIKELY(method == nullptr)) {
-    const DexFile* dex_file = caller_method->GetDeclaringClass()->GetDexCache()->GetDexFile();
+    const DexFile* dex_file = caller_method->GetDexFile();
     uint32_t shorty_len;
     const char* shorty = dex_file->GetMethodShorty(dex_file->GetMethodId(method_idx), &shorty_len);
     {
@@ -2648,7 +2648,7 @@
       dex_method_idx = instr.VRegB_3rc();
     }
 
-    const DexFile& dex_file = caller_method->GetDeclaringClass()->GetDexFile();
+    const DexFile& dex_file = *caller_method->GetDexFile();
     uint32_t shorty_len;
     const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(dex_method_idx),
                                                   &shorty_len);