[m-rev.] for review: more MLDS accurate GC changes

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jan 23 22:05:38 AEDT 2002


With these changes, all of the basic framework for accurate GC in the
MLDS->C back-end is in place; accurate GC should now in theory work for
code that does not use higher-order, type classes, or `pragma export',
modulo bugs.  However, I haven't tested it yet, and so probably there
are still plenty of bugs.

----------

Estimated hours taken: 8
Branches: main

More improvements to accurate GC for the MLDS->C back-end.

runtime/mercury_accurate_gc.h:
runtime/mercury_accurate_gc.c:
	Add new routine MR_garbage_collect().

runtime/mercury_memory_handlers.c:
	Wrap `#ifndef MR_HIGHLEVEL_CODE' around some LLDS-specific
	code for accurate GC.

runtime/mercury_accurate_gc.c:
runtime/mercury_memory_handlers.c:
	Fix some software rot: missing `MR_' and `MR_eng_' prefixes.

runtime/mercury.h:
	Add MR_GC_check() macro, which invokes MR_garbage_collect()
	if needed.

compiler/mlds.m:
	Add gc_check as a new mlds__atomic_statement.

compiler/ml_elim_nested.m:
	Insert gc_check statements at the start of every procedure
	that does any heap allocation.

compiler/ml_elim_nested.m:
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
	Minor changes to handle gc_check statements.

compiler/ml_code_util.m:
	Fix some bugs in the way that we were calling
	private_builtin__gc_trace/1.

Workspace: /home/earth/fjh/ws-earth4/mercury
Index: compiler/ml_code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.50
diff -u -d -r1.50 ml_code_util.m
--- compiler/ml_code_util.m	16 Jan 2002 01:13:32 -0000	1.50
+++ compiler/ml_code_util.m	23 Jan 2002 10:28:54 -0000
@@ -491,7 +491,7 @@
 
 	% If accurate GC is enabled, and the specified
 	% variable might contain pointers, generate code to call
-	% `private_builtin__gc_trace_var' to trace the variable.
+	% `private_builtin__gc_trace' to trace the variable.
 	% 
 :- pred ml_gen_maybe_gc_trace_code(var_name, prog_type, prog_context,
 		maybe(mlds__statement), ml_gen_info, ml_gen_info).
@@ -1987,7 +1987,7 @@
 
 	% If accurate GC is enabled, and the specified
 	% variable might contain pointers, generate code to call
-	% `private_builtin__gc_trace_var' to trace the variable.
+	% `private_builtin__gc_trace' to trace the variable.
 	%
 ml_gen_maybe_gc_trace_code(VarName, Type, Context, Maybe_GC_TraceCode) -->
 	=(MLDSGenInfo),
@@ -2068,7 +2068,7 @@
 ml_type_category_might_contain_pointers(user_type) = yes.
 
 
-	% Generate code to call to `private_builtin__gc_trace_var'
+	% Generate code to call to `private_builtin__gc_trace'
 	% to trace the specified variable.
 	%
 :- pred ml_gen_gc_trace_code(var_name, prog_type, prog_context,
@@ -2126,7 +2126,7 @@
 		[MLDS_TypeInfoStatement] ++ [MLDS_TraceStatement],
 		Context) }.
 
-	% Generate a call to `private_builtin__gc_trace_var'
+	% Generate a call to `private_builtin__gc_trace'
 	% for the specified variable, given the variable's name, type,
 	% and the already-constructed type_info variable for that type.
 	%
@@ -2144,9 +2144,9 @@
 	ml_gen_var_lval(VarName, MLDS_Type, VarLval),
 	ml_gen_var(TypeInfoVar, TypeInfoLval),
 	%
-	% Generate the address of `private_builtin__gc_trace_var/1#0'
+	% Generate the address of `private_builtin__gc_trace/1#0'
 	%
-	{ PredName = "gc_trace_var" },
+	{ PredName = "gc_trace" },
 	{ PredOrigArity = 1 },
 	{ Pred = pred((predicate), no, PredName, PredOrigArity, model_det,
 		no) },
