[MLton-commit] r6355

Matthew Fluet fluet at mlton.org
Fri Jan 25 16:22:55 PST 2008


Various updates to GC statistics gathering, motivated by
self-adjusting project.  Some basic GC statistics can be accessed from
SML by MLton.GC.Statistics.* functions.  Note: statistics are most
meaningful immediately after a garbage collection.  For example, to
determine the size of the live data at a program point, one should do:
  fun liveBytes () =
     (MLton.GC.collect()
      ; MLton.GC.Statistics.lastBytesLive())
Similarly, to determine the bytes allocated by a thunk, one should do:
  fun thunkBytesAllocated th =
     let
        val () = MLton.GC.collect()
        val start = MLton.GC.Statistics.bytesAllocated ()
        val res = th ()
        val () = MLton.GC.collect()
        val finish = MLton.GC.Statistics.bytesAllocated ()
     in
        (res, IntInf.- (finish, start))
     end


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

U   mlton/trunk/basis-library/mlton/gc.sig
U   mlton/trunk/basis-library/mlton/gc.sml
U   mlton/trunk/basis-library/primitive/prim-mlton.sml
U   mlton/trunk/runtime/gc/cheney-copy.c
U   mlton/trunk/runtime/gc/done.c
U   mlton/trunk/runtime/gc/forward.c
U   mlton/trunk/runtime/gc/garbage-collection.c
U   mlton/trunk/runtime/gc/gc_state.c
U   mlton/trunk/runtime/gc/gc_state.h
U   mlton/trunk/runtime/gc/hash-cons.c
U   mlton/trunk/runtime/gc/hash-cons.h
U   mlton/trunk/runtime/gc/heap.c
U   mlton/trunk/runtime/gc/init.c
U   mlton/trunk/runtime/gc/mark-compact.c
U   mlton/trunk/runtime/gc/new-object.c
U   mlton/trunk/runtime/gc/rusage.c
U   mlton/trunk/runtime/gc/rusage.h
U   mlton/trunk/runtime/gc/share.c
U   mlton/trunk/runtime/gc/statistics.h
U   mlton/trunk/runtime/util/to-string.c
U   mlton/trunk/runtime/util/to-string.h

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

