[MLton-commit] r4128

Matthew Fluet MLton@mlton.org
Wed, 2 Nov 2005 07:01:30 -0800


More cleanups
----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/atomic.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/atomic.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/controls.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/controls.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/dfs-mark.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/enter_leave.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.h
A   mlton/branches/on-20050822-x86_64-branch/runtime/gc/forward.c
A   mlton/branches/on-20050822-x86_64-branch/runtime/gc/forward.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/garbage-collection.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/garbage-collection.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/hash-cons.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/hash-cons.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/init.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/invariant.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/mark-compact.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.h
A   mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.c
A   mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/pack.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/ratios.h
D   mlton/branches/on-20050822-x86_64-branch/runtime/gc/ratios_predicates.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/share.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/share.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/statistics.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/translate.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.c

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

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile	2005-11-02 15:01:11 UTC (rev 4128)
@@ -90,6 +90,7 @@
 	dfs-mark.c							\
 	enter_leave.c							\
 	foreach.c							\
+	forward.c							\
 	frame.c								\
 	garbage-collection.c						\
 	gc_state.c   							\
@@ -107,7 +108,6 @@
 	pack.c								\
 	pointer.c							\
 	pointer_predicates.c						\
-	ratios_predicates.c						\
 	share.c								\
 	size.c								\
 	stack.c								\
@@ -129,8 +129,9 @@
 	safe.h								\
 	rusage.h							\
 	virtual-memory.h						\
+	model.h								\
 	pointer.h							\
-	model.h								\
+	objptr.h							\
 	object.h							\
 	array.h								\
 	frame.h								\
@@ -145,9 +146,11 @@
 	current.h							\
 	foreach.h							\
 	statistics.h							\
-	controls.h							\
 	sysvals.h							\
 	ratios.h							\
+	controls.h							\
+	forward.h							\
+	cheney-copy.h							\
 	hash-cons.h							\
 	profiling.h							\
 	signals.h							\
@@ -158,15 +161,14 @@
 	atomic.h							\
 	invariant.h							\
 	enter_leave.h							\
-	cheney-copy.h							\
 	dfs-mark.h							\
-	share.h								\
 	mark-compact.h							\
 	new-object.h							\
 	garbage-collection.h						\
 	array-allocate.h						\
 	copy-thread.h							\
 	pack.h								\
+	share.h								\
 	size.h								\
 	gc_suffix.h
 

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/atomic.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/atomic.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/atomic.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -6,13 +6,13 @@
  * See the file MLton-LICENSE for details.
  */
 
