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/nodes.h | 56 ++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 24 deletions(-) (limited to 'compiler/optimizing/nodes.h') diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index fef0c865ae..3c584bd67d 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -45,6 +45,7 @@ namespace art { +class ArenaStack; class GraphChecker; class HBasicBlock; class HConstructorFence; @@ -305,7 +306,8 @@ std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); // Control-flow graph of a method. Contains a list of basic blocks. class HGraph : public ArenaObject { public: - HGraph(ArenaAllocator* arena, + HGraph(ArenaAllocator* allocator, + ArenaStack* arena_stack, const DexFile& dex_file, uint32_t method_idx, InstructionSet instruction_set, @@ -313,10 +315,11 @@ class HGraph : public ArenaObject { bool debuggable = false, bool osr = false, int start_instruction_id = 0) - : arena_(arena), - blocks_(arena->Adapter(kArenaAllocBlockList)), - reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), - linear_order_(arena->Adapter(kArenaAllocLinearOrder)), + : allocator_(allocator), + arena_stack_(arena_stack), + blocks_(allocator->Adapter(kArenaAllocBlockList)), + reverse_post_order_(allocator->Adapter(kArenaAllocReversePostOrder)), + linear_order_(allocator->Adapter(kArenaAllocLinearOrder)), entry_block_(nullptr), exit_block_(nullptr), maximum_number_of_out_vregs_(0), @@ -337,22 +340,23 @@ class HGraph : public ArenaObject { number_of_cha_guards_(0), instruction_set_(instruction_set), cached_null_constant_(nullptr), - cached_int_constants_(std::less(), arena->Adapter(kArenaAllocConstantsMap)), - cached_float_constants_(std::less(), arena->Adapter(kArenaAllocConstantsMap)), - cached_long_constants_(std::less(), arena->Adapter(kArenaAllocConstantsMap)), - cached_double_constants_(std::less(), arena->Adapter(kArenaAllocConstantsMap)), + cached_int_constants_(std::less(), allocator->Adapter(kArenaAllocConstantsMap)), + cached_float_constants_(std::less(), allocator->Adapter(kArenaAllocConstantsMap)), + cached_long_constants_(std::less(), allocator->Adapter(kArenaAllocConstantsMap)), + cached_double_constants_(std::less(), allocator->Adapter(kArenaAllocConstantsMap)), cached_current_method_(nullptr), art_method_(nullptr), inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), osr_(osr), - cha_single_implementation_list_(arena->Adapter(kArenaAllocCHA)) { + cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) { blocks_.reserve(kDefaultNumberOfBlocks); } // Acquires and stores RTI of inexact Object to be used when creating HNullConstant. void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); - ArenaAllocator* GetArena() const { return arena_; } + ArenaAllocator* GetAllocator() const { return allocator_; } + ArenaStack* GetArenaStack() const { return arena_stack_; } const ArenaVector& GetBlocks() const { return blocks_; } bool IsInSsaForm() const { return in_ssa_form_; } @@ -613,7 +617,7 @@ class HGraph : public ArenaObject { // If not found or previously deleted, create and cache a new instruction. // Don't bother reviving a previously deleted instruction, for simplicity. if (constant == nullptr || constant->GetBlock() == nullptr) { - constant = new (arena_) InstructionType(value, dex_pc); + constant = new (allocator_) InstructionType(value, dex_pc); cache->Overwrite(value, constant); InsertConstant(constant); } @@ -629,7 +633,8 @@ class HGraph : public ArenaObject { // See CacheFloatConstant comment. void CacheDoubleConstant(HDoubleConstant* constant); - ArenaAllocator* const arena_; + ArenaAllocator* const allocator_; + ArenaStack* const arena_stack_; // List of blocks in insertion order. ArenaVector blocks_; @@ -751,9 +756,12 @@ class HLoopInformation : public ArenaObject { suspend_check_(nullptr), irreducible_(false), contains_irreducible_loop_(false), - back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), + back_edges_(graph->GetAllocator()->Adapter(kArenaAllocLoopInfoBackEdges)), // Make bit vector growable, as the number of blocks may change. - blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { + blocks_(graph->GetAllocator(), + graph->GetBlocks().size(), + true, + kArenaAllocLoopInfoBackEdges) { back_edges_.reserve(kDefaultNumberOfBackEdges); } @@ -916,11 +924,11 @@ class HBasicBlock : public ArenaObject { public: explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) : graph_(graph), - predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), - successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), + predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), + successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), loop_information_(nullptr), dominator_(nullptr), - dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), + dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), block_id_(kInvalidBlockId), dex_pc_(dex_pc), lifetime_start_(kNoLifetime), @@ -972,7 +980,7 @@ class HBasicBlock : public ArenaObject { void AddBackEdge(HBasicBlock* back_edge) { if (loop_information_ == nullptr) { - loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); + loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); } DCHECK_EQ(loop_information_->GetHeader(), this); loop_information_->AddBackEdge(back_edge); @@ -1925,7 +1933,7 @@ class HInstruction : public ArenaObject { HInstruction* GetPreviousDisregardingMoves() const; HBasicBlock* GetBlock() const { return block_; } - ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } + ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } void SetBlock(HBasicBlock* block) { block_ = block; } bool IsInBlock() const { return block_ != nullptr; } bool IsInLoop() const { return block_->IsInLoop(); } @@ -2015,7 +2023,7 @@ class HInstruction : public ArenaObject { // Note: fixup_end remains valid across push_front(). auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); HUseListNode* new_node = - new (GetBlock()->GetGraph()->GetArena()) HUseListNode(user, index); + new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode(user, index); uses_.push_front(*new_node); FixUpUserRecordsAfterUseInsertion(fixup_end); } @@ -2025,7 +2033,7 @@ class HInstruction : public ArenaObject { // Note: env_fixup_end remains valid across push_front(). auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); HUseListNode* new_node = - new (GetBlock()->GetGraph()->GetArena()) HUseListNode(user, index); + new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode(user, index); env_uses_.push_front(*new_node); FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); } @@ -2108,7 +2116,7 @@ class HInstruction : public ArenaObject { // copying, the uses lists are being updated. void CopyEnvironmentFrom(HEnvironment* environment) { DCHECK(environment_ == nullptr); - ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); + ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); environment_ = new (allocator) HEnvironment(allocator, *environment, this); environment_->CopyFrom(environment); if (environment->GetParent() != nullptr) { @@ -2119,7 +2127,7 @@ class HInstruction : public ArenaObject { void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, HBasicBlock* block) { DCHECK(environment_ == nullptr); - ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); + ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); environment_ = new (allocator) HEnvironment(allocator, *environment, this); environment_->CopyFromWithLoopPhiAdjustment(environment, block); if (environment->GetParent() != nullptr) { -- cgit v1.2.3-59-g8ed1b