[m-rev.] accurate GC => no global/solutions heap

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Mar 3 19:23:39 AEDT 2003


Estimated hours taken: 4
Branches: main

Ensure that the global heap and solutions heap are not used
in accurate GC grades.

runtime/mercury_conf_param.h:
	Define new parameters MR_RECLAIM_HP_ON_FAILURE
	and MR_MIGHT_RECLAIM_HP_ON_FAILURE.  These will
	not be defined for accurate GC grades.

runtime/mercury_engine.h:
runtime/mercury_engine.c:
	Only allocate the solutions heap and the global heap
	if MR_MIGHT_RECLAIM_HP_ON_FAILURE is set.

library/std_util.m:
	Don't define MR_RECLAIM_HP_ON_FAILURE, since it is now
	defined in runtime/mercury_conf_param.h.

library/exception.m:
	When an exception is throw, reset the heap iff
	MR_RECLAIM_HP_ON_FAILURE is set, rather than iff
	MR_CONSERVATIVE_GC is not set.

runtime/mercury_deep_copy.h:
runtime/mercury_deep_copy.c:
	Change MR_make_permanent() and MR_make_long_lived() so that they
	copy data to the global heap iff MR_MIGHT_RECLAIM_HP_ON_FAILURE
	is set, rather than iff MR_CONSERVATIVE_GC is not set.

Workspace: /home/ceres/fjh/mercury
Index: library/exception.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.74
diff -u -d -r1.74 exception.m
--- library/exception.m	2 Mar 2003 11:12:06 -0000	1.74
+++ library/exception.m	3 Mar 2003 08:06:50 -0000
@@ -1889,7 +1889,7 @@
 		MR_exception);
 	MR_discard_tickets_to(MR_EXCEPTION_STRUCT->MR_excp_ticket_counter);
 #endif
-#ifndef MR_CONSERVATIVE_GC
+#ifdef MR_RECLAIM_HP_ON_FAILURE
 	/*
 	** Reset the heap.  But we need to be careful to preserve the
 	** thrown exception object.
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.282
diff -u -d -r1.282 std_util.m
--- library/std_util.m	3 Mar 2003 03:29:37 -0000	1.282
+++ library/std_util.m	3 Mar 2003 08:06:50 -0000
@@ -826,7 +826,8 @@
 		di, uo) is det. /* really cc_multi */
 
 /*
-** In order to implement any sort of code that requires terms to survive
+** If we're doing heap reclamation on failure, then
+** in order to implement any sort of code that requires terms to survive
 ** backtracking, we need to (deeply) copy them out of the heap and into some
 ** other area before backtracking.  The obvious thing to do then is just call
 ** the generator predicate, let it run to completion, and copy its result into
@@ -868,7 +869,8 @@
 ** So we don't need to create our own exception handlers to here to
 ** cover that case.
 **
-** If we're using conservative GC, then all of the heap-swapping
+** If we're not doing heap reclamation on failure (as is currently the
+** case when using conservative GC), then all of the heap-swapping
 ** and copying operations are no-ops, so we get a "zero-copy" solution.
 */
 
@@ -1006,12 +1008,6 @@
 %
 :- impure pred get_registers(heap_ptr::out, heap_ptr::out, trail_ptr::out)
 	is det.