-void atomicBegin (GC_state s) {
+void beginAtomic (GC_state s) {
   s->atomicState++;
   if (0 == s->limit)
     s->limit = s->limitPlusSlop - GC_HEAP_LIMIT_SLOP;
 }
 
-void atomicEnd (GC_state s) {
+void endAtomic (GC_state s) {
   s->atomicState--;
   if (0 == s->atomicState 
       and s->signalsInfo.signalIsPending)

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/atomic.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/atomic.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/atomic.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -6,5 +6,5 @@
  * See the file MLton-LICENSE for details.
  */
 
-void atomicBegin (GC_state s);
-void atomicEnd (GC_state s);
+void beginAtomic (GC_state s);
+void endAtomic (GC_state s);

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-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -10,156 +10,15 @@
 /*                    Cheney Copying Collection                     */
 /* ---------------------------------------------------------------- */
 
-#define GC_FORWARDED ~((GC_header)0)
-
-/* forward (s, opp) 
- * Forwards the object pointed to by *opp and updates *opp to point to
- * the new object.  
- * It also updates the crossMap.
- */
-struct forwardState {
-  bool amInMinorGC;
-  pointer back;
-  pointer toStart;
-  pointer toLimit;
-};
-static struct forwardState forwardState;
-
-bool isPointerInToSpace (pointer p) {
-  return (not (isPointer (p))
-          or (forwardState.toStart <= p and p < forwardState.toLimit));
-}
-
-bool isObjptrInToSpace (objptr op) {
+void updateWeaksForCheneyCopy (GC_state s) {
   pointer p;
-
-  if (not (isObjptr (op)))
-    return TRUE;
-  p = objptrToPointer (op, forwardState.toStart);
-  return isPointerInToSpace (p);
-}
-
-void forwardObjptr (GC_state s, objptr *opp) {
-  objptr op;
-  pointer p;
-  GC_header header;
-
-  op = *opp;
-  p = objptrToPointer (op, s->heap.start);
-  if (DEBUG_DETAILED)
-    fprintf (stderr,
-             "forwardObjptr  opp = "FMTPTR"  op = "FMTOBJPTR"  p = "FMTPTR"\n",
-             (uintptr_t)opp, op, (uintptr_t)p);
-  assert (isObjptrInFromSpace (s, *opp));
-  header = getHeader (p);
-  if (DEBUG_DETAILED and header == GC_FORWARDED)
-    fprintf (stderr, "  already FORWARDED\n");
-  if (header != GC_FORWARDED) { /* forward the object */
-    uint16_t numNonObjptrs, numObjptrs;
-    GC_objectTypeTag tag;
-
-    splitHeader(s, header, &tag, NULL, &numNonObjptrs, &numObjptrs);
-
-    size_t headerBytes, objectBytes, size, skip;
-
-    /* Compute the space taken by the header and object body. */
-    if ((NORMAL_TAG == tag) or (WEAK_TAG == tag)) { /* Fixed size object. */
-      headerBytes = GC_NORMAL_HEADER_SIZE;
-      objectBytes = sizeofNormalNoHeader (s, numNonObjptrs, numObjptrs);
-      skip = 0;
-    } else if (ARRAY_TAG == tag) {
-      headerBytes = GC_ARRAY_HEADER_SIZE;
-      objectBytes = sizeofArrayNoHeader (s, getArrayLength (p), 
-                                         numNonObjptrs, numObjptrs);
-      skip = 0;
-    } else { /* Stack. */
-      GC_stack stack;
-
-      assert (STACK_TAG == tag);
-      headerBytes = GC_STACK_HEADER_SIZE;
-      stack = (GC_stack)p;
-
-      if (getStackCurrentObjptr(s) == op) {
-        /* Shrink stacks that don't use a lot of their reserved space;
-         * but don't violate the stack invariant.
-         */
-        if (stack->used <= stack->reserved / 4) {
-          size_t new = 
-            alignStackReserved 
-            (s, max (stack->reserved / 2, 
-                     sizeofStackMinimumReserved (s, stack)));
-          /* It's possible that new > stack->reserved if the stack
-           * invariant is violated. In that case, we want to leave the
-           * stack alone, because some other part of the gc will grow
-           * the stack.  We cannot do any growing here because we may
-           * run out of to space.
-           */
-          if (new <= stack->reserved) {
-            stack->reserved = new;
-            if (DEBUG_STACKS)
-              fprintf (stderr, "Shrinking stack to size %zu.\n",
-                       /*uintToCommaString*/(stack->reserved));
-          }
-        }
-      } else {
-        /* Shrink heap stacks. */
-        stack->reserved = 
-          alignStackReserved 
-          (s, max((size_t)(s->ratios.threadShrink * stack->reserved), stack->used));
-        if (DEBUG_STACKS)
-          fprintf (stderr, "Shrinking stack to size %zu.\n",
-                   /*uintToCommaString*/(stack->reserved));
-      }
-      objectBytes = sizeof (struct GC_stack) + stack->used;
-      skip = stack->reserved - stack->used;
-    }
-    size = headerBytes + objectBytes;
-    assert (forwardState.back + size + skip <= forwardState.toLimit);
-    /* Copy the object. */
-    GC_memcpy (p - headerBytes, forwardState.back, size);
-    /* If the object has a valid weak pointer, link it into the weaks
-     * for update after the copying GC is done.
-     */
-    if ((WEAK_TAG == tag) and (numObjptrs == 1)) {
-      GC_weak w;
-      
-      w = (GC_weak)(forwardState.back + GC_NORMAL_HEADER_SIZE);
-      if (DEBUG_WEAK)
-        fprintf (stderr, "forwarding weak "FMTPTR" ",
-                 (uintptr_t)w);
-      if (isObjptr (w->objptr)
-          and (not forwardState.amInMinorGC
-               or isObjptrInNursery (s, w->objptr))) {
-        if (DEBUG_WEAK)
-          fprintf (stderr, "linking\n");
-        w->link = s->weaks;
-        s->weaks = w;
-      } else {
-        if (DEBUG_WEAK)
-          fprintf (stderr, "not linking\n");
-      }
-    }
-    /* Store the forwarding pointer in the old object. */
-    *(GC_header*)(p - GC_HEADER_SIZE) = GC_FORWARDED;
-    *(objptr*)p = pointerToObjptr(forwardState.back + headerBytes, forwardState.toStart);
-    /* Update the back of the queue. */
-    forwardState.back += size + skip;
-    assert (isAligned ((size_t)forwardState.back + GC_NORMAL_HEADER_SIZE, 
-                       s->alignment));
-  }
-  *opp = *(objptr*)p;
-  assert (isObjptrInToSpace (*opp));
-}
-
-void updateWeaks (GC_state s) {
-  pointer p;
   GC_weak w;
 
   for (w = s->weaks; w != NULL; w = w->link) {
     assert (BOGUS_OBJPTR != w->objptr);
 
     if (DEBUG_WEAK)
-      fprintf (stderr, "updateWeaks  w = "FMTPTR"  ", (uintptr_t)w);
+      fprintf (stderr, "updateWeaksForCheneyCopy  w = "FMTPTR"  ", (uintptr_t)w);
     p = objptrToPointer (w->objptr, s->heap.start);
     if (GC_FORWARDED == getHeader (p)) {
       if (DEBUG_WEAK)
@@ -177,7 +36,7 @@
   s->weaks = NULL;
 }
 
-void swapHeaps (GC_state s) {
+void swapHeapsForCheneyCopy (GC_state s) {
   struct GC_heap tempHeap;
   
   tempHeap = s->secondaryHeap;
@@ -194,9 +53,9 @@
   if (detailedGCTime (s))
     startTiming (&ru_start);
   s->cumulativeStatistics.numCopyingGCs++;
-  forwardState.amInMinorGC = FALSE;
-  forwardState.toStart = s->secondaryHeap.start;
-  forwardState.toLimit = s->secondaryHeap.start + s->secondaryHeap.size;
+  s->forwardState.amInMinorGC = FALSE;
+  s->forwardState.toStart = s->secondaryHeap.start;
+  s->forwardState.toLimit = s->secondaryHeap.start + s->secondaryHeap.size;
   if (DEBUG or s->controls.messages) {
     fprintf (stderr, "Major copying GC.\n");
     fprintf (stderr, "fromSpace = "FMTPTR" of size %zu\n",
@@ -214,16 +73,16 @@
    */
   assert (s->secondaryHeap.size >= s->heap.oldGenSize);
   toStart = alignFrontier (s, s->secondaryHeap.start);
-  forwardState.back = toStart;
+  s->forwardState.back = toStart;
   foreachGlobalObjptr (s, forwardObjptr);
-  foreachObjptrInRange (s, toStart, &forwardState.back, TRUE, forwardObjptr);
-  updateWeaks (s);
-  s->secondaryHeap.oldGenSize = forwardState.back - s->secondaryHeap.start;
+  foreachObjptrInRange (s, toStart, &s->forwardState.back, forwardObjptr, TRUE);
+  updateWeaksForCheneyCopy (s);
+  s->secondaryHeap.oldGenSize = s->forwardState.back - s->secondaryHeap.start;
   s->cumulativeStatistics.bytesCopied += s->secondaryHeap.oldGenSize;
   if (DEBUG)
     fprintf (stderr, "%zu bytes live.\n",
              /*uintToCommaString*/(s->secondaryHeap.oldGenSize));
-  swapHeaps (s);
+  swapHeapsForCheneyCopy (s);
   clearCrossMap (s);
   s->lastMajorStatistics.kind = GC_COPYING;
   if (detailedGCTime (s))
@@ -236,111 +95,6 @@
 /*                 Minor Cheney Copying Collection                  */
 /* ---------------------------------------------------------------- */
 
-void forwardObjptrIfInNursery (GC_state s, objptr *opp) {
-  objptr op;
-  pointer p;
-
-  op = *opp;
-  p = objptrToPointer (op, s->heap.start);
-  if (p < s->heap.nursery)
-    return;
-  if (DEBUG_GENERATIONAL)
-    fprintf (stderr,
-             "forwardObjptrIfInNursery  opp = "FMTPTR"  op = "FMTOBJPTR"  p = "FMTPTR"\n",
-             (uintptr_t)opp, op, (uintptr_t)p);
-  assert (s->heap.nursery <= p and p < s->limitPlusSlop);
-  forwardObjptr (s, opp);
-}
-
-/* Walk through all the cards and forward all intergenerational pointers. */
-void forwardInterGenerationalObjptrs (GC_state s) {
-  GC_cardMapElem *cardMap;
-  GC_crossMapElem *crossMap;
-  pointer oldGenStart, oldGenEnd;
-
-  size_t cardIndex, maxCardIndex;
-  pointer cardStart, cardEnd;
-  pointer objectStart;
-  
-  if (DEBUG_GENERATIONAL)
-    fprintf (stderr, "Forwarding inter-generational pointers.\n");
-  updateCrossMap (s);
-  /* Constants. */
-  cardMap = s->generationalMaps.cardMap;
-  crossMap = s->generationalMaps.crossMap;
-  maxCardIndex = sizeToCardMapIndex (align (s->heap.oldGenSize, CARD_SIZE));
-  oldGenStart = s->heap.start;
-  oldGenEnd = oldGenStart + s->heap.oldGenSize;
-  /* Loop variables*/
-  objectStart = alignFrontier (s, s->heap.start);
-  cardIndex = 0;
-  cardStart = oldGenStart;
-checkAll:
-  assert (cardIndex <= maxCardIndex);
-  assert (isAlignedFrontier (s, objectStart));
-  if (cardIndex == maxCardIndex)
-    goto done;
-checkCard:
-  if (DEBUG_GENERATIONAL)
-    fprintf (stderr, "checking card %zu  objectStart = "FMTPTR"\n",
-             cardIndex, (uintptr_t)objectStart);
-  assert (objectStart < oldGenStart + cardMapIndexToSize (cardIndex + 1));
-  if (cardMap[cardIndex]) {
-    pointer lastObject;
-    size_t size;
-    
-    s->cumulativeStatistics.markedCards++;
-    if (DEBUG_GENERATIONAL)
-      fprintf (stderr, "card %zu is marked  objectStart = "FMTPTR"\n", 
-               cardIndex, (uintptr_t)objectStart);
-    lastObject = objectStart;
-skipObjects:
-    assert (isAlignedFrontier (s, objectStart));
-    size = sizeofObject (s, advanceToObjectData (s, objectStart));
-    if (objectStart + size < cardStart) {
-      objectStart += size;
-      goto skipObjects;
-    }
-    s->cumulativeStatistics.minorBytesSkipped += objectStart - lastObject;
-    cardEnd = cardStart + CARD_SIZE;
-    if (oldGenEnd < cardEnd) 
-      cardEnd = oldGenEnd;
-    assert (objectStart < cardEnd);
-    lastObject = objectStart;
-    /* If we ever add Weak.set, then there could be intergenerational
-     * weak pointers, in which case we would need to link the weak
-     * objects into s->weaks.  But for now, since there is no
-     * Weak.set, the foreachObjptrInRange will do the right thing on
-     * weaks, since the weak pointer will never be into the nursery.
-     */
-    objectStart = foreachObjptrInRange (s, objectStart, &cardEnd, 
-                                        FALSE, forwardObjptrIfInNursery);
-    s->cumulativeStatistics.minorBytesScanned += objectStart - lastObject;
-    if (objectStart == oldGenEnd)
-      goto done;
-    cardIndex = sizeToCardMapIndex (objectStart - oldGenStart);
-    cardStart = oldGenStart + cardMapIndexToSize (cardIndex);
-    goto checkCard;
-  } else {
-    unless (CROSS_MAP_EMPTY == crossMap[cardIndex])
-      objectStart = cardStart + (size_t)(crossMap[cardIndex]);
-    if (DEBUG_GENERATIONAL)
-      fprintf (stderr, 
-               "card %zu is not marked"
-               "  crossMap[%zu] == %zu"
-               "  objectStart = "FMTPTR"\n", 
-               cardIndex, cardIndex, 
-               (size_t)(crossMap[cardIndex]), (uintptr_t)objectStart);
-    cardIndex++;
-    cardStart += CARD_SIZE;
-    goto checkAll;
-  }
-  assert (FALSE);
-done:
-  if (DEBUG_GENERATIONAL)
-    fprintf (stderr, "Forwarding inter-generational pointers done.\n");
-}
-
 void minorCheneyCopyGC (GC_state s) {
   size_t bytesAllocated;
   size_t bytesCopied;
@@ -362,25 +116,25 @@
       fprintf (stderr, "Minor copying GC.\n");
     if (detailedGCTime (s))
       startTiming (&ru_start);
-    forwardState.amInMinorGC = TRUE;
-    forwardState.toStart = s->heap.start + s->heap.oldGenSize;
+    s->forwardState.amInMinorGC = TRUE;
+    s->forwardState.toStart = s->heap.start + s->heap.oldGenSize;
     if (DEBUG_GENERATIONAL)
-      fprintf (stderr, "toStart = "FMTPTR"\n", (uintptr_t)forwardState.toStart);
-    assert (isAlignedFrontier (s, forwardState.toStart));
-    forwardState.toLimit = forwardState.toStart + bytesAllocated;
+      fprintf (stderr, "toStart = "FMTPTR"\n", (uintptr_t)s->forwardState.toStart);
+    assert (isAlignedFrontier (s, s->forwardState.toStart));
+    s->forwardState.toLimit = s->forwardState.toStart + bytesAllocated;
     assert (invariant (s));
     s->cumulativeStatistics.numMinorGCs++;
     s->lastMajorStatistics.numMinorGCs++;
-    forwardState.back = forwardState.toStart;
+    s->forwardState.back = s->forwardState.toStart;
     /* Forward all globals.  Would like to avoid doing this once all
      * the globals have been assigned.
      */
     foreachGlobalObjptr (s, forwardObjptrIfInNursery);
     forwardInterGenerationalObjptrs (s);
-    foreachObjptrInRange (s, forwardState.toStart, &forwardState.back, 
-                          TRUE, forwardObjptrIfInNursery);
-    updateWeaks (s);
-    bytesCopied = forwardState.back - forwardState.toStart;
+    foreachObjptrInRange (s, s->forwardState.toStart, &s->forwardState.back, 
+                          forwardObjptrIfInNursery, TRUE);
+    updateWeaksForCheneyCopy (s);
+    bytesCopied = s->forwardState.back - s->forwardState.toStart;
     s->cumulativeStatistics.bytesCopiedMinor += bytesCopied;
     s->heap.oldGenSize += bytesCopied;
     if (detailedGCTime (s))

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -6,12 +6,7 @@
  * See the file MLton-LICENSE for details.
  */
 
-bool pointerIsInToSpace (pointer p);
-bool objptrIsInToSpace (objptr op);
-void forwardObjptr (GC_state s, objptr *opp);
-void updateWeaks (GC_state s);
-void swapHeaps (GC_state s);
+void updateWeaksForCheneyCopy (GC_state s);
+void swapHeapsForCheneyCopy (GC_state s);
 void majorCheneyCopyGC (GC_state s);
-void forwardObjptrIfInNursery (GC_state s, objptr *opp);
-void forwardInterGenerationalObjptrs (GC_state s);
 void minorCheneyCopyGC (GC_state s);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/controls.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/controls.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/controls.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -9,3 +9,10 @@
 bool detailedGCTime (GC_state s) {
   return s->controls.summary;
 }
+
+bool needGCTime (GC_state s) {
+  return 
+    DEBUG 
+    or s->controls.summary 
+    or s->controls.messages;
+}

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/controls.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/controls.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/controls.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -13,7 +13,9 @@
   bool mayProcessAtMLton;
   bool messages; /* Print a message at the start and end of each gc. */
   size_t oldGenArraySize; /* Arrays larger are allocated in old gen, if possible. */
+  struct GC_ratios ratios;
   bool summary; /* Print a summary of gc info when program exits. */
 };
 
 bool detailedGCTime (GC_state s);
+bool needGCTime (GC_state s);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -24,22 +24,3 @@
   pointer p = objptrToPointer(getStackCurrentObjptr(s), s->heap.start);
   return (GC_stack)p;
 }
-
-size_t sizeofStackCurrentUsed (GC_state s) {
-  return s->stackTop - s->stackBottom;
-}
-
-
-
-void setThreadAndStackCurrent (GC_state s) {
-  GC_thread thread;
-  GC_stack stack;
-  
-  thread = getThreadCurrent (s);
-  s->exnStack = thread->exnStack;
-  stack = getStackCurrent (s);
-  s->stackBottom = getStackBottom (s, stack);
-  s->stackTop = getStackTop (s, stack);
-  s->stackLimit = getStackLimit (s, stack);
-  markCard (s, (pointer)stack);
-}

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -10,6 +10,3 @@
 GC_thread getThreadCurrent (GC_state s);
 objptr getStackCurrentObjptr (GC_state s);
 GC_stack getStackCurrent (GC_state s);
-size_t sizeofStackCurrentUsed (GC_state s);
-
-void setThreadAndStackCurrent (GC_state s);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/dfs-mark.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/dfs-mark.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/dfs-mark.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -148,7 +148,7 @@
       /* There is nothing to mark. */
 normalDone:
       if (shouldHashCons)
-        cur = hashCons (s, cur, TRUE);
+        cur = hashConsPointer (s, cur, TRUE);
       goto ret;
     }
     todo = cur + sizeofNumNonObjptrs (NORMAL_TAG, numNonObjptrs);
@@ -174,7 +174,8 @@
     nextHeaderp = getHeaderp (next);
     nextHeader = *nextHeaderp;
     if (mark == (nextHeader & MARK_MASK)) {
-      maybeShareObjptr (s, (objptr*)todo, shouldHashCons);
+      if (shouldHashCons)
+        shareObjptr (s, (objptr*)todo);
       goto markNextInNormal;
     }
     *headerp = (header & ~COUNTER_MASK) | (index << COUNTER_SHIFT);
@@ -197,7 +198,7 @@
       /* There is nothing to mark. */
 arrayDone:
       if (shouldHashCons)
-        cur = hashCons (s, cur, TRUE);
+        cur = hashConsPointer (s, cur, TRUE);
       goto ret;
     }
     /* Begin marking first element. */
@@ -237,7 +238,8 @@
     nextHeaderp = getHeaderp (next);
     nextHeader = *nextHeaderp;
     if (mark == (nextHeader & MARK_MASK)) {
-      maybeShareObjptr (s, (objptr*)todo, shouldHashCons);
+      if (shouldHashCons)
+        shareObjptr (s, (objptr*)todo);
       goto markNextInArray;
     }
     /* Recur and mark next. */
@@ -287,7 +289,8 @@
     nextHeader = *nextHeaderp;
     if (mark == (nextHeader & MARK_MASK)) {
       index++;
-      maybeShareObjptr (s, (objptr*)todo, shouldHashCons);
+      if (shouldHashCons)
+        shareObjptr (s, (objptr*)todo);
       goto markInFrame;
     }
     ((GC_stack)cur)->markIndex = index;

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/enter_leave.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/enter_leave.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/enter_leave.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -15,11 +15,11 @@
   if (DEBUG)
     fprintf (stderr, "enter\n");
   /* used needs to be set because the mutator has changed s->stackTop. */
-  getStackCurrent(s)->used = sizeofStackCurrentUsed (s);
+  getStackCurrent(s)->used = sizeofGCStateCurrentStackUsed (s);
   getThreadCurrent(s)->exnStack = s->exnStack;
   if (DEBUG) 
     displayGCState (s, stderr);
-  atomicBegin (s);
+  beginAtomic (s);
   assert (invariant (s));
   if (DEBUG)
     fprintf (stderr, "enter ok\n");
@@ -32,7 +32,7 @@
    * for functions that don't ensureBytesFree.
    */
   assert (mutatorInvariant (s, FALSE, TRUE));
-  atomicEnd (s);
+  endAtomic (s);
   if (DEBUG)
     fprintf (stderr, "leave ok\n");
 }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -6,7 +6,7 @@
  * See the file MLton-LICENSE for details.
  */
 
-void maybeCall (GC_state s, GC_foreachObjptrFun f, objptr *opp) {
+void callIfIsObjptr (GC_state s, GC_foreachObjptrFun f, objptr *opp) {
   if (isObjptr (*opp))
     f (s, opp);
 }
@@ -19,18 +19,18 @@
   for (unsigned int i = 0; i < s->globalsLength; ++i) {
     if (DEBUG_DETAILED)
       fprintf (stderr, "foreachGlobal %u\n", i);
-    maybeCall (s, f, &s->globals [i]);
+    callIfIsObjptr (s, f, &s->globals [i]);
   }
   if (DEBUG_DETAILED)
     fprintf (stderr, "foreachGlobal threads\n");
-  maybeCall (s, f, &s->callFromCHandlerThread);
-  maybeCall (s, f, &s->currentThread);
-  maybeCall (s, f, &s->savedThread);
-  maybeCall (s, f, &s->signalHandlerThread);
+  callIfIsObjptr (s, f, &s->callFromCHandlerThread);
+  callIfIsObjptr (s, f, &s->currentThread);
+  callIfIsObjptr (s, f, &s->savedThread);
+  callIfIsObjptr (s, f, &s->signalHandlerThread);
 }
 
 
-/* foreachObjptrInObject (s, p, skipWeaks, f) 
+/* foreachObjptrInObject (s, p, f, skipWeaks) 
  * 
  * Applies f to each object pointer in the object pointed to by p.
  * Returns pointer to the end of object, i.e. just past object.
@@ -38,7 +38,7 @@
  * If skipWeaks, then the object pointer in weak objects is skipped.
  */
 pointer foreachObjptrInObject (GC_state s, pointer p,
-                               bool skipWeaks, GC_foreachObjptrFun f) {
+                               GC_foreachObjptrFun f, bool skipWeaks) {
   GC_header header;
   uint16_t numNonObjptrs;
   uint16_t numObjptrs;
@@ -64,12 +64,12 @@
         fprintf (stderr, 
                  "  p = "FMTPTR"  *p = "FMTOBJPTR"\n",
                  (uintptr_t)p, *(objptr*)p);
-      maybeCall (s, f, (objptr*)p);
+      callIfIsObjptr (s, f, (objptr*)p);
     }
   } else if (WEAK_TAG == tag) {
     p += sizeofNumNonObjptrs (NORMAL_TAG, numNonObjptrs);
     if (not skipWeaks and 1 == numObjptrs) {
-      maybeCall (s, f, (objptr*)p);
+      callIfIsObjptr (s, f, (objptr*)p);
       p += OBJPTR_SIZE;
     }
   } else if (ARRAY_TAG == tag) {
@@ -97,7 +97,7 @@
       if (0 == numNonObjptrs)
         /* Array with only pointers. */
         for ( ; p < last; p += OBJPTR_SIZE)
-          maybeCall (s, f, (objptr*)p);
+          callIfIsObjptr (s, f, (objptr*)p);
       else {
         /* Array with a mix of pointers and non-pointers. */
         size_t nonObjptrBytes;
@@ -115,7 +115,7 @@
           next = p + objptrBytes;
           /* For each internal pointer. */
           for ( ; p < next; p += OBJPTR_SIZE) 
-            maybeCall (s, f, (objptr*)p);
+            callIfIsObjptr (s, f, (objptr*)p);
         }
       }
       assert (p == last);
@@ -153,7 +153,7 @@
         if (DEBUG)
           fprintf(stderr, "  offset %"PRIx16"  address "FMTOBJPTR"\n",
                   frameOffsets[i + 1], *(objptr*)(top + frameOffsets[i + 1]));
-        maybeCall (s, f, (objptr*)(top + frameOffsets[i + 1]));
+        callIfIsObjptr (s, f, (objptr*)(top + frameOffsets[i + 1]));
       }
     }
     assert(top == bottom);
@@ -162,7 +162,7 @@
   return p;
 }
 
-/* foreachObjptrInRange (s, front, back, skipWeaks, f)
+/* foreachObjptrInRange (s, front, back, f, skipWeaks)
  *
  * Apply f to each pointer between front and *back, which should be a
  * contiguous sequence of objects, where front points at the beginning
@@ -175,7 +175,7 @@
  */
 
 pointer foreachObjptrInRange (GC_state s, pointer front, pointer *back,
-                              bool skipWeaks, GC_foreachObjptrFun f) {
+                              GC_foreachObjptrFun f, bool skipWeaks) {
   pointer b;
 
   assert (isAlignedFrontier (s, front));
@@ -192,7 +192,7 @@
         fprintf (stderr, 
                  "  front = "FMTPTR"  *back = "FMTPTR"\n",
                  (uintptr_t)front, (uintptr_t)(*back));
-      front = foreachObjptrInObject (s, advanceToObjectData (s, front), skipWeaks, f);
+      front = foreachObjptrInObject (s, advanceToObjectData (s, front), f, skipWeaks);
     }
     b = *back;
   }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -8,7 +8,7 @@
 
 typedef void (*GC_foreachObjptrFun) (GC_state s, objptr *opp);
 
-void maybeCall (GC_state s, GC_foreachObjptrFun f, objptr *opp);
+void callIfIsObjptr (GC_state s, GC_foreachObjptrFun f, objptr *opp);
 /* foreachGlobalObjptr (s, f)
  * 
  * Apply f to each global object pointer into the heap. 
@@ -22,8 +22,8 @@
  * If skipWeaks, then the object pointer in weak objects is skipped.
  */
 pointer foreachObjptrInObject (GC_state s, pointer p,
-                               bool skipWeaks, GC_foreachObjptrFun f);
-/* foreachObjptrInRange (s, front, back, skipWeaks, f)
+                               GC_foreachObjptrFun f, bool skipWeaks);
+/* foreachObjptrInRange (s, front, back, f, skipWeaks)
  *
  * Apply f to each pointer between front and *back, which should be a
  * contiguous sequence of objects, where front points at the beginning
@@ -35,7 +35,7 @@
  * If skipWeaks, then the object pointer in weak objects is skipped.
  */
 pointer foreachObjptrInRange (GC_state s, pointer front, pointer *back,
-                              bool skipWeaks, GC_foreachObjptrFun f);
+                              GC_foreachObjptrFun f, bool skipWeaks);
 
 
 typedef void (*GC_foreachStackFrameFun) (GC_state s, GC_frameIndex i);

