summaryrefslogtreecommitdiff
path: root/runtime/mirror/array-inl.h
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2013-11-14 17:45:16 -0800
committer Mathieu Chartier <mathieuc@google.com> 2013-11-20 11:14:11 -0800
commitcbb2d20bea2861f244da2e2318d8c088300a3710 (patch)
tree9735d496716cf165ea0ee2d7e2f62d723ffc7734 /runtime/mirror/array-inl.h
parentd31fb9718a6180304cd951619dc36be8e090a641 (diff)
Refactor allocation entrypoints.
Adds support for switching entrypoints during runtime. Enables addition of new allocators with out requiring significant copy paste. Slight speedup on ritzperf probably due to more inlining. TODO: Ensuring that the entire allocation path is inlined so that the switch statement in the allocation code is optimized out. Rosalloc measurements: 4583 4453 4439 4434 4751 After change: 4184 4287 4131 4335 4097 Change-Id: I1352a3cbcdf6dae93921582726324d91312df5c9
Diffstat (limited to 'runtime/mirror/array-inl.h')
-rw-r--r--runtime/mirror/array-inl.h45
1 files changed, 23 insertions, 22 deletions
diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h
index ef73e4df47..2955faa3c8 100644
--- a/runtime/mirror/array-inl.h
+++ b/runtime/mirror/array-inl.h
@@ -59,43 +59,44 @@ static inline size_t ComputeArraySize(Thread* self, Class* array_class, int32_t
}
static inline Array* SetArrayLength(Array* array, size_t length) {
- if (LIKELY(array != NULL)) {
+ if (LIKELY(array != nullptr)) {
DCHECK(array->IsArrayInstance());
array->SetLength(length);
}
return array;
}
-template <bool kIsMovable, bool kIsInstrumented>
+template <bool kIsInstrumented>
inline Array* Array::Alloc(Thread* self, Class* array_class, int32_t component_count,
- size_t component_size) {
+ size_t component_size, gc::AllocatorType allocator_type) {
size_t size = ComputeArraySize(self, array_class, component_count, component_size);
if (UNLIKELY(size == 0)) {
- return NULL;
+ return nullptr;
}
gc::Heap* heap = Runtime::Current()->GetHeap();
- Array* array = nullptr;
- if (kIsMovable) {
- if (kIsInstrumented) {
- array = down_cast<Array*>(heap->AllocMovableObjectInstrumented(self, array_class, size));
- } else {
- array = down_cast<Array*>(heap->AllocMovableObjectUninstrumented(self, array_class, size));
- }
- } else {
- if (kIsInstrumented) {
- array = down_cast<Array*>(heap->AllocNonMovableObjectInstrumented(self, array_class, size));
- } else {
- array = down_cast<Array*>(heap->AllocNonMovableObjectUninstrumented(self, array_class, size));
- }
- }
+ Array* array = down_cast<Array*>(
+ heap->AllocObjectWithAllocator<kIsInstrumented>(self, array_class, size, allocator_type));
return SetArrayLength(array, component_count);
}
-template <bool kIsMovable, bool kIsInstrumented>
-inline Array* Array::Alloc(Thread* self, Class* array_class, int32_t component_count) {
+template <bool kIsInstrumented>
+inline Array* Array::Alloc(Thread* self, Class* array_class, int32_t component_count,
+ gc::AllocatorType allocator_type) {
DCHECK(array_class->IsArrayClass());
- return Alloc<kIsMovable, kIsInstrumented>(self, array_class, component_count,
- array_class->GetComponentSize());
+ return Alloc<kIsInstrumented>(self, array_class, component_count, array_class->GetComponentSize(),
+ allocator_type);
+}
+template <bool kIsInstrumented>
+inline Array* Array::Alloc(Thread* self, Class* array_class, int32_t component_count) {
+ return Alloc<kIsInstrumented>(self, array_class, component_count,
+ Runtime::Current()->GetHeap()->GetCurrentAllocator());
+}
+
+template <bool kIsInstrumented>
+inline Array* Array::Alloc(Thread* self, Class* array_class, int32_t component_count,
+ size_t component_size) {
+ return Alloc<kIsInstrumented>(self, array_class, component_count, component_size,
+ Runtime::Current()->GetHeap()->GetCurrentAllocator());
}
} // namespace mirror