From 76ce917c546d4793316cd8356a12c2791406ae39 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Wed, 27 Jan 2016 10:44:20 -0800 Subject: [PATCH] Move heap trim outside of zygote creation lock region Fixes lock order violation due if non moving space is a RosAllocSpace since the trim requires acquiring the mutator lock. Change-Id: Iff0b8c943e261702eda65b3c255fda24a6fe14c2 --- runtime/gc/heap.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index 137540afd..39645391c 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -347,7 +347,7 @@ Heap::Heap(size_t initial_size, bool separate_non_moving_space = is_zygote || support_homogeneous_space_compaction || IsMovingGc(foreground_collector_type_) || IsMovingGc(background_collector_type_); - if (foreground_collector_type == kCollectorTypeGSS) { + if (foreground_collector_type_ == kCollectorTypeGSS) { separate_non_moving_space = false; } std::unique_ptr main_mem_map_1; @@ -2346,6 +2346,9 @@ void Heap::PreZygoteFork() { // We still want to GC in case there is some unreachable non moving objects that could cause a // suboptimal bin packing when we compact the zygote space. CollectGarbageInternal(collector::kGcTypeFull, kGcCauseBackground, false); + // Trim the pages at the end of the non moving space. Trim while not holding zygote lock since + // the trim process may require locking the mutator lock. + non_moving_space_->Trim(); } Thread* self = Thread::Current(); MutexLock mu(self, zygote_creation_lock_); @@ -2356,8 +2359,6 @@ void Heap::PreZygoteFork() { Runtime::Current()->GetInternTable()->AddNewTable(); Runtime::Current()->GetClassLinker()->MoveClassTableToPreZygote(); VLOG(heap) << "Starting PreZygoteFork"; - // Trim the pages at the end of the non moving space. - non_moving_space_->Trim(); // The end of the non-moving space may be protected, unprotect it so that we can copy the zygote // there. non_moving_space_->GetMemMap()->Protect(PROT_READ | PROT_WRITE); -- 2.11.0