Copied: mlton/branches/on-20050822-x86_64-branch/runtime/gc/forward.c (from rev 4127, 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-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/forward.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -0,0 +1,245 @@
+/* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh
+ *    Jagannathan, and Stephen Weeks.
+ * Copyright (C) 1997-2000 NEC Research Institute.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ */
+
+bool isPointerInToSpace (GC_state s, pointer p) {
+  return (not (isPointer (p))
+          or (s->forwardState.toStart <= p and p < s->forwardState.toLimit));
+}
+
+bool isObjptrInToSpace (GC_state s, objptr op) {
+  pointer p;
+
+  if (not (isObjptr (op)))
+    return TRUE;
+  p = objptrToPointer (op, s->forwardState.toStart);
+  return isPointerInToSpace (s, p);
+}
+
+/* forward (s, opp) 
+ * Forwards the object pointed to by *opp and updates *opp to point to
+ * the new object.  
+ * It also updates the crossMap.
+ */
+void forwardObjptr (GC_state s, objptr *opp) {
+  objptr op;
+  pointer p;
+  GC_header header;
+
+  op = *opp;
+  p = objptrToPointer (op, s->heap.start);
+  if (DEBUG_DETAILED)
+    fprintf (stderr,
+             "forwardObjptr  opp = "FMTPTR"  op = "FMTOBJPTR"  p = "FMTPTR"\n",
+             (uintptr_t)opp, op, (uintptr_t)p);
+  assert (isObjptrInFromSpace (s, *opp));
+  header = getHeader (p);
+  if (DEBUG_DETAILED and header == GC_FORWARDED)
+    fprintf (stderr, "  already FORWARDED\n");
+  if (header != GC_FORWARDED) { /* forward the object */
+    uint16_t numNonObjptrs, numObjptrs;
+    GC_objectTypeTag tag;
+
+    splitHeader(s, header, &tag, NULL, &numNonObjptrs, &numObjptrs);
+
+    size_t headerBytes, objectBytes, size, skip;
+
+    /* Compute the space taken by the header and object body. */
+    if ((NORMAL_TAG == tag) or (WEAK_TAG == tag)) { /* Fixed size object. */
+      headerBytes = GC_NORMAL_HEADER_SIZE;
+      objectBytes = sizeofNormalNoHeader (s, numNonObjptrs, numObjptrs);
+      skip = 0;
+    } else if (ARRAY_TAG == tag) {
+      headerBytes = GC_ARRAY_HEADER_SIZE;
+      objectBytes = sizeofArrayNoHeader (s, getArrayLength (p), 
+                                         numNonObjptrs, numObjptrs);
+      skip = 0;
+    } else { /* Stack. */
+      GC_stack stack;
+
+      assert (STACK_TAG == tag);
+      headerBytes = GC_STACK_HEADER_SIZE;
+      stack = (GC_stack)p;
+
+      if (getStackCurrentObjptr(s) == op) {
+        /* Shrink stacks that don't use a lot of their reserved space;
+         * but don't violate the stack invariant.
+         */
+        if (stack->used <= stack->reserved / 4) {
+          size_t new = 
+            alignStackReserved 
+            (s, max (stack->reserved / 2, 
+                     sizeofStackMinimumReserved (s, stack)));
+          /* It's possible that new > stack->reserved if the stack
+           * invariant is violated. In that case, we want to leave the
+           * stack alone, because some other part of the gc will grow
+           * the stack.  We cannot do any growing here because we may
+           * run out of to space.
+           */
+          if (new <= stack->reserved) {
+            stack->reserved = new;
+            if (DEBUG_STACKS)
+              fprintf (stderr, "Shrinking stack to size %zu.\n",
+                       /*uintToCommaString*/(stack->reserved));
+          }
+        }
+      } else {
+        /* Shrink heap stacks. */
+        stack->reserved = 
+          alignStackReserved 
+          (s, max((size_t)(s->controls.ratios.threadShrink * stack->reserved), 
+                  stack->used));
+        if (DEBUG_STACKS)
+          fprintf (stderr, "Shrinking stack to size %zu.\n",
+                   /*uintToCommaString*/(stack->reserved));
+      }
+      objectBytes = sizeof (struct GC_stack) + stack->used;
+      skip = stack->reserved - stack->used;
+    }
+    size = headerBytes + objectBytes;
+    assert (s->forwardState.back + size + skip <= s->forwardState.toLimit);
+    /* Copy the object. */
+    GC_memcpy (p - headerBytes, s->forwardState.back, size);
+    /* If the object has a valid weak pointer, link it into the weaks
+     * for update after the copying GC is done.
+     */
+    if ((WEAK_TAG == tag) and (numObjptrs == 1)) {
+      GC_weak w;
+      
+      w = (GC_weak)(s->forwardState.back + GC_NORMAL_HEADER_SIZE);
+      if (DEBUG_WEAK)
+        fprintf (stderr, "forwarding weak "FMTPTR" ",
+                 (uintptr_t)w);
+      if (isObjptr (w->objptr)
+          and (not s->forwardState.amInMinorGC
+               or isObjptrInNursery (s, w->objptr))) {
+        if (DEBUG_WEAK)
+          fprintf (stderr, "linking\n");
+        w->link = s->weaks;
+        s->weaks = w;
+      } else {
+        if (DEBUG_WEAK)
+          fprintf (stderr, "not linking\n");
+      }
+    }
+    /* Store the forwarding pointer in the old object. */
+    *(GC_header*)(p - GC_HEADER_SIZE) = GC_FORWARDED;
+    *(objptr*)p = pointerToObjptr(s->forwardState.back + headerBytes, 
+                                  s->forwardState.toStart);
+    /* Update the back of the queue. */
+    s->forwardState.back += size + skip;
+    assert (isAligned ((size_t)s->forwardState.back + GC_NORMAL_HEADER_SIZE, 
+                       s->alignment));
+  }
+  *opp = *(objptr*)p;
+  assert (isObjptrInToSpace (s, *opp));
+}
+
+void forwardObjptrIfInNursery (GC_state s, objptr *opp) {
+  objptr op;
+  pointer p;
+
+  op = *opp;
+  p = objptrToPointer (op, s->heap.start);
+  if (p < s->heap.nursery)
+    return;
+  if (DEBUG_GENERATIONAL)
+    fprintf (stderr,
+             "forwardObjptrIfInNursery  opp = "FMTPTR"  op = "FMTOBJPTR"  p = "FMTPTR"\n",
+             (uintptr_t)opp, op, (uintptr_t)p);
+  assert (s->heap.nursery <= p and p < s->limitPlusSlop);
+  forwardObjptr (s, opp);
+}
+
+/* Walk through all the cards and forward all intergenerational pointers. */
+void forwardInterGenerationalObjptrs (GC_state s) {
+  GC_cardMapElem *cardMap;
+  GC_crossMapElem *crossMap;
+  pointer oldGenStart, oldGenEnd;
+
+  size_t cardIndex, maxCardIndex;
+  pointer cardStart, cardEnd;
+  pointer objectStart;
+  
+  if (DEBUG_GENERATIONAL)
+    fprintf (stderr, "Forwarding inter-generational pointers.\n");
+  updateCrossMap (s);
+  /* Constants. */
+  cardMap = s->generationalMaps.cardMap;
+  crossMap = s->generationalMaps.crossMap;
+  maxCardIndex = sizeToCardMapIndex (align (s->heap.oldGenSize, CARD_SIZE));
+  oldGenStart = s->heap.start;
+  oldGenEnd = oldGenStart + s->heap.oldGenSize;
+  /* Loop variables*/
+  objectStart = alignFrontier (s, s->heap.start);
+  cardIndex = 0;
+  cardStart = oldGenStart;
+checkAll:
+  assert (cardIndex <= maxCardIndex);
+  assert (isAlignedFrontier (s, objectStart));
+  if (cardIndex == maxCardIndex)
+    goto done;
+checkCard:
+  if (DEBUG_GENERATIONAL)
+    fprintf (stderr, "checking card %zu  objectStart = "FMTPTR"\n",
+             cardIndex, (uintptr_t)objectStart);
+  assert (objectStart < oldGenStart + cardMapIndexToSize (cardIndex + 1));
+  if (cardMap[cardIndex]) {
+    pointer lastObject;
+    size_t size;
+    
+    s->cumulativeStatistics.markedCards++;
+    if (DEBUG_GENERATIONAL)
+      fprintf (stderr, "card %zu is marked  objectStart = "FMTPTR"\n", 
+               cardIndex, (uintptr_t)objectStart);
+    lastObject = objectStart;
+skipObjects:
+    assert (isAlignedFrontier (s, objectStart));
+    size = sizeofObject (s, advanceToObjectData (s, objectStart));
+    if (objectStart + size < cardStart) {
+      objectStart += size;
+      goto skipObjects;
+    }
+    s->cumulativeStatistics.minorBytesSkipped += objectStart - lastObject;
+    cardEnd = cardStart + CARD_SIZE;
+    if (oldGenEnd < cardEnd) 
+      cardEnd = oldGenEnd;
+    assert (objectStart < cardEnd);
+    lastObject = objectStart;
+    /* If we ever add Weak.set, then there could be intergenerational
+     * weak pointers, in which case we would need to link the weak
+     * objects into s->weaks.  But for now, since there is no
+     * Weak.set, the foreachObjptrInRange will do the right thing on
+     * weaks, since the weak pointer will never be into the nursery.
+     */
+    objectStart = foreachObjptrInRange (s, objectStart, &cardEnd, 
+                                        forwardObjptrIfInNursery, FALSE);
+    s->cumulativeStatistics.minorBytesScanned += objectStart - lastObject;
+    if (objectStart == oldGenEnd)
+      goto done;
+    cardIndex = sizeToCardMapIndex (objectStart - oldGenStart);
+    cardStart = oldGenStart + cardMapIndexToSize (cardIndex);
+    goto checkCard;
+  } else {
+    unless (CROSS_MAP_EMPTY == crossMap[cardIndex])
+      objectStart = cardStart + (size_t)(crossMap[cardIndex]);
+    if (DEBUG_GENERATIONAL)
+      fprintf (stderr, 
+               "card %zu is not marked"
+               "  crossMap[%zu] == %zu"
+               "  objectStart = "FMTPTR"\n", 
+               cardIndex, cardIndex, 
+               (size_t)(crossMap[cardIndex]), (uintptr_t)objectStart);
+    cardIndex++;
+    cardStart += CARD_SIZE;
+    goto checkAll;
+  }
+  assert (FALSE);
+done:
+  if (DEBUG_GENERATIONAL)
+    fprintf (stderr, "Forwarding inter-generational pointers done.\n");
+}

Copied: mlton/branches/on-20050822-x86_64-branch/runtime/gc/forward.h (from rev 4127, mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.h)
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/forward.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -0,0 +1,22 @@
+/* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh
+ *    Jagannathan, and Stephen Weeks.
+ * Copyright (C) 1997-2000 NEC Research Institute.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ */
+
+struct GC_forwardState {
+  bool amInMinorGC;
+  pointer back;
+  pointer toStart;
+  pointer toLimit;
+};
+
+#define GC_FORWARDED ~((GC_header)0)
+
+bool isPointerInToSpace (GC_state s, pointer p);
+bool isObjptrsInToSpace (GC_state s, objptr op);
+void forwardObjptr (GC_state s, objptr *opp);
+void forwardObjptrIfInNursery (GC_state s, objptr *opp);
+void forwardInterGenerationalObjptrs (GC_state s);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/garbage-collection.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/garbage-collection.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/garbage-collection.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -20,7 +20,7 @@
     + s->cumulativeStatistics.numMarkCompactGCs;
   if (0 < numGCs
       and ((float)(s->cumulativeStatistics.numHashConsGCs) / (float)(numGCs)
-           < s->ratios.hashCons))
+           < s->controls.ratios.hashCons))
     s->hashConsDuringGC = TRUE;
   desiredSize = 
     sizeofHeapDesired (s, s->lastMajorStatistics.bytesLive + bytesRequested, 0);
