More space refactoring.

Add common interface, AllocSpace.

Renamed the old AllocSpace to DLMallocSpace.

Added an new option enforce_target_size_, which when enabled, doesn't let
the heap grow past ideal heap size calculated during last Gc.

Removed redundant AllocationSize calls.

Moved large object space to its own file instead of being in space.h/cc.

Change-Id: I15e60531114bf213800599737cbd66ef44b46b15
diff --git a/src/gc/mark_sweep.cc b/src/gc/mark_sweep.cc
index b82bc6e..e19e2c4 100644
--- a/src/gc/mark_sweep.cc
+++ b/src/gc/mark_sweep.cc
@@ -26,6 +26,7 @@
 #include "indirect_reference_table.h"
 #include "intern_table.h"
 #include "jni_internal.h"
+#include "large_object_space.h"
 #include "logging.h"
 #include "macros.h"
 #include "monitor.h"
@@ -208,7 +209,7 @@
 
 void MarkSweep::BindLiveToMarkBitmap(ContinuousSpace* space) {
   CHECK(space->IsAllocSpace());
-  AllocSpace* alloc_space = space->AsAllocSpace();
+  DlMallocSpace* alloc_space = space->AsAllocSpace();
   SpaceBitmap* live_bitmap = space->GetLiveBitmap();
   SpaceBitmap* mark_bitmap = alloc_space->mark_bitmap_.release();
   GetHeap()->GetMarkBitmap()->ReplaceBitmap(mark_bitmap, live_bitmap);
@@ -499,17 +500,12 @@
   // TODO: investigate performance
   static const bool kUseFreeList = true;
   if (kUseFreeList) {
-    for (size_t i = 0; i < num_ptrs; ++i) {
-      Object* obj = static_cast<Object*>(ptrs[i]);
-      freed_bytes += space->AllocationSize(obj);
-    }
     // AllocSpace::FreeList clears the value in ptrs, so perform after clearing the live bit
-    space->FreeList(self, num_ptrs, ptrs);
+    freed_bytes += space->FreeList(self, num_ptrs, ptrs);
   } else {
     for (size_t i = 0; i < num_ptrs; ++i) {
       Object* obj = static_cast<Object*>(ptrs[i]);
-      freed_bytes += space->AllocationSize(obj);
-      space->Free(self, obj);
+      freed_bytes += space->Free(self, obj);
     }
   }
 
@@ -532,7 +528,7 @@
 
 void MarkSweep::SweepArray(TimingLogger& logger, ObjectStack* allocations, bool swap_bitmaps) {
   size_t freed_bytes = 0;
-  AllocSpace* space = heap_->GetAllocSpace();
+  DlMallocSpace* space = heap_->GetAllocSpace();
 
   // If we don't swap bitmaps then newly allocated Weaks go into the live bitmap but not mark
   // bitmap, resulting in occasional frees of Weaks which are still in use.
@@ -566,22 +562,18 @@
       if (!mark_bitmap->Test(obj)) {
         // Don't bother un-marking since we clear the mark bitmap anyways.
         *(out++) = obj;
-        size_t size = space->AllocationSize(obj);
-        freed_bytes += size;
       }
     } else if (!large_mark_objects->Test(obj)) {
       ++freed_large_objects;
-      size_t size = large_object_space->AllocationSize(obj);
-      freed_bytes += size;
-      large_object_space->Free(self, obj);
+      freed_bytes += large_object_space->Free(self, obj);
     }
   }
   logger.AddSplit("Process allocation stack");
 
   size_t freed_objects = out - objects;
+  freed_bytes += space->FreeList(self, freed_objects, objects);
   VLOG(heap) << "Freed " << freed_objects << "/" << count
              << " objects with size " << PrettySize(freed_bytes);
-  space->FreeList(self, freed_objects, objects);
   heap_->RecordFree(freed_objects + freed_large_objects, freed_bytes);
   freed_objects_ += freed_objects;
   freed_bytes_ += freed_bytes;
@@ -645,8 +637,7 @@
   Thread* self = Thread::Current();
   for (SpaceSetMap::Objects::iterator it = live_objects.begin(); it != live_objects.end(); ++it) {
     if (!large_mark_objects->Test(*it)) {
-      freed_bytes += large_object_space->AllocationSize(*it);
-      large_object_space->Free(self, const_cast<Object*>(*it));
+      freed_bytes += large_object_space->Free(self, const_cast<Object*>(*it));
       ++freed_objects;
     }
   }
@@ -1017,7 +1008,7 @@
   for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) {
     Space* space = *it;
     if (space->IsAllocSpace()) {
-      AllocSpace* alloc_space = space->AsAllocSpace();
+      DlMallocSpace* alloc_space = space->AsAllocSpace();
       if (alloc_space->temp_bitmap_.get() != NULL) {
         // At this point, the temp_bitmap holds our old mark bitmap.
         SpaceBitmap* new_bitmap = alloc_space->temp_bitmap_.release();