Partially ObjPtr<>-ify HandleScope.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing --interpreter
Bug: 31113334
Change-Id: I560683b5345bda9df4b22903d032b593d6c2dd4f
diff --git a/runtime/handle_scope-inl.h b/runtime/handle_scope-inl.h
index 765ed7d..6d8a05d 100644
--- a/runtime/handle_scope-inl.h
+++ b/runtime/handle_scope-inl.h
@@ -22,6 +22,7 @@
#include "base/mutex.h"
#include "handle.h"
#include "handle_wrapper.h"
+#include "mirror/object_reference-inl.h"
#include "obj_ptr-inl.h"
#include "thread-current-inl.h"
#include "verify_object.h"
@@ -30,7 +31,7 @@
template<size_t kNumReferences>
inline FixedSizeHandleScope<kNumReferences>::FixedSizeHandleScope(BaseHandleScope* link,
- mirror::Object* fill_value)
+ ObjPtr<mirror::Object> fill_value)
: HandleScope(link, kNumReferences) {
if (kDebugLocking) {
Locks::mutator_lock_->AssertSharedHeld(Thread::Current());
@@ -43,7 +44,8 @@
}
template<size_t kNumReferences>
-inline StackHandleScope<kNumReferences>::StackHandleScope(Thread* self, mirror::Object* fill_value)
+inline StackHandleScope<kNumReferences>::StackHandleScope(Thread* self,
+ ObjPtr<mirror::Object> fill_value)
: FixedSizeHandleScope<kNumReferences>(self->GetTopHandleScope(), fill_value),
self_(self) {
DCHECK_EQ(self, Thread::Current());
@@ -72,7 +74,7 @@
return header_size + data_size;
}
-inline mirror::Object* HandleScope::GetReference(size_t i) const {
+inline ObjPtr<mirror::Object> HandleScope::GetReference(size_t i) const {
DCHECK_LT(i, NumberOfReferences());
if (kDebugLocking) {
Locks::mutator_lock_->AssertSharedHeld(Thread::Current());
@@ -90,7 +92,7 @@
return MutableHandle<mirror::Object>(&GetReferences()[i]);
}
-inline void HandleScope::SetReference(size_t i, mirror::Object* object) {
+inline void HandleScope::SetReference(size_t i, ObjPtr<mirror::Object> object) {
if (kDebugLocking) {
Locks::mutator_lock_->AssertSharedHeld(Thread::Current());
}
@@ -118,16 +120,16 @@
template<size_t kNumReferences> template<class T>
inline MutableHandle<T> FixedSizeHandleScope<kNumReferences>::NewHandle(T* object) {
- SetReference(pos_, object);
- MutableHandle<T> h(GetHandle<T>(pos_));
- pos_++;
- return h;
+ return NewHandle(ObjPtr<T>(object));
}
template<size_t kNumReferences> template<class MirrorType>
inline MutableHandle<MirrorType> FixedSizeHandleScope<kNumReferences>::NewHandle(
ObjPtr<MirrorType> object) {
- return NewHandle(object.Ptr());
+ SetReference(pos_, object);
+ MutableHandle<MirrorType> h(GetHandle<MirrorType>(pos_));
+ ++pos_;
+ return h;
}
template<size_t kNumReferences> template<class T>
@@ -142,7 +144,8 @@
}
template<size_t kNumReferences>
-inline void FixedSizeHandleScope<kNumReferences>::SetReference(size_t i, mirror::Object* object) {
+inline void FixedSizeHandleScope<kNumReferences>::SetReference(size_t i,
+ ObjPtr<mirror::Object> object) {
if (kDebugLocking) {
Locks::mutator_lock_->AssertSharedHeld(Thread::Current());
}
@@ -194,16 +197,16 @@
}
template<class T>
-MutableHandle<T> VariableSizedHandleScope::NewHandle(T* object) {
- if (current_scope_->RemainingSlots() == 0) {
- current_scope_ = new LocalScopeType(current_scope_);
- }
- return current_scope_->NewHandle(object);
+inline MutableHandle<T> VariableSizedHandleScope::NewHandle(T* object) {
+ return NewHandle(ObjPtr<T>(object));
}
template<class MirrorType>
inline MutableHandle<MirrorType> VariableSizedHandleScope::NewHandle(ObjPtr<MirrorType> ptr) {
- return NewHandle(ptr.Ptr());
+ if (current_scope_->RemainingSlots() == 0) {
+ current_scope_ = new LocalScopeType(current_scope_);
+ }
+ return current_scope_->NewHandle(ptr);
}
inline VariableSizedHandleScope::VariableSizedHandleScope(Thread* const self)
diff --git a/runtime/handle_scope.h b/runtime/handle_scope.h
index 5a6f1ac..61f99b0 100644
--- a/runtime/handle_scope.h
+++ b/runtime/handle_scope.h
@@ -105,7 +105,7 @@
// Returns the size of a HandleScope containing num_references handles.
static size_t SizeOf(PointerSize pointer_size, uint32_t num_references);
- ALWAYS_INLINE mirror::Object* GetReference(size_t i) const
+ ALWAYS_INLINE ObjPtr<mirror::Object> GetReference(size_t i) const
REQUIRES_SHARED(Locks::mutator_lock_);
ALWAYS_INLINE Handle<mirror::Object> GetHandle(size_t i);
@@ -113,7 +113,7 @@
ALWAYS_INLINE MutableHandle<mirror::Object> GetMutableHandle(size_t i)
REQUIRES_SHARED(Locks::mutator_lock_);
- ALWAYS_INLINE void SetReference(size_t i, mirror::Object* object)
+ ALWAYS_INLINE void SetReference(size_t i, ObjPtr<mirror::Object> object)
REQUIRES_SHARED(Locks::mutator_lock_);
ALWAYS_INLINE bool Contains(StackReference<mirror::Object>* handle_scope_entry) const;
@@ -187,7 +187,7 @@
ALWAYS_INLINE MutableHandle<MirrorType> NewHandle(ObjPtr<MirrorType> object)
REQUIRES_SHARED(Locks::mutator_lock_);
- ALWAYS_INLINE void SetReference(size_t i, mirror::Object* object)
+ ALWAYS_INLINE void SetReference(size_t i, ObjPtr<mirror::Object> object)
REQUIRES_SHARED(Locks::mutator_lock_);
size_t RemainingSlots() const {
@@ -196,7 +196,7 @@
private:
explicit ALWAYS_INLINE FixedSizeHandleScope(BaseHandleScope* link,
- mirror::Object* fill_value = nullptr);
+ ObjPtr<mirror::Object> fill_value = nullptr);
ALWAYS_INLINE ~FixedSizeHandleScope() {}
template<class T>
@@ -219,7 +219,8 @@
template<size_t kNumReferences>
class PACKED(4) StackHandleScope final : public FixedSizeHandleScope<kNumReferences> {
public:
- explicit ALWAYS_INLINE StackHandleScope(Thread* self, mirror::Object* fill_value = nullptr);
+ explicit ALWAYS_INLINE StackHandleScope(Thread* self,
+ ObjPtr<mirror::Object> fill_value = nullptr);
ALWAYS_INLINE ~StackHandleScope();
Thread* Self() const {
diff --git a/runtime/instrumentation.cc b/runtime/instrumentation.cc
index 57f7948..984f947 100644
--- a/runtime/instrumentation.cc
+++ b/runtime/instrumentation.cc
@@ -288,7 +288,10 @@
}
if (GetCurrentQuickFrame() == nullptr) {
bool interpreter_frame = true;
- InstrumentationStackFrame instrumentation_frame(GetThisObject(), m, 0, GetFrameId(),
+ InstrumentationStackFrame instrumentation_frame(GetThisObject().Ptr(),
+ m,
+ /*return_pc=*/ 0,
+ GetFrameId(),
interpreter_frame);
if (kVerboseInstrumentation) {
LOG(INFO) << "Pushing shadow frame " << instrumentation_frame.Dump();
@@ -352,7 +355,7 @@
UNREACHABLE();
}
InstrumentationStackFrame instrumentation_frame(
- m->IsRuntimeMethod() ? nullptr : GetThisObject(),
+ m->IsRuntimeMethod() ? nullptr : GetThisObject().Ptr(),
m,
return_pc,
GetFrameId(), // A runtime method still gets a frame id.
diff --git a/runtime/stack.cc b/runtime/stack.cc
index 2ea3949..6466efd 100644
--- a/runtime/stack.cc
+++ b/runtime/stack.cc
@@ -112,7 +112,7 @@
extern "C" mirror::Object* artQuickGetProxyThisObject(ArtMethod** sp)
REQUIRES_SHARED(Locks::mutator_lock_);
-mirror::Object* StackVisitor::GetThisObject() const {
+ObjPtr<mirror::Object> StackVisitor::GetThisObject() const {
DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize);
ArtMethod* m = GetMethod();
if (m->IsStatic()) {
diff --git a/runtime/stack.h b/runtime/stack.h
index 4bc0fc8..ff80d13 100644
--- a/runtime/stack.h
+++ b/runtime/stack.h
@@ -194,7 +194,7 @@
uint32_t GetDexPc(bool abort_on_failure = true) const REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Object* GetThisObject() const REQUIRES_SHARED(Locks::mutator_lock_);
+ ObjPtr<mirror::Object> GetThisObject() const REQUIRES_SHARED(Locks::mutator_lock_);
size_t GetNativePcOffset() const REQUIRES_SHARED(Locks::mutator_lock_);