@@ -69,14 +69,6 @@
   s->amInGC = FALSE;
 }
 
-bool needGCTime (GC_state s) {
-  return 
-    DEBUG 
-    or s->controls.summary 
-    or s->controls.messages 
-    or s->rusageIsEnabled;
-}
-
 void doGC (GC_state s, 
            size_t oldGenBytesRequested,
            size_t nurseryBytesRequested, 
@@ -109,13 +101,13 @@
   if (forceMajor 
       or totalBytesRequested > s->heap.size - s->heap.oldGenSize)
     majorGC (s, totalBytesRequested, mayResize);
-  setHeapNursery (s, oldGenBytesRequested + stackBytesRequested, 
-                  nurseryBytesRequested);
+  setGCStateCurrentHeap (s, oldGenBytesRequested + stackBytesRequested, 
+                         nurseryBytesRequested);
   assert (hasHeapBytesFree (s, oldGenBytesRequested + stackBytesRequested,
                             nurseryBytesRequested));
   unless (stackTopOk)
     growStack (s);
-  setThreadAndStackCurrent (s);
+  setGCStateCurrentThreadAndStack (s);
   if (needGCTime (s)) {
     gcTime = stopTiming (&ru_start, &s->cumulativeStatistics.ru_gc);
     s->cumulativeStatistics.maxPause = 
@@ -179,7 +171,7 @@
              op, stack->used, stack->reserved);
   }
   s->currentThread = op;
-  setThreadAndStackCurrent (s);
+  setGCStateCurrentThreadAndStack (s);
 }
 
 /* GC_startHandler does not do an enter()/leave(), even though it is
@@ -246,9 +238,9 @@
     leave (s);
   } else {
     /* BEGIN: enter(s); */
