From aa866f51bccc2f017a2e65925748b7a1c701d3f6 Mon Sep 17 00:00:00 2001 From: Hiroshi Yamauchi Date: Fri, 21 Mar 2014 16:18:30 -0700 Subject: [PATCH] Deduplicate the code that hardcodes the array header layout. Get rid of HeaderSize() in array-inl.h and use DataOffset() instead. Bug: 12687968 Change-Id: Ic81cf3fa6bb9b2440d351a73f5fd6a2d6908d15b --- runtime/mirror/array-inl.h | 10 +++------- runtime/offsets.h | 4 ++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h index 1d37775f9..dac287fbd 100644 --- a/runtime/mirror/array-inl.h +++ b/runtime/mirror/array-inl.h @@ -27,10 +27,6 @@ namespace art { namespace mirror { -static inline size_t HeaderSize(size_t component_size) { - return sizeof(Object) + (component_size == sizeof(int64_t) ? 8 : 4); -} - template inline size_t Array::SizeOf() { // This is safe from overflow because the array was already allocated, so we know it's sane. @@ -38,7 +34,7 @@ inline size_t Array::SizeOf() { // Don't need to check this since we already check this in GetClass. int32_t component_count = GetLength(kVerifyFlags & ~kVerifyThis)>(); - size_t header_size = HeaderSize(component_size); + size_t header_size = DataOffset(component_size).SizeValue(); size_t data_size = component_count * component_size; return header_size + data_size; } @@ -50,7 +46,7 @@ static inline size_t ComputeArraySize(Thread* self, Class* array_class, int32_t DCHECK_GE(component_count, 0); DCHECK(array_class->IsArrayClass()); - size_t header_size = HeaderSize(component_size); + size_t header_size = Array::DataOffset(component_size).SizeValue(); size_t data_size = component_count * component_size; size_t size = header_size + data_size; @@ -134,7 +130,7 @@ inline Array* Array::Alloc(Thread* self, Class* array_class, int32_t component_c heap->AllocObjectWithAllocator(self, array_class, size, allocator_type, visitor)); } else { - SetLengthToUsableSizeVisitor visitor(component_count, HeaderSize(component_size), + SetLengthToUsableSizeVisitor visitor(component_count, DataOffset(component_size).SizeValue(), component_size); result = down_cast( heap->AllocObjectWithAllocator(self, array_class, size, diff --git a/runtime/offsets.h b/runtime/offsets.h index e2dba9d97..ed4e49ea6 100644 --- a/runtime/offsets.h +++ b/runtime/offsets.h @@ -32,6 +32,10 @@ class Offset { uint32_t Uint32Value() const { return static_cast(val_); } + size_t SizeValue() const { + return val_; + } + protected: size_t val_; }; -- 2.11.0