[MLton-commit] r5790
Matthew Fluet
fluet at mlton.org
Wed Jul 25 16:04:11 PDT 2007
More cosmetic improvements to gc-messages
----------------------------------------------------------------------
U mlton/trunk/runtime/gc/cheney-copy.c
U mlton/trunk/runtime/gc/garbage-collection.c
U mlton/trunk/runtime/gc/gc_state.h
U mlton/trunk/runtime/gc/heap.c
U mlton/trunk/runtime/gc/heap.h
U mlton/trunk/runtime/gc/init.c
U mlton/trunk/runtime/gc/mark-compact.c
U mlton/trunk/runtime/gc/pack.c
U mlton/trunk/runtime/gc/statistics.h
U mlton/trunk/runtime/gc/translate.c
U mlton/trunk/runtime/gc/translate.h
----------------------------------------------------------------------
Modified: mlton/trunk/runtime/gc/cheney-copy.c
===================================================================
--- mlton/trunk/runtime/gc/cheney-copy.c 2007-07-25 07:04:26 UTC (rev 5789)
+++ mlton/trunk/runtime/gc/cheney-copy.c 2007-07-25 23:04:09 UTC (rev 5790)
@@ -55,16 +55,20 @@
startTiming (&ru_start);
s->cumulativeStatistics.numCopyingGCs++;
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, "[GC: Major Cheney-copy; from heap at "FMTPTR" of size %s bytes,]\n",
+ fprintf (stderr,
+ "[GC: Starting major Cheney-copy;]\n");
+ fprintf (stderr,
+ "[GC:\tfrom heap at "FMTPTR" of size %s bytes,]\n",
(uintptr_t)(s->heap.start),
uintmaxToCommaString(s->heap.size));
- fprintf (stderr, "[GC: to heap at "FMTPTR" of size %s bytes.]\n",
+ fprintf (stderr,
+ "[GC:\tto heap at "FMTPTR" of size %s bytes.]\n",
(uintptr_t)(s->secondaryHeap.start),
uintmaxToCommaString(s->secondaryHeap.size));
}
+ s->forwardState.toStart = s->secondaryHeap.start;
+ s->forwardState.toLimit = s->secondaryHeap.start + s->secondaryHeap.size;
assert (s->secondaryHeap.start != (pointer)NULL);
/* The next assert ensures there is enough space for the copy to
* succeed. It does not assert
@@ -86,7 +90,8 @@
if (detailedGCTime (s))
stopTiming (&ru_start, &s->cumulativeStatistics.ru_gcCopy);
if (DEBUG or s->controls.messages)
- fprintf (stderr, "[GC: Major Cheney-copy done; %s bytes copied.]\n",
+ fprintf (stderr,
+ "[GC: Finished major Cheney-copy; copied %s bytes.]\n",
uintmaxToCommaString(bytesCopied));
}
@@ -111,22 +116,22 @@
s->heap.oldGenSize += bytesAllocated;
bytesCopied = 0;
} else {
- if (DEBUG_GENERATIONAL or s->controls.messages)
- fprintf (stderr, "[GC: Minor Cheney-copy; nursery at "FMTPTR" of size %s bytes,]\n",
- (uintptr_t)(s->heap.nursery),
- uintmaxToCommaString(bytesAllocated));
if (detailedGCTime (s))
startTiming (&ru_start);
+ s->cumulativeStatistics.numMinorGCs++;
s->forwardState.amInMinorGC = TRUE;
+ if (DEBUG_GENERATIONAL or s->controls.messages) {
+ fprintf (stderr,
+ "[GC: Starting minor Cheney-copy;]\n");
+ fprintf (stderr,
+ "[GC:\tfrom nursery at "FMTPTR" of size %s bytes.]\n",
+ (uintptr_t)(s->heap.nursery),
+ uintmaxToCommaString(bytesAllocated));
+ }
s->forwardState.toStart = s->heap.start + s->heap.oldGenSize;
- if (DEBUG_GENERATIONAL or s->controls.messages)
- fprintf (stderr, "[GC: to "FMTPTR".]\n",
- (uintptr_t)(s->forwardState.toStart));
assert (isFrontierAligned (s, s->forwardState.toStart));
s->forwardState.toLimit = s->forwardState.toStart + bytesAllocated;
assert (invariantForGC (s));
- s->cumulativeStatistics.numMinorGCs++;
- s->lastMajorStatistics.numMinorGCs++;
s->forwardState.back = s->forwardState.toStart;
/* Forward all globals. Would like to avoid doing this once all
* the globals have been assigned.
@@ -139,10 +144,12 @@
bytesCopied = s->forwardState.back - s->forwardState.toStart;
s->cumulativeStatistics.bytesCopiedMinor += bytesCopied;
s->heap.oldGenSize += bytesCopied;
+ s->lastMajorStatistics.numMinorGCs++;
if (detailedGCTime (s))
stopTiming (&ru_start, &s->cumulativeStatistics.ru_gcMinor);
if (DEBUG_GENERATIONAL or s->controls.messages)
- fprintf (stderr, "[GC: Minor Cheney-copy done; %s bytes copied.]\n",
+ fprintf (stderr,
+ "[GC: Finished minor Cheney-copy; copied %s bytes.]\n",
uintmaxToCommaString(bytesCopied));
}
}
Modified: mlton/trunk/runtime/gc/garbage-collection.c
===================================================================
--- mlton/trunk/runtime/gc/garbage-collection.c 2007-07-25 07:04:26 UTC (rev 5789)
+++ mlton/trunk/runtime/gc/garbage-collection.c 2007-07-25 23:04:09 UTC (rev 5790)
@@ -53,7 +53,8 @@
size = sizeofStackGrow (s, getStackCurrent(s));
if (DEBUG_STACKS or s->controls.messages)
- fprintf (stderr, "[GC: Growing stack to size %s bytes.]\n",
+ fprintf (stderr,
+ "[GC: Growing stack to size %s bytes.]\n",
uintmaxToCommaString(sizeofStackWithHeaderAligned (s, size)));
assert (hasHeapBytesFree (s, sizeofStackWithHeaderAligned (s, size), 0));
stack = newStack (s, size, TRUE);
@@ -96,10 +97,33 @@
size_t totalBytesRequested;
enterGC (s);
- if (DEBUG or s->controls.messages)
- fprintf (stderr, "[GC: Starting gc; request %s nursery bytes and %s old-gen bytes.]\n",
+ s->cumulativeStatistics.numGCs++;
+ if (DEBUG or s->controls.messages) {
+ size_t nurserySize = s->heap.size - (s->heap.nursery - s->heap.start);
+ size_t nurseryUsed = s->frontier - s->heap.nursery;
+ fprintf (stderr,
+ "[GC: Starting gc #%s; requesting %s nursery bytes and %s old-gen bytes,]\n",
+ uintmaxToCommaString(s->cumulativeStatistics.numGCs),
uintmaxToCommaString(nurseryBytesRequested),
uintmaxToCommaString(oldGenBytesRequested));
+ fprintf (stderr,
+ "[GC:\theap at "FMTPTR" of size %s bytes,]\n",
+ (uintptr_t)(s->heap.start),
+ uintmaxToCommaString(s->heap.size));
+ fprintf (stderr,
+ "[GC:\twith nursery of size %s bytes (%.1f%% of heap),]\n",
+ uintmaxToCommaString(nurserySize),
+ 100.0 * ((double)(nurserySize) / (double)(s->heap.size)));
+ fprintf (stderr,
+ "[GC:\tand old-gen of size %s bytes (%.1f%% of heap),]\n",
+ uintmaxToCommaString(s->heap.oldGenSize),
+ 100.0 * ((double)(s->heap.oldGenSize) / (double)(s->heap.size)));
+ fprintf (stderr,
+ "[GC:\tand nursery using %s bytes (%.1f%% of heap, %.1f%% of nursery).]\n",
+ uintmaxToCommaString(nurseryUsed),
+ 100.0 * ((double)(nurseryUsed) / (double)(s->heap.size)),
+ 100.0 * ((double)(nurseryUsed) / (double)(nurserySize)));
+ }
assert (invariantForGC (s));
if (needGCTime (s))
startTiming (&ru_start);
@@ -130,11 +154,23 @@
} else
gcTime = 0; /* Assign gcTime to quell gcc warning. */
if (DEBUG or s->controls.messages) {
- fprintf (stderr, "[GC: Finished gc; time: %s ms, old-gen: %s bytes (%.1f%%).]\n",
- uintmaxToCommaString(gcTime),
+ size_t nurserySize = s->heap.size - (s->heap.nursery - s->heap.start);
+ fprintf (stderr,
+ "[GC: Finished gc #%s; time %s ms,]\n",
+ uintmaxToCommaString(s->cumulativeStatistics.numGCs),
+ uintmaxToCommaString(gcTime));
+ fprintf (stderr,
+ "[GC:\theap at "FMTPTR" of size %s bytes,]\n",
+ (uintptr_t)(s->heap.start),
+ uintmaxToCommaString(s->heap.size));
+ fprintf (stderr,
+ "[GC:\twith nursery of size %s bytes (%.1f%% of heap),]\n",
+ uintmaxToCommaString(nurserySize),
+ 100.0 * ((double)(nurserySize) / (double)(s->heap.size)));
+ fprintf (stderr,
+ "[GC:\tand old-gen of size %s bytes (%.1f%% of heap).]\n",
uintmaxToCommaString(s->heap.oldGenSize),
- 100.0 * ((double)(s->heap.oldGenSize)
- / (double)(s->heap.size)));
+ 100.0 * ((double)(s->heap.oldGenSize) / (double)(s->heap.size)));
}
/* Send a GC signal. */
if (s->signalsInfo.gcSignalHandled
Modified: mlton/trunk/runtime/gc/gc_state.h
===================================================================
--- mlton/trunk/runtime/gc/gc_state.h 2007-07-25 07:04:26 UTC (rev 5789)
+++ mlton/trunk/runtime/gc/gc_state.h 2007-07-25 23:04:09 UTC (rev 5790)
@@ -64,6 +64,7 @@
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;
uint32_t vectorInitsLength;
GC_weak weaks; /* Linked list of (live) weak pointers */
Modified: mlton/trunk/runtime/gc/heap.c
===================================================================
--- mlton/trunk/runtime/gc/heap.c 2007-07-25 07:04:26 UTC (rev 5789)
+++ mlton/trunk/runtime/gc/heap.c 2007-07-25 23:04:09 UTC (rev 5790)
@@ -51,8 +51,8 @@
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.
+ * happens. This is so resizeHeapSecondary 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->controls.ratios.copy + s->controls.ratios.grow) {
@@ -110,7 +110,8 @@
if (NULL == h->start)
return;
if (DEBUG or s->controls.messages)
- fprintf (stderr, "[GC: Releasing heap at "FMTPTR" of size %s bytes.]\n",
+ fprintf (stderr,
+ "[GC: Releasing heap at "FMTPTR" of size %s bytes.]\n",
(uintptr_t)(h->start),
uintmaxToCommaString(h->size));
GC_release (h->start, h->size);
@@ -190,20 +191,23 @@
if (h->size > s->cumulativeStatistics.maxHeapSizeSeen)
s->cumulativeStatistics.maxHeapSizeSeen = h->size;
if (DEBUG or s->controls.messages)
- fprintf (stderr, "[GC: Created heap at "FMTPTR" of size %s bytes.]\n",
+ fprintf (stderr,
+ "[GC: Created heap at "FMTPTR" of size %s bytes.]\n",
(uintptr_t)(h->start),
uintmaxToCommaString(h->size));
assert (h->size >= minSize);
return TRUE;
}
}
- if (s->controls.messages)
- fprintf(stderr,
- "[GC: Creating heap of size %s bytes cannot be satisfied; "
- "backing off by %s bytes (min size = %s).]\n",
- sizeToBytesApproxString (h->size),
- sizeToBytesApproxString (backoff),
- sizeToBytesApproxString (minSize));
+ if (s->controls.messages) {
+ fprintf (stderr,
+ "[GC: Creating heap of size %s bytes cannot be satisfied,]\n",
+ uintmaxToCommaString (h->size));
+ fprintf (stderr,
+ "[GC:\tbacking off by %s bytes with minimum size of %s bytes.]\n",
+ uintmaxToCommaString (backoff),
+ uintmaxToCommaString (minSize));
+ }
}
h->size = 0;
return FALSE;
@@ -267,13 +271,18 @@
pointer orig;
size_t size;
- curHeapp = &s->heap;
assert (desiredSize >= s->heap.size);
- if (DEBUG_RESIZING)
- fprintf (stderr, "Growing heap at "FMTPTR" of size %s to %s bytes.\n",
+ if (DEBUG_RESIZING or s->controls.messages) {
+ fprintf (stderr,
+ "[GC: Growing heap at "FMTPTR" of size %s bytes,]\n",
(uintptr_t)s->heap.start,
- uintmaxToCommaString(s->heap.size),
- uintmaxToCommaString(desiredSize));
+ uintmaxToCommaString(s->heap.size));
+ fprintf (stderr,
+ "[GC:\tto desired size of %s bytes and minimum size of %s bytes.]\n",
+ uintmaxToCommaString(desiredSize),
+ uintmaxToCommaString(minSize));
+ }
+ curHeapp = &s->heap;
orig = curHeapp->start;
size = curHeapp->oldGenSize;
assert (size <= s->heap.size);
@@ -311,9 +320,21 @@
/* Write the heap to disk and try again. */
void *data;
+ if (DEBUG or s->controls.messages) {
+ fprintf (stderr,
+ "[GC: Writing heap at "FMTPTR" of size %s bytes to disk.]\n",
+ (uintptr_t)orig,
+ uintmaxToCommaString(size));
+ }
data = GC_diskBack_write (orig, size);
releaseHeap (s, curHeapp);
if (createHeap (s, curHeapp, desiredSize, minSize)) {
+ if (DEBUG or s->controls.messages) {
+ fprintf (stderr,
+ "[GC: Reading heap at "FMTPTR" of size %s bytes from disk.]\n",
+ (uintptr_t)orig,
+ uintmaxToCommaString(size));
+ }
GC_diskBack_read (data, curHeapp->start, size);
GC_diskBack_close (data);
} else {
Modified: mlton/trunk/runtime/gc/heap.h
===================================================================
--- mlton/trunk/runtime/gc/heap.h 2007-07-25 07:04:26 UTC (rev 5789)
+++ mlton/trunk/runtime/gc/heap.h 2007-07-25 23:04:09 UTC (rev 5790)
@@ -22,8 +22,8 @@
*/
typedef struct GC_heap {
+ pointer nursery; /* start of nursery */
size_t oldGenSize; /* size of old generation */
- pointer nursery; /* start of nursery */
size_t size; /* size of heap */
pointer start; /* start of heap (and old generation) */
} *GC_heap;
Modified: mlton/trunk/runtime/gc/init.c
===================================================================
--- mlton/trunk/runtime/gc/init.c 2007-07-25 07:04:26 UTC (rev 5789)
+++ mlton/trunk/runtime/gc/init.c 2007-07-25 23:04:09 UTC (rev 5790)
@@ -307,9 +307,10 @@
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, "[GC: total RAM = %s, using RAM = %s.]\n",
+ fprintf (stderr, "[GC: Found %s bytes of RAM; using %s bytes (%.1f%% of RAM).]\n",
uintmaxToCommaString(s->sysvals.totalRam),
- uintmaxToCommaString(s->sysvals.ram));
+ uintmaxToCommaString(s->sysvals.ram),
+ 100.0 * s->controls.ratios.ramSlop);
if (DEBUG_SOURCES or DEBUG_PROFILE) {
uint32_t i;
for (i = 0; i < s->sourceMaps.frameSourcesLength; i++) {
Modified: mlton/trunk/runtime/gc/mark-compact.c
===================================================================
--- mlton/trunk/runtime/gc/mark-compact.c 2007-07-25 07:04:26 UTC (rev 5789)
+++ mlton/trunk/runtime/gc/mark-compact.c 2007-07-25 23:04:09 UTC (rev 5790)
@@ -284,7 +284,10 @@
startTiming (&ru_start);
s->cumulativeStatistics.numMarkCompactGCs++;
if (DEBUG or s->controls.messages) {
- fprintf (stderr, "[GC: Major mark-compact; heap at "FMTPTR" of size %s bytes.]\n",
+ fprintf (stderr,
+ "[GC: Starting major mark-compact;]\n");
+ fprintf (stderr,
+ "[GC:\theap at "FMTPTR" of size %s bytes.]\n",
(uintptr_t)(s->heap.start),
uintmaxToCommaString(s->heap.size));
}
@@ -307,7 +310,8 @@
if (detailedGCTime (s))
stopTiming (&ru_start, &s->cumulativeStatistics.ru_gcMarkCompact);
if (DEBUG or s->controls.messages) {
- fprintf (stderr, "[GC: Major mark-compact done; %s bytes mark compacted.]\n",
+ fprintf (stderr,
+ "[GC: Finished major mark-compact; mark compacted %s bytes.]\n",
uintmaxToCommaString(bytesMarkCompacted));
if (s->hashConsDuringGC)
printBytesHashConsedMessage(s,
Modified: mlton/trunk/runtime/gc/pack.c
===================================================================
--- mlton/trunk/runtime/gc/pack.c 2007-07-25 07:04:26 UTC (rev 5789)
+++ mlton/trunk/runtime/gc/pack.c 2007-07-25 23:04:09 UTC (rev 5790)
@@ -11,7 +11,8 @@
enter (s);
if (DEBUG or s->controls.messages)
- fprintf (stderr, "[GC: Packing heap at "FMTPTR" of size %s bytes.]\n",
+ fprintf (stderr,
+ "[GC: Packing heap at "FMTPTR" of size %s bytes.]\n",
(uintptr_t)(s->heap.start),
uintmaxToCommaString(s->heap.size));
/* Could put some code here to skip the GC if there hasn't been much
@@ -27,7 +28,8 @@
}
releaseHeap (s, &s->secondaryHeap);
if (DEBUG or s->controls.messages)
- fprintf (stderr, "[GC: Packed heap at "FMTPTR" to size %s bytes.]\n",
+ fprintf (stderr,
+ "[GC: Packed heap at "FMTPTR" to size %s bytes.]\n",
(uintptr_t)(s->heap.start),
uintmaxToCommaString(s->heap.size));
leave (s);
@@ -36,7 +38,8 @@
void GC_unpack (GC_state s) {
enter (s);
if (DEBUG or s->controls.messages)
- fprintf (stderr, "[GC: Unpacking heap at "FMTPTR" of size %s bytes.]\n",
+ fprintf (stderr,
+ "[GC: Unpacking heap at "FMTPTR" of size %s bytes.]\n",
(uintptr_t)(s->heap.start),
uintmaxToCommaString(s->heap.size));
/* The enterGC is needed here because minorGC and resizeHeap might
@@ -51,7 +54,8 @@
setGCStateCurrentThreadAndStack (s);
leaveGC (s);
if (DEBUG or s->controls.messages)
- fprintf (stderr, "[GC: Unpacked heap at "FMTPTR" to size %s bytes.]\n",
+ fprintf (stderr,
+ "[GC: Unpacked heap at "FMTPTR" to size %s bytes.]\n",
(uintptr_t)(s->heap.start),
uintmaxToCommaString(s->heap.size));
leave (s);
Modified: mlton/trunk/runtime/gc/statistics.h
===================================================================
--- mlton/trunk/runtime/gc/statistics.h 2007-07-25 07:04:26 UTC (rev 5789)
+++ mlton/trunk/runtime/gc/statistics.h 2007-07-25 23:04:09 UTC (rev 5790)
@@ -24,6 +24,7 @@
uintmax_t numLimitChecks;
+ uintmax_t numGCs;
uintmax_t numCopyingGCs;
uintmax_t numHashConsGCs;
uintmax_t numMarkCompactGCs;
Modified: mlton/trunk/runtime/gc/translate.c
===================================================================
--- mlton/trunk/runtime/gc/translate.c 2007-07-25 07:04:26 UTC (rev 5789)
+++ mlton/trunk/runtime/gc/translate.c 2007-07-25 23:04:09 UTC (rev 5790)
@@ -10,19 +10,16 @@
/* translateHeap */
/* ---------------------------------------------------------------- */
-struct translateState {
- pointer from;
- pointer to;
-};
-static struct translateState translateState;
-
-void translateObjptr (__attribute__ ((unused)) GC_state s,
+void translateObjptr (GC_state s,
objptr *opp) {
pointer p;
+ pointer from, to;
- p = objptrToPointer (*opp, translateState.from);
- p = (p - translateState.from) + translateState.to;
- *opp = pointerToObjptr (p, translateState.to);
+ from = s->translateState.from;
+ to = s->translateState.to;
+ p = objptrToPointer (*opp, from);
+ p = (p - from) + to;
+ *opp = pointerToObjptr (p, to);
}
/* translateHeap (s, from, to, size)
@@ -30,17 +27,17 @@
void translateHeap (GC_state s, pointer from, pointer to, size_t size) {
pointer limit;
- if (DEBUG or s->controls.messages)
- fprintf (stderr, "[GC: Translating heap at "FMTPTR" of size %s bytes to "FMTPTR".]\n",
- (uintptr_t)from,
- uintmaxToCommaString(size),
- (uintptr_t)to);
if (from == to)
return;
- else {
- translateState.from = from;
- translateState.to = to;
- }
+
+ if (DEBUG or s->controls.messages)
+ fprintf (stderr,
+ "[GC: Translating heap at "FMTPTR" of size %s bytes from "FMTPTR".]\n",
+ (uintptr_t)to,
+ uintmaxToCommaString(size),
+ (uintptr_t)from);
+ s->translateState.from = from;
+ s->translateState.to = to;
/* Translate globals and heap. */
foreachGlobalObjptr (s, translateObjptr);
limit = to + size;
Modified: mlton/trunk/runtime/gc/translate.h
===================================================================
--- mlton/trunk/runtime/gc/translate.h 2007-07-25 07:04:26 UTC (rev 5789)
+++ mlton/trunk/runtime/gc/translate.h 2007-07-25 23:04:09 UTC (rev 5790)
@@ -6,6 +6,15 @@
* See the file MLton-LICENSE for details.
*/
+#if (defined (MLTON_GC_INTERNAL_TYPES))
+
+struct GC_translateState {
+ pointer from;
+ pointer to;
+};
+
+#endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
+
#if (defined (MLTON_GC_INTERNAL_FUNCS))
static inline void translateObjptr (GC_state s, objptr *opp);
More information about the MLton-commit
mailing list