diff options
author | 2016-09-27 18:43:30 -0700 | |
---|---|---|
committer | 2016-09-29 17:31:09 -0700 | |
commit | 0795f23920ee9aabf28e45c63cd592dcccf00216 (patch) | |
tree | ff3f880c5e84f3316532b47d0e9a7729ade848ac /runtime/obj_ptr.h | |
parent | d1224dce59eb0019507e41da5e10f12dda66bee4 (diff) |
Clean up ScopedThreadStateChange to use ObjPtr
Also fixed inclusion of -inl.h files in .h files by adding
scoped_object_access-inl.h and scoped_fast_natvie_object_access-inl.h
Changed AddLocalReference / Decode to use ObjPtr.
Changed libartbenchmark to be debug to avoid linkage errors.
Bug: 31113334
Test: test-art-host
Change-Id: I4d2e160483a29d21e1e0e440585ed328b9811483
Diffstat (limited to 'runtime/obj_ptr.h')
-rw-r--r-- | runtime/obj_ptr.h | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/runtime/obj_ptr.h b/runtime/obj_ptr.h index d4076beb3c..d5ac33d8b3 100644 --- a/runtime/obj_ptr.h +++ b/runtime/obj_ptr.h @@ -17,6 +17,8 @@ #ifndef ART_RUNTIME_OBJ_PTR_H_ #define ART_RUNTIME_OBJ_PTR_H_ +#include <ostream> + #include "base/mutex.h" // For Locks::mutator_lock_. #include "globals.h" #include "mirror/object_reference.h" @@ -45,10 +47,13 @@ class ObjPtr { ALWAYS_INLINE ObjPtr(Type* ptr) REQUIRES_SHARED(Locks::mutator_lock_) : reference_(Encode(static_cast<MirrorType*>(ptr))) {} - ALWAYS_INLINE ObjPtr(const ObjPtr& other) REQUIRES_SHARED(Locks::mutator_lock_) = default; + template <typename Type> + ALWAYS_INLINE ObjPtr(const ObjPtr<Type>& other) REQUIRES_SHARED(Locks::mutator_lock_) + : reference_(Encode(static_cast<MirrorType*>(other.Decode()))) {} + template <typename Type> ALWAYS_INLINE ObjPtr& operator=(const ObjPtr& other) { - reference_ = other.reference_; + reference_ = Encode(static_cast<MirrorType*>(other.Decode())); return *this; } @@ -65,7 +70,6 @@ class ObjPtr { return Decode(); } - ALWAYS_INLINE bool IsNull() const { return reference_ == 0; } @@ -104,6 +108,16 @@ class ObjPtr { return !IsNull(); } + // Decode unchecked does not check that object pointer is valid. Do not use if you can avoid it. + ALWAYS_INLINE MirrorType* DecodeUnchecked() const REQUIRES_SHARED(Locks::mutator_lock_) { + if (kPoison) { + return reinterpret_cast<MirrorType*>( + static_cast<uintptr_t>(static_cast<uint32_t>(reference_ << kObjectAlignmentShift))); + } else { + return reinterpret_cast<MirrorType*>(reference_); + } + } + private: // Trim off high bits of thread local cookie. ALWAYS_INLINE static uintptr_t TrimCookie(uintptr_t cookie) { @@ -114,16 +128,6 @@ class ObjPtr { return reference_ >> kCookieShift; } - // Decode makes sure that the object pointer is valid. - ALWAYS_INLINE MirrorType* DecodeUnchecked() const REQUIRES_SHARED(Locks::mutator_lock_) { - if (kPoison) { - return reinterpret_cast<MirrorType*>( - static_cast<uintptr_t>(static_cast<uint32_t>(reference_ << kObjectAlignmentShift))); - } else { - return reinterpret_cast<MirrorType*>(reference_); - } - } - ALWAYS_INLINE static uintptr_t Encode(MirrorType* ptr) REQUIRES_SHARED(Locks::mutator_lock_); // The encoded reference and cookie. uintptr_t reference_; @@ -134,6 +138,10 @@ static inline ObjPtr<MirrorType, kPoison> MakeObjPtr(MirrorType* ptr) { return ObjPtr<MirrorType, kPoison>(ptr); } +template<class MirrorType, bool kPoison> +ALWAYS_INLINE std::ostream& operator<<(std::ostream& os, ObjPtr<MirrorType, kPoison> ptr) + REQUIRES_SHARED(Locks::mutator_lock_); + } // namespace art #endif // ART_RUNTIME_OBJ_PTR_H_ |