cvs commit: fixed @MLton {fixed,max}-heap

Stephen Weeks sweeks@users.sourceforge.net
Mon, 08 Sep 2003 17:51:06 -0700


sweeks      03/09/08 17:51:06

  Modified:    doc      changelog
               runtime  gc.c gc.h
  Log:
  Fixed @MLton max-heap, which was mistakenly ignored.  Cleaned up
  @MLton fixed-heap.  Both fixed-heap and max-heap can use copying or
  mark-compact collection.
  
  Added check to runtime so that one can use max-heap or fixed-heap, but
  not both.
  
  The way both now work is that heapDesired size adjusts the amount of
  heap space to meet the constraint.  Then, there is another check
  before allocating a second semispace that the sum of the semispace
  sizes meets the constraint.

Revision  Changes    Path
1.72      +5 -0      mlton/doc/changelog

Index: changelog
===================================================================
RCS file: /cvsroot/mlton/mlton/doc/changelog,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- changelog	6 Sep 2003 19:42:43 -0000	1.71
+++ changelog	9 Sep 2003 00:51:06 -0000	1.72
@@ -1,5 +1,10 @@
 Here are the changes since version 20030716.
 
+* 2003-09-08
+  - Fixed @MLton max-heap, which was mistakenly ignored.  Cleaned up
+    @MLton fixed-heap.  Both fixed-heap and max-heap can use copying
+    or mark-compact collection.
+
 * 2003-09-06
   - Int64 is completely there.
   - Fixed OS.FileSys.tmpName so that it creates the file, and doesn't



1.155     +36 -17    mlton/runtime/gc.c

Index: gc.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/gc.c,v
retrieving revision 1.154
retrieving revision 1.155
diff -u -r1.154 -r1.155
--- gc.c	29 Aug 2003 00:25:21 -0000	1.154
+++ gc.c	9 Sep 2003 00:51:06 -0000	1.155
@@ -78,7 +78,7 @@
 	DEBUG_MARK_COMPACT = FALSE,
 	DEBUG_MEM = FALSE,
 	DEBUG_PROFILE = FALSE,
-	DEBUG_RESIZING = FALSE,
+	DEBUG_RESIZING = TRUE,
 	DEBUG_SIGNALS = FALSE,
 	DEBUG_STACKS = FALSE,
 	DEBUG_THREADS = FALSE,
@@ -224,7 +224,7 @@
 
 static void sunlink (char *path) {
 	unless (0 == unlink (path))
-		diee ("unkink (%s) failed", path);
+		diee ("unlink (%s) failed", path);
 }
 
 /* ---------------------------------------------------------------- */
@@ -378,7 +378,7 @@
 	result = mmapAnon (NULL, length);
 	if ((void*)-1 == result) {
 		showMem ();
-		diee ("Out of memory.");
+		die ("Out of memory.");
 	}
 	return result;
 }
@@ -1339,9 +1339,7 @@
 		die ("Out of memory: %s bytes live.", 
 				ullongToCommaString (live));
 	ratio = (float)s->ram / (float)live;
