diff options
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 |
commit | cbb2d20bea2861f244da2e2318d8c088300a3710 (patch) | |
tree | 9735d496716cf165ea0ee2d7e2f62d723ffc7734 /runtime/mirror/object_array-inl.h | |
parent | d31fb9718a6180304cd951619dc36be8e090a641 (diff) | |
download | android_art-cbb2d20bea2861f244da2e2318d8c088300a3710.tar.gz android_art-cbb2d20bea2861f244da2e2318d8c088300a3710.tar.bz2 android_art-cbb2d20bea2861f244da2e2318d8c088300a3710.zip |
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/object_array-inl.h')
-rw-r--r-- | runtime/mirror/object_array-inl.h | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/runtime/mirror/object_array-inl.h b/runtime/mirror/object_array-inl.h index 478f4ec210..be49b42f0d 100644 --- a/runtime/mirror/object_array-inl.h +++ b/runtime/mirror/object_array-inl.h @@ -30,16 +30,25 @@ namespace art { namespace mirror { template<class T> -inline ObjectArray<T>* ObjectArray<T>::Alloc(Thread* self, Class* object_array_class, int32_t length) { - Array* array = Array::Alloc<kMovingCollector, true>(self, object_array_class, length, sizeof(Object*)); - if (UNLIKELY(array == NULL)) { - return NULL; +inline ObjectArray<T>* ObjectArray<T>::Alloc(Thread* self, Class* object_array_class, + int32_t length, gc::AllocatorType allocator_type) { + Array* array = Array::Alloc<true>(self, object_array_class, length, sizeof(Object*), + allocator_type); + if (UNLIKELY(array == nullptr)) { + return nullptr; } else { return array->AsObjectArray<T>(); } } template<class T> +inline ObjectArray<T>* ObjectArray<T>::Alloc(Thread* self, Class* object_array_class, + int32_t length) { + return Alloc(self, object_array_class, length, + Runtime::Current()->GetHeap()->GetCurrentAllocator()); +} + +template<class T> inline T* ObjectArray<T>::Get(int32_t i) const { if (UNLIKELY(!IsValidIndex(i))) { return NULL; @@ -137,7 +146,10 @@ template<class T> inline ObjectArray<T>* ObjectArray<T>::CopyOf(Thread* self, int32_t new_length) { // We may get copied by a compacting GC. SirtRef<ObjectArray<T> > sirt_this(self, this); - ObjectArray<T>* new_array = Alloc(self, GetClass(), new_length); + gc::Heap* heap = Runtime::Current()->GetHeap(); + gc::AllocatorType allocator_type = heap->IsMovableObject(this) ? heap->GetCurrentAllocator() : + heap->GetCurrentNonMovingAllocator(); + ObjectArray<T>* new_array = Alloc(self, GetClass(), new_length, allocator_type); if (LIKELY(new_array != nullptr)) { Copy(sirt_this.get(), 0, new_array, 0, std::min(sirt_this->GetLength(), new_length)); } |