@@ -2154,16 +2154,19 @@
 	{ mercury_private_builtin_module(PredModule) },
 	{ MLDS_Module = mercury_module_name_to_mlds(PredModule) },
 	{ Proc = qual(MLDS_Module, Pred - ProcId) },
-	{ ArgTypes = [mlds__pseudo_type_info_type,
-		mlds__ptr_type(mlds__generic_type)] },
+	{ CPointerType = mercury_type(c_pointer_type, user_type,
+			non_foreign_type(c_pointer_type)) },
+	{ ArgTypes = [mlds__pseudo_type_info_type, CPointerType] },
 	{ Signature = mlds__func_signature(ArgTypes, []) },
 	{ FuncAddr = const(code_addr_const(proc(Proc, Signature))) },
 	%
-	% Generate the call `private_builtin__gc_trace_var(TypeInfoVar, &Var)'
+	% Generate the call
+	% `private_builtin__gc_trace(TypeInfoVar, (MR_C_Pointer) &Var);'.
 	%
+	{ CastVarAddr = unop(cast(CPointerType), mem_addr(VarLval)) },
 	{ MLDS_TraceStatement = mlds__statement(
 		call(Signature, FuncAddr, no,	
-			[lval(TypeInfoLval), mem_addr(VarLval)], [], call
+			[lval(TypeInfoLval), CastVarAddr], [], call
 		), mlds__make_context(Context)) }.
 
 	% Generate HLDS code to construct the type_info for this type.
Index: compiler/ml_elim_nested.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_elim_nested.m,v
retrieving revision 1.46
diff -u -d -r1.46 ml_elim_nested.m
--- compiler/ml_elim_nested.m	11 Jan 2002 07:41:25 -0000	1.46
+++ compiler/ml_elim_nested.m	23 Jan 2002 10:49:40 -0000
@@ -151,8 +151,6 @@
 %
 % XXX Accurate GC is still not yet fully implemented.
 % TODO:
