diff options
author | David Brazdil <dbrazdil@google.com> | 2015-03-31 13:08:21 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-03-31 13:08:22 +0000 |
commit | f1c2b1f395b8d47aa54a3b7a4ef1329eeb8af5d4 (patch) | |
tree | 5398a63d54c41fecc8c7d7133832cd3fa7572c91 /runtime/memory_region.h | |
parent | 7411a69982c055692966c685636b6a226f10215e (diff) | |
parent | b765683d995dc8f226c1ea5483ad08b5fac1afa8 (diff) | |
download | art-f1c2b1f395b8d47aa54a3b7a4ef1329eeb8af5d4.zip art-f1c2b1f395b8d47aa54a3b7a4ef1329eeb8af5d4.tar.gz art-f1c2b1f395b8d47aa54a3b7a4ef1329eeb8af5d4.tar.bz2 |
Merge "ART: Inline MemoryRegion operations"
Diffstat (limited to 'runtime/memory_region.h')
-rw-r--r-- | runtime/memory_region.h | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/runtime/memory_region.h b/runtime/memory_region.h index e275f0f..6a784eb 100644 --- a/runtime/memory_region.h +++ b/runtime/memory_region.h @@ -49,7 +49,8 @@ class MemoryRegion FINAL : public ValueObject { // Load value of type `T` at `offset`. The memory address corresponding // to `offset` should be word-aligned (on ARM, this is a requirement). - template<typename T> T Load(uintptr_t offset) const { + template<typename T> + ALWAYS_INLINE T Load(uintptr_t offset) const { T* address = ComputeInternalPointer<T>(offset); DCHECK(IsWordAligned(address)); return *address; @@ -58,7 +59,8 @@ class MemoryRegion FINAL : public ValueObject { // Store `value` (of type `T`) at `offset`. The memory address // corresponding to `offset` should be word-aligned (on ARM, this is // a requirement). - template<typename T> void Store(uintptr_t offset, T value) const { + template<typename T> + ALWAYS_INLINE void Store(uintptr_t offset, T value) const { T* address = ComputeInternalPointer<T>(offset); DCHECK(IsWordAligned(address)); *address = value; @@ -66,7 +68,8 @@ class MemoryRegion FINAL : public ValueObject { // Load value of type `T` at `offset`. The memory address corresponding // to `offset` does not need to be word-aligned. - template<typename T> T LoadUnaligned(uintptr_t offset) const { + template<typename T> + ALWAYS_INLINE T LoadUnaligned(uintptr_t offset) const { // Equivalent unsigned integer type corresponding to T. typedef typename UnsignedIntegerType<sizeof(T)>::type U; U equivalent_unsigned_integer_value = 0; @@ -80,7 +83,8 @@ class MemoryRegion FINAL : public ValueObject { // Store `value` (of type `T`) at `offset`. The memory address // corresponding to `offset` does not need to be word-aligned. - template<typename T> void StoreUnaligned(uintptr_t offset, T value) const { + template<typename T> + ALWAYS_INLINE void StoreUnaligned(uintptr_t offset, T value) const { // Equivalent unsigned integer type corresponding to T. typedef typename UnsignedIntegerType<sizeof(T)>::type U; U equivalent_unsigned_integer_value = bit_cast<U, T>(value); @@ -91,19 +95,20 @@ class MemoryRegion FINAL : public ValueObject { } } - template<typename T> T* PointerTo(uintptr_t offset) const { + template<typename T> + ALWAYS_INLINE T* PointerTo(uintptr_t offset) const { return ComputeInternalPointer<T>(offset); } // Load a single bit in the region. The bit at offset 0 is the least // significant bit in the first byte. - bool LoadBit(uintptr_t bit_offset) const { + ALWAYS_INLINE bool LoadBit(uintptr_t bit_offset) const { uint8_t bit_mask; uint8_t byte = *ComputeBitPointer(bit_offset, &bit_mask); return byte & bit_mask; } - void StoreBit(uintptr_t bit_offset, bool value) const { + ALWAYS_INLINE void StoreBit(uintptr_t bit_offset, bool value) const { uint8_t bit_mask; uint8_t* byte = ComputeBitPointer(bit_offset, &bit_mask); if (value) { @@ -154,7 +159,8 @@ class MemoryRegion FINAL : public ValueObject { } private: - template<typename T> T* ComputeInternalPointer(size_t offset) const { + template<typename T> + ALWAYS_INLINE T* ComputeInternalPointer(size_t offset) const { CHECK_GE(size(), sizeof(T)); CHECK_LE(offset, size() - sizeof(T)); return reinterpret_cast<T*>(start() + offset); @@ -162,7 +168,7 @@ class MemoryRegion FINAL : public ValueObject { // Locate the bit with the given offset. Returns a pointer to the byte // containing the bit, and sets bit_mask to the bit within that byte. - uint8_t* ComputeBitPointer(uintptr_t bit_offset, uint8_t* bit_mask) const { + ALWAYS_INLINE uint8_t* ComputeBitPointer(uintptr_t bit_offset, uint8_t* bit_mask) const { uintptr_t bit_remainder = (bit_offset & (kBitsPerByte - 1)); *bit_mask = (1U << bit_remainder); uintptr_t byte_offset = (bit_offset >> kBitsPerByteLog2); |