Make dvmCardTableStartup be more independant of HeapSource startup.

Also added a call to dvmCardTableShutdown. Also removed the dependency
on GcHeap from CardTable.h.

Change-Id: Icf0293572371cc8a30b55672816fdd75a151e82c
diff --git a/vm/alloc/Heap.c b/vm/alloc/Heap.c
index f3a4e2d..b94f106 100644
--- a/vm/alloc/Heap.c
+++ b/vm/alloc/Heap.c
@@ -84,6 +84,11 @@
     gcHeap->pendingFinalizationRefs = NULL;
     gcHeap->referenceOperations = NULL;
 
+    if (!dvmCardTableStartup()) {
+        LOGE_HEAP("card table startup failed.");
+        return false;
+    }
+
     /* Initialize the HeapWorker locks and other state
      * that the GC uses.
      */
@@ -105,10 +110,10 @@
 {
 //TODO: make sure we're locked
     if (gDvm.gcHeap != NULL) {
-        /* Tables are allocated on the native heap;
-         * they need to be cleaned up explicitly.
-         * The process may stick around, so we don't
-         * want to leak any native memory.
+        dvmCardTableShutdown();
+         /* Tables are allocated on the native heap; they need to be
+         * cleaned up explicitly.  The process may stick around, so we
+         * don't want to leak any native memory.
          */
         dvmHeapFreeLargeTable(gDvm.gcHeap->finalizableRefs);
         gDvm.gcHeap->finalizableRefs = NULL;
@@ -119,10 +124,9 @@
         dvmHeapFreeLargeTable(gDvm.gcHeap->referenceOperations);
         gDvm.gcHeap->referenceOperations = NULL;
 
-        /* Destroy the heap.  Any outstanding pointers
-         * will point to unmapped memory (unless/until
-         * someone else maps it).  This frees gDvm.gcHeap
-         * as a side-effect.
+        /* Destroy the heap.  Any outstanding pointers will point to
+         * unmapped memory (unless/until someone else maps it).  This
+         * frees gDvm.gcHeap as a side-effect.
          */
         dvmHeapSourceShutdown(&gDvm.gcHeap);
     }