summaryrefslogtreecommitdiff
path: root/runtime/obj_ptr-inl.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/obj_ptr-inl.h')
-rw-r--r--runtime/obj_ptr-inl.h17
1 files changed, 12 insertions, 5 deletions
diff --git a/runtime/obj_ptr-inl.h b/runtime/obj_ptr-inl.h
index f1e3b5053b..b949c96dd2 100644
--- a/runtime/obj_ptr-inl.h
+++ b/runtime/obj_ptr-inl.h
@@ -24,18 +24,27 @@
namespace art {
template<class MirrorType>
+inline uintptr_t ObjPtr<MirrorType>::GetCurrentTrimedCookie() {
+ Thread* self = Thread::Current();
+ if (UNLIKELY(self == nullptr)) {
+ return kCookieMask;
+ }
+ return self->GetPoisonObjectCookie() & kCookieMask;
+}
+
+template<class MirrorType>
inline bool ObjPtr<MirrorType>::IsValid() const {
if (!kObjPtrPoisoning || IsNull()) {
return true;
}
- return GetCookie() == TrimCookie(Thread::Current()->GetPoisonObjectCookie());
+ return GetCookie() == GetCurrentTrimedCookie();
}
template<class MirrorType>
inline void ObjPtr<MirrorType>::AssertValid() const {
if (kObjPtrPoisoning) {
CHECK(IsValid()) << "Stale object pointer " << PtrUnchecked() << " , expected cookie "
- << TrimCookie(Thread::Current()->GetPoisonObjectCookie()) << " but got " << GetCookie();
+ << GetCurrentTrimedCookie() << " but got " << GetCookie();
}
}
@@ -47,9 +56,7 @@ inline uintptr_t ObjPtr<MirrorType>::Encode(MirrorType* ptr) {
DCHECK_LE(ref, 0xFFFFFFFFU);
ref >>= kObjectAlignmentShift;
// Put cookie in high bits.
- Thread* self = Thread::Current();
- DCHECK(self != nullptr);
- ref |= self->GetPoisonObjectCookie() << kCookieShift;
+ ref |= GetCurrentTrimedCookie() << kCookieShift;
}
return ref;
}