-
-:- pragma foreign_decl("C", "
-#if !defined(MR_CONSERVATIVE_GC) && !defined(MR_NATIVE_GC)
-  #define MR_RECLAIM_HP_ON_FAILURE
-#endif
-").
 
 :- pragma foreign_proc("C", 
 	get_registers(HeapPtr::out, SolutionsHeapPtr::out, TrailPtr::out),
Index: runtime/mercury_conf_param.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.68
diff -u -d -r1.68 mercury_conf_param.h
--- runtime/mercury_conf_param.h	14 Feb 2003 09:57:29 -0000	1.68
+++ runtime/mercury_conf_param.h	3 Mar 2003 06:30:30 -0000
@@ -450,6 +450,59 @@
 #endif
 
 /*
+** MR_MIGHT_RECLAIM_HP_ON_FAILURE should be set if the grade allows
+** the heap to be reset on failure.
+**
+** XXX In the long run it would be nice to allow heap reclamation on
+**     failure with accurate GC, but this requires liveness-accuracy,
+**     which is not yet implemented;
+**     see the comments in the TODO list in compiler/ml_elim_nested.m.
+*/
+#if !defined(MR_CONSERVATIVE_GC) && !defined(MR_NATIVE_GC)
+  #define MR_MIGHT_RECLAIM_HP_ON_FAILURE
+#endif
+
+/*
+** MR_RECLAIM_HP_ON_FAILURE should be set if C code in the
+** current translation unit should reclaim heap on failure of a
+** subgoal.  Note that this only affects heap reclamation in
+** C code, not in Mercury code; heap reclamation in Mercury code
+** is determined by mmc options (e.g. `--reclaim-hp-on-semidet-failure')
+** which affect the generated C code.
+**
+** This is defined separately from MR_MIGHT_RECLAIM_HP_ON_FAILURE
+** because in theory different translation units might be compiled
+** with different settings; it might be important to reclaim heap
+** in some translation units but not others.  But currently we
+** always reclaim heap on failure if we can.
+*/
+#ifdef MR_MIGHT_RECLAIM_HP_ON_FAILURE
+  #define MR_RECLAIM_HP_ON_FAILURE
+#endif
+
+/* Some sanity checking */
+#ifdef MR_RECLAIM_HP_ON_FAILURE
+  #ifndef MR_MIGHT_RECLAIM_HP_ON_FAILURE
+    #error "MR_RECLAIM_HP_ON_FAILURE && ! MR_MIGHT_RECLAIM_HP_ON_FAILURE"
+  #endif
+  #ifdef MR_CONSERVATIVE_GC
+     /*
+     ** Heap reclamation on failure is not supported with conservative GC,
+     ** because the conservative collectors don't provide any way to do it.
+     */
+     #error "MR_RECLAIM_HP_ON_FAILURE and MR_CONSERVATIVE_GC both defined"
+  #endif
+  #ifdef MR_NATIVE_GC
+     /*
+     ** Heap reclamation on failure is not supported with accurate GC,
+     ** because it requires liveness accuracy, which is not yet implemented.
+     ** See the comments in the TODO list in compiler/ml_elim_nested.m.
+     */
+     #error "MR_RECLAIM_HP_ON_FAILURE and MR_NATIVE_GC both defined"
+  #endif
+#endif
+
+/*
 ** Static code addresses are available unless using gcc non-local gotos,
 ** without assembler labels.
 */
Index: runtime/mercury_deep_copy.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy.c,v
retrieving revision 1.29
diff -u -d -r1.29 mercury_deep_copy.c
--- runtime/mercury_deep_copy.c	7 Jun 2002 00:49:00 -0000	1.29
+++ runtime/mercury_deep_copy.c	3 Mar 2003 08:01:10 -0000
@@ -137,7 +137,7 @@
 		(val2) = swap_tmp;	\
 	} while (0)
 
-#ifndef MR_CONSERVATIVE_GC
+#ifdef MR_MIGHT_RECLAIM_HP_ON_FAILURE
 
 /*
 ** MR_make_long_lived(): see mercury_deep_copy.h for documentation.
@@ -176,4 +176,4 @@
 	return result;
 }
 
-#endif	/* not MR_CONSERVATIVE_GC */
+#endif	/* MIGHT_RECLAIM_HP_ON_FAILURE */
Index: runtime/mercury_deep_copy.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy.h,v
retrieving revision 1.15
diff -u -d -r1.15 mercury_deep_copy.h
--- runtime/mercury_deep_copy.h	21 Aug 2002 11:27:41 -0000	1.15
+++ runtime/mercury_deep_copy.h	3 Mar 2003 08:00:35 -0000
@@ -11,7 +11,7 @@
 
 #include "mercury_types.h"	/* for `MR_Word' */
 #include "mercury_type_info.h"	/* for `MR_TypeInfo' */
-#include "mercury_conf.h"	/* for `MR_CONSERVATIVE_GC' */
+#include "mercury_conf.h"	/* for `MR_MIGHT_RECLAIM_HP_ON_FAILURE' */
 
 /*
 ** MR_deep_copy:
@@ -110,7 +110,8 @@
 **	Mercury execution has backtracked past the point at which the
 **	term was allocated.
 **
-**	Note that in conservative GC grades nothing needs to be done, and
+**	Note that if we're never going to reclaim heap on failure
+**	(e.g. in conservative GC grades) then nothing needs to be done, and
 **	hence the term is just returned.
 **
 **	When not using a conservative GC grade, MR_save_transient_hp()
@@ -136,7 +137,7 @@
 **	"heap," but don't see how to.
 */
 
-#ifdef MR_CONSERVATIVE_GC
+#ifndef MR_MIGHT_RECLAIM_HP_ON_FAILURE
   #define MR_make_long_lived(term, type_info, lower_limit) (term)
 #else
   extern	MR_Word MR_make_long_lived(MR_Word term, MR_TypeInfo type_info,
Index: runtime/mercury_engine.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_engine.c,v
retrieving revision 1.39
diff -u -d -r1.39 mercury_engine.c
--- runtime/mercury_engine.c	18 Feb 2002 07:01:15 -0000	1.39
+++ runtime/mercury_engine.c	3 Mar 2003 06:33:01 -0000
@@ -80,18 +80,19 @@
 			MR_default_handler);
 	eng->MR_eng_hp = eng->MR_eng_heap_zone->min;
 
-#ifdef	MR_NATIVE_GC
+  #ifdef MR_NATIVE_GC
 	eng->MR_eng_heap_zone2 = MR_create_zone("heap2", 1, MR_heap_size,
 			MR_next_offset(), MR_heap_zone_size,
 			MR_default_handler);
 
-  #ifdef MR_DEBUG_AGC_PRINT_VARS
+    #ifdef MR_DEBUG_AGC_PRINT_VARS
 	eng->MR_eng_debug_heap_zone = MR_create_zone("debug_heap", 1,
 			MR_debug_heap_size, MR_next_offset(),
 			MR_debug_heap_zone_size, MR_default_handler);
-  #endif
-#endif
+    #endif
+  #endif /* MR_NATIVE_GC */
 
+  #ifdef MR_MIGHT_RECLAIM_HP_ON_FAILURE
 	eng->MR_eng_solutions_heap_zone = MR_create_zone("solutions_heap", 1,
 			MR_solutions_heap_size, MR_next_offset(),
 			MR_solutions_heap_zone_size, MR_default_handler);
@@ -101,7 +102,8 @@
 			MR_global_heap_size, MR_next_offset(),
 			MR_global_heap_zone_size, MR_default_handler);
 	eng->MR_eng_global_hp = eng->MR_eng_global_heap_zone->min;
-#endif
+  #endif /* MR_MIGHT_RECLAIM_HP_ON_FAILURE */
+#endif /* !MR_CONSERVATIVE_GC */
 
 #ifdef	MR_THREAD_SAFE
 	eng->MR_eng_owner_thread = pthread_self();
Index: runtime/mercury_engine.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_engine.h,v
retrieving revision 1.27
diff -u -d -r1.27 mercury_engine.h
--- runtime/mercury_engine.h	21 Aug 2002 11:27:41 -0000	1.27
+++ runtime/mercury_engine.h	3 Mar 2003 06:35:16 -0000
@@ -287,8 +287,10 @@
 	MR_Word		*MR_eng_exception;
 #ifndef	MR_CONSERVATIVE_GC
 	MR_MemoryZone	*MR_eng_heap_zone;
+  #ifdef MR_MIGHT_RECLAIM_HP_ON_FAILURE
 	MR_MemoryZone	*MR_eng_solutions_heap_zone;
 	MR_MemoryZone	*MR_eng_global_heap_zone;
+  #endif
 #endif
 #ifdef	MR_NATIVE_GC
 	MR_MemoryZone	*MR_eng_heap_zone2;

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