diff options
author | 2017-01-31 08:58:55 -0800 | |
---|---|---|
committer | 2017-02-03 10:03:52 -0800 | |
commit | 90b936ddda63139ff46a6755c3b83ad6e4ab4ac5 (patch) | |
tree | c7ce2c3004eecc16ab41ed7cde105c3019638d4b /runtime/mirror/object.h | |
parent | b78a8af993e877d74c5938f65f95feaf2fa01321 (diff) |
ART: Refactor verify_object.h
Move the actual VerifyObject check into a new cc file, as we
commonly don't enable the check at all. This allows to cut the
-inl include from almost all current users.
This also exposes missing -inl includes. Also fix up some of our old
mess where .h defined functions require -inl.h defined functions.
Test: m
Change-Id: I3dd821bbe2015564a29bf1ed9be00f7a7276ad61
Diffstat (limited to 'runtime/mirror/object.h')
-rw-r--r-- | runtime/mirror/object.h | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/runtime/mirror/object.h b/runtime/mirror/object.h index db58a60994..4541ce2a42 100644 --- a/runtime/mirror/object.h +++ b/runtime/mirror/object.h @@ -17,6 +17,7 @@ #ifndef ART_RUNTIME_MIRROR_OBJECT_H_ #define ART_RUNTIME_MIRROR_OBJECT_H_ +#include "atomic.h" #include "base/casts.h" #include "base/enums.h" #include "globals.h" @@ -432,11 +433,18 @@ class MANAGED LOCKABLE Object { template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> ALWAYS_INLINE int32_t GetField32(MemberOffset field_offset) - REQUIRES_SHARED(Locks::mutator_lock_); + REQUIRES_SHARED(Locks::mutator_lock_) { + if (kVerifyFlags & kVerifyThis) { + VerifyObject(this); + } + return GetField<int32_t, kIsVolatile>(field_offset); + } template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ALWAYS_INLINE int32_t GetField32Volatile(MemberOffset field_offset) - REQUIRES_SHARED(Locks::mutator_lock_); + REQUIRES_SHARED(Locks::mutator_lock_) { + return GetField32<kVerifyFlags, true>(field_offset); + } template<bool kTransactionActive, bool kCheckTransaction = true, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> @@ -611,10 +619,28 @@ class MANAGED LOCKABLE Object { private: template<typename kSize, bool kIsVolatile> ALWAYS_INLINE void SetField(MemberOffset field_offset, kSize new_value) - REQUIRES_SHARED(Locks::mutator_lock_); + REQUIRES_SHARED(Locks::mutator_lock_) { + uint8_t* raw_addr = reinterpret_cast<uint8_t*>(this) + field_offset.Int32Value(); + kSize* addr = reinterpret_cast<kSize*>(raw_addr); + if (kIsVolatile) { + reinterpret_cast<Atomic<kSize>*>(addr)->StoreSequentiallyConsistent(new_value); + } else { + reinterpret_cast<Atomic<kSize>*>(addr)->StoreJavaData(new_value); + } + } + template<typename kSize, bool kIsVolatile> ALWAYS_INLINE kSize GetField(MemberOffset field_offset) - REQUIRES_SHARED(Locks::mutator_lock_); + REQUIRES_SHARED(Locks::mutator_lock_) { + const uint8_t* raw_addr = reinterpret_cast<const uint8_t*>(this) + field_offset.Int32Value(); + const kSize* addr = reinterpret_cast<const kSize*>(raw_addr); + if (kIsVolatile) { + return reinterpret_cast<const Atomic<kSize>*>(addr)->LoadSequentiallyConsistent(); + } else { + return reinterpret_cast<const Atomic<kSize>*>(addr)->LoadJavaData(); + } + } + // Get a field with acquire semantics. template<typename kSize> ALWAYS_INLINE kSize GetFieldAcquire(MemberOffset field_offset) |