Add some debugging output for b/261719949.

Test: test.py
Bug: 261719949
Change-Id: Id3e2ee5b50dfb0e47203cea76d60835ca1cf3b35
diff --git a/runtime/interpreter/mterp/nterp.cc b/runtime/interpreter/mterp/nterp.cc
index 81e80ed..f46091b 100644
--- a/runtime/interpreter/mterp/nterp.cc
+++ b/runtime/interpreter/mterp/nterp.cc
@@ -29,6 +29,7 @@
 #include "interpreter/shadow_frame-inl.h"
 #include "mirror/string-alloc-inl.h"
 #include "nterp_helpers.h"
+#include "verify_object-inl.h"
 
 namespace art {
 namespace interpreter {
@@ -231,9 +232,39 @@
 
 static constexpr std::array<uint8_t, 256u> kOpcodeInvokeTypes = GenerateOpcodeInvokeTypes();
 
+// Temporary dumping output for helping diagnose b/261719949.
+static std::string DumpInformation(
+    Thread* self, ArtMethod* caller, const uint16_t* dex_pc_ptr) {
+  return android::base::StringPrintf(
+      "b/261719949: self=%p, caller=%p, dex_pc_ptr=%p", self, caller, dex_pc_ptr);
+}
+
+NO_INLINE static void CheckParameters(Thread* self, ArtMethod* caller, const uint16_t* dex_pc_ptr)
+    REQUIRES_SHARED(Locks::mutator_lock_) {
+  CHECK_EQ(self, Thread::Current()) << DumpInformation(self, caller, dex_pc_ptr);
+  // AOT compiler cross-compiles 64bits to 32bits, so for simplicity, don't
+  // check.
+  if (!Runtime::Current()->IsAotCompiler()) {
+    CHECK(IsAligned<sizeof(void*)>(caller)) << DumpInformation(self, caller, dex_pc_ptr);
+  }
+  ObjPtr<mirror::Class> cls = caller->GetDeclaringClass();
+  CHECK(IsAligned<kObjectAlignment>(cls.Ptr())) << DumpInformation(self, caller, dex_pc_ptr);
+  CHECK(VerifyClassClass(cls)) << DumpInformation(self, caller, dex_pc_ptr);
+  const DexFile& dex_file = cls->GetDexFile();
+  if (!caller->IsObsolete()) {
+    CHECK_LT(reinterpret_cast<uintptr_t>(dex_pc_ptr),
+             reinterpret_cast<uintptr_t>(dex_file.DataBegin() + dex_file.DataSize()))
+        << DumpInformation(self, caller, dex_pc_ptr);
+    CHECK_GT(reinterpret_cast<uintptr_t>(dex_pc_ptr),
+             reinterpret_cast<uintptr_t>(dex_file.DataBegin()))
+        << DumpInformation(self, caller, dex_pc_ptr);
+  }
+}
+
 FLATTEN
 extern "C" size_t NterpGetMethod(Thread* self, ArtMethod* caller, const uint16_t* dex_pc_ptr)
     REQUIRES_SHARED(Locks::mutator_lock_) {
+  CheckParameters(self, caller, dex_pc_ptr);
   UpdateHotness(caller);
   const Instruction* inst = Instruction::At(dex_pc_ptr);
   Instruction::Code opcode = inst->Opcode();
@@ -309,6 +340,7 @@
                                       const uint16_t* dex_pc_ptr,
                                       size_t resolve_field_type)  // Resolve if not zero
     REQUIRES_SHARED(Locks::mutator_lock_) {
+  CheckParameters(self, caller, dex_pc_ptr);
   UpdateHotness(caller);
   const Instruction* inst = Instruction::At(dex_pc_ptr);
   uint16_t field_index = inst->VRegB_21c();
@@ -364,6 +396,7 @@
                                                 const uint16_t* dex_pc_ptr,
                                                 size_t resolve_field_type)  // Resolve if not zero
     REQUIRES_SHARED(Locks::mutator_lock_) {
+  CheckParameters(self, caller, dex_pc_ptr);
   UpdateHotness(caller);
   const Instruction* inst = Instruction::At(dex_pc_ptr);
   uint16_t field_index = inst->VRegC_22c();
@@ -468,6 +501,7 @@
 
 extern "C" mirror::Object* NterpLoadObject(Thread* self, ArtMethod* caller, uint16_t* dex_pc_ptr)
     REQUIRES_SHARED(Locks::mutator_lock_) {
+  CheckParameters(self, caller, dex_pc_ptr);
   const Instruction* inst = Instruction::At(dex_pc_ptr);
   ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
   switch (inst->Opcode()) {