[MLton-commit] r6774

Matthew Fluet fluet at mlton.org
Tue Aug 19 17:43:36 PDT 2008


Separate functions for cardMap and crossMap sizes.
----------------------------------------------------------------------

U   mlton/trunk/runtime/gc/generational.c
U   mlton/trunk/runtime/gc/generational.h
U   mlton/trunk/runtime/gc/heap.c

----------------------------------------------------------------------

Modified: mlton/trunk/runtime/gc/generational.c
===================================================================
--- mlton/trunk/runtime/gc/generational.c	2008-08-20 00:43:27 UTC (rev 6773)
+++ mlton/trunk/runtime/gc/generational.c	2008-08-20 00:43:34 UTC (rev 6774)
@@ -35,15 +35,15 @@
   }
 }
 
-GC_cardMapIndex pointerToCardMapIndexAbsolute (pointer p) {
-  return (GC_cardMapIndex)p >> CARD_SIZE_LOG2;
-}
 GC_cardMapIndex sizeToCardMapIndex (size_t z) {
   return (GC_cardMapIndex)z >> CARD_SIZE_LOG2;
 }
 size_t cardMapIndexToSize (GC_cardMapIndex i) {
   return (size_t)i << CARD_SIZE_LOG2;
 }
+GC_cardMapIndex pointerToCardMapIndexAbsolute (pointer p) {
+  return (GC_cardMapIndex)p >> CARD_SIZE_LOG2;
+}
 GC_cardMapElem *pointerToCardMapAddr (GC_state s, pointer p) {
   GC_cardMapElem *res;
 
@@ -54,6 +54,10 @@
   return res;
 }
 
+GC_crossMapIndex sizeToCrossMapIndex (size_t z) {
+  return (GC_crossMapIndex)z >> CARD_SIZE_LOG2;
+}
+
 bool isCardMarked (GC_state s, pointer p) {
   return (*pointerToCardMapAddr (s, p) != 0x0);
 }
@@ -104,6 +108,58 @@
     : (p - 1) - ((uintptr_t)(p - 1) % CARD_SIZE);
 }
 
+size_t sizeofCardMap (GC_state s, size_t heapSize) {
+  unless (s->mutatorMarksCards) {
+    return 0;
+  }
+  assert (isAligned (heapSize, CARD_SIZE));
+
+  GC_cardMapIndex cardMapLength;
+  size_t cardMapSize;
+
+  cardMapLength = sizeToCardMapIndex (heapSize);
+  cardMapSize = align (cardMapLength * CARD_MAP_ELEM_SIZE, s->sysvals.pageSize);
+
+  return cardMapSize;
+}
+
+GC_cardMapIndex lenofCardMap (__attribute__ ((unused)) GC_state s, size_t cardMapSize) {
+  GC_cardMapIndex cardMapLength;
+
+  assert (isAligned (cardMapSize, s->sysvals.pageSize));
+  assert (isAligned (cardMapSize, CARD_MAP_ELEM_SIZE));
+
+  cardMapLength = (GC_cardMapIndex)(cardMapSize / CARD_MAP_ELEM_SIZE);
+
+  return cardMapLength;
+}
+
+size_t sizeofCrossMap (GC_state s, size_t heapSize) {
+  unless (s->mutatorMarksCards) {
+    return 0;
+  }
+  assert (isAligned (heapSize, CARD_SIZE));
+
+  GC_crossMapIndex crossMapLength;
+  size_t crossMapSize;
+
+  crossMapLength = sizeToCrossMapIndex (heapSize);
+  crossMapSize = align (crossMapLength * CROSS_MAP_ELEM_SIZE, s->sysvals.pageSize);
+
+  return crossMapSize;
+}
+
+GC_crossMapIndex lenofCrossMap (__attribute__ ((unused)) GC_state s, size_t crossMapSize) {
+  GC_crossMapIndex crossMapLength;
+
+  assert (isAligned (crossMapSize, s->sysvals.pageSize));
+  assert (isAligned (crossMapSize, CROSS_MAP_ELEM_SIZE));
+
+  crossMapLength = (GC_crossMapIndex)(crossMapSize / CROSS_MAP_ELEM_SIZE);
+
+  return crossMapLength;
+}
+
 void clearCardMap (GC_state s) {
   if (DEBUG_GENERATIONAL and DEBUG_DETAILED)
     fprintf (stderr, "clearCardMap ()\n");
@@ -119,30 +175,13 @@
           s->generationalMaps.crossMapLength * CROSS_MAP_ELEM_SIZE);
 }
 
-/* Compute the number of bytes that are needed to store the card map and
-   cross map at the end of a heap with the given size. */
-size_t computeCardMapAndCrossMapSize (GC_state s, size_t size) {
-  unless (s->mutatorMarksCards) {
-    return 0;
-  }
-  assert (isAligned (size, CARD_SIZE));
-
-  GC_cardMapIndex cardMapLength;
-  size_t cardMapSize;
-  GC_crossMapIndex crossMapLength;
-  size_t crossMapSize;
+size_t sizeofCardMapAndCrossMap (GC_state s, size_t heapSize) {
   size_t totalMapSize;
 
-  cardMapLength = sizeToCardMapIndex (size);
-  cardMapSize = align (cardMapLength * CARD_MAP_ELEM_SIZE, s->sysvals.pageSize);
-  cardMapLength = (GC_cardMapIndex)(cardMapSize / CARD_MAP_ELEM_SIZE);
+  totalMapSize = sizeofCardMap (s, heapSize) + sizeofCrossMap (s, heapSize);
 
-  crossMapLength = sizeToCardMapIndex (size);
-  crossMapSize = align (crossMapLength * CROSS_MAP_ELEM_SIZE, s->sysvals.pageSize);
-  crossMapLength = (GC_crossMapIndex)(crossMapSize / CROSS_MAP_ELEM_SIZE);
+  assert (isAligned (totalMapSize, s->sysvals.pageSize));
 
-  totalMapSize = cardMapSize + crossMapSize;
-
   return totalMapSize;
 }
 

Modified: mlton/trunk/runtime/gc/generational.h
===================================================================
--- mlton/trunk/runtime/gc/generational.h	2008-08-20 00:43:27 UTC (rev 6773)
+++ mlton/trunk/runtime/gc/generational.h	2008-08-20 00:43:34 UTC (rev 6774)
@@ -61,11 +61,13 @@
                                      struct GC_generationalMaps *generational,
                                      FILE *stream);
 
