diff options
| -rw-r--r-- | compiler/dex/frontend.cc | 16 | ||||
| -rw-r--r-- | compiler/utils/scoped_arena_allocator.cc | 10 | ||||
| -rw-r--r-- | compiler/utils/scoped_arena_allocator.h | 2 |
3 files changed, 23 insertions, 5 deletions
diff --git a/compiler/dex/frontend.cc b/compiler/dex/frontend.cc index 7890d81236..64fa685c19 100644 --- a/compiler/dex/frontend.cc +++ b/compiler/dex/frontend.cc @@ -251,6 +251,15 @@ static CompiledMethod* CompileMethod(CompilerDriver& driver, /* Reassociate sreg names with original Dalvik vreg names. */ cu.mir_graph->RemapRegLocations(); + /* Free Arenas from the cu.arena_stack for reuse by the cu.arena in the codegen. */ + if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) { + if (cu.arena_stack.PeakBytesAllocated() > 256 * 1024) { + MemStats stack_stats(cu.arena_stack.GetPeakStats()); + LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(stack_stats); + } + } + cu.arena_stack.Reset(); + CompiledMethod* result = NULL; cu.cg->Materialize(); @@ -266,12 +275,9 @@ static CompiledMethod* CompileMethod(CompilerDriver& driver, } if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) { - if (cu.arena.BytesAllocated() > (1 * 1024 *1024) || - cu.arena_stack.PeakBytesAllocated() > 256 * 1024) { + if (cu.arena.BytesAllocated() > (1 * 1024 *1024)) { MemStats mem_stats(cu.arena.GetMemStats()); - MemStats peak_stats(cu.arena_stack.GetPeakStats()); - LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(mem_stats) - << Dumpable<MemStats>(peak_stats); + LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(mem_stats); } } diff --git a/compiler/utils/scoped_arena_allocator.cc b/compiler/utils/scoped_arena_allocator.cc index ee3b07ebe9..a78d28792b 100644 --- a/compiler/utils/scoped_arena_allocator.cc +++ b/compiler/utils/scoped_arena_allocator.cc @@ -34,7 +34,17 @@ ArenaStack::ArenaStack(ArenaPool* arena_pool) } ArenaStack::~ArenaStack() { + DebugStackRefCounter::CheckNoRefs(); + stats_and_pool_.pool->FreeArenaChain(bottom_arena_); +} + +void ArenaStack::Reset() { + DebugStackRefCounter::CheckNoRefs(); stats_and_pool_.pool->FreeArenaChain(bottom_arena_); + bottom_arena_ = nullptr; + top_arena_ = nullptr; + top_ptr_ = nullptr; + top_end_ = nullptr; } MemStats ArenaStack::GetPeakStats() const { diff --git a/compiler/utils/scoped_arena_allocator.h b/compiler/utils/scoped_arena_allocator.h index 24a8afea6e..28e86ec005 100644 --- a/compiler/utils/scoped_arena_allocator.h +++ b/compiler/utils/scoped_arena_allocator.h @@ -37,6 +37,8 @@ class ArenaStack : private DebugStackRefCounter { explicit ArenaStack(ArenaPool* arena_pool); ~ArenaStack(); + void Reset(); + size_t PeakBytesAllocated() { return PeakStats()->BytesAllocated(); } |