#include"base/locks.h"// For Locks::mutator_lock_. #include"base/macros.h" #include"runtime_globals.h"
// Always inline ObjPtr methods even in debug builds. #define OBJPTR_INLINE __attribute__ ((always_inline))
namespace art HIDDEN {
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> class ObjPtr { static constexpr size_t kCookieShift =
kHeapReferenceSize * kBitsPerByte - kObjectAlignmentShift; static constexpr size_t kCookieBits = sizeof(uintptr_t) * kBitsPerByte - kCookieShift; static constexpr uintptr_t kCookieMask = (static_cast<uintptr_t>(1u) << kCookieBits) - 1;
static_assert(kCookieBits >= kObjectAlignmentShift, "must have a least kObjectAlignmentShift bits");
// Note: The following constructors allow implicit conversion. This simplifies code that uses // them, e.g., for parameter passing. However, in general, implicit-conversion constructors // are discouraged and detected by clang-tidy.
// Ptr unchecked does not check that object pointer is valid. Do not use if you can avoid it.
OBJPTR_INLINE MirrorType* PtrUnchecked() const { if (kObjPtrPoisoning) { returnreinterpret_cast<MirrorType*>( static_cast<uintptr_t>(static_cast<uint32_t>(reference_ << kObjectAlignmentShift)));
} else { returnreinterpret_cast<MirrorType*>(reference_);
}
}
// Static function to be friendly with null pointers. template <typename SourceType> static ObjPtr<MirrorType> DownCast(ObjPtr<SourceType> ptr) REQUIRES_SHARED(Locks::mutator_lock_);
// Static function to be friendly with null pointers. template <typename SourceType> static ObjPtr<MirrorType> DownCast(SourceType* ptr) REQUIRES_SHARED(Locks::mutator_lock_);
private: // Trim off high bits of thread local cookie.
OBJPTR_INLINE static uintptr_t GetCurrentTrimedCookie();
OBJPTR_INLINE static uintptr_t Encode(MirrorType* ptr) REQUIRES_SHARED(Locks::mutator_lock_); // The encoded reference and cookie.
uintptr_t reference_;
template <class T> friendclass ObjPtr; // Required for reference_ access in copy cons/operator.
};
static_assert(std::is_trivially_copyable<ObjPtr<void>>::value, "ObjPtr should be trivially copyable");
// Hash function for stl data structures. class HashObjPtr { public: template<class MirrorType>
size_t operator()(const ObjPtr<MirrorType>& ptr) const NO_THREAD_SAFETY_ANALYSIS;
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.