[m-rev.] diff: MLDS accurate GC heap resizing

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Nov 13 21:45:40 AEDT 2003


On 22-Oct-2003, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Various improvements for accurate GC in LLDS grades:
> 
>     - allow the active heap size to vary
>       (XXX currently we still allocate a fixed-size heap, and allow
>       the active heap size to vary within that; it would be better
>       to avoid that, by reallocating a bigger heap if the heap
>       fills up)

And likewise for MLDS accurate GC.

----------

Estimated hours taken: 0.25
Branches: main

runtime/mercury_accurate_gc.c:
	For MLDS accurate GC, recompute heap_zone->gc_theshhold at the
	end of each collection, similar to the way we recompute the
	red zone sizes for LLDS accurate GC.

	(Also, improve the debugging output for LLDS GC scheduling.)

Workspace: /home/jupiter/fjh/ws-jupiter/mercury
Index: runtime/mercury_accurate_gc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_accurate_gc.c,v
retrieving revision 1.30
diff -u -d -b -r1.30 mercury_accurate_gc.c
--- runtime/mercury_accurate_gc.c	12 Nov 2003 13:56:30 -0000	1.30
+++ runtime/mercury_accurate_gc.c	13 Nov 2003 10:28:34 -0000
@@ -161,6 +161,12 @@
     maybe_clear_old_heap(old_heap, old_hp);
 
     /*
+    ** Compute the new size at which to GC,
+    ** and reset the gc_threshold on the new heap.
+    */
+    resize_and_reset_gc_threshold(old_heap, new_heap);
+
+    /*
     ** Print some more debugging messages,
     */
     if (MR_agc_debug) {
@@ -182,6 +188,35 @@
     }
 }
 
+/*
+** Compute the new size at which to GC,
+** and reset the redzone on the new heap.
+*/
+static void
+resize_and_reset_gc_threshold(MR_MemoryZone *old_heap, MR_MemoryZone *new_heap)
+{
+    /* These counts include some wasted space between ->min and ->bottom. */
+    size_t old_heap_space =
+        (char *) old_heap->gc_threshold - (char *) old_heap->bottom;
+    size_t new_heap_usage =
+        (char *) MR_virtual_hp - (char *) new_heap->bottom;
+    size_t gc_heap_size;
+
+    /*
+    ** Set the size at which to GC to be MR_heap_expansion_factor
+    ** (which defaults to two) times the current usage,
+    ** or the size at which we GC'd last time, whichever is larger.
+    */
+    gc_heap_size = MR_round_up(
+            (size_t) (MR_heap_expansion_factor * new_heap_usage),
+            MR_unit);
+    if (gc_heap_size < old_heap_space) {
+        gc_heap_size = old_heap_space;
+    }
+    old_heap->gc_threshold = (MR_Word *)
+            ((char *) old_heap->bottom + gc_heap_size);
+}
+
 /*---------------------------------------------------------------------------*/
 /*
 ** The LLDS version of the collector.
@@ -271,6 +306,9 @@
                 fprintf(stderr, "at address %p "
                         "has no stack layout info\n", entry_label->e_addr);
             }
+            fprintf(stderr, "Mercury runtime: PC address = %p\n", pc_at_signal);
+            fprintf(stderr, "Mercury runtime: PC = label + 0x%lx\n",
+                (long) ((char *)pc_at_signal - (char *)entry_label->e_addr));
         } else {
             fprintf(stderr, "Mercury runtime: no entry label ");
             fprintf(stderr, "for PC address %p\n", pc_at_signal);
@@ -884,8 +922,6 @@
 static void
 resize_and_reset_redzone(MR_MemoryZone *old_heap, MR_MemoryZone *new_heap)
 {
-    /* Reset the redzone on the new heap */
-    {
         /* These counts include some wasted space between ->min and ->bottom. */
         size_t old_heap_space =
             (char *) old_heap->redzone_base - (char *) old_heap->bottom;
@@ -904,10 +940,11 @@
         if (gc_heap_size < old_heap_space) {
             gc_heap_size = old_heap_space;
         }
+
+    /* Reset the redzone on the new heap */
         old_heap->redzone_base = (MR_Word *)
                 ((char *) old_heap->bottom + gc_heap_size);
         MR_reset_redzone(old_heap);
-    }
 }
 
 #endif /* !MR_HIGHLEVEL_CODE */

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list