Don't create bump pointer spaces unless necessary.

We now only create these spaces if the foreground or background
collector is a moving collector.

Bug: 13564922
Bug: 14059466
Change-Id: I9f83c7881bc28423b78d5249c8e8854add91b60c
diff --git a/runtime/gc/collector/semi_space.cc b/runtime/gc/collector/semi_space.cc
index d4e26ab..e5bb1cc 100644
--- a/runtime/gc/collector/semi_space.cc
+++ b/runtime/gc/collector/semi_space.cc
@@ -272,12 +272,12 @@
   from_space_->Clear();
   VLOG(heap) << "Protecting from_space_: " << *from_space_;
   from_space_->GetMemMap()->Protect(kProtectFromSpace ? PROT_NONE : PROT_READ);
-  if (swap_semi_spaces_) {
-    heap_->SwapSemiSpaces();
-  }
   timings_.StartSplit("PreSweepingGcVerification");
   heap_->PreSweepingGcVerification(this);
   timings_.EndSplit();
+  if (swap_semi_spaces_) {
+    heap_->SwapSemiSpaces();
+  }
 }
 
 void SemiSpace::UpdateAndMarkModUnion() {
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index a6093ca..e03b6f7 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -234,10 +234,10 @@
   // create the bump pointer space if we are not a moving foreground collector but have a moving
   // background collector since the heap transition code will create the temp space by recycling
   // the bitmap from the main space.
-  if (kMovingCollector) {
+  if (kMovingCollector &&
+      (IsMovingGc(foreground_collector_type_) || IsMovingGc(background_collector_type_))) {
     // TODO: Place bump-pointer spaces somewhere to minimize size of card table.
-    // TODO: Not create all the bump pointer spaces if not necessary (currently only GSS needs all
-    // 2 of bump pointer spaces + main space) b/14059466. Divide by 2 for a temporary fix.
+    // Divide by 2 for a temporary fix for reducing virtual memory usage.
     const size_t bump_pointer_space_capacity = capacity / 2;
     bump_pointer_space_ = space::BumpPointerSpace::Create("Bump pointer space",
                                                           bump_pointer_space_capacity, nullptr);
@@ -2366,7 +2366,6 @@
     WriterMutexLock mu(self, *Locks::heap_bitmap_lock_);
     // Swapping bound bitmaps does nothing.
     gc->SwapBitmaps();
-    SwapSemiSpaces();
     // Pass in false since concurrent reference processing can mean that the reference referents
     // may point to dead objects at the point which PreSweepingGcVerification is called.
     size_t failures = VerifyHeapReferences(false);
@@ -2374,7 +2373,6 @@
       LOG(FATAL) << "Pre sweeping " << gc->GetName() << " GC verification failed with " << failures
           << " failures";
     }
-    SwapSemiSpaces();
     gc->SwapBitmaps();
   }
   if (verify_pre_sweeping_rosalloc_) {