[m-rev.] diff: LLDS accurate GC fixes

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Oct 13 20:16:54 AEST 2003


Estimated hours taken: 10
Branches: main

Some fixes for accurate GC in LLDS grades (i.e. asm_fast.agc).

runtime/mercury_accurate_gc.c:
	Factor out the code for initializing the forwarding pointer
	bitmap from the MLDS accurate GC code, so that it can be shared
	between the MLDS and LLDS versions.

	Update the code for doing accurate GC in the LLDS case: add
	missing MR_ prefixes, and add a call to the procedure which
	initializes the forwarding pointer bitmap.

compiler/handle_options.m:
	For LLDS accurate GC grades, turn off opt_no_return_calls and
	middle recursion optimization, since those optimizations don't
	preserve agc typeinfo liveness and agc stack layouts (respectively).
	But don't turn off optimize_higher_order; that only causes
	problems for MLDS accurate GC grades.

Workspace: /home/ceres/fjh/mercury
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.186
diff -u -d -r1.186 handle_options.m
--- compiler/handle_options.m	6 Aug 2003 12:38:09 -0000	1.186
+++ compiler/handle_options.m	13 Oct 2003 10:08:06 -0000
@@ -850,9 +850,12 @@
 	% `trace' stack layouts need `procid' stack layouts
 	option_implies(trace_stack_layout, procid_stack_layout, bool(yes)),
 
-	% --gc accurate for the LLDS back-end (not yet implemented...)
-	% requires `agc' stack layouts, typeinfo liveness, and
-	% needs hijacks and frameopt to be switched off.
+	% --gc accurate for the LLDS back-end requires `agc' stack layouts,
+	% typeinfo liveness, and needs hijacks, frameopt, and middle recursion
+	% optimization to be switched off.
+	% We also turn off optimization of stack slots for no_return calls,
+	% because that optimization does not preserve agc typeinfo liveness.
+	%
 	% For the MLDS back-end, `--gc accurate' requires just typeinfo
 	% liveness.
 	%
@@ -871,7 +874,8 @@
 	%      GC occurs. A better method would be to just allocate a
 	%      word of heap space at each choice point.
 	%
-	% XXX currently accurate GC also requires disabling the higher-order
+	% XXX for the MLDS back-end,
+	% accurate GC currently also requires disabling the higher-order
 	% specialization pass, since that pass creates procedures
 	% which don't respect left-to-right scoping of type_info parameters,
 	% i.e. in which a parameter X may have a type whose type_info var
@@ -883,11 +887,13 @@
 		globals__io_set_option(body_typeinfo_liveness, bool(yes)),
 		globals__io_set_option(allow_hijacks, bool(no)),
 		globals__io_set_option(optimize_frames, bool(no)),
+		globals__io_set_option(opt_no_return_calls, bool(no)),
+		globals__io_set_option(middle_rec, bool(no)),
 		globals__io_set_option(
 			reclaim_heap_on_semidet_failure, bool(no)),
 		globals__io_set_option(
 			reclaim_heap_on_nondet_failure, bool(no)),
-		globals__io_set_option(optimize_higher_order, bool(no))
+		option_implies(highlevel_code, optimize_higher_order, bool(no))
 	;
 		[]
 	),
Index: runtime/mercury_accurate_gc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_accurate_gc.c,v
retrieving revision 1.23
diff -u -d -r1.23 mercury_accurate_gc.c
--- runtime/mercury_accurate_gc.c	19 Aug 2002 06:42:08 -0000	1.23
+++ runtime/mercury_accurate_gc.c	13 Oct 2003 09:02:24 -0000
@@ -60,6 +60,31 @@
 /* The last root on the list */
 static MR_RootList last_root = NULL;
 
+/*
+** Initialize the forwarding pointer bitmap (MR_has_forwarding_pointer[])
+** with all bits unset (zero).
+*/
+static void
+init_forwarding_pointer_bitmap(const MR_MemoryZone *old_heap)
+{
+    size_t			    heap_size_in_words;
+    size_t			    num_words_for_bitmap;
+    size_t			    num_bytes_for_bitmap;
+    static size_t		    prev_num_bytes_for_bitmap;
+
+    heap_size_in_words = old_heap->hardmax - old_heap->min;
+    num_words_for_bitmap = (heap_size_in_words + MR_WORDBITS - 1) / MR_WORDBITS;
+    num_bytes_for_bitmap = num_words_for_bitmap * sizeof(MR_Word);
+    if (MR_has_forwarding_pointer == NULL
+	|| num_bytes_for_bitmap > prev_num_bytes_for_bitmap)
+    {
+	MR_has_forwarding_pointer = MR_realloc(MR_has_forwarding_pointer,
+					num_bytes_for_bitmap);
+	prev_num_bytes_for_bitmap = num_bytes_for_bitmap;
+    }
+    memset(MR_has_forwarding_pointer, 0, num_bytes_for_bitmap);
+}
+
 #ifdef MR_HIGHLEVEL_CODE
 
 /*
@@ -76,10 +101,6 @@
 {
     MR_MemoryZone                   *old_heap, *new_heap;
     MR_Word                         *old_hp, *new_hp;
-    size_t			    heap_size_in_words;
-    size_t			    num_words_for_bitmap;
-    size_t			    num_bytes_for_bitmap;
-    static size_t		    prev_num_bytes_for_bitmap;
 
     old_heap = MR_ENGINE(MR_eng_heap_zone);
     new_heap = MR_ENGINE(MR_eng_heap_zone2);
@@ -108,17 +129,7 @@
     /*
     ** Initialize the forwarding pointer bitmap.
     */
-    heap_size_in_words = old_heap->hardmax - old_heap->min;
-    num_words_for_bitmap = (heap_size_in_words + MR_WORDBITS - 1) / MR_WORDBITS;
-    num_bytes_for_bitmap = num_words_for_bitmap * sizeof(MR_Word);
-    if (MR_has_forwarding_pointer == NULL
-	|| num_bytes_for_bitmap > prev_num_bytes_for_bitmap)
-    {
-	MR_has_forwarding_pointer = MR_realloc(MR_has_forwarding_pointer,
-					num_bytes_for_bitmap);
-	prev_num_bytes_for_bitmap = num_bytes_for_bitmap;
-    }
-    memset(MR_has_forwarding_pointer, 0, num_bytes_for_bitmap);
+    init_forwarding_pointer_bitmap(old_heap);
 
     /*
     ** Swap the two heaps.
@@ -197,7 +208,7 @@
 	}
 }
 
-#else
+#else /* !MR_HIGHLEVEL_CODE */
 
 /*
 ** MR_schedule_agc:
@@ -344,7 +355,7 @@
 	** Replace the old succip with the address of the
 	** garbage collector.
 	*/
-	*saved_success_location = (Word) mercury__garbage_collect_0_0;
+	*saved_success_location = (MR_Word) mercury__garbage_collect_0_0;
 
 #ifdef MR_DEBUG_AGC_SCHEDULING
 	fprintf(stderr, "Accurate GC scheduled.\n");
@@ -384,7 +395,10 @@
 **
 ** 	The main garbage collection routine.
 **
-**  (We use 4 space tabs here because of the depth of indentation).
+** This is the version for the LLDS back-end.  Beware that there is some
+** code duplication with the version for the MLDS back-end, which is above.
+**
+** (We use 4 space tabs here because of the depth of indentation).
 */
 static void
 garbage_collect(MR_Code *success_ip, MR_Word *stack_pointer, 
@@ -426,6 +440,11 @@
     MR_virtual_hp = new_heap->min;
 
     /*
+    ** Initialize the forwarding pointer bitmap.
+    */
+    init_forwarding_pointer_bitmap(old_heap);
+
+    /*
     ** Swap the two heaps.
     */
     {
@@ -466,6 +485,14 @@
     }
 
     /*
+    ** First, traverse the call stack.  This includes all of the det stack
+    ** and the success continuation frames on the nondet stack.  It does not
+    ** include the failure continuation frames on the nondet stack.
+    ** (We really only need to traverse the det stack here, but there's no
+    ** way to do that without traversing the success continuation frames of
+    ** the nondet stack too.)
+    */
+    /*
     ** For each stack frame ...
     */
     do {
@@ -475,7 +502,7 @@
 	int				short_var_count, long_var_count;
 
 	if (MR_agc_debug) {
-	    printlabel((MR_Code *) (Word) label->i_addr);
+	    MR_printlabel(stderr, (MR_Code *) (MR_Word) label->i_addr);
        	    fflush(NULL);
 	}
 
@@ -536,7 +563,7 @@
 		type = MR_LONG_LVAL_TYPE(location);
 		number = MR_LONG_LVAL_NUMBER(location);
 		if (type != MR_LONG_LVAL_TYPE_STACKVAR) {
-			fatal_error("can only handle stackvars");
+			MR_fatal_error("can only handle stackvars");
 			}
 		
 		success_ip = (MR_Code *) MR_based_stackvar(stack_pointer, number);
@@ -566,8 +593,11 @@
     } while (label_layout != NULL); /* end for each stack frame... */
 
     /* 
-    ** New code for nondet.
-    ** XXX Will we need correct value of stack_pointer?
+    ** Next, traverse the whole of the nondet stack.
+    ** XXX Will we need correct value of stack_pointer (the pointer
+    **     to the det stack)?
+    **     Hopefully not, since I think that for nondet code, all values
+    **     should be saved on the nondet stack, not the det stack?
     */ 
     
     while (max_frame > MR_nondet_stack_trace_bottom) {
@@ -579,22 +609,23 @@
 
 	if (frame_size == MR_NONDET_TEMP_SIZE) {
 	    if (MR_agc_debug) {
-		printlabel(MR_redoip_slot(max_frame));
+		MR_printlabel(stderr, MR_redoip_slot(max_frame));
 		fflush(NULL);
 	    }
 	} else if (frame_size == MR_DET_TEMP_SIZE) {
 	    if (MR_agc_debug) {
-		printlabel(MR_redoip_slot(max_frame));
+		MR_printlabel(stderr, MR_redoip_slot(max_frame));
 		fflush(NULL);
 	    }
 	    stack_pointer = MR_tmp_detfr_slot(max_frame); /* XXX ??? */
 	} else {
 	    if (MR_agc_debug) {
-		printlabel(MR_redoip_slot(max_frame));
+		MR_printlabel(stderr, MR_redoip_slot(max_frame));
 		fflush(NULL);
 	    }
 	}
 	label = MR_lookup_internal_by_addr(MR_redoip_slot(max_frame));
+	stack_pointer = NULL; /* XXX ??? */
 
 	if (label != NULL) {
 		int short_var_count, long_var_count;
@@ -657,7 +688,7 @@
         fprintf(stderr, "Clearing old heap:\n");
 
         {
-	    Word *tmp_hp;
+	    MR_Word *tmp_hp;
 
 	    for (tmp_hp = old_heap->min; tmp_hp <= old_hp; tmp_hp++) {
 		*tmp_hp = 0xDEADBEAF;

-- 
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