Quicker partial collection by using card marking.

Add calls to the card marking from the write barrier routines, so that
a write to an Object marks the appropriate card. Add code in the GC to
use and rebuild the cards at a partial GC, clearing cards in the
Zygote heap which do not in fact contain references to the application
heap.

Change-Id: Ie6f29fd096e029f48085715b282b6db8a7122555
diff --git a/vm/alloc/HeapSource.c b/vm/alloc/HeapSource.c
index 86f9207..f55ccc5 100644
--- a/vm/alloc/HeapSource.c
+++ b/vm/alloc/HeapSource.c
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-#include <cutils/ashmem.h>
 #include <cutils/mspace.h>
 #include <limits.h>     // for INT_MAX
 #include <sys/mman.h>
@@ -473,7 +472,6 @@
     mspace msp;
     size_t length;
     void *base;
-    int fd, ret;
 
     assert(gHs == NULL);
 
@@ -488,18 +486,10 @@
      * among the heaps managed by the garbage collector.
      */
     length = ALIGN_UP_TO_PAGE_SIZE(absoluteMaxSize);
-    fd = ashmem_create_region("dalvik-heap", length);
-    if (fd == -1) {
+    base = dvmAllocRegion(length, PROT_NONE, "dalvik-heap");
+    if (base == NULL) {
         return NULL;
     }
-    base = mmap(NULL, length, PROT_NONE, MAP_PRIVATE, fd, 0);
-    if (base == MAP_FAILED) {
-        return NULL;
-    }
-    ret = close(fd);
-    if (ret == -1) {
-        goto fail;
-    }
 
     /* Create an unlocked dlmalloc mspace to use as
      * the small object heap source.
@@ -557,6 +547,10 @@
     countAllocation(hs2heap(hs), hs, false);
 
     gHs = hs;
+    if (!dvmCardTableStartup(gcHeap, base)) {
+        LOGE_HEAP("card table allocation failed.");
+        goto fail;
+    }
     return gcHeap;
 
 fail: