From 4cbfadc29b4ba89b32fa6eb55a287db78d12a45c Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Wed, 10 Oct 2018 16:09:43 +0100 Subject: 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 --- test/common/stack_inspect.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/common/stack_inspect.cc') diff --git a/test/common/stack_inspect.cc b/test/common/stack_inspect.cc index d74d2efa12..581aa74d4e 100644 --- a/test/common/stack_inspect.cc +++ b/test/common/stack_inspect.cc @@ -196,4 +196,24 @@ extern "C" JNIEXPORT void JNICALL Java_Main_assertCallerIsManaged(JNIEnv* env, j } } +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 context(art::Context::Create()); + GetCallingFrameVisitor visitor(soa.Self(), context.get()); + visitor.WalkStack(); + return soa.AddLocalReference(visitor.GetThisObject()); +} + } // namespace art -- cgit v1.2.3-59-g8ed1b