-%	- add call to GC_check at start of every possibly-recursive function
-%	  that might allocate memory (probably via a separate MLDS pass)
 %	- fix problem with undeclared local vars for some test cases
 %	  (e.g. tests/valid/agc_unbound_typevars*).
 %	- fix problem with type classes & `constraint(...)' types
@@ -320,7 +318,7 @@
 %	MR_traverse_stack(struct MR_StackChain *stack_chain)
 %	{
 %		while (stack_chain != NULL) {
-%			(*stack_chain->traverse)(stack_chain);
+%			(*stack_chain->trace)(stack_chain);
 %			stack_chain = stack_chain->prev;
 %		}
 %	}
@@ -487,6 +485,29 @@
 				HoistedDefns = HoistedDefns0
 			;
 				%
+				% for accurate GC,
+				% add a call to GC_check() at start of every
+				% function that might allocate memory
+				%
+				% (XXX we could perhaps reduce the overhead of
+				% this slightly by only doing it for
+				% possibly-recursive functions, i.e.
+				% by not doing it for leaf functions).
+				% 
+				(
+					Action = chain_gc_stack_frames,
+					statement_contains_statement(FuncBody2,
+						NewObject),
+					NewObject = mlds__statement(atomic(
+					    new_object(_, _, _, _, _, _, _, _)
+					    ), _)
+				->
+					GC_Check = [mlds__statement(
+						atomic(gc_check), Context)]
+				;
+					GC_Check = []
+				),
+				%
 				% If the function's arguments are
 				% referenced by nested functions,
 				% or (for accurate GC) may contain pointers,
@@ -539,9 +560,9 @@
 				% (if any) at the end
 				%
 				FuncBody = ml_block(EnvDecls,
-						InitEnv ++ CodeToCopyArgs ++
-						[FuncBody2] ++ UnchainFrame,
-						Context),
+					InitEnv ++ CodeToCopyArgs ++ GC_Check ++
+					[FuncBody2] ++ UnchainFrame,
+					Context),
 				%
 				% insert the environment struct type at
 				% the start of the list of hoisted definitions
@@ -1597,6 +1618,7 @@
 			MaybeCtorName, Args, ArgTypes)) -->
 	fixup_lval(Target0, Target),
 	fixup_rvals(Args0, Args).
+fixup_atomic_stmt(gc_check, gc_check) --> [].
 fixup_atomic_stmt(mark_hp(Lval0), mark_hp(Lval)) -->
 	fixup_lval(Lval0, Lval).
 fixup_atomic_stmt(restore_hp(Rval0), restore_hp(Rval)) -->
@@ -2135,6 +2157,7 @@
 	( lval_contains_var(Target, Name)
 	; rvals_contains_var(Args, Name)
 	).
+% atomic_stmt_contains_var(gc_check, _) :- fail.
 atomic_stmt_contains_var(mark_hp(Lval), Name) :-
 	lval_contains_var(Lval, Name).
 atomic_stmt_contains_var(restore_hp(Rval), Name) :-
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.80
diff -u -d -r1.80 mlds.m
--- compiler/mlds.m	16 Jan 2002 01:13:33 -0000	1.80
+++ compiler/mlds.m	23 Jan 2002 09:15:42 -0000
@@ -1156,6 +1156,12 @@
 					% 
 		)
 
+	;	gc_check
+			% Check to see if we need to do a garbage collection,
+			% and if so, do it.
+			% This is used for accurate garbage collection
+			% with the MLDS->C back-end.
+
 	;	mark_hp(mlds__lval)
 			% Tell the heap sub-system to store a marker
 			% (for later use in restore_hp/1 instructions)
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.114
diff -u -d -r1.114 mlds_to_c.m
--- compiler/mlds_to_c.m	16 Jan 2002 01:13:34 -0000	1.114
+++ compiler/mlds_to_c.m	23 Jan 2002 09:16:34 -0000
@@ -2589,6 +2589,10 @@
 	mlds_indent(Context, Indent),
 	io__write_string("}\n").
 
+mlds_output_atomic_stmt(Indent, _FuncInfo, gc_check, _) -->
+	mlds_indent(Indent),
+	io__write_string("MR_GC_check();\n").
+
 mlds_output_atomic_stmt(Indent, _FuncInfo, mark_hp(Lval), _) -->
 	mlds_indent(Indent),
 	io__write_string("MR_mark_hp("),
Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.57
diff -u -d -r1.57 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m	16 Jan 2002 01:13:35 -0000	1.57
+++ compiler/mlds_to_gcc.m	23 Jan 2002 09:16:52 -0000
@@ -2773,6 +2773,9 @@
 	gen_init_args(Args, ArgTypes, Context, 0, Target, Type, Tag,
 		DefnInfo).
 
+gen_atomic_stmt(_DefnInfo, gc_check, _) -->
+	{ sorry(this_file, "gc_check") }.
+
 gen_atomic_stmt(_DefnInfo, mark_hp(_Lval), _) -->
 	{ sorry(this_file, "mark_hp") }.
 
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.97
diff -u -d -r1.97 mlds_to_il.m
--- compiler/mlds_to_il.m	21 Jan 2002 04:39:18 -0000	1.97
+++ compiler/mlds_to_il.m	23 Jan 2002 09:17:28 -0000
@@ -415,6 +415,7 @@
 rename_atomic(new_object(L, Tag, HasSecTag, Type, MaybeSize, Ctxt, Args, Types))
 	= new_object(rename_lval(L), Tag, HasSecTag, Type, MaybeSize,
 			Ctxt, list__map(rename_rval, Args), Types).
+rename_atomic(gc_check) = gc_check.
 rename_atomic(mark_hp(L)) = mark_hp(rename_lval(L)).
 rename_atomic(restore_hp(R)) = restore_hp(rename_rval(R)).
 rename_atomic(trail_op(T)) = trail_op(T).
@@ -1757,6 +1758,9 @@
 	il_info, il_info).
 :- mode atomic_statement_to_il(in, out, in, out) is det.
 
+atomic_statement_to_il(gc_check, node(Instrs)) --> 
+	{ Instrs = [comment(
+		"gc check -- not relevant for this backend")] }.
 atomic_statement_to_il(mark_hp(_), node(Instrs)) --> 
 	{ Instrs = [comment(
 		"mark hp -- not relevant for this backend")] }.
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.18
diff -u -d -r1.18 mlds_to_java.m
--- compiler/mlds_to_java.m	16 Jan 2002 01:13:38 -0000	1.18
+++ compiler/mlds_to_java.m	23 Jan 2002 09:18:11 -0000
@@ -1815,6 +1815,9 @@
 	indent_line(Context, Indent),
 	io__write_string("}\n").
 
+output_atomic_stmt(_Indent, _FuncInfo, gc_check, _) -->
+	{ error("mlds_to_java.m: sorry, gc_check not implemented") }.
+
 output_atomic_stmt(_Indent, _FuncInfo, mark_hp(_Lval), _) -->
 	{ error("mlds_to_java.m: sorry, mark_hp not implemented") }.
 
Index: runtime/mercury.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury.h,v
retrieving revision 1.43
diff -u -d -r1.43 mercury.h
--- runtime/mercury.h	12 Dec 2001 09:40:47 -0000	1.43
+++ runtime/mercury.h	23 Jan 2002 10:05:14 -0000
@@ -40,9 +40,10 @@
     #include "gc_inl.h"
   #endif
 #else
-  #include "mercury_regs.h"	/* for MR_hp */
-  #include "mercury_engine.h"	/* for MR_fake_reg (needed by MR_hp) */
-  #include "mercury_overflow.h"	/* for MR_heap_overflow_check() */
+  #include "mercury_regs.h"		/* for MR_hp */
+  #include "mercury_engine.h"		/* for MR_fake_reg (needed by MR_hp) */
+  #include "mercury_overflow.h"		/* for MR_heap_overflow_check() */
+  #include "mercury_accurate_gc.h"	/* for MR_garbage_collect() */
 #endif
 
 #if defined(MR_MPROF_PROFILE_CALLS) || defined(MR_MPROF_PROFILE_TIME)
@@ -499,6 +500,21 @@
 ** GCC back-end interface.
 */
 MR_Box MR_asm_box_float(MR_Float f);
+
+/*
+** MR_GC_check():
+**	Check to see if we need to do a garbage collection, and if so, do it.
+*/
+#define MR_GC_check()							\
+	do {								\
+		if ((char *) MR_hp + MR_heap_zone_size >=		\
+		    (char *) MR_ENGINE(MR_eng_heap_zone)->MR_zone_end)	\
+		{							\
+			MR_save_registers();				\
+			MR_garbage_collect();				\
+			MR_restore_registers();				\
+		}							\
+	} while (0)
 
 /*---------------------------------------------------------------------------*/
 /*
Index: runtime/mercury_accurate_gc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_accurate_gc.c,v
retrieving revision 1.12
diff -u -d -r1.12 mercury_accurate_gc.c
--- runtime/mercury_accurate_gc.c	5 Mar 2001 03:50:09 -0000	1.12
+++ runtime/mercury_accurate_gc.c	23 Jan 2002 11:00:24 -0000
@@ -20,10 +20,18 @@
 ** Function prototypes.
 */
 
+#ifdef MR_HIGHLEVEL_CODE
+
+void		MR_garbage_collect(void);
+static void	traverse_stack(struct MR_StackChain *top);
+
+#else /* !MR_HIGHLEVEL_CODE */
+
+MR_define_extern_entry(mercury__garbage_collect_0_0);
+
 static	void	garbage_collect(MR_Code *saved_success,
 			MR_Word *stack_pointer,
 			MR_Word *max_frame, MR_Word *current_frame);
-static	void	garbage_collect_roots(void);
 static	void	copy_long_value(MR_Long_Lval locn, MR_TypeInfo type_info, 
 			bool copy_regs, MR_Word *stack_pointer,
 			MR_Word *current_frame);
@@ -31,14 +39,20 @@
 			bool copy_regs, MR_Word *stack_pointer,
 			MR_Word *current_frame);
 
+#endif
+
+static	void	garbage_collect_roots(void);
+
 /*
 ** Global variables (only used in this module, however).
 */
 
+#ifndef MR_HIGHLEVEL_CODE
 static MR_Code	*saved_success = (MR_Code *) NULL;
 static MR_Word	*saved_success_location = (MR_Word *) NULL;
 static bool	gc_scheduled = FALSE;
 static bool	gc_running = FALSE;
+#endif
 
 /* The list of roots */
 static MR_RootList root_list = NULL;
@@ -46,7 +60,126 @@
 /* The last root on the list */
 static MR_RootList last_root = NULL;
 
-MR_define_extern_entry(mercury__garbage_collect_0_0);
+#ifdef MR_HIGHLEVEL_CODE
+
+/*
+** Perform a garbage collection:
+**	swap the two heaps;
+**	traverse the roots, copying data from the old heap to the new heap;
+**	reset the old heap;
+**
+** This is the version for the MLDS back-end.  Beware that there is some
+** code duplication with the version for the LLDS back-end, which is below.
+*/
+void
+MR_garbage_collect(void)
+{
+    MR_MemoryZone                   *old_heap, *new_heap;
+    MR_Word                         *old_hp, *new_hp;
+
+    old_heap = MR_ENGINE(MR_eng_heap_zone);
+    new_heap = MR_ENGINE(MR_eng_heap_zone2);
+
+#ifdef MR_DEBUG_AGC_COLLECTION
+    fprintf(stderr, "\ngarbage_collect() called.\n");
+
+    fprintf(stderr, "old_heap->min:  %lx \t old_heap->hardmax:  %lx\n", 
+        (long) old_heap->min, (long) old_heap->hardmax);
+	fprintf(stderr, "new_heap->min: %lx \t new_heap->hardmax: %lx\n", 
+        (long) new_heap->min, (long) new_heap->hardmax);
+
+    fprintf(stderr, "MR_virtual_hp:  %lx\n", (long) MR_virtual_hp);
+#endif
+
+    old_hp = MR_virtual_hp;
+
+    /*
+    ** The new heap pointer starts at the bottom of the new heap.
+    */
+    MR_virtual_hp = new_heap->min;
+
+    /*
+    ** Swap the two heaps.
+    */
+    {
+        MR_MemoryZone *tmp;
+
+        tmp = MR_ENGINE(MR_eng_heap_zone2);
+        MR_ENGINE(MR_eng_heap_zone2) = MR_ENGINE(MR_eng_heap_zone);
+        MR_ENGINE(MR_eng_heap_zone) = tmp; 
+    }
+
+#ifdef MR_DEBUG_AGC_COLLECTION
+    fprintf(stderr, "Swapped heaps\n"); 
+    fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+#endif
+
+    /*
+    ** Copy any roots on the stack
+    */
+    traverse_stack(mercury__private_builtin__stack_chain);
+    
+    /*
+    ** Copy any roots that are not on the stack.
+    */
+    garbage_collect_roots();
+
+#ifdef MR_DEBUG_AGC_COLLECTION
+    fprintf(stderr, "Clearing old heap:\n");
+
+    {
+	Word *tmp_hp;
+
+	for (tmp_hp = old_heap->min; tmp_hp <= old_hp; tmp_hp++) {
+		*tmp_hp = 1;
+	}
+    }
+
+    fprintf(stderr, "AFTER:\n");
+
+    	/* XXX save this, it appears to get clobbered */
+    new_hp = MR_virtual_hp;
+
+    MR_agc_dump_roots(root_list);
+
+    	/* XXX restore this, it appears to get clobbered */
+    fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+    MR_virtual_hp = new_hp;
+    fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+
+    fprintf(stderr, "old heap: %ld bytes, new heap: %ld bytes\n",
+        (long) ((char *) old_hp - (char *) old_heap->min),
+        (long) ((char *) MR_virtual_hp - (char *) new_heap->min));
+    fprintf(stderr, "%ld bytes recovered\n", 
+        (long) ((char *) old_hp - (char *) old_heap->min) -
+        ((char *) MR_virtual_hp - (char *) new_heap->min));
+
+#endif
+
+    /* Reset the redzone on the old heap */
+    MR_reset_redzone(old_heap);
+
+#ifdef MR_DEBUG_AGC_COLLECTION
+    fprintf(stderr, "garbage_collect() done.\n\n");
+#endif
+}
+
+static void
+traverse_stack(struct MR_StackChain *stack_chain)
+{
+	/*
+	** The trace() routines may themselves allocate heap space.
+	** However, the space that they allocate is only used transiently.
+	** XXX We ought to therefore reset the heap pointer
+	** after each iteration of this loop.
+	*/
+	while (stack_chain != NULL) {
+		(*stack_chain->trace)(stack_chain);
+		stack_chain = stack_chain->prev;
+	}
+}
+
+#else
 
 /*
 ** MR_schedule_agc:
@@ -253,8 +386,8 @@
     MR_Word                         *first_current_frame;
     MR_Word                         *first_max_frame;
 
-    old_heap = MR_ENGINE(heap_zone);
-    new_heap = MR_ENGINE(heap_zone2);
+    old_heap = MR_ENGINE(MR_eng_heap_zone);
+    new_heap = MR_ENGINE(MR_eng_heap_zone2);
 
 #ifdef MR_DEBUG_AGC_COLLECTION
     fprintf(stderr, "\ngarbage_collect() called.\n");
@@ -280,9 +413,9 @@
     {
         MR_MemoryZone *tmp;
 
-        tmp = MR_ENGINE(heap_zone2);
-        MR_ENGINE(heap_zone2) = MR_ENGINE(heap_zone);
-        MR_ENGINE(heap_zone) = tmp; 
+        tmp = MR_ENGINE(MR_eng_heap_zone2);
+        MR_ENGINE(MR_eng_heap_zone2) = MR_ENGINE(MR_eng_heap_zone);
+        MR_ENGINE(MR_eng_heap_zone) = tmp; 
     }
 
 #ifdef MR_DEBUG_AGC_COLLECTION
@@ -570,8 +703,8 @@
 			if (copy_regs) {
 				MR_virtual_reg(locn_num) = MR_agc_deep_copy(
 					&MR_virtual_reg(locn_num), type_info,
-					MR_ENGINE(heap_zone2->min),
-					MR_ENGINE(heap_zone2->hardmax));
+					MR_ENGINE(MR_eng_heap_zone2->min),
+					MR_ENGINE(MR_eng_heap_zone2->hardmax));
 			}
 			break;
 
@@ -582,8 +715,9 @@
 			MR_based_stackvar(stack_pointer, locn_num) =
 				MR_agc_deep_copy(&MR_based_stackvar(
 						stack_pointer,locn_num),
-					type_info, MR_ENGINE(heap_zone2->min),
-					MR_ENGINE(heap_zone2->hardmax));
+					type_info,
+					MR_ENGINE(MR_eng_heap_zone2->min),
+					MR_ENGINE(MR_eng_heap_zone2->hardmax));
 			break;
 
 		case MR_LONG_LVAL_TYPE_FRAMEVAR:
@@ -591,8 +725,8 @@
 				MR_agc_deep_copy(
 				&MR_based_framevar(current_frame, locn_num),
 				type_info,
-				MR_ENGINE(heap_zone2->min),
-				MR_ENGINE(heap_zone2->hardmax));
+				MR_ENGINE(MR_eng_heap_zone2->min),
+				MR_ENGINE(MR_eng_heap_zone2->hardmax));
 			break;
 
 		case MR_LONG_LVAL_TYPE_SUCCIP:
@@ -635,8 +769,8 @@
 				locn_num = MR_SHORT_LVAL_NUMBER(locn);
 				MR_virtual_reg(locn_num) = MR_agc_deep_copy(
 					&MR_virtual_reg(locn_num), type_info,
-					MR_ENGINE(heap_zone2->min),
-					MR_ENGINE(heap_zone2->hardmax));
+					MR_ENGINE(MR_eng_heap_zone2->min),
+					MR_ENGINE(MR_eng_heap_zone2->hardmax));
 			}
 			break;
 
@@ -645,8 +779,9 @@
 			MR_based_stackvar(stack_pointer, locn_num) =
 				MR_agc_deep_copy(&MR_based_stackvar(
 						stack_pointer,locn_num),
-					type_info, MR_ENGINE(heap_zone2->min),
-					MR_ENGINE(heap_zone2->hardmax));
+					type_info,
+					MR_ENGINE(MR_eng_heap_zone2->min),
+					MR_ENGINE(MR_eng_heap_zone2->hardmax));
 			break;
 
 		case MR_SHORT_LVAL_TYPE_FRAMEVAR:
@@ -656,8 +791,8 @@
 					&MR_based_framevar(current_frame,
 						locn_num),
 					type_info,
-					MR_ENGINE(heap_zone2->min),
-					MR_ENGINE(heap_zone2->hardmax));
+					MR_ENGINE(MR_eng_heap_zone2->min),
+					MR_ENGINE(MR_eng_heap_zone2->hardmax));
 				break;
 
 		default:
@@ -667,6 +802,8 @@
 	}
 }
 
+#endif /* !MR_HIGHLEVEL_CODE */
+
 /*
 ** garbage_collect_roots:
 ** 
@@ -681,8 +818,8 @@
 
 	while (current != NULL) {
 		*current->root = MR_agc_deep_copy(current->root,
-			current->type_info, MR_ENGINE(heap_zone2->min), 
-			MR_ENGINE(heap_zone2->hardmax));
+			current->type_info, MR_ENGINE(MR_eng_heap_zone2->min), 
+			MR_ENGINE(MR_eng_heap_zone2->hardmax));
 		current = current->next;
 	}
 
Index: runtime/mercury_accurate_gc.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_accurate_gc.h,v
retrieving revision 1.11
diff -u -d -r1.11 mercury_accurate_gc.h
--- runtime/mercury_accurate_gc.h	7 Nov 2000 08:58:32 -0000	1.11
+++ runtime/mercury_accurate_gc.h	23 Jan 2002 10:11:48 -0000
@@ -18,6 +18,10 @@
 
 /*---------------------------------------------------------------------------*/
 
+#ifdef MR_HIGHLEVEL_CODE
+/* Perform a garbage collection. */
+extern	void	MR_garbage_collect(void);
+#else
 /*
 ** MR_schedule_agc:
 ** 	Schedule a garbage collection as soon as possible.  The PC
@@ -28,6 +32,7 @@
 */
 extern	void	MR_schedule_agc(MR_Code *pc_at_signal, MR_Word *sp_at_signal,
 			MR_Word *curfr_at_signal);
+#endif
 
 /*
 ** Roots apart from the stacks are stored in this data structure.
Index: runtime/mercury_memory_handlers.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory_handlers.c,v
retrieving revision 1.20
diff -u -d -r1.20 mercury_memory_handlers.c
--- runtime/mercury_memory_handlers.c	13 Mar 2001 18:02:26 -0000	1.20
+++ runtime/mercury_memory_handlers.c	23 Jan 2002 10:51:45 -0000
@@ -249,7 +249,7 @@
 		zone->name, zone->id, (void *) zone->redzone,
 		(void *) zone->top);
 	}
-  #ifdef NATIVE_GC
+  #if defined(NATIVE_GC) && !defined(MR_HIGHLEVEL_CODE)
 	MR_schedule_agc(get_pc_from_context(context),
 		get_sp_from_context(context),
 		get_curfr_from_context(context));
@@ -930,7 +930,7 @@
 ** 	the time of the signal, if available.  If it is unavailable,
 ** 	return NULL.
 **
-** XXX We only define this function in accurate gc grades for the moment,
+** XXX We only define this function in LLDS accurate gc grades for the moment,
 ** because it's unlikely to compile everywhere.  It relies on
 ** MR_real_reg_number_sp being defined, which is the name/number of the
 ** machine register that is used for MR_sp.
@@ -940,7 +940,7 @@
 get_sp_from_context(void *the_context)
 {
 	MR_Word *sp_at_signal = NULL;
-#ifdef NATIVE_GC
+#if defined(NATIVE_GC) && !defined(MR_HIGHLEVEL_CODE)
   #if defined(HAVE_SIGCONTEXT_STRUCT)
 
     #ifdef PC_ACCESS

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