[MLton-commit] r4085

Matthew Fluet MLton@mlton.org
Fri, 9 Sep 2005 16:29:52 -0700


(Mostly) converted cheneyCopy; missing rusage and card/cross map stuff
----------------------------------------------------------------------

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

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

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile	2005-09-09 22:48:09 UTC (rev 4084)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile	2005-09-09 23:29:50 UTC (rev 4085)
@@ -89,6 +89,8 @@
 	stack.h								\
 	thread.h							\
 	weak.h								\
+	major.h								\
+	statistics.h							\
 	heap.h								\
 	gc_state.h							\
 	gc_suffix.h

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c	2005-09-09 22:48:09 UTC (rev 4084)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c	2005-09-09 23:29:50 UTC (rev 4085)
@@ -183,7 +183,7 @@
   s->weaks = NULL;
 }
 
-static inline void swapSemis (GC_state s) {
+static inline void swapHeaps (GC_state s) {
   struct GC_heap tempHeap;
   
   tempHeap = s->secondaryHeap;
@@ -196,46 +196,47 @@
 /*         return s->summary; */
 /* } */
 
-/* static void cheneyCopy (GC_state s) { */
-/*         struct rusage ru_start; */
-/*         pointer toStart; */
+static void majorCheneyCopyGC (GC_state s) {
+  // struct rusage ru_start;
+  pointer toStart;
 
-/*         assert (s->heap2.size >= s->oldGenSize); */
-/*         if (detailedGCTime (s)) */
-/*                 startTiming (&ru_start); */
-/*         s->numCopyingGCs++; */
-/*         s->toSpace = s->secondaryHeap.start; */
-/*         s->toLimit = s->secondaryHeap.start + s->secondaryHeap.size; */
-/*         if (DEBUG or s->messages) { */
-/*                 fprintf (stderr, "Major copying GC.\n"); */
-/*                 fprintf (stderr, "fromSpace = 0x%08x of size %s\n",  */
-/*                                 (uint) s->heap.start, */
-/*                                 uintToCommaString (s->heap.size)); */
-/*                 fprintf (stderr, "toSpace = 0x%08x of size %s\n", */
-/*                                 (uint) s->heap2.start, */
-/*                                 uintToCommaString (s->heap2.size)); */
-/*         } */
-/*         assert (s->heap2.start != (void*)NULL); */
-/*         /\* The next assert ensures there is enough space for the copy to succeed. */
-/*          * It does not assert (s->heap2.size >= s->heap.size) because that */
-/*          * is too strong. */
-/*          *\/ */
-/*         assert (s->heap2.size >= s->oldGenSize); */
-/*         toStart = alignFrontier (s, s->heap2.start); */
-/*         s->back = toStart; */
-/*         foreachGlobal (s, forward); */
-/*         foreachPointerInRange (s, toStart, &s->back, TRUE, forward); */
-/*         updateWeaks (s); */
-/*         s->oldGenSize = s->back - s->heap2.start; */
-/*         s->bytesCopied += s->oldGenSize; */
-/*         if (DEBUG) */
-/*                 fprintf (stderr, "%s bytes live.\n",  */
-/*                                 uintToCommaString (s->oldGenSize)); */
-/*         swapSemis (s); */
-/*         clearCrossMap (s); */
-/*         s->lastMajor = GC_COPYING; */
-/*         if (detailedGCTime (s)) */
-/*                 stopTiming (&ru_start, &s->ru_gcCopy);           */
-/*         if (DEBUG or s->messages) */
-/*                 fprintf (stderr, "Major copying GC done.\n"); */
-/* } */
+  assert (s->secondaryHeap.totalBytes >= s->heap.oldGenBytes);
+/*   if (detailedGCTime (s)) */
+/*     startTiming (&ru_start); */
+  s->cumulative.numCopyingGCs++;
+  forwardState.toStart = s->secondaryHeap.start;
+  forwardState.toLimit = s->secondaryHeap.start + s->secondaryHeap.totalBytes;
+  if (DEBUG or s->messages) {
+    fprintf (stderr, "Major copying GC.\n");
+    fprintf (stderr, "fromSpace = "FMTPTR" of size %zd\n",
+             (uintptr_t) s->heap.start, 
+             /*uintToCommaString*/(s->heap.totalBytes));
+    fprintf (stderr, "toSpace = "FMTPTR" of size %zd\n",
+             (uintptr_t) s->secondaryHeap.start, 
+             /*uintToCommaString*/(s->secondaryHeap.totalBytes));
+  }
+  assert (s->secondaryHeap.start != (pointer)NULL);
+  /* The next assert ensures there is enough space for the copy to
+   * succeed.  It does not assert 
+   *   (s->secondaryHeap.totalBytes >= s->heap.totalByes) 
+   * because that is too strong.
+   */
+  assert (s->secondaryHeap.totalBytes >= s->heap.oldGenBytes);
+  toStart = alignFrontier (s, s->secondaryHeap.start);
+  forwardState.back = toStart;
+  foreachGlobalObjptr (s, forward);
+  foreachObjptrInRange (s, toStart, &forwardState.back, TRUE, forward);
+  updateWeaks (s);
+  s->secondaryHeap.oldGenBytes = forwardState.back - s->secondaryHeap.start;
+  s->cumulative.bytesCopied += s->secondaryHeap.oldGenBytes;
+  if (DEBUG)
+    fprintf (stderr, "%zd bytes live.\n",
+             /*uintToCommaString*/(s->secondaryHeap.oldGenBytes));
+  swapHeaps (s);
+  // clearCrossMap (s);
+  s->lastMajor.kind = GC_COPYING;
+/*   if (detailedGCTime (s)) */
+/*     stopTiming (&ru_start, &s->ru_gcCopy); */
+  if (DEBUG or s->messages)
+    fprintf (stderr, "Major copying GC done.\n");
+}

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h	2005-09-09 22:48:09 UTC (rev 4084)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h	2005-09-09 23:29:50 UTC (rev 4085)
@@ -4,6 +4,7 @@
   bool amInGC;
   bool amInMinorGC;
   objptr callFromCHandler; /* Handler for exported C calls (in heap). */
+  struct GC_cumulativeStatistics cumulative;
   objptr currentThread; /* Currently executing thread (in heap). */
   GC_frameLayout *frameLayouts; /* Array of frame layouts. */
   uint32_t frameLayoutsSize; /* Cardinality of frameLayouts array. */
@@ -11,6 +12,7 @@
   objptr *globals;
   uint32_t globalsSize;
   struct GC_heap heap;
+  struct GC_lastMajorStatistics lastMajor;
   pointer limit; /* limit = heap.start + heap.totalBytes */
   uint32_t maxFrameSize;
   GC_objectType *objectTypes; /* Array of object types. */
@@ -24,6 +26,7 @@
   pointer stackBottom; /* Bottom of stack in current thread. */
   pointer stackTop; /* Top of stack in current thread. */
   /*Bool*/bool summary; /* Print a summary of gc info when program exits. */
+  /*Bool*/bool messages; /* Print a message at the start and end of each gc. */
   float threadShrinkRatio;
   GC_weak weaks; /* Linked list of (live) weak pointers */
 } *GC_state;

Added: mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.c	2005-09-09 22:48:09 UTC (rev 4084)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.c	2005-09-09 23:29:50 UTC (rev 4085)
@@ -0,0 +1,47 @@
+/* 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.
+ */
+
+static inline bool pointerIsInHeap (GC_state s, pointer p) {
+  return (not (isPointer (p))
+          or (s->heap.start <= p 
+              and p < s->frontier));
+}
+
+static inline bool objptrIsInHeap (GC_state s, objptr op) {
+  pointer p;
+  if (not (isObjptr(op)))
+    return TRUE;
+  p = objptrToPointer (op, s->heap.start);
+  return pointerIsInHeap (s, p);
+}
+
+static inline bool pointerIsInOldGen (GC_state s, pointer p) {
+  return (not (isPointer (p))
+          or (s->heap.start <= p 
+              and p < s->heap.start + s->heap.oldGenBytes));
+}
+
+static inline bool objptrIsInOldGen (GC_state s, objptr op) {
+  pointer p;
+  if (not (isObjptr(op)))
+    return TRUE;
+  p = objptrToPointer (op, s->heap.start);
+  return pointerIsInOldGen (s, p);
+}
+
+static inline bool pointerIsInNursery (GC_state s, pointer p) {
+  return (not (isPointer (p))
+          or (s->heap.nursery <= p and p < s->frontier));
+}
+
+static inline bool objptrIsInNursery (GC_state s, objptr op) {
+  pointer p;
+  if (not (isObjptr(op)))
+    return TRUE;
+  p = objptrToPointer (op, s->heap.start);
+  return pointerIsInNursery (s, p);
+}

Copied: mlton/branches/on-20050822-x86_64-branch/runtime/gc/major.h (from rev 4078, mlton/branches/on-20050822-x86_64-branch/runtime/gc.h)
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc.h	2005-09-07 00:47:05 UTC (rev 4078)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/major.h	2005-09-09 23:29:50 UTC (rev 4085)
@@ -0,0 +1,12 @@
+/* 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.
+ */
+
+typedef enum {
+        GC_COPYING,
+        GC_MARK_COMPACT,
+} GC_MajorKind;

Copied: mlton/branches/on-20050822-x86_64-branch/runtime/gc/statistics.h (from rev 4078, mlton/branches/on-20050822-x86_64-branch/runtime/gc.h)
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc.h	2005-09-07 00:47:05 UTC (rev 4078)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/statistics.h	2005-09-09 23:29:50 UTC (rev 4085)
@@ -0,0 +1,40 @@
+/* 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_cumulativeStatistics {
+  uintmax_t bytesAllocated;
+  uintmax_t bytesCopied;
+  uintmax_t bytesCopiedMinor;
+  uintmax_t bytesHashConsed;
+  uintmax_t bytesMarkCompacted;
+
+  size_t maxBytesLive;
+  size_t maxHeapSizeSeen;
+  size_t maxStackSizeSeen;
+
+  uintmax_t minorBytesScanned;
+  uintmax_t minorBytesSkipped;
+
+  uintmax_t numLimitChecks;
+
+  unsigned int numCopyingGCs;
+  unsigned int numHashConsGCs;
+  unsigned int numMarkCompactGCs;
+  unsigned int numMinorGCs;
+
+/*   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 GC_lastMajorStatistics {
+  size_t bytesLive; /* Number of bytes live at most recent major GC. */
+  GC_MajorKind kind;
+  unsigned int numMinorsGCs;
+};