OSDN Git Service

Only GC the first time we call PreZygoteFork
authorMathieu Chartier <mathieuc@google.com>
Tue, 31 Mar 2015 23:28:53 +0000 (16:28 -0700)
committerMathieu Chartier <mathieuc@google.com>
Tue, 31 Mar 2015 23:29:46 +0000 (16:29 -0700)
PreZygoteFork is called for every app launch, it is overkill to GC
each time since it takes 20-30ms and blocks app launch for that long.

Change-Id: I647c8ccca767ceca67a006c1d80a739c7860f0d0

runtime/gc/heap.cc

index 51cf558..7e967f9 100644 (file)
@@ -2056,7 +2056,11 @@ void Heap::UnBindBitmaps() {
 }
 
 void Heap::PreZygoteFork() {
-  CollectGarbageInternal(collector::kGcTypeFull, kGcCauseBackground, false);
+  if (!HasZygoteSpace()) {
+    // 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);
+  }
   Thread* self = Thread::Current();
   MutexLock mu(self, zygote_creation_lock_);
   // Try to see if we have any Zygote spaces.
@@ -2125,7 +2129,7 @@ void Heap::PreZygoteFork() {
     // Update the end and write out image.
     non_moving_space_->SetEnd(target_space.End());
     non_moving_space_->SetLimit(target_space.Limit());
-    VLOG(heap) << "Zygote space size " << non_moving_space_->Size() << " bytes";
+    VLOG(heap) << "Create zygote space with size=" << non_moving_space_->Size() << " bytes";
   }
   // Change the collector to the post zygote one.
   ChangeCollector(foreground_collector_type_);