Use correct handle scope offset from StackVisitor
Incorrect offset resulted in bad GC roots due to invalid
Stack::GetThisObject for native methods.
Bug: 19070497
Bug: 18785293
(cherry picked from commit e4b7c892c4f40e76c172a77069afde3fe5ce87da)
Change-Id: I10e144cffac00978e3c84d43a30caccd61559b27
diff --git a/runtime/mirror/art_method.h b/runtime/mirror/art_method.h
index 7066cf6..2e26d9c 100644
--- a/runtime/mirror/art_method.h
+++ b/runtime/mirror/art_method.h
@@ -25,6 +25,7 @@
#include "object_callbacks.h"
#include "quick/quick_method_frame_info.h"
#include "read_barrier_option.h"
+#include "stack.h"
namespace art {
@@ -407,8 +408,10 @@
return frame_size_in_bytes - kPointerSize;
}
- size_t GetHandleScopeOffsetInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- return kPointerSize;
+ FrameOffset GetHandleScopeOffsetInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+ constexpr size_t handle_scope_offset = sizeof(StackReference<mirror::ArtMethod>);
+ DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes());
+ return FrameOffset(handle_scope_offset);
}
void RegisterNative(Thread* self, const void* native_method, bool is_fast)
diff --git a/runtime/stack.cc b/runtime/stack.cc
index f0b6c21..7dd4f08 100644
--- a/runtime/stack.cc
+++ b/runtime/stack.cc
@@ -122,7 +122,7 @@
} else if (m->IsNative()) {
if (cur_quick_frame_ != NULL) {
HandleScope* hs = reinterpret_cast<HandleScope*>(
- reinterpret_cast<char*>(cur_quick_frame_) + m->GetHandleScopeOffsetInBytes());
+ reinterpret_cast<char*>(cur_quick_frame_) + m->GetHandleScopeOffsetInBytes().SizeValue());
return hs->GetReference(0);
} else {
return cur_shadow_frame_->GetVRegReference(0);