[MLton-commit] r4400

Stephen Weeks MLton@mlton.org
Wed, 19 Apr 2006 13:09:56 -0700


Fixed a bug in GC_share that could cause a segfault.  The problem was
that GC_share could introduce intergenerational pointers, but didn't
update the card map.  Now, it marks the appropriate card whenever it
creates an intergenerational pointer.


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

U   mlton/trunk/doc/changelog
U   mlton/trunk/runtime/gc.c

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

Modified: mlton/trunk/doc/changelog
===================================================================
--- mlton/trunk/doc/changelog	2006-04-19 02:46:47 UTC (rev 4399)
+++ mlton/trunk/doc/changelog	2006-04-19 20:09:54 UTC (rev 4400)
@@ -1,3 +1,10 @@
+Here are the changes since version 20051202.
+
+* 2006-04-19
+  - Fixed a bug in MLton.share that could cause a segfault.
+
+--------------------------------------------------------------------------------
+
 Here are the changes from version 20041109 to version 20051202.
 
 Summary:

Modified: mlton/trunk/runtime/gc.c
===================================================================
--- mlton/trunk/runtime/gc.c	2006-04-19 02:46:47 UTC (rev 4399)
+++ mlton/trunk/runtime/gc.c	2006-04-19 20:09:54 UTC (rev 4400)
@@ -880,12 +880,12 @@
         return s->nursery <= p and p < s->frontier;
 }
 
-#if ASSERT
-
 static inline bool isInOldGen (GC_state s, pointer p) {
         return s->heap.start <= p and p < s->heap.start + s->oldGenSize;
 }
 
+#if ASSERT
+
 static inline bool isInFromSpace (GC_state s, pointer p) {
         return (isInOldGen (s, p) or isInNursery (s, p));
 }
@@ -2094,6 +2094,13 @@
         return res;
 }
 
+static inline void markIntergenerational (GC_state s, Pointer *pp) {
+        if (s->mutatorMarksCards
+                and isInOldGen (s, (pointer)pp)
+                and isInNursery (s, *pp))
+                markCard (s, (pointer)pp);
+}
+
 static inline void maybeSharePointer (GC_state s,
                                         Pointer *pp, 
                                         Bool shouldHashCons) {
@@ -2103,6 +2110,7 @@
                 fprintf (stderr, "maybeSharePointer  pp = 0x%08x  *pp = 0x%08x\n",
                                 (uint)pp, (uint)*pp);
         *pp = hashCons (s, *pp, FALSE); 
+        markIntergenerational (s, pp);
 }
 
 /* ---------------------------------------------------------------- */
@@ -2377,6 +2385,8 @@
                 todo += index * POINTER_SIZE;
                 prev = *(pointer*)todo;
                 *(pointer*)todo = next;
+                if (shouldHashCons)
+                        markIntergenerational (s, (pointer*)todo);
                 goto markNextInNormal;
         } else if (ARRAY_TAG == tag) {
                 arrayIndex = arrayCounter (cur);
@@ -2386,6 +2396,8 @@
                 todo += numNonPointers + index * POINTER_SIZE;
                 prev = *(pointer*)todo;
                 *(pointer*)todo = next;
+                if (shouldHashCons)
+                        markIntergenerational (s, (pointer*)todo);
                 goto markNextInArray;
         } else {
                 assert (STACK_TAG == tag);
@@ -2396,6 +2408,8 @@
                 todo = top - layout->numBytes + frameOffsets [index + 1];
                 prev = *(pointer*)todo;
                 *(pointer*)todo = next;
+                if (shouldHashCons)
+                        markIntergenerational (s, (pointer*)todo);
                 index++;
                 goto markInFrame;
         }