[MLton-commit] r4084

Matthew Fluet MLton@mlton.org
Fri, 9 Sep 2005 15:48:11 -0700


Filling in forward assertion predicates
----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h

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

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile	2005-09-09 21:56:06 UTC (rev 4083)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile	2005-09-09 22:48:09 UTC (rev 4084)
@@ -71,6 +71,7 @@
 	frame.c								\
 	stack.c								\
 	thread.c							\
+	heap.c   							\
 	foreach.c							\
 	cheney-copy.c							\
 	assumptions.c							\

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c	2005-09-09 21:56:06 UTC (rev 4083)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c	2005-09-09 22:48:09 UTC (rev 4084)
@@ -19,12 +19,33 @@
  */
 struct forwardState {
   pointer back;
-  pointer fromBase;
-  pointer toBase;
+  pointer toStart;
   pointer toLimit;
 };
 static struct forwardState forwardState;
 
+static inline bool pointerIsInFromSpace (GC_state s, pointer p) {
+  return (pointerIsInOldGen (s, p) or pointerIsInNursery (s, p));
+}
+
+static inline bool objptrIsInFromSpace (GC_state s, objptr op) {
+  return (objptrIsInOldGen (s, op) or objptrIsInNursery (s, op));
+}
+
+static inline bool pointerIsInToSpace (pointer p) {
+  return (not (isPointer (p))
+          or (forwardState.toStart <= p and p < forwardState.toLimit));
+}
+
+static inline bool objptrIsInToSpace (objptr op) {
+  pointer p;
+
+  if (not (isObjptr (op)))
+    return TRUE;
+  p = objptrToPointer (op, forwardState.toStart);
+  return pointerIsInToSpace (p);
+}
+
 static inline void forward (GC_state s, objptr *opp) {
   objptr op;
   pointer p;
@@ -32,12 +53,12 @@
   GC_objectTypeTag tag;
 
   op = *opp;
-  p = objptrToPointer (op, forwardState.fromBase);
+  p = objptrToPointer (op, s->heap.start);
   if (DEBUG_DETAILED)
     fprintf (stderr,
              "forward  opp = "FMTPTR"  op = "FMTOBJPTR"  p = "FMTPTR"\n",
              (uintptr_t)opp, op, (uintptr_t)p);
-  // assert (isInFromSpace (s, *pp));
+  assert (objptrIsInFromSpace (s, *opp));
   header = getHeader (p);
   if (DEBUG_DETAILED and header == GC_FORWARDED)
     fprintf (stderr, "  already FORWARDED\n");
@@ -82,18 +103,17 @@
           if (new <= stack->reserved) {
             stack->reserved = new;
             if (DEBUG_STACKS)
-              fprintf (stderr, "Shrinking stack to size %"PRId32".\n",
+              fprintf (stderr, "Shrinking stack to size %zd.\n",
                        /*uintToCommaString*/(stack->reserved));
           }
         }
       } else {
-        /* Shrink heap stacks.
-         */
+        /* Shrink heap stacks. */
         stack->reserved = 
           stackReserved (s, maxZ((size_t)(s->threadShrinkRatio * stack->reserved),
                                  stack->used));
         if (DEBUG_STACKS)
-          fprintf (stderr, "Shrinking stack to size %"PRId32".\n",
+          fprintf (stderr, "Shrinking stack to size %zd.\n",
                    /*uintToCommaString*/(stack->reserved));
       }
       objectBytes = sizeof (struct GC_stack) + stack->used;
@@ -115,7 +135,7 @@
                  (uintptr_t)w);
       if (isObjptr (w->objptr)
           and (not s->amInMinorGC
-               or isInNursery (s, w->objptr))) {
+               or objptrIsInNursery (s, w->objptr))) {
         if (DEBUG_WEAK)
           fprintf (stderr, "linking\n");
         w->link = s->weaks;
@@ -127,14 +147,14 @@
     }
     /* Store the forwarding pointer in the old object. */
     *(GC_header*)(p - GC_HEADER_SIZE) = GC_FORWARDED;
-    *(objptr*)p = pointerToObjptr(forwardState.back + headerBytes, forwardState.toBase);
+    *(objptr*)p = pointerToObjptr(forwardState.back + headerBytes, forwardState.toStart);
     /* Update the back of the queue. */
     forwardState.back += size + skip;
     assert (isAligned ((uintptr_t)forwardState.back + GC_NORMAL_HEADER_SIZE, 
                        s->alignment));
   }
   *opp = *(objptr*)p;
-  // assert (isInToSpace (s, *opp));
+  assert (objptrIsInToSpace (*opp));
 }
 
 static inline void updateWeaks (GC_state s) {
@@ -146,7 +166,7 @@
 
     if (DEBUG_WEAK)
       fprintf (stderr, "updateWeaks  w = "FMTPTR"  ", (uintptr_t)w);
-    p = objptrToPointer (w->objptr, forwardState.fromBase);
+    p = objptrToPointer (w->objptr, s->heap.start);
     if (GC_FORWARDED == getHeader (p)) {
       if (DEBUG_WEAK)
         fprintf (stderr, "forwarded from "FMTOBJPTR" to "FMTOBJPTR"\n",

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h	2005-09-09 21:56:06 UTC (rev 4083)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h	2005-09-09 22:48:09 UTC (rev 4084)
@@ -7,9 +7,11 @@
   objptr currentThread; /* Currently executing thread (in heap). */
   GC_frameLayout *frameLayouts; /* Array of frame layouts. */
   uint32_t frameLayoutsSize; /* Cardinality of frameLayouts array. */
+  pointer frontier; /* heap.start <= frontier < limit */
   objptr *globals;
   uint32_t globalsSize;
   struct GC_heap heap;
+  pointer limit; /* limit = heap.start + heap.totalBytes */
   uint32_t maxFrameSize;
   GC_objectType *objectTypes; /* Array of object types. */
   uint32_t objectTypesSize; /* Cardinality of objectTypes array. */

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.h	2005-09-09 21:56:06 UTC (rev 4083)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.h	2005-09-09 22:48:09 UTC (rev 4084)
@@ -10,14 +10,16 @@
  * All ML objects (including ML execution stacks) are allocated in a
  * contiguous heap.  The heap has the following general layout:
  * 
- * ---------------------------------------------------
- * |                                                 |
- * ---------------------------------------------------
- * ^
- * start
+ *  ---------------------------------------------------
+ *  |    old generation    |              |  nursery  |
+ *  ---------------------------------------------------
+ *  ^                                     ^
+ *  start                                 nursery
 */
 
 typedef struct GC_heap {
-  size_t numBytes; /* size of heap */
-  pointer start; /* start of heap */
+  pointer nursery; /* start of nursery */
+  size_t oldGenBytes; /* size of old generation */
+  pointer start; /* start of heap (and old generation) */
+  size_t totalBytes; /* size of heap */
 } *GC_heap;

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h	2005-09-09 21:56:06 UTC (rev 4083)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h	2005-09-09 22:48:09 UTC (rev 4084)
@@ -37,11 +37,11 @@
   /* reserved is the number of bytes reserved for stack, 
    * i.e. its maximum size.
    */
-  uint32_t reserved;
+  size_t reserved;
   /* used is the number of bytes used by the stack.  
    * Stacks with used == reserved are continuations.
    */
-  uint32_t used;      
+  size_t used;      
   /* The next address is the bottom of the stack, and the following
    * reserved bytes hold space for the stack.
    */