summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Andreas Gampe <agampe@google.com> 2017-10-11 21:52:42 -0700
committer Andreas Gampe <agampe@google.com> 2017-10-12 08:09:37 -0700
commit81e893809d51c3d784d295604c2963997235f2ed (patch)
treea4f3e3938171e16c62e20c3bb952d0dc7c2afec0
parent6783118d2ad9d759f0617b1219a9e29a10a569f7 (diff)
ART: Change ObjPtr validation
Do not validate for copy constructor and assignment. This is the majority of overhead in practice. Invalid ObjPtrs will still be detected when they are used. Bug: 35644369 Test: m test-art-host Change-Id: I74378afdf69164046d854a0804465b83592f0873
-rw-r--r--runtime/obj_ptr.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/runtime/obj_ptr.h b/runtime/obj_ptr.h
index 416287370e..9a66983de7 100644
--- a/runtime/obj_ptr.h
+++ b/runtime/obj_ptr.h
@@ -28,6 +28,10 @@ namespace art {
constexpr bool kObjPtrPoisoning = kIsDebugBuild;
+// It turns out that most of the performance overhead comes from copying. Don't validate for now.
+// This defers finding stale ObjPtr objects until they are used.
+constexpr bool kObjPtrPoisoningValidateOnCopy = false;
+
// Value type representing a pointer to a mirror::Object of type MirrorType
// Since the cookie is thread based, it is not safe to share an ObjPtr between threads.
template<class MirrorType>
@@ -63,14 +67,18 @@ class ObjPtr {
typename = typename std::enable_if<std::is_base_of<MirrorType, Type>::value>::type>
ALWAYS_INLINE ObjPtr(const ObjPtr<Type>& other) // NOLINT
REQUIRES_SHARED(Locks::mutator_lock_)
- : reference_(Encode(static_cast<MirrorType*>(other.Ptr()))) {
+ : reference_(kObjPtrPoisoningValidateOnCopy
+ ? Encode(static_cast<MirrorType*>(other.Ptr()))
+ : other.reference_) {
}
template <typename Type,
typename = typename std::enable_if<std::is_base_of<MirrorType, Type>::value>::type>
ALWAYS_INLINE ObjPtr& operator=(const ObjPtr<Type>& other)
REQUIRES_SHARED(Locks::mutator_lock_) {
- reference_ = Encode(static_cast<MirrorType*>(other.Ptr()));
+ reference_ = kObjPtrPoisoningValidateOnCopy
+ ? Encode(static_cast<MirrorType*>(other.Ptr()))
+ : other.reference_;
return *this;
}
@@ -160,6 +168,8 @@ class ObjPtr {
ALWAYS_INLINE static uintptr_t Encode(MirrorType* ptr) REQUIRES_SHARED(Locks::mutator_lock_);
// The encoded reference and cookie.
uintptr_t reference_;
+
+ template <class T> friend class ObjPtr; // Required for reference_ access in copy cons/operator.
};
static_assert(std::is_trivially_copyable<ObjPtr<void>>::value,