From ca6fff898afcb62491458ae8bcd428bfb3043da1 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Tue, 3 Oct 2017 14:49:14 +0100 Subject: ART: Use ScopedArenaAllocator for pass-local data. Passes using local ArenaAllocator were hiding their memory usage from the allocation counting, making it difficult to track down where memory was used. Using ScopedArenaAllocator reveals the memory usage. This changes the HGraph constructor which requires a lot of changes in tests. Refactor these tests to limit the amount of work needed the next time we change that constructor. Test: m test-art-host-gtest Test: testrunner.py --host Test: Build with kArenaAllocatorCountAllocations = true. Bug: 64312607 Change-Id: I34939e4086b500d6e827ff3ef2211d1a421ac91a --- compiler/optimizing/loop_optimization.cc | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'compiler/optimizing/loop_optimization.cc') diff --git a/compiler/optimizing/loop_optimization.cc b/compiler/optimizing/loop_optimization.cc index c51fafa695..d87861bde0 100644 --- a/compiler/optimizing/loop_optimization.cc +++ b/compiler/optimizing/loop_optimization.cc @@ -429,7 +429,7 @@ static HInstruction* Insert(HBasicBlock* block, HInstruction* instruction) { // Check that instructions from the induction sets are fully removed: have no uses // and no other instructions use them. -static bool CheckInductionSetFullyRemoved(ArenaSet* iset) { +static bool CheckInductionSetFullyRemoved(ScopedArenaSet* iset) { for (HInstruction* instr : *iset) { if (instr->GetBlock() != nullptr || !instr->GetUses().empty() || @@ -453,7 +453,7 @@ HLoopOptimization::HLoopOptimization(HGraph* graph, compiler_driver_(compiler_driver), induction_range_(induction_analysis), loop_allocator_(nullptr), - global_allocator_(graph_->GetArena()), + global_allocator_(graph_->GetAllocator()), top_loop_(nullptr), last_loop_(nullptr), iset_(nullptr), @@ -465,7 +465,12 @@ HLoopOptimization::HLoopOptimization(HGraph* graph, vector_runtime_test_a_(nullptr), vector_runtime_test_b_(nullptr), vector_map_(nullptr), - vector_permanent_map_(nullptr) { + vector_permanent_map_(nullptr), + vector_mode_(kSequential), + vector_preheader_(nullptr), + vector_header_(nullptr), + vector_body_(nullptr), + vector_index_(nullptr) { } void HLoopOptimization::Run() { @@ -475,10 +480,8 @@ void HLoopOptimization::Run() { return; } - // Phase-local allocator that draws from the global pool. Since the allocator - // itself resides on the stack, it is destructed on exiting Run(), which - // implies its underlying memory is released immediately. - ArenaAllocator allocator(global_allocator_->GetArenaPool()); + // Phase-local allocator. + ScopedArenaAllocator allocator(graph_->GetArenaStack()); loop_allocator_ = &allocator; // Perform loop optimizations. @@ -499,8 +502,8 @@ void HLoopOptimization::Run() { void HLoopOptimization::LocalRun() { // Build the linear order using the phase-local allocator. This step enables building // a loop hierarchy that properly reflects the outer-inner and previous-next relation. - ArenaVector linear_order(loop_allocator_->Adapter(kArenaAllocLinearOrder)); - LinearizeGraph(graph_, loop_allocator_, &linear_order); + ScopedArenaVector linear_order(loop_allocator_->Adapter(kArenaAllocLinearOrder)); + LinearizeGraph(graph_, &linear_order); // Build the loop hierarchy. for (HBasicBlock* block : linear_order) { @@ -513,13 +516,13 @@ void HLoopOptimization::LocalRun() { // temporary data structures using the phase-local allocator. All new HIR // should use the global allocator. if (top_loop_ != nullptr) { - ArenaSet iset(loop_allocator_->Adapter(kArenaAllocLoopOptimization)); - ArenaSafeMap reds( + ScopedArenaSet iset(loop_allocator_->Adapter(kArenaAllocLoopOptimization)); + ScopedArenaSafeMap reds( std::less(), loop_allocator_->Adapter(kArenaAllocLoopOptimization)); - ArenaSet refs(loop_allocator_->Adapter(kArenaAllocLoopOptimization)); - ArenaSafeMap map( + ScopedArenaSet refs(loop_allocator_->Adapter(kArenaAllocLoopOptimization)); + ScopedArenaSafeMap map( std::less(), loop_allocator_->Adapter(kArenaAllocLoopOptimization)); - ArenaSafeMap perm( + ScopedArenaSafeMap perm( std::less(), loop_allocator_->Adapter(kArenaAllocLoopOptimization)); // Attach. iset_ = &iset; -- cgit v1.2.3-59-g8ed1b