-    getStackCurrent(s)->used = sizeofStackCurrentUsed (s);
+    getStackCurrent(s)->used = sizeofGCStateCurrentStackUsed (s);
     getThreadCurrent(s)->exnStack = s->exnStack;
-    atomicBegin (s);
+    beginAtomic (s);
     /* END: enter(s); */
     getThreadCurrent(s)->bytesNeeded = ensureBytesFree;
     switchToThread (s, pointerToObjptr((pointer)t, s->heap.start));
@@ -262,7 +254,7 @@
     }
     /* END: ensureMutatorInvariant */
     /* BEGIN: leave(s); */
-    atomicEnd (s);
+    endAtomic (s);
     /* END: leave(s); */
   }
   assert (mutatorFrontierInvariant(s));

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/garbage-collection.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/garbage-collection.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/garbage-collection.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -10,7 +10,6 @@
 void majorGC (GC_state s, size_t bytesRequested, bool mayResize);
 void enterGC (GC_state s);
 void leaveGC (GC_state s);
-bool needGCTime (GC_state s);
 void doGC (GC_state s, 
            size_t oldGenBytesRequested,
            size_t nurseryBytesRequested, 

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -26,3 +26,86 @@
            (uintptr_t)s->stackBottom,
            (uintptr_t)s->stackTop);
 }
+
+size_t sizeofGCStateCurrentStackUsed (GC_state s) {
+  return s->stackTop - s->stackBottom;
+}
+
+void setGCStateCurrentThreadAndStack (GC_state s) {
+  GC_thread thread;
+  GC_stack stack;
+  
+  thread = getThreadCurrent (s);
+  s->exnStack = thread->exnStack;
+  stack = getStackCurrent (s);
+  s->stackBottom = getStackBottom (s, stack);
+  s->stackTop = getStackTop (s, stack);
+  s->stackLimit = getStackLimit (s, stack);
+  markCard (s, (pointer)stack);
+}
+
+void setGCStateCurrentHeap (GC_state s, 
+                            size_t oldGenBytesRequested,
+                            size_t nurseryBytesRequested) {
+  GC_heap h;
+  size_t nurserySize;
+
+  if (DEBUG_DETAILED)
+    fprintf (stderr, "setGCStateCurrentHeap(%zu, %zu)\n",
+             /*uintToCommaString*/(oldGenBytesRequested),
+             /*uintToCommaString*/(nurseryBytesRequested));
+  h = &s->heap;
+  assert (isAlignedFrontier (s, h->start + h->oldGenSize + oldGenBytesRequested));
+  nurserySize = h->size - h->oldGenSize - oldGenBytesRequested;
+  s->limitPlusSlop = h->start + h->size;
+  s->limit = s->limitPlusSlop - GC_HEAP_LIMIT_SLOP;
+  assert (isAligned (nurserySize, POINTER_SIZE));
+  if (/* The mutator marks cards. */
+      s->mutatorMarksCards
+      /* There is enough space in the nursery. */
+      and (nurseryBytesRequested
+           <= (size_t)(s->limitPlusSlop
+                       - alignFrontier (s, (s->limitPlusSlop 
+                                            - nurserySize / 2 + 2))))
+      /* The nursery is large enough to be worth it. */
+      and (((float)(h->size - s->lastMajorStatistics.bytesLive) 
+            / (float)nurserySize) 
+           <= s->controls.ratios.nursery)
+      and /* There is a reason to use generational GC. */
+      (
+       /* We must use it for debugging pruposes. */
+       FORCE_GENERATIONAL
+       /* We just did a mark compact, so it will be advantageous to to
+        * use it.
+        */
+       or (s->lastMajorStatistics.kind == GC_MARK_COMPACT)
+       /* The live ratio is low enough to make it worthwhile. */
+       or ((float)h->size / (float)s->lastMajorStatistics.bytesLive
+           <= (h->size < s->sysvals.ram
+               ? s->controls.ratios.copyGenerational
+               : s->controls.ratios.markCompactGenerational))
+       )) {
+    s->canMinor = TRUE;
+    nurserySize /= 2;
+    while (not (isAligned (nurserySize, POINTER_SIZE))) {
+      nurserySize -= 2;
+    }
+    clearCardMap (s);
+  } else {
+    unless (nurseryBytesRequested
+            <= (size_t)(s->limitPlusSlop
+                        - alignFrontier (s, s->limitPlusSlop
+                                         - nurserySize)))
+      die ("Out of memory.  Insufficient space in nursery.");
+    s->canMinor = FALSE;
+  }
+  assert (nurseryBytesRequested
+          <= (size_t)(s->limitPlusSlop
+                      - alignFrontier (s, s->limitPlusSlop
+                                       - nurserySize)));
+  s->heap.nursery = alignFrontier (s, s->limitPlusSlop - nurserySize);
+  s->frontier = s->heap.nursery;
+  assert (nurseryBytesRequested <= (size_t)(s->limitPlusSlop - s->frontier));
+  assert (isAlignedFrontier (s, s->heap.nursery));
+  assert (hasHeapBytesFree (s, oldGenBytesRequested, nurseryBytesRequested));
+}

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-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -19,13 +19,14 @@
   struct GC_cumulativeStatistics cumulativeStatistics;
   objptr currentThread; /* Currently executing thread (in heap). */
   uint32_t exnStack;
+  struct GC_forwardState forwardState;
   GC_frameLayout frameLayouts; /* Array of frame layouts. */
   uint32_t frameLayoutsLength; /* Cardinality of frameLayouts array. */
   pointer frontier; /* heap.start <= frontier < limit */
   struct GC_generationalMaps generationalMaps;
   objptr *globals;
   uint32_t globalsLength;
-  /*Bool*/bool hashConsDuringGC;
+  bool hashConsDuringGC;
   struct GC_heap heap;
   struct GC_intInfInit *intInfInits;
   uint32_t intInfInitsLength;
@@ -35,14 +36,12 @@
   void (*loadGlobals)(int fd); /* loads the globals from the fd. */
   uint32_t magic; /* The magic number for this executable. */
   uint32_t maxFrameSize;
-  /*Bool*/bool mutatorMarksCards;
+  bool mutatorMarksCards;
   GC_objectHashTable objectHashTable;
   GC_objectType objectTypes; /* Array of object types. */
   uint32_t objectTypesLength; /* Cardinality of objectTypes array. */
   struct GC_profiling profiling;
   uint32_t (*returnAddressToFrameIndex) (GC_returnAddress ra);
-  struct GC_ratios ratios;
-  bool rusageIsEnabled;
   objptr savedThread; /* Result of GC_copyCurrentThread.
                        * Thread interrupted by arrival of signal.
                        */
@@ -61,3 +60,9 @@
 };
 
 void displayGCState (GC_state s, FILE *stream);
+
+size_t sizeofGCStateCurrentStackUsed (GC_state s);
+void setGCStateCurrentThreadAndStack (GC_state s);
+void setGCStateCurrentHeap (GC_state s, 
+                            size_t oldGenBytesRequested, 
+                            size_t nurseryBytesRequested);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/hash-cons.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/hash-cons.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/hash-cons.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -25,7 +25,7 @@
  *   we ensure by making it odd and keeping the table size as a power of 2.
  */
 
-GC_objectHashTable newHashTable (GC_state s) {
+GC_objectHashTable allocHashTable (GC_state s) {
   uint32_t elementsLengthMax;
   pointer regionStart;
   pointer regionEnd;
@@ -82,22 +82,21 @@
     fprintf (stderr, "elementsIsInHeap = %s\n", 
              boolToString (t->elementsIsInHeap));
     fprintf (stderr, "elementsLengthMax = %"PRIu32"\n", t->elementsLengthMax);
-    fprintf (stderr, FMTPTR" = newHashTable ()\n", (uintptr_t)t);
+    fprintf (stderr, FMTPTR" = allocHashTable ()\n", (uintptr_t)t);
   }
   return t;
 }
 