-	if (s->useFixedHeap)
-		res = s->fixedHeapSize;
-        else if (ratio >= s->liveRatio + s->growRatio) {
+        if (ratio >= s->liveRatio + s->growRatio) {
 		/* Cheney copying fits in RAM with desired liveRatio. */
 		res = live * s->liveRatio;
 		/* If the heap is currently close in size to what we want, leave
@@ -1386,6 +1384,21 @@
 		 * in growFromSpace will make the right thing happen.
 		 */ 
 	}
+	if (s->fixedHeap > 0) {
+		if (res > s->fixedHeap / 2)
+			res = s->fixedHeap;
+		else
+			res = s->fixedHeap / 2;
+		if (res < live)
+			die ("Out of memory with fixed heap size %s.",
+				uintToCommaString (s->fixedHeap));
+	} else if (s->maxHeap > 0) {
+		if (res > s->maxHeap)
+			res = s->maxHeap;
+		if (res < live)
+			die ("Out of memory with max heap size %s.",
+				uintToCommaString (s->maxHeap));
+	}
 	if (DEBUG_RESIZING)
 		fprintf (stderr, "%s = heapDesiredSize (%s)\n",
 				uintToCommaString (res),
@@ -2880,15 +2893,19 @@
 /*                        Garbage Collection                        */
 /* ---------------------------------------------------------------- */
 
+static bool heapAllocateSecondSemi (GC_state s, W32 size) {
+	if ((s->fixedHeap > 0 and s->heap.size + size > s->fixedHeap)
+		or (s->maxHeap > 0 and s->heap.size + size > s->maxHeap))
+		return FALSE;
+	return heapCreate (s, &s->heap2, size, s->oldGenSize);
+}
+
 static void majorGC (GC_state s, W32 bytesRequested, bool mayResize) {
 	s->numMinorsSinceLastMajor = 0;
         if (not FORCE_MARK_COMPACT
-		and not s->useFixedHeap
  		and s->heap.size < s->ram
 		and (not heapIsInit (&s->heap2)
-			or heapCreate (s, &s->heap2,
-					heapDesiredSize (s, (W64)s->bytesLive + bytesRequested, 0),
-					s->oldGenSize)))
+			or heapAllocateSecondSemi (s, heapDesiredSize (s, (W64)s->bytesLive + bytesRequested, 0))))
 		cheneyCopy (s);
 	else
 		markCompact (s);
@@ -4285,9 +4302,9 @@
 					++i;
 					if (i == argc)
 						die ("@MLton fixed-heap missing argument.");
-					s->useFixedHeap = TRUE;
-					s->fixedHeapSize =
-						stringToBytes (argv[i++]);
+					s->fixedHeap = 
+						align (stringToBytes (argv[i++]),
+							2 * s->pageSize);
 				} else if (0 == strcmp (arg, "gc-messages")) {
 					++i;
 					s->messages = TRUE;
@@ -4324,8 +4341,8 @@
 					++i;
 					if (i == argc) 
 						die ("@MLton max-heap missing argument.");
-					s->useFixedHeap = FALSE;
-					s->maxHeap = stringToBytes (argv[i++]);
+					s->maxHeap = align (stringToBytes (argv[i++]),
+								2 * s->pageSize);
 				} else if (0 == strcmp (arg, "mark-compact-generational-ratio")) {
 					++i;
 					if (i == argc)
@@ -4389,6 +4406,7 @@
 	s->copyRatio = 4.0;
 	s->copyGenerationalRatio = 4.0;
 	s->currentThread = BOGUS_THREAD;
+	s->fixedHeap = 0.0;
 	s->gcSignalIsPending = FALSE;
 	s->growRatio = 8.0;
 	s->handleGCSignal = FALSE;
@@ -4421,7 +4439,6 @@
 	s->signalIsPending = FALSE;
 	s->startTime = currentTime ();
 	s->summary = FALSE;
-	s->useFixedHeap = FALSE;
 	s->weaks = NULL;
 	heapInit (&s->heap);
 	heapInit (&s->heap2);
@@ -4435,9 +4452,11 @@
  	readProcessor ();
 	worldFile = NULL;
 	unless (isAligned (s->pageSize, s->cardSize))
-		die ("page size must be a multiple of card size");
+		die ("Page size must be a multiple of card size.");
 	processAtMLton (s, s->atMLtonsSize, s->atMLtons, &worldFile);
 	i = processAtMLton (s, argc, argv, &worldFile);
+	if (s->fixedHeap > 0 and s->maxHeap > 0)
+		die ("Cannot use both fixed-heap and max-heap.\n");
 	unless (ratiosOk (s))
 		die ("invalid ratios");
 	setMemInfo (s);



1.68      +1 -4      mlton/runtime/gc.h

Index: gc.h
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/gc.h,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- gc.h	29 Aug 2003 00:25:21 -0000	1.67
+++ gc.h	9 Sep 2003 00:51:06 -0000	1.68
@@ -351,7 +351,7 @@
 	 */
 	uint crossMapValidSize;
 	GC_thread currentThread; /* This points to a thread in the heap. */
-	uint fixedHeapSize; 	/* Only meaningful if useFixedHeap. */
+	uint fixedHeap;	/* If 0, then no fixed heap. */
 	GC_frameLayout *frameLayouts;
 	uint frameLayoutsSize;
 	/* frameSources is an array of length frameLayoutsSize that for each
@@ -488,7 +488,6 @@
 	uint totalSwap; 	/* bytes */
 	uint translateDiff;	/* used by translateHeap */
  	bool translateUp;	/* used by translateHeap */
-	bool useFixedHeap; 	/* if true, then don't resize the heap */
 	GC_weak weaks;
 } *GC_state;
 
@@ -593,7 +592,6 @@
  * strings and intInfs.
  *
  * Before calling GC_init, you must initialize:
- *   fixedHeapSize
  *   frameLayouts
  *   globals 
  *   intInfInits
@@ -607,7 +605,6 @@
  *   objectTypes
  *   saveGlobals
  *   stringInits
- *   useFixedHeap
  *
  * GC_init returns the index of the first non-runtime command-line arg.
  */