Remove CHECK that GetThis() must always work.

Ensures GetVReg of a reference on compiled code checks that the
value is indeed a reference from the stack maps.

bug: 116683601
bug: 117452149
Test: 686-get-this
Change-Id: I3a370c45786a4892c7888491bec6d5ae64672f6c
diff --git a/test/common/stack_inspect.cc b/test/common/stack_inspect.cc
index d74d2ef..581aa74 100644
--- a/test/common/stack_inspect.cc
+++ b/test/common/stack_inspect.cc
@@ -196,4 +196,24 @@
   }
 }
 
+struct GetCallingFrameVisitor : public StackVisitor {
+  GetCallingFrameVisitor(Thread* thread, Context* context)
+      REQUIRES_SHARED(Locks::mutator_lock_)
+      : StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {}
+
+  bool VisitFrame() override NO_THREAD_SAFETY_ANALYSIS {
+    // Discard stubs and Main.getThisOfCaller.
+    return GetMethod() == nullptr || GetMethod()->IsNative();
+  }
+};
+
+extern "C" JNIEXPORT jobject JNICALL Java_Main_getThisOfCaller(
+    JNIEnv* env, jclass cls ATTRIBUTE_UNUSED) {
+  ScopedObjectAccess soa(env);
+  std::unique_ptr<art::Context> context(art::Context::Create());
+  GetCallingFrameVisitor visitor(soa.Self(), context.get());
+  visitor.WalkStack();
+  return soa.AddLocalReference<jobject>(visitor.GetThisObject());
+}
+
 }  // namespace art