Modified: mlton/trunk/basis-library/mlton/gc.sig
===================================================================
--- mlton/trunk/basis-library/mlton/gc.sig	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/basis-library/mlton/gc.sig	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-(* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh
+(* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -13,4 +13,15 @@
       val setMessages: bool -> unit
       val setSummary: bool -> unit
       val unpack: unit -> unit
+
+      (* Most meaningful immediately after 'collect()'. *)
+      structure Statistics :
+         sig
+            val bytesAllocated: unit -> IntInf.int
+            val lastBytesLive: unit -> IntInf.int
+            val numCopyingGCs: unit -> IntInf.int
+            val numMarkCompactGCs: unit -> IntInf.int
+            val numMinorGCs: unit -> IntInf.int
+            val maxBytesLive: unit -> IntInf.int
+         end
    end

Modified: mlton/trunk/basis-library/mlton/gc.sml
===================================================================
--- mlton/trunk/basis-library/mlton/gc.sml	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/basis-library/mlton/gc.sml	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+(* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -26,4 +26,21 @@
       val setSummary : bool -> unit =
          fn b => setSummary (gcState, b)
 
+      structure Statistics =
+         struct
+            local
+               fun mk conv prim =
+                  fn () => conv (prim gcState)
+               val mkSize = mk C_Size.toLargeInt
+               val mkUIntmax = mk C_UIntmax.toLargeInt
+            in
+               val bytesAllocated = mkUIntmax getBytesAllocated
+               val lastBytesLive = mkSize getLastBytesLive
+               val maxBytesLive = mkSize getMaxBytesLive
+               val numCopyingGCs = mkUIntmax getNumCopyingGCs
+               val numMarkCompactGCs = mkUIntmax getNumMarkCompactGCs
+               val numMinorGCs = mkUIntmax getNumMinorGCs
+            end
+         end
+
    end

Modified: mlton/trunk/basis-library/primitive/prim-mlton.sml
===================================================================
--- mlton/trunk/basis-library/primitive/prim-mlton.sml	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/basis-library/primitive/prim-mlton.sml	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-(* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+(* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -139,12 +139,24 @@
    struct
       val collect = _prim "GC_collect": unit -> unit;
       val pack = _import "GC_pack": GCState.t -> unit;
+      val getBytesAllocated =
+         _import "GC_getCumulativeStatisticsBytesAllocated": GCState.t -> C_UIntmax.t;
+      val getNumCopyingGCs =
+         _import "GC_getCumulativeStatisticsNumCopyingGCs": GCState.t -> C_UIntmax.t;
+      val getNumMarkCompactGCs =
+         _import "GC_getCumulativeStatisticsNumMarkCompactGCs": GCState.t -> C_UIntmax.t;
+      val getNumMinorGCs =
+         _import "GC_getCumulativeStatisticsNumMinorGCs": GCState.t -> C_UIntmax.t;
+      val getLastBytesLive =
+         _import "GC_getLastMajorStatisticsBytesLive": GCState.t -> C_Size.t;
+      val getMaxBytesLive =
+         _import "GC_getCumulativeStatisticsMaxBytesLive": GCState.t -> C_Size.t;
       val setHashConsDuringGC =
          _import "GC_setHashConsDuringGC": GCState.t * bool -> unit;
-      val setMessages = _import "GC_setMessages": GCState.t * bool -> unit;
+      val setMessages = _import "GC_setControlsMessages": GCState.t * bool -> unit;
       val setRusageMeasureGC = 
-         _import "GC_setRusageMeasureGC": GCState.t * bool -> unit;
-      val setSummary = _import "GC_setSummary": GCState.t * bool -> unit;
+         _import "GC_setControlsRusageMeasureGC": GCState.t * bool -> unit;
+      val setSummary = _import "GC_setControlsSummary": GCState.t * bool -> unit;
       val unpack = _import "GC_unpack": GCState.t -> unit;
    end
 

Modified: mlton/trunk/runtime/gc/cheney-copy.c
===================================================================
--- mlton/trunk/runtime/gc/cheney-copy.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/cheney-copy.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -88,7 +88,7 @@
   clearCrossMap (s);
   s->lastMajorStatistics.kind = GC_COPYING;
   if (detailedGCTime (s))
-    stopTiming (&ru_start, &s->cumulativeStatistics.ru_gcCopy);
+    stopTiming (&ru_start, &s->cumulativeStatistics.ru_gcCopying);
   if (DEBUG or s->controls.messages)
     fprintf (stderr, 
              "[GC: Finished major Cheney-copy; copied %s bytes.]\n",

Modified: mlton/trunk/runtime/gc/done.c
===================================================================
--- mlton/trunk/runtime/gc/done.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/done.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -43,15 +43,18 @@
   minorGC (s);
   out = stderr;
   if (s->controls.summary) {
+    struct rusage ru_total;
+    uintmax_t gcTime;
     uintmax_t totalTime;
-    uintmax_t gcTime;
 
+    getrusage (RUSAGE_SELF, &ru_total);
+    totalTime = rusageTime (&ru_total);
     gcTime = rusageTime (&s->cumulativeStatistics.ru_gc);
     fprintf (out, "GC type\t\ttime ms\t number\t\t  bytes\t      bytes/sec\n");
     fprintf (out, "-------------\t-------\t-------\t---------------\t---------------\n");
     displayCollectionStats
       (out, "copying\t\t", 
-       &s->cumulativeStatistics.ru_gcCopy, 
+       &s->cumulativeStatistics.ru_gcCopying, 
        s->cumulativeStatistics.numCopyingGCs, 
        s->cumulativeStatistics.bytesCopied);
     displayCollectionStats
@@ -64,26 +67,29 @@
        &s->cumulativeStatistics.ru_gcMinor, 
        s->cumulativeStatistics.numMinorGCs, 
        s->cumulativeStatistics.bytesCopiedMinor);
-    totalTime = getCurrentTime () - s->startTime;
+    fprintf (out, "total time: %s ms\n",
+             uintmaxToCommaString (totalTime));
     fprintf (out, "total GC time: %s ms (%.1f%%)\n",
              uintmaxToCommaString (gcTime), 
              (0 == totalTime) 
              ? 0.0 
              : 100.0 * ((double) gcTime) / (double)totalTime);
-    fprintf (out, "max pause: %s ms\n",
-             uintmaxToCommaString (s->cumulativeStatistics.maxPause));
-    fprintf (out, "total allocated: %s bytes\n",
+    fprintf (out, "max pause time: %s ms\n",
+             uintmaxToCommaString (s->cumulativeStatistics.maxPauseTime));
+    fprintf (out, "total bytes allocated: %s bytes\n",
              uintmaxToCommaString (s->cumulativeStatistics.bytesAllocated));
-    fprintf (out, "max live: %s bytes\n",
+    fprintf (out, "max bytes live: %s bytes\n",
              uintmaxToCommaString (s->cumulativeStatistics.maxBytesLive));
-    fprintf (out, "max semispace: %s bytes\n", 
-             uintmaxToCommaString (s->cumulativeStatistics.maxHeapSizeSeen));
+    fprintf (out, "max heap size: %s bytes\n", 
+             uintmaxToCommaString (s->cumulativeStatistics.maxHeapSize));
     fprintf (out, "max stack size: %s bytes\n", 
-             uintmaxToCommaString (s->cumulativeStatistics.maxStackSizeSeen));
-    fprintf (out, "marked cards: %s\n", 
-             uintmaxToCommaString (s->cumulativeStatistics.markedCards));
-    fprintf (out, "minor scanned: %s bytes\n",
-             uintmaxToCommaString (s->cumulativeStatistics.minorBytesScanned));
+             uintmaxToCommaString (s->cumulativeStatistics.maxStackSize));
+    fprintf (out, "num cards marked: %s\n", 
+             uintmaxToCommaString (s->cumulativeStatistics.numCardsMarked));
+    fprintf (out, "bytes scanned: %s bytes\n",
+             uintmaxToCommaString (s->cumulativeStatistics.bytesScannedMinor));
+    fprintf (out, "bytes hash consed: %s bytes\n",
+             uintmaxToCommaString (s->cumulativeStatistics.bytesHashConsed));
   }
   releaseHeap (s, &s->heap);
   releaseHeap (s, &s->secondaryHeap);

Modified: mlton/trunk/runtime/gc/forward.c
===================================================================
--- mlton/trunk/runtime/gc/forward.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/forward.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -195,7 +195,7 @@
   if (cardMap[cardIndex]) {
     pointer lastObject;
 
-    s->cumulativeStatistics.markedCards++;
+    s->cumulativeStatistics.numCardsMarked++;
     if (DEBUG_GENERATIONAL)
       fprintf (stderr, "card %"PRIuMAX" is marked  objectStart = "FMTPTR"\n",
                (uintmax_t)cardIndex, (uintptr_t)objectStart);
@@ -213,7 +213,7 @@
      */
     objectStart = foreachObjptrInRange (s, objectStart, &cardEnd,
                                         forwardObjptrIfInNursery, FALSE);
-    s->cumulativeStatistics.minorBytesScanned += objectStart - lastObject;
+    s->cumulativeStatistics.bytesScannedMinor += objectStart - lastObject;
     if (objectStart == oldGenEnd)
       goto done;
     cardIndex = sizeToCardMapIndex (objectStart - oldGenStart);

Modified: mlton/trunk/runtime/gc/garbage-collection.c
===================================================================
--- mlton/trunk/runtime/gc/garbage-collection.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/garbage-collection.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -36,10 +36,10 @@
   s->lastMajorStatistics.bytesLive = s->heap.oldGenSize;
   if (s->lastMajorStatistics.bytesLive > s->cumulativeStatistics.maxBytesLive)
     s->cumulativeStatistics.maxBytesLive = s->lastMajorStatistics.bytesLive;
-  /* Notice that the s->bytesLive below is different than the
-   * s->bytesLive used as an argument to createHeapSecondary above.
-   * Above, it was an estimate.  Here, it is exactly how much was live
-   * after the GC.
+  /* Notice that the s->lastMajorStatistics.bytesLive below is
+   * different than the s->lastMajorStatistics.bytesLive used as an
+   * argument to createHeapSecondary above.  Above, it was an
+   * estimate.  Here, it is exactly how much was live after the GC.
    */
   if (mayResize)
     resizeHeap (s, s->lastMajorStatistics.bytesLive + bytesRequested);
@@ -149,8 +149,8 @@
   setGCStateCurrentThreadAndStack (s);
   if (needGCTime (s)) {
     gcTime = stopTiming (&ru_start, &s->cumulativeStatistics.ru_gc);
-    s->cumulativeStatistics.maxPause = 
-      max (s->cumulativeStatistics.maxPause, gcTime);
+    s->cumulativeStatistics.maxPauseTime = 
+      max (s->cumulativeStatistics.maxPauseTime, gcTime);
   } else
     gcTime = 0;  /* Assign gcTime to quell gcc warning. */
   if (DEBUG or s->controls.messages) {

Modified: mlton/trunk/runtime/gc/gc_state.c
===================================================================
--- mlton/trunk/runtime/gc/gc_state.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/gc_state.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -111,46 +111,47 @@
   s->amOriginal = b;
 }
 
-void GC_setMessages (GC_state s, bool b) {
+void GC_setControlsMessages (GC_state s, bool b) {
   s->controls.messages = b;
 }
 
-void GC_setSummary (GC_state s, bool b) {
+void GC_setControlsSummary (GC_state s, bool b) {
   s->controls.summary = b;
 }
 
-void GC_setRusageMeasureGC (GC_state s, bool b) {
+void GC_setControlsRusageMeasureGC (GC_state s, bool b) {
   s->controls.rusageMeasureGC = b;
 }
 
-void GC_setHashConsDuringGC (GC_state s, bool b) {
-  s->hashConsDuringGC = b;
+uintmax_t GC_getCumulativeStatisticsBytesAllocated (GC_state s) {
+  return s->cumulativeStatistics.bytesAllocated;
 }
 
-struct rusage* GC_getRusageGCAddr (GC_state s) {
-  return &(s->cumulativeStatistics.ru_gc);
+uintmax_t GC_getCumulativeStatisticsNumCopyingGCs (GC_state s) {
+  return s->cumulativeStatistics.numCopyingGCs;
 }
 
-sigset_t* GC_getSignalsHandledAddr (GC_state s) {
-  return &(s->signalsInfo.signalsHandled);
+uintmax_t GC_getCumulativeStatisticsNumMarkCompactGCs (GC_state s) {
+  return s->cumulativeStatistics.numMarkCompactGCs;
 }
 
-sigset_t* GC_getSignalsPendingAddr (GC_state s) {
-  return &(s->signalsInfo.signalsPending);
+uintmax_t GC_getCumulativeStatisticsNumMinorGCs (GC_state s) {
+  return s->cumulativeStatistics.numMinorGCs;
 }
 
-void GC_setGCSignalHandled (GC_state s, bool b) {
-  s->signalsInfo.gcSignalHandled = b;
+size_t GC_getCumulativeStatisticsMaxBytesLive (GC_state s) {
+  return s->cumulativeStatistics.maxBytesLive;
 }
 
-bool GC_getGCSignalPending (GC_state s) {
-  return (s->signalsInfo.gcSignalPending);
+void GC_setHashConsDuringGC (GC_state s, bool b) {
+  s->hashConsDuringGC = b;
 }
 
-void GC_setGCSignalPending (GC_state s, bool b) {
-  s->signalsInfo.gcSignalPending = b;
+size_t GC_getLastMajorStatisticsBytesLive (GC_state s) {
+  return s->lastMajorStatistics.bytesLive;
 }
 
+
 pointer GC_getCallFromCHandlerThread (GC_state s) {
   pointer p = objptrToPointer (s->callFromCHandlerThread, s->heap.start);
   return p;
@@ -187,3 +188,27 @@
   objptr op = pointerToObjptr (p, s->heap.start);
   s->signalHandlerThread = op;
 }
+
+struct rusage* GC_getRusageGCAddr (GC_state s) {
+  return &(s->cumulativeStatistics.ru_gc);
+}
+
+sigset_t* GC_getSignalsHandledAddr (GC_state s) {
+  return &(s->signalsInfo.signalsHandled);
+}
+
+sigset_t* GC_getSignalsPendingAddr (GC_state s) {
+  return &(s->signalsInfo.signalsPending);
+}
+
+void GC_setGCSignalHandled (GC_state s, bool b) {
+  s->signalsInfo.gcSignalHandled = b;
+}
+
+bool GC_getGCSignalPending (GC_state s) {
+  return (s->signalsInfo.gcSignalPending);
+}
+
+void GC_setGCSignalPending (GC_state s, bool b) {
+  s->signalsInfo.gcSignalPending = b;
+}

Modified: mlton/trunk/runtime/gc/gc_state.h
===================================================================
--- mlton/trunk/runtime/gc/gc_state.h	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/gc_state.h	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -62,7 +62,6 @@
   struct GC_signalsInfo signalsInfo;
   struct GC_sourceMaps sourceMaps;
   pointer stackBottom; /* Bottom of stack in current thread. */
-  uintmax_t startTime; /* The time when GC_init or GC_loadWorld was called. */
   struct GC_sysvals sysvals;
   struct GC_translateState translateState;
   struct GC_vectorInit *vectorInits;
@@ -88,15 +87,21 @@
 
 bool GC_getAmOriginal (GC_state s);
 void GC_setAmOriginal (GC_state s, bool b);
-void GC_setMessages (GC_state s, bool b);
-void GC_setSummary (GC_state s, bool b);
-void GC_setRusageMeasureGC (GC_state s, bool b);
+void GC_setControlsMessages (GC_state s, bool b);
+void GC_setControlsSummary (GC_state s, bool b);
+void GC_setControlsRusageMeasureGC (GC_state s, bool b);
+uintmax_t GC_getCumulativeStatisticsBytesAllocated (GC_state s);
+uintmax_t GC_getCumulativeStatisticsNumCopyingGCs (GC_state s);
+uintmax_t GC_getCumulativeStatisticsNumMarkCompactGCs (GC_state s);
+uintmax_t GC_getCumulativeStatisticsNumMinorGCs (GC_state s);
+size_t GC_getCumulativeStatisticsMaxBytesLive (GC_state s);
 void GC_setHashConsDuringGC (GC_state s, bool b);
+size_t GC_getLastMajorStatisticsBytesLive (GC_state s);
 
 pointer GC_getCallFromCHandlerThread (GC_state s);
+void GC_setCallFromCHandlerThread (GC_state s, pointer p);
 pointer GC_getCurrentThread (GC_state s);
 pointer GC_getSavedThread (GC_state s);
-void GC_setCallFromCHandlerThread (GC_state s, pointer p);
 void GC_setSavedThread (GC_state s, pointer p);
 void GC_setSignalHandlerThread (GC_state s, pointer p);
 

Modified: mlton/trunk/runtime/gc/hash-cons.c
===================================================================
--- mlton/trunk/runtime/gc/hash-cons.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/hash-cons.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -290,10 +290,8 @@
   markIntergenerationalObjptr (s, opp);
 }
 
-void printBytesHashConsedMessage (GC_state s, uintmax_t total) {
-  fprintf (stderr, "%s bytes hash-consed (%.1f%%).\n",
-           uintmaxToCommaString(s->lastMajorStatistics.bytesHashConsed),
-           (100.0 
-            * ((double)s->lastMajorStatistics.bytesHashConsed 
-               / (double)total)));
+void printBytesHashConsedMessage (size_t bytesHashConsed, size_t bytesExamined) {
+  fprintf (stderr, "[GC: hash-consed %s bytes (%.1f%% of bytes examined).]\n",
+           uintmaxToCommaString(bytesHashConsed),
+           100.0 * ((double)bytesHashConsed / (double)bytesExamined));
 }

Modified: mlton/trunk/runtime/gc/hash-cons.h
===================================================================
--- mlton/trunk/runtime/gc/hash-cons.h	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/hash-cons.h	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -46,6 +46,6 @@
 static pointer hashConsPointer (GC_state s, pointer object, bool countBytesHashConsed);
 static inline void shareObjptr (GC_state s, objptr *opp);
 
-static void printBytesHashConsedMessage (GC_state s, uintmax_t total);
+static void printBytesHashConsedMessage (size_t bytesHashConsed, size_t bytesExamined);
 
 #endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */

Modified: mlton/trunk/runtime/gc/heap.c
===================================================================
--- mlton/trunk/runtime/gc/heap.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/heap.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 2005-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  *
  * MLton is released under a BSD-style license.
@@ -188,8 +188,8 @@
         h->start = (void*)NULL;
       unless ((void*)NULL == h->start) {
         direction = not direction;
-        if (h->size > s->cumulativeStatistics.maxHeapSizeSeen)
-          s->cumulativeStatistics.maxHeapSizeSeen = h->size;
+        if (h->size > s->cumulativeStatistics.maxHeapSize)
+          s->cumulativeStatistics.maxHeapSize = h->size;
         if (DEBUG or s->controls.messages)
           fprintf (stderr,
                    "[GC: Created heap at "FMTPTR" of size %s bytes.]\n",
@@ -249,8 +249,8 @@
     unless ((void*)-1 == new) {
       h->start = new;
       h->size = size;
-      if (h->size > s->cumulativeStatistics.maxHeapSizeSeen)
-        s->cumulativeStatistics.maxHeapSizeSeen = h->size;
+      if (h->size > s->cumulativeStatistics.maxHeapSize)
+        s->cumulativeStatistics.maxHeapSize = h->size;
       assert (minSize <= h->size and h->size <= desiredSize);
       return TRUE;
     }

Modified: mlton/trunk/runtime/gc/init.c
===================================================================
--- mlton/trunk/runtime/gc/init.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/init.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -254,20 +254,20 @@
   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.bytesScannedMinor = 0;
   s->cumulativeStatistics.maxBytesLive = 0;
-  s->cumulativeStatistics.maxHeapSizeSeen = 0;
-  s->cumulativeStatistics.maxStackSizeSeen = 0;
-  s->cumulativeStatistics.minorBytesScanned = 0;
-  s->cumulativeStatistics.numLimitChecks = 0;
+  s->cumulativeStatistics.maxHeapSize = 0;
+  s->cumulativeStatistics.maxPauseTime = 0;
+  s->cumulativeStatistics.maxStackSize = 0;
+  s->cumulativeStatistics.numCardsMarked = 0;
   s->cumulativeStatistics.numCopyingGCs = 0;
   s->cumulativeStatistics.numHashConsGCs = 0;
   s->cumulativeStatistics.numMarkCompactGCs = 0;
   s->cumulativeStatistics.numMinorGCs = 0;
-  s->cumulativeStatistics.maxPause = 0;
   rusageZero (&s->cumulativeStatistics.ru_gc);
-  rusageZero (&s->cumulativeStatistics.ru_gcCopy);
+  rusageZero (&s->cumulativeStatistics.ru_gcCopying);
   rusageZero (&s->cumulativeStatistics.ru_gcMarkCompact);
   rusageZero (&s->cumulativeStatistics.ru_gcMinor);
   s->currentThread = BOGUS_OBJPTR;
@@ -286,7 +286,6 @@
   s->signalsInfo.signalIsPending = FALSE;
   sigemptyset (&s->signalsInfo.signalsHandled);
   sigemptyset (&s->signalsInfo.signalsPending);
-  s->startTime = getCurrentTime ();
   s->sysvals.pageSize = GC_pageSize ();
   s->sysvals.physMem = GC_physMem ();
   s->weaks = NULL;

Modified: mlton/trunk/runtime/gc/mark-compact.c
===================================================================
--- mlton/trunk/runtime/gc/mark-compact.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/mark-compact.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -274,6 +274,7 @@
 }
 
 void majorMarkCompactGC (GC_state s) {
+  size_t bytesHashConsed;
   size_t bytesMarkCompacted;
   struct rusage ru_start;
 
@@ -302,6 +303,8 @@
   updateForwardPointersForMarkCompact (s);
   updateBackwardPointersAndSlideForMarkCompact (s);
   clearCrossMap (s);
+  bytesHashConsed = s->lastMajorStatistics.bytesHashConsed;
+  s->cumulativeStatistics.bytesHashConsed += bytesHashConsed;
   bytesMarkCompacted = s->heap.oldGenSize;
   s->cumulativeStatistics.bytesMarkCompacted += bytesMarkCompacted;
   s->lastMajorStatistics.kind = GC_MARK_COMPACT;
@@ -312,8 +315,7 @@
              "[GC: Finished major mark-compact; mark compacted %s bytes.]\n",
              uintmaxToCommaString(bytesMarkCompacted));
     if (s->hashConsDuringGC)
-      printBytesHashConsedMessage(s,
-                                  s->lastMajorStatistics.bytesHashConsed
-                                  + s->heap.oldGenSize);
+      printBytesHashConsedMessage(bytesHashConsed, 
+                                  bytesHashConsed + bytesMarkCompacted);
   }
 }

Modified: mlton/trunk/runtime/gc/new-object.c
===================================================================
--- mlton/trunk/runtime/gc/new-object.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/new-object.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2005, 2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -53,8 +53,8 @@
   GC_stack stack;
 
   reserved = alignStackReserved (s, reserved);
-  if (reserved > s->cumulativeStatistics.maxStackSizeSeen)
-    s->cumulativeStatistics.maxStackSizeSeen = reserved;
+  if (reserved > s->cumulativeStatistics.maxStackSize)
+    s->cumulativeStatistics.maxStackSize = reserved;
   stack = (GC_stack)(newObject (s, GC_STACK_HEADER,
                                 sizeofStackWithHeaderAligned (s, reserved),
                                 allocInOldGen));

Modified: mlton/trunk/runtime/gc/rusage.c
===================================================================
--- mlton/trunk/runtime/gc/rusage.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/rusage.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -65,18 +65,11 @@
   return result;
 }
 
-/* Return time as number of milliseconds. */
-uintmax_t getCurrentTime (void) {
-  struct rusage ru;
-
-  getrusage (RUSAGE_SELF, &ru);
-  return rusageTime (&ru);
-}
-
 void startTiming (struct rusage *ru_start) {
   getrusage (RUSAGE_SELF, ru_start);
 }
 
+/* Accumulate and return time as number of milliseconds. */
 uintmax_t stopTiming (struct rusage *ru_start, struct rusage *ru_acc) {
   struct rusage ru_finish, ru_total;
 

Modified: mlton/trunk/runtime/gc/rusage.h
===================================================================
--- mlton/trunk/runtime/gc/rusage.h	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/rusage.h	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -16,7 +16,6 @@
                                    struct rusage *ru2,
                                    struct rusage *ru);
 static inline uintmax_t rusageTime (struct rusage *ru);
-static inline uintmax_t getCurrentTime (void);
 static inline void startTiming (struct rusage *ru_start);
 static uintmax_t stopTiming (struct rusage *ru_start, struct rusage *ru_gc);
 

Modified: mlton/trunk/runtime/gc/share.c
===================================================================
--- mlton/trunk/runtime/gc/share.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/share.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -7,18 +7,21 @@
  */
 
 void GC_share (GC_state s, pointer object) {
-  size_t total;
+  size_t bytesExamined;
+  size_t bytesHashConsed;
 
   if (DEBUG_SHARE)
     fprintf (stderr, "GC_share "FMTPTR"\n", (uintptr_t)object);
   if (DEBUG_SHARE or s->controls.messages)
     s->lastMajorStatistics.bytesHashConsed = 0;
   // Don't hash cons during the first round of marking.
-  total = dfsMarkByMode (s, object, MARK_MODE, FALSE, FALSE);
+  bytesExamined = dfsMarkByMode (s, object, MARK_MODE, FALSE, FALSE);
   s->objectHashTable = allocHashTable (s);
   // Hash cons during the second round of (un)marking.
   dfsMarkByMode (s, object, UNMARK_MODE, TRUE, FALSE);
   freeHashTable (s->objectHashTable);
+  bytesHashConsed = s->lastMajorStatistics.bytesHashConsed;
+  s->cumulativeStatistics.bytesHashConsed += bytesHashConsed;
   if (DEBUG_SHARE or s->controls.messages)
-    printBytesHashConsedMessage (s, total);
+    printBytesHashConsedMessage (bytesHashConsed, bytesExamined);
 }

Modified: mlton/trunk/runtime/gc/statistics.h
===================================================================
--- mlton/trunk/runtime/gc/statistics.h	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/gc/statistics.h	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -12,33 +12,31 @@
   uintmax_t bytesAllocated;
   uintmax_t bytesCopied;
   uintmax_t bytesCopiedMinor;
+  uintmax_t bytesHashConsed;
   uintmax_t bytesMarkCompacted;
+  uintmax_t bytesScannedMinor;
 
-  uintmax_t markedCards; /* Number of marked cards seen during minor GCs. */
-
   size_t maxBytesLive;
-  size_t maxHeapSizeSeen;
-  size_t maxStackSizeSeen;
+  size_t maxHeapSize;
+  uintmax_t maxPauseTime;
+  size_t maxStackSize;
 
-  uintmax_t minorBytesScanned;
+  uintmax_t numCardsMarked; /* Number of marked cards seen during minor GCs. */
 
-  uintmax_t numLimitChecks;
-
   uintmax_t numGCs;
   uintmax_t numCopyingGCs;
   uintmax_t numHashConsGCs;
   uintmax_t numMarkCompactGCs;
   uintmax_t numMinorGCs;
 
-  uintmax_t maxPause;
-  struct rusage ru_gc; /* total resource usage spent in gc */
-  struct rusage ru_gcCopy; /* resource usage in major copying gcs. */
-  struct rusage ru_gcMarkCompact; /* resource usage in mark-compact gcs. */
-  struct rusage ru_gcMinor; /* resource usage in minor gcs. */
+  struct rusage ru_gc; /* total resource usage in gc. */
+  struct rusage ru_gcCopying; /* resource usage in major copying gcs. */
+  struct rusage ru_gcMarkCompact; /* resource usage in major mark-compact gcs. */
+  struct rusage ru_gcMinor; /* resource usage in minor copying gcs. */
 };
 
 struct GC_lastMajorStatistics {
-  uintmax_t bytesHashConsed;
+  size_t bytesHashConsed;
   size_t bytesLive; /* Number of bytes live at most recent major GC. */
   GC_majorKind kind;
   uintmax_t numMinorGCs;

Modified: mlton/trunk/runtime/util/to-string.c
===================================================================
--- mlton/trunk/runtime/util/to-string.c	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/util/to-string.c	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004-2007 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 2004-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  *
  * MLton is released under a BSD-style license.
@@ -102,31 +102,4 @@
   }
   return buf + i + 1;
 }
-
-char* sizeToBytesApproxString (size_t amount) {
-  static const char* suffixs[] = {"", "K", "M", "G"};
-  static char buf1[BUF_SIZE];
-  static char buf2[BUF_SIZE];
-  static char buf3[BUF_SIZE];
-  static char buf4[BUF_SIZE];
-  static char buf5[BUF_SIZE];
-  static char *bufs[] = {buf1, buf2, buf3, buf4, buf5};
-  static int bufIndex = 0;
-  static char *buf;
-  size_t factor = 1;
-  int suffixIndex = 0;
-
-  buf = bufs[bufIndex++];
-  bufIndex %= 5;
-
-  while (amount > 1024 * factor
-         and suffixIndex < 4) {
-    factor *= 1024;
-    amount /= factor;
-    suffixIndex++;
-  }
-  snprintf (buf, BUF_SIZE, "%"PRIuMAX"%s",
-            (uintmax_t)amount, suffixs[suffixIndex]);
-  return buf;
-}
 #undef BUF_SIZE

Modified: mlton/trunk/runtime/util/to-string.h
===================================================================
--- mlton/trunk/runtime/util/to-string.h	2008-01-25 14:31:44 UTC (rev 6354)
+++ mlton/trunk/runtime/util/to-string.h	2008-01-26 00:22:52 UTC (rev 6355)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004-2005 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 2004-2008 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  *
  * MLton is released under a BSD-style license.
@@ -8,4 +8,3 @@
 const char* boolToString (bool b);
 char* intmaxToCommaString (intmax_t n);
 char* uintmaxToCommaString (uintmax_t n);
-char* sizeToBytesApproxString (size_t z);




More information about the MLton-commit mailing list