[MLton-commit] r7050

Matthew Fluet fluet at mlton.org
Wed Apr 8 05:31:29 PDT 2009


A function to invert card/cross map sizes of heaps.
----------------------------------------------------------------------

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

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

Modified: mlton/trunk/runtime/gc/generational.c
===================================================================
--- mlton/trunk/runtime/gc/generational.c	2009-04-08 12:31:25 UTC (rev 7049)
+++ mlton/trunk/runtime/gc/generational.c	2009-04-08 12:31:28 UTC (rev 7050)
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 2009 Matthew Fluet.
+ * Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -190,6 +191,61 @@
   return totalMapSize;
 }
 
+/*
+ * heapSize = invertSizeofCardMapAndCrossMap (s, heapWithMapsSize);
+ * implies
+ * heapSize + sizeofCardMapAndCrossMap (s, heapSize)
+ *  <= heapWithMapsSize
+ *  < (heapSize + s->sysvals.pageSize)
+ *    + sizeofCardMapAndCrossMap (s, heapSize + s->sysvals.pageSize)
+ */
+size_t invertSizeofCardMapAndCrossMap (GC_state s, size_t heapWithMapsSize) {
+  unless (s->mutatorMarksCards) {
+    return heapWithMapsSize;
+  }
+  assert (isAligned (heapWithMapsSize, s->sysvals.pageSize));
+
+  size_t minHeapSize;
+  if (heapWithMapsSize <= 3 * s->sysvals.pageSize) {
+    minHeapSize = 0;
+  } else {
+    double minHeapSizeD;
+    minHeapSizeD =
+      (((double)(CARD_SIZE)
+        / (double)(CARD_SIZE + CARD_MAP_ELEM_SIZE + CROSS_MAP_ELEM_SIZE))
+       * (double)(heapWithMapsSize - 3 * s->sysvals.pageSize)) -
+      (((double)(CARD_MAP_ELEM_SIZE + CROSS_MAP_ELEM_SIZE)
+        / (double)(CARD_SIZE + CARD_MAP_ELEM_SIZE + CROSS_MAP_ELEM_SIZE)) *
+       (double)(s->sysvals.pageSize));
+    minHeapSize = alignDown ((size_t)minHeapSizeD, s->sysvals.pageSize);
+  }
+
+  size_t heapSize = minHeapSize;
+  size_t nextHeapSize = heapSize + s->sysvals.pageSize;
+  /* The termination condition is:
+   *   heapWithMapsSize >= nextHeapSize + sizeofCardMapAndCrossMap (s, nextHeapSize)
+   * However, nextHeapSize + sizeofCardMapAndCrossMap (s, nextHeapSize) may overflow.
+   */
+  while (heapWithMapsSize >= sizeofCardMapAndCrossMap (s, nextHeapSize) and
+         heapWithMapsSize - sizeofCardMapAndCrossMap (s, nextHeapSize) >= nextHeapSize) {
+    heapSize = nextHeapSize;
+    nextHeapSize += s->sysvals.pageSize;
+  }
+
+  assert (isAligned (heapSize, s->sysvals.pageSize));
+  assert (heapSize + sizeofCardMapAndCrossMap (s, heapSize) <= heapWithMapsSize);
+  assert (nextHeapSize == heapSize + s->sysvals.pageSize);
+  assert (heapWithMapsSize < sizeofCardMapAndCrossMap (s, nextHeapSize) or
+          heapWithMapsSize - sizeofCardMapAndCrossMap (s, nextHeapSize) < nextHeapSize);
+
+  if (DEBUG_DETAILED)
+    fprintf (stderr, "invertSizeofCardMapAndCrossMap(%s) = %s\n",
+             uintmaxToCommaString(heapWithMapsSize),
+             uintmaxToCommaString(heapSize));
+
+  return heapSize;
+}
+
 void setCardMapAndCrossMap (GC_state s) {
   unless (s->mutatorMarksCards) {
     s->generationalMaps.cardMapLength = 0;

Modified: mlton/trunk/runtime/gc/generational.h
===================================================================
--- mlton/trunk/runtime/gc/generational.h	2009-04-08 12:31:25 UTC (rev 7049)
+++ mlton/trunk/runtime/gc/generational.h	2009-04-08 12:31:28 UTC (rev 7050)
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 2009 Matthew Fluet.
+ * Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -81,6 +82,7 @@
 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 size_t invertSizeofCardMapAndCrossMap (GC_state s, size_t heapWithMapsSize);
 
 static inline void clearCardMap (GC_state s);
 static inline void clearCrossMap (GC_state s);




More information about the MLton-commit mailing list