Each space has its own bitmap(s)

Each alloc space now has One mark+live bitmap. Each image space has only one live bitmap.

Change-Id: I2e919d1bd7d9f4d35d0e95ed83a58df6f754df6e
diff --git a/src/native/dalvik_system_DexFile.cc b/src/native/dalvik_system_DexFile.cc
index ef38f00..3e749e5 100644
--- a/src/native/dalvik_system_DexFile.cc
+++ b/src/native/dalvik_system_DexFile.cc
@@ -224,12 +224,20 @@
     return JNI_TRUE;
   }
 
-  const ImageHeader& image_header = runtime->GetHeap()->GetImageSpace()->GetImageHeader();
-  if (oat_file->GetOatHeader().GetImageFileLocationChecksum() != image_header.GetOatChecksum()) {
-    LOG(INFO) << "DexFile_isDexOptNeeded cache file " << cache_location
-              << " has out-of-date checksum compared to "
-              << image_header.GetImageRoot(ImageHeader::kOatLocation)->AsString()->ToModifiedUtf8();
-    return JNI_TRUE;
+  Heap* heap = runtime->GetHeap();
+  const Spaces& spaces = heap->GetSpaces();
+  // TODO: C++0x auto
+  for (Spaces::const_iterator cur = spaces.begin(); cur != spaces.end(); ++cur) {
+    if ((*cur)->IsImageSpace()) {
+      // TODO: Ensure this works with multiple image spaces.
+      const ImageHeader& image_header = (*cur)->AsImageSpace()->GetImageHeader();
+      if (oat_file->GetOatHeader().GetImageFileLocationChecksum() != image_header.GetOatChecksum()) {
+        LOG(INFO) << "DexFile_isDexOptNeeded cache file " << cache_location
+                  << " has out-of-date checksum compared to "
+                  << image_header.GetImageRoot(ImageHeader::kOatLocation)->AsString()->ToModifiedUtf8();
+        return JNI_TRUE;
+      }
+    }
   }
 
   uint32_t location_checksum;
diff --git a/src/native/dalvik_system_VMRuntime.cc b/src/native/dalvik_system_VMRuntime.cc
index 417ae5b..4ec1b92 100644
--- a/src/native/dalvik_system_VMRuntime.cc
+++ b/src/native/dalvik_system_VMRuntime.cc
@@ -164,23 +164,27 @@
 
   // Trim the managed heap.
   Heap* heap = Runtime::Current()->GetHeap();
-  size_t alloc_space_size = heap->GetAllocSpace()->Size();
-  float utilization = static_cast<float>(heap->GetBytesAllocated()) / alloc_space_size;
-  uint64_t start_ns = NanoTime();
-
-  heap->Trim();
-
-  // Trim the native heap.
-  dlmalloc_trim(0);
+  const Spaces& spaces = heap->GetSpaces();
+  // TODO: C++0x auto
+  for (Spaces::const_iterator cur = spaces.begin(); cur != spaces.end(); ++cur) {
+    if ((*cur)->IsAllocSpace()) {
+      uint64_t start_ns = NanoTime();
+      AllocSpace* alloc_space = (*cur)->AsAllocSpace();
+      size_t alloc_space_size = alloc_space->Size();
+      float utilization = static_cast<float>(heap->GetBytesAllocated()) / alloc_space_size;
+      heap->Trim(alloc_space);
+      // Trim the native heap.
+      dlmalloc_trim(0);
 #if 0 // TODO: switch over to this when bionic has moved to dlmalloc 2.8.5
-  dlmalloc_inspect_all(MspaceMadviseCallback, NULL);
+      dlmalloc_inspect_all(MspaceMadviseCallback, NULL);
 #else
-  dlmalloc_walk_free_pages(MspaceMadviseCallback, NULL);
+      dlmalloc_walk_free_pages(MspaceMadviseCallback, NULL);
 #endif
-
-  LOG(INFO) << "Parallel heap trimming took " << PrettyDuration(NanoTime() - start_ns)
-            << " on a " << PrettySize(alloc_space_size)
-            << " heap with " << static_cast<int>(100 * utilization) << "% utilization";
+      LOG(INFO) << "Parallel heap trimming took " << PrettyDuration(NanoTime() - start_ns)
+                << " on a " << PrettySize(alloc_space_size)
+                << " alloc space with " << static_cast<int>(100 * utilization) << "% utilization";
+    }
+  }
 }
 
 static void VMRuntime_concurrentGC(JNIEnv*, jobject) {