diff options
| author | 2018-10-10 16:09:43 +0100 | |
|---|---|---|
| committer | 2018-10-12 10:07:41 +0100 | |
| commit | 4cbfadc29b4ba89b32fa6eb55a287db78d12a45c (patch) | |
| tree | 70cd681c4326ab8cf034da6c0fb0fef222cd67b1 /test/common/stack_inspect.cc | |
| parent | a48eb7e0690187618d2824a7d9b5601e7f5cdf80 (diff) | |
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
Diffstat (limited to 'test/common/stack_inspect.cc')
| -rw-r--r-- | test/common/stack_inspect.cc | 20 |
1 files changed, 20 insertions, 0 deletions
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<art::Context> context(art::Context::Create()); + GetCallingFrameVisitor visitor(soa.Self(), context.get()); + visitor.WalkStack(); + return soa.AddLocalReference<jobject>(visitor.GetThisObject()); +} + } // namespace art |