diff options
author | Vladimir Marko <vmarko@google.com> | 2015-02-13 18:09:07 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-02-13 18:09:07 +0000 |
commit | bce889940f10319bf67bdc5630c84dd7f6e5c246 (patch) | |
tree | 429100e6d3cf9c78707bfe81fbacab81dfec851c /compiler/utils | |
parent | 58e42c6e5571b1d3940561399faf163b9c219b57 (diff) | |
parent | e4fcc5ba2284c201c022b52d27f7a1201d696324 (diff) | |
download | art-bce889940f10319bf67bdc5630c84dd7f6e5c246.zip art-bce889940f10319bf67bdc5630c84dd7f6e5c246.tar.gz art-bce889940f10319bf67bdc5630c84dd7f6e5c246.tar.bz2 |
Merge "Clean up Scoped-/ArenaAlocator array allocations."
Diffstat (limited to 'compiler/utils')
-rw-r--r-- | compiler/utils/arena_allocator.h | 7 | ||||
-rw-r--r-- | compiler/utils/arena_containers.h | 3 | ||||
-rw-r--r-- | compiler/utils/growable_array.h | 9 | ||||
-rw-r--r-- | compiler/utils/scoped_arena_allocator.h | 7 |
4 files changed, 14 insertions, 12 deletions
diff --git a/compiler/utils/arena_allocator.h b/compiler/utils/arena_allocator.h index 7f5bc9a..e730fd7 100644 --- a/compiler/utils/arena_allocator.h +++ b/compiler/utils/arena_allocator.h @@ -176,7 +176,7 @@ class ArenaAllocator : private DebugStackRefCounter, private ArenaAllocatorStats ArenaAllocatorAdapter<void> Adapter(ArenaAllocKind kind = kArenaAllocSTL); // Returns zeroed memory. - void* Alloc(size_t bytes, ArenaAllocKind kind) ALWAYS_INLINE { + void* Alloc(size_t bytes, ArenaAllocKind kind = kArenaAllocMisc) ALWAYS_INLINE { if (UNLIKELY(running_on_valgrind_)) { return AllocValgrind(bytes, kind); } @@ -194,8 +194,9 @@ class ArenaAllocator : private DebugStackRefCounter, private ArenaAllocatorStats return ret; } - template <typename T> T* AllocArray(size_t length) { - return static_cast<T*>(Alloc(length * sizeof(T), kArenaAllocMisc)); + template <typename T> + T* AllocArray(size_t length, ArenaAllocKind kind = kArenaAllocMisc) { + return static_cast<T*>(Alloc(length * sizeof(T), kind)); } void* AllocValgrind(size_t bytes, ArenaAllocKind kind); diff --git a/compiler/utils/arena_containers.h b/compiler/utils/arena_containers.h index 8252591..a7a7438 100644 --- a/compiler/utils/arena_containers.h +++ b/compiler/utils/arena_containers.h @@ -161,8 +161,7 @@ class ArenaAllocatorAdapter : private DebugStackReference, private ArenaAllocato pointer allocate(size_type n, ArenaAllocatorAdapter<void>::pointer hint = nullptr) { UNUSED(hint); DCHECK_LE(n, max_size()); - return reinterpret_cast<T*>(arena_allocator_->Alloc(n * sizeof(T), - ArenaAllocatorAdapterKind::Kind())); + return arena_allocator_->AllocArray<T>(n, ArenaAllocatorAdapterKind::Kind()); } void deallocate(pointer p, size_type n) { UNUSED(p, n); diff --git a/compiler/utils/growable_array.h b/compiler/utils/growable_array.h index 6af4853..fd43ea6 100644 --- a/compiler/utils/growable_array.h +++ b/compiler/utils/growable_array.h @@ -33,16 +33,14 @@ class GrowableArray : public ArenaObject<kArenaAllocGrowableArray> { : arena_(arena), num_allocated_(init_length), num_used_(0) { - elem_list_ = static_cast<T*>(arena_->Alloc(sizeof(T) * init_length, - kArenaAllocGrowableArray)); + elem_list_ = arena_->AllocArray<T>(init_length, kArenaAllocGrowableArray); } GrowableArray(ArenaAllocator* arena, size_t init_length, T initial_data) : arena_(arena), num_allocated_(init_length), num_used_(init_length) { - elem_list_ = static_cast<T*>(arena_->Alloc(sizeof(T) * init_length, - kArenaAllocGrowableArray)); + elem_list_ = arena_->AllocArray<T>(init_length, kArenaAllocGrowableArray); for (size_t i = 0; i < init_length; ++i) { elem_list_[i] = initial_data; } @@ -58,8 +56,7 @@ class GrowableArray : public ArenaObject<kArenaAllocGrowableArray> { if (new_length > target_length) { target_length = new_length; } - T* new_array = static_cast<T*>(arena_->Alloc(sizeof(T) * target_length, - kArenaAllocGrowableArray)); + T* new_array = arena_->AllocArray<T>(target_length, kArenaAllocGrowableArray); memcpy(new_array, elem_list_, sizeof(T) * num_allocated_); num_allocated_ = target_length; elem_list_ = new_array; diff --git a/compiler/utils/scoped_arena_allocator.h b/compiler/utils/scoped_arena_allocator.h index 523f158..c46acbc 100644 --- a/compiler/utils/scoped_arena_allocator.h +++ b/compiler/utils/scoped_arena_allocator.h @@ -115,11 +115,16 @@ class ScopedArenaAllocator void Reset(); - void* Alloc(size_t bytes, ArenaAllocKind kind) ALWAYS_INLINE { + void* Alloc(size_t bytes, ArenaAllocKind kind = kArenaAllocMisc) ALWAYS_INLINE { DebugStackReference::CheckTop(); return arena_stack_->Alloc(bytes, kind); } + template <typename T> + T* AllocArray(size_t length, ArenaAllocKind kind = kArenaAllocMisc) { + return static_cast<T*>(Alloc(length * sizeof(T), kind)); + } + // Get adapter for use in STL containers. See scoped_arena_containers.h . ScopedArenaAllocatorAdapter<void> Adapter(ArenaAllocKind kind = kArenaAllocSTL); |