OSDN Git Service

Move heap trim outside of zygote creation lock region
authorMathieu Chartier <mathieuc@google.com>
Wed, 27 Jan 2016 18:44:20 +0000 (10:44 -0800)
committerMathieu Chartier <mathieuc@google.com>
Wed, 27 Jan 2016 18:46:12 +0000 (10:46 -0800)
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

index 137540a..3964539 100644 (file)
@@ -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<MemMap> 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);