Refactor some GC code.

Reduced amount of code in mark sweep / semi space by moving
common logic to garbage_collector.cc. Cleaned up mod union tables
and deleted an unused implementation.

Change-Id: I4bcc6ba41afd96d230cfbaf4d6636f37c52e37ea
diff --git a/runtime/gc/collector/semi_space.cc b/runtime/gc/collector/semi_space.cc
index d4f47ef..222bd63 100644
--- a/runtime/gc/collector/semi_space.cc
+++ b/runtime/gc/collector/semi_space.cc
@@ -25,7 +25,7 @@
 #include "base/macros.h"
 #include "base/mutex-inl.h"
 #include "base/timing_logger.h"
-#include "gc/accounting/heap_bitmap.h"
+#include "gc/accounting/heap_bitmap-inl.h"
 #include "gc/accounting/mod_union_table.h"
 #include "gc/accounting/remembered_set.h"
 #include "gc/accounting/space_bitmap-inl.h"
@@ -726,8 +726,8 @@
     return obj;
   }
   if (from_space_->HasAddress(obj)) {
-    mirror::Object* forwarding_address = GetForwardingAddressInFromSpace(const_cast<Object*>(obj));
-    return forwarding_address;  // Returns either the forwarding address or nullptr.
+    // Returns either the forwarding address or nullptr.
+    return GetForwardingAddressInFromSpace(obj);
   } else if (to_space_->HasAddress(obj)) {
     // Should be unlikely.
     // Already forwarded, must be marked.
@@ -751,38 +751,12 @@
   Heap* heap = GetHeap();
   timings_.NewSplit("PostGcVerification");
   heap->PostGcVerification(this);
-
   // Null the "to" and "from" spaces since compacting from one to the other isn't valid until
   // further action is done by the heap.
   to_space_ = nullptr;
   from_space_ = nullptr;
-
-  // Update the cumulative statistics
-  total_freed_objects_ += GetFreedObjects() + GetFreedLargeObjects();
-  total_freed_bytes_ += GetFreedBytes() + GetFreedLargeObjectBytes();
-
-  // Ensure that the mark stack is empty.
   CHECK(mark_stack_->IsEmpty());
-
-  // Update the cumulative loggers.
-  cumulative_timings_.Start();
-  cumulative_timings_.AddLogger(timings_);
-  cumulative_timings_.End();
-
-  // Clear all of the spaces' mark bitmaps.
-  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
-    accounting::SpaceBitmap* bitmap = space->GetMarkBitmap();
-    if (bitmap != nullptr &&
-        space->GetGcRetentionPolicy() != space::kGcRetentionPolicyNeverCollect) {
-      bitmap->Clear();
-    }
-  }
   mark_stack_->Reset();
-
-  // Reset the marked large objects.
-  space::LargeObjectSpace* large_objects = GetHeap()->GetLargeObjectsSpace();
-  large_objects->GetMarkObjects()->Clear();
-
   if (generational_) {
     // Decide whether to do a whole heap collection or a bump pointer
     // only space collection at the next collection by updating
@@ -800,6 +774,9 @@
       whole_heap_collection_ = false;
     }
   }
+  // Clear all of the spaces' mark bitmaps.
+  WriterMutexLock mu(Thread::Current(), *Locks::heap_bitmap_lock_);
+  heap_->ClearMarkedObjects();
 }
 
 void SemiSpace::RevokeAllThreadLocalBuffers() {