-static inline GC_cardMapIndex pointerToCardMapIndexAbsolute (pointer p);
 static inline GC_cardMapIndex sizeToCardMapIndex (size_t z);
 static inline size_t cardMapIndexToSize (GC_cardMapIndex i);
+static inline GC_cardMapIndex pointerToCardMapIndexAbsolute (pointer p);
 static inline GC_cardMapElem *pointerToCardMapAddr (GC_state s, pointer p);
 
+static inline GC_crossMapIndex sizeToCrossMapIndex (size_t z);
+
 static inline bool isCardMarked (GC_state s, pointer p);
 static inline void markCard (GC_state s, pointer p);
 static inline void markIntergenerationalPointer (GC_state s, pointer *pp);
@@ -74,9 +76,14 @@
 static inline void setCardMapAbsolute (GC_state s);
 static inline pointer getCrossMapCardStart (GC_state s, pointer p);
 
+static inline size_t sizeofCardMap (GC_state s, size_t heapSize);
+static inline GC_cardMapIndex lenofCardMap (GC_state s, size_t cardMapSize);
+static inline size_t sizeofCrossMap (GC_state s, size_t heapSize);
+static inline GC_crossMapIndex lenofCrossMap (GC_state s, size_t crossMapSize);
+static size_t sizeofCardMapAndCrossMap (GC_state s, size_t heapSize);
+
 static inline void clearCardMap (GC_state s);
 static inline void clearCrossMap (GC_state s);
-static size_t computeCardMapAndCrossMapSize (GC_state s, size_t size);
 static void createCardMapAndCrossMap (GC_state s);
 static void copyCardMapAndCrossMap (GC_state s, GC_heap h);
 static void shrinkCardMapAndCrossMap (GC_state s, size_t keep);

Modified: mlton/trunk/runtime/gc/heap.c
===================================================================
--- mlton/trunk/runtime/gc/heap.c	2008-08-20 00:43:27 UTC (rev 6773)
+++ mlton/trunk/runtime/gc/heap.c	2008-08-20 00:43:34 UTC (rev 6774)
@@ -114,7 +114,7 @@
              "[GC: Releasing heap at "FMTPTR" of size %s bytes.]\n",
              (uintptr_t)(h->start),
              uintmaxToCommaString(h->size));
-  GC_release (h->start, h->size + computeCardMapAndCrossMapSize(s, h->size));
+  GC_release (h->start, h->size + sizeofCardMapAndCrossMap (s, h->size));
   initHeap (s, h);
 }
 
@@ -133,9 +133,9 @@
                (uintptr_t)(h->start),
                uintmaxToCommaString(h->size),
                uintmaxToCommaString(keep));
-    shrinkCardMapAndCrossMap(s, keep);
-    oldMapSize = computeCardMapAndCrossMapSize(s, h->size);
-    newMapSize = computeCardMapAndCrossMapSize(s, keep);
+    shrinkCardMapAndCrossMap (s, keep);
+    oldMapSize = sizeofCardMapAndCrossMap (s, h->size);
+    newMapSize = sizeofCardMapAndCrossMap (s, keep);
     GC_decommit (h->start + keep + newMapSize, h->size - keep + oldMapSize - newMapSize);
     h->size = keep;
   }
@@ -188,7 +188,7 @@
     static bool direction = TRUE;
     unsigned int i;
 
-    newWithMapsSize = newSize + computeCardMapAndCrossMapSize (s, newSize);
+    newWithMapsSize = newSize + sizeofCardMapAndCrossMap (s, newSize);
 
     assert (isAligned (newWithMapsSize, s->sysvals.pageSize));
 
@@ -276,12 +276,12 @@
     backoff = 1; /* enough to terminate the loop below */
   backoff = align (backoff, s->sysvals.pageSize);
   origSize = h->size;
-  origWithMapsSize = origSize + computeCardMapAndCrossMapSize (s, origSize);
+  origWithMapsSize = origSize + sizeofCardMapAndCrossMap (s, origSize);
   newSize = desiredSize;
   do {
     pointer newStart;
 
-    newWithMapsSize = newSize + computeCardMapAndCrossMapSize (s, newSize);
+    newWithMapsSize = newSize + sizeofCardMapAndCrossMap (s, newSize);
 
     assert (isAligned (newWithMapsSize, s->sysvals.pageSize));
 
@@ -366,7 +366,7 @@
     to = newHeap.start + size;
     remaining = size;
     copyCardMapAndCrossMap(s, &newHeap);
-    GC_decommit(orig + curHeapp->size, computeCardMapAndCrossMapSize(s, curHeapp->size));
+    GC_decommit(orig + curHeapp->size, sizeofCardMapAndCrossMap (s, curHeapp->size));
 copy:
     assert (remaining == (size_t)(from - curHeapp->start)
             and from >= curHeapp->start




More information about the MLton-commit mailing list