From 4e335d0279038d9a33628e7174eecbd1e540ab6e Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Mon, 19 Dec 2016 16:04:33 +0000 Subject: [PATCH] Fix arena allocation counting. Add the "CHA" allocation kind description. Move the statistics to the heap to avoid excessively large frames triggering errors with -Werror, -Wframe-larger-than=. Test: m test-art-host Test: m test-art-host with arena allocation counting. Change-Id: I7947a3a17b4c1ed773742516b1f7ab9a58c92150 --- runtime/base/arena_allocator.cc | 9 +++++---- runtime/base/arena_allocator.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/runtime/base/arena_allocator.cc b/runtime/base/arena_allocator.cc index 5cdf6718f..61e0aabba 100644 --- a/runtime/base/arena_allocator.cc +++ b/runtime/base/arena_allocator.cc @@ -83,18 +83,19 @@ const char* const ArenaAllocatorStatsImpl::kAllocNames[] = { "GraphChecker ", "Verifier ", "CallingConv ", + "CHA ", }; template ArenaAllocatorStatsImpl::ArenaAllocatorStatsImpl() - : num_allocations_(0u) { - std::fill_n(alloc_stats_, arraysize(alloc_stats_), 0u); + : num_allocations_(0u), + alloc_stats_(kNumArenaAllocKinds, 0u) { } template void ArenaAllocatorStatsImpl::Copy(const ArenaAllocatorStatsImpl& other) { num_allocations_ = other.num_allocations_; - std::copy(other.alloc_stats_, other.alloc_stats_ + arraysize(alloc_stats_), alloc_stats_); + std::copy_n(other.alloc_stats_.begin(), kNumArenaAllocKinds, alloc_stats_.begin()); } template @@ -111,7 +112,7 @@ size_t ArenaAllocatorStatsImpl::NumAllocations() const { template size_t ArenaAllocatorStatsImpl::BytesAllocated() const { const size_t init = 0u; // Initial value of the correct type. - return std::accumulate(alloc_stats_, alloc_stats_ + arraysize(alloc_stats_), init); + return std::accumulate(alloc_stats_.begin(), alloc_stats_.end(), init); } template diff --git a/runtime/base/arena_allocator.h b/runtime/base/arena_allocator.h index 2feb28a77..6c764cb71 100644 --- a/runtime/base/arena_allocator.h +++ b/runtime/base/arena_allocator.h @@ -21,6 +21,7 @@ #include #include "base/bit_utils.h" +#include "base/dchecked_vector.h" #include "base/memory_tool.h" #include "debug_stack.h" #include "macros.h" @@ -132,8 +133,7 @@ class ArenaAllocatorStatsImpl { private: size_t num_allocations_; - // TODO: Use std::array from C++11 when we upgrade the STL. - size_t alloc_stats_[kNumArenaAllocKinds]; // Bytes used by various allocation kinds. + dchecked_vector alloc_stats_; // Bytes used by various allocation kinds. static const char* const kAllocNames[]; }; -- 2.11.0