Only GC the first time we call PreZygoteFork

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
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 51cf558..7e967f9 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -2056,7 +2056,11 @@
 }
 
 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 @@
     // 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_);