summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHiroshi Yamauchi <yamauchi@google.com>2014-03-21 16:18:30 -0700
committerHiroshi Yamauchi <yamauchi@google.com>2014-03-21 16:27:11 -0700
commitaa866f51bccc2f017a2e65925748b7a1c701d3f6 (patch)
tree9fa6ca9147b1e08a0f6798a2a00e2a7324a2df7b
parentfaa93b3ab455492dad1a9d3fb630e3936d389c85 (diff)
downloadart-aa866f51bccc2f017a2e65925748b7a1c701d3f6.zip
art-aa866f51bccc2f017a2e65925748b7a1c701d3f6.tar.gz
art-aa866f51bccc2f017a2e65925748b7a1c701d3f6.tar.bz2
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
-rw-r--r--runtime/mirror/array-inl.h10
-rw-r--r--runtime/offsets.h4
2 files changed, 7 insertions, 7 deletions
diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h
index 1d37775..dac287f 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<VerifyObjectFlags kVerifyFlags>
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<static_cast<VerifyObjectFlags>(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<kIsInstrumented, true>(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<Array*>(
heap->AllocObjectWithAllocator<kIsInstrumented, true>(self, array_class, size,
diff --git a/runtime/offsets.h b/runtime/offsets.h
index e2dba9d..ed4e49e 100644
--- a/runtime/offsets.h
+++ b/runtime/offsets.h
@@ -32,6 +32,10 @@ class Offset {
uint32_t Uint32Value() const {
return static_cast<uint32_t>(val_);
}
+ size_t SizeValue() const {
+ return val_;
+ }
+
protected:
size_t val_;
};