-void destroyHashTable (GC_objectHashTable t) {
+void freeHashTable (GC_objectHashTable t) {
   unless (t->elementsIsInHeap)
     free (t->elements);
   free (t);
 }
 
-pointer tableInsert (__attribute__ ((unused)) GC_state s, 
-                     GC_objectHashTable t, 
-                     GC_hash hash, pointer object,
-                     bool mightBeThere, 
-                     GC_header header, GC_objectTypeTag tag, pointer max) {
+pointer insertHashTableElem (__attribute__ ((unused)) GC_state s, 
+                             GC_objectHashTable t, 
+                             GC_hash hash, pointer object, 
+                             pointer max, bool mightBeThere) {
   static bool init = FALSE;
   static uint64_t mult; // magic multiplier for hashing
   static uint32_t maxNumProbes = 0;
@@ -110,10 +109,11 @@
   unsigned int *p2;
   
   if (DEBUG_SHARE)
-    fprintf (stderr, "tableInsert ("FMTHASH", "FMTPTR", %s, "FMTHDR", "FMTPTR")\n",
-             hash, (uintptr_t)object,
-             boolToString (mightBeThere),
-             header, (uintptr_t)max);
+    fprintf (stderr, "insertHashTableElem ("FMTHASH", "FMTPTR", "FMTPTR", %s)\n",
+             hash, 
+             (uintptr_t)object, 
+             (uintptr_t)max,
+             boolToString (mightBeThere));
   if (! init) {
     init = TRUE;
     mult = floor (((sqrt (5.0) - 1.0) / 2.0)
@@ -160,6 +160,10 @@
              (uintptr_t)object, (uintptr_t)e->object);
   /* Compare object to e->object. */
   unless (object == e->object) {
+    GC_header header;
+    GC_objectTypeTag tag;
+
+    header = getHeader (object);
     unless (header == getHeader (e->object))
       goto lookNext;
     for (p1 = (unsigned int*)object, 
@@ -168,6 +172,7 @@
          ++p1, ++p2)
       unless (*p1 == *p2)
         goto lookNext;
+    splitHeader (s, header, &tag, NULL, NULL, NULL);
     if (ARRAY_TAG == tag
         and (getArrayLength (object) != getArrayLength (e->object)))
       goto lookNext;
@@ -176,7 +181,7 @@
   return e->object;
 }
 
-void maybeGrowTable (GC_state s, GC_objectHashTable t) {
+void growHashTableMaybe (GC_state s, GC_objectHashTable t) {
   GC_objectHashElement oldElement;
   struct GC_objectHashElement *oldElements;
   uint32_t oldElementsLengthMax;
@@ -207,8 +212,8 @@
   for (unsigned int i = 0; i < oldElementsLengthMax; ++i) {
     oldElement = &oldElements[i];
     unless (NULL == oldElement->object)
-      tableInsert (s, t, oldElement->hash, oldElement->object,
-                   FALSE, 0, 0, NULL);
+      insertHashTableElem 
+      (s, t, oldElement->hash, oldElement->object, NULL, FALSE);
   }
   if (t->elementsIsInHeap)
     t->elementsIsInHeap = FALSE;
@@ -218,7 +223,7 @@
     fprintf (stderr, "done growing table\n");
 }
 
-pointer hashCons (GC_state s, pointer object, bool countBytesHashConsed) {
+pointer hashConsPointer (GC_state s, pointer object, bool countBytesHashConsed) {
   GC_objectHashTable t;
   GC_header header;
   uint16_t numNonObjptrs;
@@ -246,15 +251,14 @@
     + (ARRAY_TAG == tag
        ? (sizeofArrayNoHeader (s, getArrayLength (object),
                                numNonObjptrs, numObjptrs))
-       : (sizeofNumNonObjptrs (NORMAL_TAG, numNonObjptrs)
-          + (numObjptrs * OBJPTR_SIZE)));
+       : (sizeofNormalNoHeader (s, numNonObjptrs, numObjptrs)));
   // Compute the hash.
   hash = (GC_hash)header;
   for (p = (GC_hash*)object; p < (GC_hash*)max; ++p)
     hash = hash * 31 + *p;
   /* Insert into table. */
-  res = tableInsert (s, t, hash, object, TRUE, header, tag, max);
-  maybeGrowTable (s, t);
+  res = insertHashTableElem (s, t, hash, object, max, TRUE);
+  growHashTableMaybe (s, t);
   if (countBytesHashConsed and res != object) {
     size_t amount;
     
@@ -263,45 +267,30 @@
       amount += GC_ARRAY_HEADER_SIZE;
     else
       amount += GC_NORMAL_HEADER_SIZE;
-    s->cumulativeStatistics.bytesHashConsed += amount;
+    s->lastMajorStatistics.bytesHashConsed += amount;
   }
 done:
   if (DEBUG_SHARE)
-    fprintf (stderr, FMTPTR" = hashCons ("FMTPTR")\n",
+    fprintf (stderr, FMTPTR" = hashConsPointer ("FMTPTR")\n",
              (uintptr_t)res, (uintptr_t)object);
   return res;
 }
 
-void maybeSharePointer (GC_state s,
-                        pointer *pp,
-                        bool shouldHashCons) {
-  unless (shouldHashCons)
-    return;
-  if (DEBUG_SHARE)
-    fprintf (stderr, "maybeSharePointer  pp = "FMTPTR"  *pp = "FMTPTR"\n",
-             (uintptr_t)pp, (uintptr_t)*pp);
-  *pp = hashCons (s, *pp, FALSE);
-}
-
-void maybeShareObjptr (GC_state s,
-                       objptr *opp,
-                       bool shouldHashCons) {
+void shareObjptr (GC_state s, objptr *opp) {
   pointer p;
   
-  unless (shouldHashCons)
-    return;
   p = objptrToPointer (*opp, s->heap.start);
   if (DEBUG_SHARE)
-    fprintf (stderr, "maybeShareObjptr  opp = "FMTPTR"  *opp = "FMTOBJPTR"\n",
+    fprintf (stderr, "shareObjptrMaybe  opp = "FMTPTR"  *opp = "FMTOBJPTR"\n",
              (uintptr_t)opp, *opp);
-  p = hashCons (s, p, FALSE);
+  p = hashConsPointer (s, p, FALSE);
   *opp = pointerToObjptr (p, s->heap.start);
 }
 
-void bytesHashConsedMessage (GC_state s, uintmax_t total) {
-  fprintf (stderr, "%"PRIuMAX" bytes hash consed (%.1f%%).\n",
-           /*ullongToCommaString*/(s->cumulativeStatistics.bytesHashConsed),
+void printBytesHashConsedMessage (GC_state s, uintmax_t total) {
+  fprintf (stderr, "%"PRIuMAX" bytes hash-consed (%.1f%%).\n",
+           /*ullongToCommaString*/(s->lastMajorStatistics.bytesHashConsed),
            (100.0 
-            * ((double)s->cumulativeStatistics.bytesHashConsed 
+            * ((double)s->lastMajorStatistics.bytesHashConsed 
                / (double)total)));
 }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/hash-cons.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/hash-cons.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/hash-cons.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -29,14 +29,15 @@
   bool mayInsert;
 } *GC_objectHashTable;
 
-GC_objectHashTable newHashTable (GC_state s);
-void destroyHashTable (GC_objectHashTable t);
-pointer tableInsert (GC_state s, GC_objectHashTable t, 
-                     GC_hash hash, pointer object,
-                     bool mightBeThere, 
-                     GC_header header, GC_objectTypeTag tag, pointer max);
-void maybeGrowTable (GC_state s, GC_objectHashTable t);
-pointer hashCons (GC_state s, pointer object, bool countBytesHashConsed);
-void maybeSharePointer (GC_state s, pointer *pp, bool shouldHashCons);
-void maybeShareObjptr (GC_state s, objptr *opp, bool shouldHashCons);
-void bytesHashConsedMessage (GC_state s, uintmax_t total);
+GC_objectHashTable allocHashTable (GC_state s);
+void freeHashTable (GC_objectHashTable t);
+
+pointer insertHashTableElem (GC_state s, 
+                             GC_objectHashTable t, GC_hash hash, 
+                             pointer object, pointer max, bool mightBeThere);
+void growHashTableMaybe (GC_state s, GC_objectHashTable t);
+
+pointer hashConsPointer (GC_state s, pointer object, bool countBytesHashConsed);
+void shareObjptr (GC_state s, objptr *opp);
+
+void printBytesHashConsedMessage (GC_state s, uintmax_t total);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -38,26 +38,26 @@
   float ratio;
 
   ratio = (float)s->sysvals.ram / (float)live;
-  if (ratio >= s->ratios.live + s->ratios.grow) {
+  if (ratio >= s->controls.ratios.live + s->controls.ratios.grow) {
     /* Cheney copying fits in RAM with desired ratios.live. */
-    res = live * s->ratios.live;
+    res = live * s->controls.ratios.live;
     /* If the heap is currently close in size to what we want, leave
      * it alone.  Favor growing over shrinking.
      */
     unless (1.1 * currentSize <= res
             or res <= .5 * currentSize)
       res = currentSize;
-  } else if (s->ratios.grow >= s->ratios.copy
-             and ratio >= 2 * s->ratios.copy) {
+  } else if (s->controls.ratios.grow >= s->controls.ratios.copy
+             and ratio >= 2 * s->controls.ratios.copy) {
     /* Split RAM in half.  Round down by pageSize so that the total
      * amount of space taken isn't greater than RAM once rounding
      * happens.  This is so resizeHeap2 doesn't get confused and free
      * a semispace in a misguided attempt to avoid paging.
      */
     res = alignDown (s->sysvals.ram / 2, s->sysvals.pageSize);
-  } else if (ratio >= s->ratios.copy + s->ratios.grow) {
+  } else if (ratio >= s->controls.ratios.copy + s->controls.ratios.grow) {
     /* Cheney copying fits in RAM. */
-    res = s->sysvals.ram - s->ratios.grow * live;
+    res = s->sysvals.ram - s->controls.ratios.grow * live;
     /* If the heap isn't too much smaller than what we want, leave it
      * alone.  On the other hand, if it is bigger we want to leave res
      * as is so that the heap is shrunk, to try to avoid paging.
@@ -65,7 +65,7 @@
     if (currentSize <= res 
         and res <= 1.1 * currentSize)
       res = currentSize;
-  } else if (ratio >= s->ratios.markCompact) {
+  } else if (ratio >= s->controls.ratios.markCompact) {
     /* Mark compact fits in RAM.  It doesn't matter what the current
      * size is.  If the heap is currently smaller, we are using
      * copying and should switch to mark-compact.  If the heap is
@@ -74,7 +74,7 @@
      */
     res = s->sysvals.ram;
   } else { /* Required live ratio. */
-    res = live * s->ratios.markCompact;
+    res = live * s->controls.ratios.markCompact;
     /* If the current heap is bigger than res, then shrinking always
      * sounds like a good idea.  However, depending on what pages the
      * VM keeps around, growing could be very expensive, if it
@@ -394,70 +394,3 @@
   assert (0 == s->secondaryHeap.size 
           or s->heap.size == s->secondaryHeap.size);
 }
-
-
-void setHeapNursery (GC_state s, 
-                     size_t oldGenBytesRequested,
-                     size_t nurseryBytesRequested) {
-  GC_heap h;
-  size_t nurserySize;
-
-  if (DEBUG_DETAILED)
-    fprintf (stderr, "setHeapNursery(%zu, %zu)\n",
-             /*uintToCommaString*/(oldGenBytesRequested),
-             /*uintToCommaString*/(nurseryBytesRequested));
-  h = &s->heap;
-  assert (isAlignedFrontier (s, h->start + h->oldGenSize + oldGenBytesRequested));
-  nurserySize = h->size - h->oldGenSize - oldGenBytesRequested;
-  s->limitPlusSlop = h->start + h->size;
-  s->limit = s->limitPlusSlop - GC_HEAP_LIMIT_SLOP;
-  assert (isAligned (nurserySize, POINTER_SIZE));
-  if (/* The mutator marks cards. */
-      s->mutatorMarksCards
-      /* There is enough space in the nursery. */
-      and (nurseryBytesRequested
-           <= (size_t)(s->limitPlusSlop
-                       - alignFrontier (s, (s->limitPlusSlop 
-                                            - nurserySize / 2 + 2))))
-      /* The nursery is large enough to be worth it. */
-      and (((float)(h->size - s->lastMajorStatistics.bytesLive) 
-            / (float)nurserySize) 
-           <= s->ratios.nursery)
-      and /* There is a reason to use generational GC. */
-      (
-       /* We must use it for debugging pruposes. */
-       FORCE_GENERATIONAL
-       /* We just did a mark compact, so it will be advantageous to to
-        * use it.
-        */
-       or (s->lastMajorStatistics.kind == GC_MARK_COMPACT)
-       /* The live ratio is low enough to make it worthwhile. */
-       or ((float)h->size / (float)s->lastMajorStatistics.bytesLive
-           <= (h->size < s->sysvals.ram
-               ? s->ratios.copyGenerational
-               : s->ratios.markCompactGenerational))
-       )) {
-    s->canMinor = TRUE;
-    nurserySize /= 2;
-    while (not (isAligned (nurserySize, POINTER_SIZE))) {
-      nurserySize -= 2;
-    }
-    clearCardMap (s);
-  } else {
-    unless (nurseryBytesRequested
-            <= (size_t)(s->limitPlusSlop
-                        - alignFrontier (s, s->limitPlusSlop
-                                         - nurserySize)))
-      die ("Out of memory.  Insufficient space in nursery.");
-    s->canMinor = FALSE;
-  }
-  assert (nurseryBytesRequested
-          <= (size_t)(s->limitPlusSlop
-                      - alignFrontier (s, s->limitPlusSlop
-                                       - nurserySize)));
-  s->heap.nursery = alignFrontier (s, s->limitPlusSlop - nurserySize);
-  s->frontier = s->heap.nursery;
-  assert (nurseryBytesRequested <= (size_t)(s->limitPlusSlop - s->frontier));
-  assert (isAlignedFrontier (s, s->heap.nursery));
-  assert (hasHeapBytesFree (s, oldGenBytesRequested, nurseryBytesRequested));
-}

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -52,6 +52,3 @@
 void resizeHeap (GC_state s, size_t minSize);
 void resizeHeapSecondary (GC_state s);
 
-void setHeapNursery (GC_state s, 
-                     size_t oldGenBytesRequested, 
-                     size_t nurseryBytesRequested);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/init.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/init.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/init.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -258,7 +258,7 @@
   initVectors (s);
   assert ((size_t)(s->frontier - start) <= s->lastMajorStatistics.bytesLive);
   s->heap.oldGenSize = s->frontier - s->heap.start;
-  setHeapNursery (s, 0, 0);
+  setGCStateCurrentHeap (s, 0, 0);
   thread = newThread (s, sizeofStackInitial (s));
   switchToThread (s, pointerToObjptr((pointer)thread, s->heap.start));
 }
@@ -292,7 +292,9 @@
           i++;
           if (i == argc)
             die ("@MLton copy-ratio missing argument.");
-          s->ratios.copy = stringToFloat (argv[i++]);
+          s->controls.ratios.copy = stringToFloat (argv[i++]);
+          unless (1.0 < s->controls.ratios.copy)
+            die ("@MLton copy-ratio argument must be greater than 1.0");
         } else if (0 == strcmp(arg, "fixed-heap")) {
           i++;
           if (i == argc)
@@ -313,25 +315,31 @@
           i++;
           if (i == argc)
             die ("@MLton copy-generational-ratio missing argument.");
-          s->ratios.copyGenerational = stringToFloat (argv[i++]);
+          s->controls.ratios.copyGenerational = stringToFloat (argv[i++]);
+          unless (1.0 < s->controls.ratios.copyGenerational)
+            die ("@MLton copy-generational-ratio argument must be greater than 1.0");
         } else if (0 == strcmp (arg, "grow-ratio")) {
           i++;
           if (i == argc)
             die ("@MLton grow-ratio missing argument.");
-          s->ratios.grow = stringToFloat (argv[i++]);
+          s->controls.ratios.grow = stringToFloat (argv[i++]);
+          unless (1.0 < s->controls.ratios.grow)
+            die ("@MLton grow-ratio argument must be greater than 1.0");
         } else if (0 == strcmp (arg, "hash-cons")) {
           i++;
           if (i == argc)
             die ("@MLton hash-cons missing argument.");
-          s->ratios.hashCons = stringToFloat (argv[i++]);
-          unless (0.0 <= s->ratios.hashCons
-                  and s->ratios.hashCons <= 1.0)
+          s->controls.ratios.hashCons = stringToFloat (argv[i++]);
+          unless (0.0 <= s->controls.ratios.hashCons
+                  and s->controls.ratios.hashCons <= 1.0)
             die ("@MLton hash-cons argument must be between 0.0 and 1.0");
         } else if (0 == strcmp (arg, "live-ratio")) {
           i++;
           if (i == argc)
             die ("@MLton live-ratio missing argument.");
-          s->ratios.live = stringToFloat (argv[i++]);
+          s->controls.ratios.live = stringToFloat (argv[i++]);
+          unless (1.0 < s->controls.ratios.live)
+            die ("@MLton live-ratio argument must be greater than 1.0");
         } else if (0 == strcmp (arg, "load-world")) {
           unless (s->controls.mayLoadWorld)
             die ("May not load world.");
@@ -350,12 +358,16 @@
           i++;
           if (i == argc)
             die ("@MLton mark-compact-generational-ratio missing argument.");
-          s->ratios.markCompactGenerational = stringToFloat (argv[i++]);
+          s->controls.ratios.markCompactGenerational = stringToFloat (argv[i++]);
+          unless (1.0 < s->controls.ratios.markCompactGenerational)
+            die ("@MLton mark-compact-generational-ratio argument must be greater than 1.0");
         } else if (0 == strcmp (arg, "mark-compact-ratio")) {
           i++;
           if (i == argc)
             die ("@MLton mark-compact-ratio missing argument.");
-          s->ratios.markCompact = stringToFloat (argv[i++]);
+          s->controls.ratios.markCompact = stringToFloat (argv[i++]);
+          unless (1.0 < s->controls.ratios.markCompact)
+            die ("@MLton mark-compact-ratio argument must be greater than 1.0");
         } else if (0 == strcmp (arg, "no-load-world")) {
           i++;
           s->controls.mayLoadWorld = FALSE;
@@ -363,12 +375,14 @@
           i++;
           if (i == argc)
             die ("@MLton nursery-ratio missing argument.");
-          s->ratios.nursery = stringToFloat (argv[i++]);
+          s->controls.ratios.nursery = stringToFloat (argv[i++]);
+          unless (1.0 < s->controls.ratios.nursery)
+            die ("@MLton nursery-ratio argument must be greater than 1.0");
         } else if (0 == strcmp (arg, "ram-slop")) {
           i++;
           if (i == argc)
             die ("@MLton ram-slop missing argument.");
-          s->ratios.ramSlop = stringToFloat (argv[i++]);
+          s->controls.ratios.ramSlop = stringToFloat (argv[i++]);
         } else if (0 == strcmp (arg, "show-prof")) {
           showProf (s);
           exit (0);
@@ -379,7 +393,10 @@
           i++;
           if (i == argc)
             die ("@MLton thread-shrink-ratio missing argument.");
-          s->ratios.threadShrink = stringToFloat (argv[i++]);
+          s->controls.ratios.threadShrink = stringToFloat (argv[i++]);
+          unless (0.0 <= s->controls.ratios.threadShrink
+                  and s->controls.ratios.threadShrink <= 1.0)
+            die ("@MLton thread-shrink-ratio argument must be between 0.0 and 1.0");
         } else if (0 == strcmp (arg, "use-mmap")) {
           i++;
           MLton_Platform_CygwinUseMmap = TRUE;
@@ -415,11 +432,20 @@
   s->controls.mayProcessAtMLton = TRUE;
   s->controls.messages = FALSE;
   s->controls.oldGenArraySize = 0x100000;
+  s->controls.ratios.copy = 4.0;
+  s->controls.ratios.copyGenerational = 4.0;
+  s->controls.ratios.grow = 8.0;
+  s->controls.ratios.hashCons = 0.0;
+  s->controls.ratios.live = 8.0;
+  s->controls.ratios.markCompact = 1.04;
+  s->controls.ratios.markCompactGenerational = 8.0;
+  s->controls.ratios.nursery = 10.0;
+  s->controls.ratios.ramSlop = 0.5;
+  s->controls.ratios.threadShrink = 0.5;
   s->controls.summary = FALSE;
   s->cumulativeStatistics.bytesAllocated = 0;
   s->cumulativeStatistics.bytesCopied = 0;
   s->cumulativeStatistics.bytesCopiedMinor = 0;
-  s->cumulativeStatistics.bytesHashConsed = 0;
   s->cumulativeStatistics.bytesMarkCompacted = 0;
   s->cumulativeStatistics.markedCards = 0;
   s->cumulativeStatistics.maxBytesLive = 0;
@@ -440,20 +466,10 @@
   s->currentThread = BOGUS_OBJPTR;
   s->hashConsDuringGC = FALSE;
   initHeap (s, &s->heap);
+  s->lastMajorStatistics.bytesHashConsed = 0;
   s->lastMajorStatistics.bytesLive = 0;
   s->lastMajorStatistics.kind = GC_COPYING;
   s->lastMajorStatistics.numMinorGCs = 0;
-  s->ratios.copy = 4.0;
-  s->ratios.copyGenerational = 4.0;
-  s->ratios.grow = 8.0;
-  s->ratios.hashCons = 0.0;
-  s->ratios.live = 8.0;
-  s->ratios.markCompact = 1.04;
-  s->ratios.markCompactGenerational = 8.0;
-  s->ratios.nursery = 10.0;
-  s->ratios.ramSlop = 0.5;
-  s->ratios.threadShrink = 0.5;
-  s->rusageIsEnabled = FALSE;
   s->savedThread = BOGUS_OBJPTR;
   initHeap (s, &s->secondaryHeap);
   s->signalHandlerThread = BOGUS_OBJPTR;
@@ -477,15 +493,17 @@
   processAtMLton (s, s->atMLtonsLength, s->atMLtons, &worldFile);
   res = processAtMLton (s, argc, argv, &worldFile);
   if (s->controls.fixedHeap > 0 and s->controls.maxHeap > 0)
-    die ("Cannot use both fixed-heap and max-heap.\n");
-  unless (ratiosOk (s->ratios))
-    die ("invalid ratios");
+    die ("Cannot use both fixed-heap and max-heap.");
+  unless (s->controls.ratios.markCompact <= s->controls.ratios.copy
+          and s->controls.ratios.copy <= s->controls.ratios.live)
+    die ("Ratios must satisfy mark-compact-ratio <= copy-ratio <= live-ratio");
   // s->totalRam = totalRam (s);
   /* We align s->ram by pageSize so that we can test whether or not we
    * we are using mark-compact by comparing heap size to ram size.  If
    * we didn't round, the size might be slightly off.
    */
-  s->sysvals.ram = align ((size_t)(s->ratios.ramSlop * s->sysvals.totalRam), s->sysvals.pageSize);
+  s->sysvals.ram = align ((size_t)(s->controls.ratios.ramSlop * s->sysvals.totalRam), 
+                          s->sysvals.pageSize);
   if (DEBUG or DEBUG_RESIZING or s->controls.messages)
     fprintf (stderr, "total RAM = %zu  RAM = %zu\n",
              /*uintToCommaString*/(s->sysvals.totalRam),

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/invariant.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/invariant.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/invariant.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -17,7 +17,6 @@
 bool invariant (GC_state s) {
   if (DEBUG)
     fprintf (stderr, "invariant\n");
-  assert (ratiosOk (s->ratios));
   /* Frame layouts */
   for (unsigned int i = 0; i < s->frameLayoutsLength; ++i) {
     GC_frameLayout layout;
@@ -60,11 +59,11 @@
   if (DEBUG_DETAILED)
     fprintf (stderr, "Checking old generation.\n");
   foreachObjptrInRange (s, alignFrontier (s, s->heap.start), &back, 
-                        FALSE, assertObjptrIsInFromSpace);
+                        assertObjptrIsInFromSpace, FALSE);
   if (DEBUG_DETAILED)
     fprintf (stderr, "Checking nursery.\n");
   foreachObjptrInRange (s, s->heap.nursery, &s->frontier, 
-                        FALSE, assertObjptrIsInFromSpace);
+                        assertObjptrIsInFromSpace, FALSE);
   /* Current thread. */
   GC_stack stack = getStackCurrent(s);
   assert (isAlignedStackReserved (s, stack->reserved));
@@ -72,7 +71,7 @@
   assert (s->stackTop == getStackTop (s, stack));
   assert (s->stackLimit == getStackLimit (s, stack));
   assert (s->stackBottom <= s->stackTop);
-  assert (stack->used == sizeofStackCurrentUsed (s));
+  assert (stack->used == sizeofGCStateCurrentStackUsed (s));
   assert (stack->used <= stack->reserved);
   if (DEBUG)
     fprintf (stderr, "invariant passed\n");

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/mark-compact.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/mark-compact.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/mark-compact.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -129,7 +129,7 @@
       }
       front += size;
       endOfLastMarked = front;
-      foreachObjptrInObject (s, p, FALSE, threadInternalObjptr);
+      foreachObjptrInObject (s, p, threadInternalObjptr, FALSE);
       goto updateObject;
     } else {
       /* It's not marked. */
@@ -267,11 +267,11 @@
              /*uintToCommaString*/(s->heap.size));
   }
   if (s->hashConsDuringGC) {
-    s->cumulativeStatistics.bytesHashConsed = 0;
+    s->lastMajorStatistics.bytesHashConsed = 0;
     s->cumulativeStatistics.numHashConsGCs++;
-    s->objectHashTable = newHashTable (s);
+    s->objectHashTable = allocHashTable (s);
     foreachGlobalObjptr (s, dfsMarkTrue);
-    destroyHashTable (s->objectHashTable);
+    freeHashTable (s->objectHashTable);
   } else {
     foreachGlobalObjptr (s, dfsMarkFalse);
   }
@@ -286,8 +286,8 @@
   if (DEBUG or s->controls.messages) {
     fprintf (stderr, "Major mark-compact GC done.\n");
     if (s->hashConsDuringGC)
-      bytesHashConsedMessage(s, 
-                             s->cumulativeStatistics.bytesHashConsed 
-                             + s->heap.oldGenSize);
+      printBytesHashConsedMessage(s, 
+                                  s->lastMajorStatistics.bytesHashConsed 
+                                  + s->heap.oldGenSize);
   }
 }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -4,61 +4,3 @@
  * MLton is released under a BSD-style license.
  * See the file MLton-LICENSE for details.
  */
-
-pointer objptrToPointer (objptr O, pointer B) {
-  uintptr_t O_ = (uintptr_t)O;
-  uintptr_t B_;
-  unsigned int S_ = GC_MODEL_SHIFT;
-  uintptr_t P_;
-  pointer P;
-
-  if GC_MODEL_USEBASE {
-    B_ = (uintptr_t)B;
-  } else {
-    B_ = 0;
-  }
-
-  P_ = ((O_ << S_) + B_);
-  P = (pointer)P_;
-  if (DEBUG_DETAILED) 
-    fprintf (stderr, "objptrToPointer ("FMTOBJPTR") = "FMTPTR"\n", O, (uintptr_t)P);
-  
-  return P;
-}
-
-objptr pointerToObjptr (pointer P, pointer B) {
-  uintptr_t P_ = (uintptr_t)P;
-  uintptr_t B_;
-  unsigned int S_ = GC_MODEL_SHIFT;
-  uintptr_t O_;
-  objptr O;
-
-  if GC_MODEL_USEBASE {
-    B_ = (uintptr_t)B;
-  } else {
-    B_ = 0;
-  }
-
-  O_ = ((P_ - B_) >> S_);
-  O = (objptr)O_;
-  if (DEBUG_DETAILED) 
-    fprintf (stderr, "pointerToObjptr ("FMTPTR") = "FMTOBJPTR"\n", (uintptr_t)P, O);
-
-  return O;
-}
-
-/*
- * Note that by indirectly fetching and storing object pointers, the
- * following functions admit implementations that behave according to
- * model characteristics determined at runtime.  Hence, by making
- * exclusive use of these functions (and adding a GC_state->model
- * field set by the compiled program), we may be able to implement the
- * runtime in a manner which is agnostic to the actual objptr
- * representation.
- */
-pointer fetchObjptrToPointer (pointer OP, pointer B) {
-  return objptrToPointer (*((objptr*)OP), B);
-}
-void storeObjptrFromPointer (pointer OP, pointer P, pointer B) {
-  *((objptr*)OP) = pointerToObjptr (P, B);
-}

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -205,25 +205,3 @@
 #endif
 #define GC_MODEL_NONOBJPTR ((GC_MODEL_MINALIGN_SHIFT - GC_MODEL_SHIFT) > 0)
 #define GC_MODEL_MINALIGN TWOPOWER(GC_MODEL_MINALIGN_SHIFT)
-
-#define OBJPTR_TYPE__(z) uint ## z ## _t
-#define OBJPTR_TYPE_(z) OBJPTR_TYPE__(z)
-#define OBJPTR_TYPE OBJPTR_TYPE_(GC_MODEL_BITSIZE)
-typedef OBJPTR_TYPE objptr;
-#define OBJPTR_SIZE sizeof(objptr)
-#define PRIxOBJPTR__(z) PRIx ## z
-#define PRIxOBJPTR_(z) PRIxOBJPTR__(z)
-#define PRIxOBJPTR PRIxOBJPTR_(GC_MODEL_BITSIZE)
-#define FMTOBJPTR "0x%016"PRIxOBJPTR
-
-#if GC_MODEL_NONOBJPTR
-#define BOGUS_OBJPTR (objptr)0x1
-#else
-#error gc model does not admit bogus object pointer
-#endif
-
-bool isObjptr (objptr p);
-pointer objptrToPointer (objptr O, pointer B);
-objptr pointerToObjptr (pointer P, pointer B);
-pointer fetchObjptrToPointer (pointer OP, pointer B);
-void storeObjptrFromPointer (pointer OP, pointer P, pointer B);

Copied: mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.c (from rev 4127, mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.c)

Copied: mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.h (from rev 4127, mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.h)
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -0,0 +1,28 @@
+/* Copyright (C) 2005-2005 Henry Cejtin, Matthew Fluet, Suresh
+ *    Jagannathan, and Stephen Weeks.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ */
+
+#define OBJPTR_TYPE__(z) uint ## z ## _t
+#define OBJPTR_TYPE_(z) OBJPTR_TYPE__(z)
+#define OBJPTR_TYPE OBJPTR_TYPE_(GC_MODEL_BITSIZE)
+typedef OBJPTR_TYPE objptr;
+#define OBJPTR_SIZE sizeof(objptr)
+#define PRIxOBJPTR__(z) PRIx ## z
+#define PRIxOBJPTR_(z) PRIxOBJPTR__(z)
+#define PRIxOBJPTR PRIxOBJPTR_(GC_MODEL_BITSIZE)
+#define FMTOBJPTR "0x%016"PRIxOBJPTR
+
+#if GC_MODEL_NONOBJPTR
+#define BOGUS_OBJPTR (objptr)0x1
+#else
+#error gc model does not admit bogus object pointer
+#endif
+
+bool isObjptr (objptr p);
+pointer objptrToPointer (objptr O, pointer B);
+objptr pointerToObjptr (pointer P, pointer B);
+pointer fetchObjptrToPointer (pointer OP, pointer B);
+void storeObjptrFromPointer (pointer OP, pointer P, pointer B);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/pack.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/pack.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/pack.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -21,8 +21,8 @@
   keep = s->heap.oldGenSize * 1.1;
   if (keep <= s->heap.size) {
     shrinkHeap (s, &s->heap, keep);
-    setHeapNursery (s, 0, 0);
-    setThreadAndStackCurrent (s);
+    setGCStateCurrentHeap (s, 0, 0);
+    setGCStateCurrentThreadAndStack (s);
   }
   releaseHeap (s, &s->secondaryHeap);
   if (DEBUG or s->controls.messages)
@@ -44,8 +44,8 @@
   minorGC (s);
   resizeHeap (s, s->heap.oldGenSize);
   resizeHeapSecondary (s);
-  setHeapNursery (s, 0, 0);
-  setThreadAndStackCurrent (s);
+  setGCStateCurrentHeap (s, 0, 0);
+  setGCStateCurrentThreadAndStack (s);
   leaveGC (s);
   if (DEBUG or s->controls.messages)
     fprintf (stderr, "Unpacked heap to size %zu.\n",

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/ratios.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/ratios.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/ratios.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -31,6 +31,3 @@
   float ramSlop;
   float threadShrink; 
 };
-
-bool ratiosOk (struct GC_ratios ratios);
-

Deleted: mlton/branches/on-20050822-x86_64-branch/runtime/gc/ratios_predicates.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/ratios_predicates.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/ratios_predicates.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -1,15 +0,0 @@
-/* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh
- *    Jagannathan, and Stephen Weeks.
- * Copyright (C) 1997-2000 NEC Research Institute.
- *
- * MLton is released under a BSD-style license.
- * See the file MLton-LICENSE for details.
- */
-
-bool ratiosOk (struct GC_ratios ratios) {
-  return 1.0 < ratios.grow
-    and 1.0 < ratios.nursery
-    and 1.0 < ratios.markCompact
-    and ratios.markCompact <= ratios.copy
-    and ratios.copy <= ratios.live;
-}

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/share.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/share.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/share.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -6,19 +6,19 @@
  * See the file MLton-LICENSE for details.
  */
 
-void share (GC_state s, pointer object) {
+void GC_share (GC_state s, pointer object) {
   size_t total;
   
   if (DEBUG_SHARE)
     fprintf (stderr, "GC_share "FMTPTR"\n", (uintptr_t)object);
   if (DEBUG_SHARE or s->controls.messages)
-    s->cumulativeStatistics.bytesHashConsed = 0;
+    s->lastMajorStatistics.bytesHashConsed = 0;
   // Don't hash cons during the first round of marking.
   total = dfsMark (s, object, MARK_MODE, FALSE);
-  s->objectHashTable = newHashTable (s);
+  s->objectHashTable = allocHashTable (s);
   // Hash cons during the second round of marking.
   dfsMark (s, object, UNMARK_MODE, TRUE);
-  destroyHashTable (s->objectHashTable);
+  freeHashTable (s->objectHashTable);
   if (DEBUG_SHARE or s->controls.messages)
-    bytesHashConsedMessage (s, total);
+    printBytesHashConsedMessage (s, total);
 }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/share.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/share.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/share.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -6,4 +6,4 @@
  * See the file MLton-LICENSE for details.
  */
 
-void share (GC_state s, pointer object);
+void GC_share (GC_state s, pointer object);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/statistics.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/statistics.h	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/statistics.h	2005-11-02 15:01:11 UTC (rev 4128)
@@ -10,7 +10,6 @@
   uintmax_t bytesAllocated;
   uintmax_t bytesCopied;
   uintmax_t bytesCopiedMinor;
-  uintmax_t bytesHashConsed;
   uintmax_t bytesMarkCompacted;
 
   uintmax_t markedCards; /* Number of marked cards seen during minor GCs. */
@@ -37,6 +36,7 @@
 };
 
 struct GC_lastMajorStatistics {
+  uintmax_t bytesHashConsed;
   size_t bytesLive; /* Number of bytes live at most recent major GC. */
   GC_majorKind kind;
   uintmax_t numMinorGCs;

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/translate.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/translate.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/translate.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -43,5 +43,5 @@
   /* Translate globals and heap. */
   foreachGlobalObjptr (s, translateObjptr);
   limit = to + size;
-  foreachObjptrInRange (s, alignFrontier (s, to), &limit, FALSE, translateObjptr);
+  foreachObjptrInRange (s, alignFrontier (s, to), &limit, translateObjptr, FALSE);
 }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.c	2005-10-31 02:52:58 UTC (rev 4127)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.c	2005-11-02 15:01:11 UTC (rev 4128)
@@ -34,8 +34,8 @@
    * since it changes pointers in all of them.
    */
   translateHeap (s, start, s->heap.start, s->heap.oldGenSize);
-  setHeapNursery (s, 0, 0); 
-  setThreadAndStackCurrent (s); 
+  setGCStateCurrentHeap (s, 0, 0); 
+  setGCStateCurrentThreadAndStack (s); 
 }
 
 void loadWorldFromFileName (GC_state s, char *fileName) {