[m-rev.] for review: add support for MPS GC

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jul 31 11:23:59 AEST 2002


On 31-Jul-2002, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Add support for interfacing Mercury with the MPS garbage collector.
> 
> This change is broken into three parts:
> 
> 	1. Import version 1.100.1 of the MPS kit into the Mercury
> 	   CVS repository, in the directory `mercury/mps_gc'.
> 
> 	2. Make some changes to the MPS kit for Mercury,
> 	   to support fully-conservative collection and tagged pointers,
> 	   and to wrap it in an interface that is similar to that of
> 	   the Boehm collector.
> 
> 	3. Modify the rest of the Mercury implementation
> 	   to support linking with the MPS kit instead
> 	   of the Boehm collector.  This involved defining
> 	   `mps' as a new GC method and a new grade component.

This is part 3 of 3.

Mmake.workspace:
	Include the MPS directories in the header file and library search
	paths.

Mmake.workspace:
runtime/Mmakefile:
scripts/ml.in:
	For *.mps grades, link in mps.a.
	(XXX ml.in is linking in libmps.a, which is wrong.)

scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade.sh-subr:
	Handle the new `mps' GC method and grade component.

compiler/globals.m:
compiler/options.m:
doc/user_guide.texi:
	Replace gc_method `conservative' with two alternatives
	`boehm' and `mps'. ("--gc conservative" is still allowed,
	and treated as equivalent to "--gc boehm".)
	Add new function `gc_is_conservative' to globals.m.

compiler/mercury_compile.m:
compiler/handle_options.m:
	Use `gc_is_conservative' rather than `= conservative'.

compiler/handle_options.m:
	Handle the "mps" grade component.
	(XXX need to document this in options.m and user_guide.texi)

compiler/compile_target_code.m:
	Pass the appropriate C defines for the new GC methods.

compiler/mercury_compile.m:
	Wrap the work-around for a Boehm GC bug inside `#ifndef MR_MPS_GC'.

library/array.m:
	Use GC_FREE() rather than GC_free().
	This is needed for two reasons:
	- so that it works with MPS, which only defines GC_FREE
	- so that it works with then Boehm collector when
	  GC debugging is enabled

library/benchmarking.m:
	Output GC statistics for the MPS collector.

runtime/mercury.h:
runtime/mercury_heap.h:
runtime/mercury_init.h:
runtime/mercury_memory.h:
	If MR_MPS_GC is defined, use mercury_mps.h rather than gc.h.

runtime/mercury_conf_param.h:
	Add configuration macros MR_BOEHM_GC and MR_MPS_GC.
	Set MR_CONSERVATIVE_GC if either of these is set.
	Default to MR_BOEHM_GC if only MR_CONSERVATIVE_GC is set.

runtime/mercury_context.h:
runtime/mercury_deep_copy.h:
runtime/mercury_engine.h:
runtime/mercury_float.h:
runtime/mercury_heap.h:
	Explictly #include "mercury_conf.h", so that
	MR_CONSERVATIVE_GC will be set properly before it is tested.

runtime/mercury_grade.h:
	Handle the .mps grade component.

runtime/mercury_memory.c:
runtime/mercury_wrapper.c:
runtime/mercury_memory_handlers.c:
	Move the call to MR_setup_signals() earlier in the
	initialization sequence, so that the MPS signal handlers
	get installed after our signal handlers.  This is needed
	because our signal handlers assume that any signals that
	they can't handle are fatal errors, which interfere's
	with MPS's use of signal handlers for memory barriers.

runtime/mercury_wrapper.c:
	Add code to initialize the MPS collector.
	Put code which is specific to the Boehm collector inside
	#ifdef MR_BOEHM_GC rather than #ifdef MR_CONSERVATIVE_GC.

runtime/mercury_wrapper.h:
	Update a comment.

Workspace: /home/earth/fjh/ws-earth3/mercury
Index: Mmake.workspace
===================================================================
RCS file: /home/mercury1/repository/mercury/Mmake.workspace,v
retrieving revision 1.7
diff -u -d -r1.7 Mmake.workspace
--- Mmake.workspace	22 Jun 2002 19:15:49 -0000	1.7
+++ Mmake.workspace	30 Jul 2002 06:18:36 -0000
@@ -20,12 +20,12 @@
 # the installed library directory.
 #
 # Setting LINK_BOEHM_GC_ONLY to `yes' causes only the boehm_gc directory
-# to be included in MLFLAGS, MLLIBS and CFLAGS.
+# (and/or the mps_gc directory) to be included in MLFLAGS, MLLIBS and CFLAGS.
 
-# Setting LINK_RUNTIME_ONLY to `yes' causes only the boehm_gc and runtime
+# Setting LINK_RUNTIME_ONLY to `yes' causes only the *_gc and runtime
 # directories to be included in MLFLAGS, MLLIBS and CFLAGS.
 
-# Setting LINK_STDLIB_ONLY to `yes' causes only the boehm_gc, runtime
+# Setting LINK_STDLIB_ONLY to `yes' causes only the *_gc, runtime
 # and library directories to be included in MLFLAGS, MLLIBS and CFLAGS.
 
 #-----------------------------------------------------------------------------#
@@ -51,9 +51,21 @@
 TRACE_DIR = $(WORKSPACE)/trace
 BROWSER_DIR = $(WORKSPACE)/browser
 BOEHM_GC_DIR = $(WORKSPACE)/boehm_gc
+MPS_GC_DIR = $(WORKSPACE)/mps_gc/code
 COMPILER_DIR = $(WORKSPACE)/compiler
 UTIL_DIR = $(WORKSPACE)/util
 
+# Specify the MPS "platform"
+# E.g. lii4gc means Linux, i486, gcc
+MPS_PFM = lii4gc
+
+# Specify the MPS "variety"
+# E.g. "hi" means "hot internal" (production version),
+# "ci" means "cold internal" (version with extra debugging checks)
+MPS_VARIETY = hi
+
+MPS_GC_OBJ_DIR=$(MPS_GC_DIR)/$(MPS_PFM)/$(MPS_VARIETY)
+
 # The names of the various libraries.
 # The archives and shared object objects have a "lib" prefix and a ".a" or
 # ".so" (or ".dll") suffix around these names; the initialization files
@@ -98,7 +110,7 @@
 #
 # Work out the C include directories.
 #
-C_INCL_DIRS =	-I$(BOEHM_GC_DIR) -I$(BOEHM_GC_DIR)/include
+C_INCL_DIRS =	-I$(BOEHM_GC_DIR) -I$(BOEHM_GC_DIR)/include -I$(MPS_GC_DIR)
 ifneq ($(LINK_BOEHM_GC_ONLY),yes)
 C_INCL_DIRS +=	-I$(RUNTIME_DIR)
 ifneq ($(LINK_RUNTIME_ONLY),yes)
@@ -125,6 +137,7 @@
 		*.par*.gc*)	echo $(BOEHM_GC_DIR)/libpar_gc.$A ;; \
 		*.gc*.prof*)	echo $(BOEHM_GC_DIR)/libgc_prof.$A ;; \
 		*.gc*)		echo $(BOEHM_GC_DIR)/libgc.$A ;; \
+		*.mps*)		echo $(MPS_GC_OBJ_DIR)/mps.$A ;; \
 	    esac						\
 	`
 STATIC_GC_LIBS = $(shell echo $(STATIC_GC_LIBS_0))
@@ -136,6 +149,7 @@
 		*.par*.gc*)	echo -lpar_gc ;;		\
 		*.gc*.prof*)	echo -lgc_prof ;;		\
 		*.gc*)		echo -lgc ;;			\
+		*.mps*)		echo $(MPS_GC_OBJ_DIR)/mps.$A ;; \
 	    esac						\
 	`
 SHARED_GC_LIBS = $(shell echo $(SHARED_GC_LIBS_0))
@@ -176,8 +190,8 @@
 
 LINK_LIB_OPTS = $(LINK_TRACE_LIB_OPTS) $(LINK_STD_LIB_OPTS) \
 			$(LINK_RT_LIB_OPTS) $(SHARED_GC_LIBS) 
-LIB_DIR_OPTS = -L$(BOEHM_GC_DIR) -L$(RUNTIME_DIR) -L$(LIBRARY_DIR) \
-			-L$(TRACE_DIR) -L$(BROWSER_DIR)
+LIB_DIR_OPTS = -L$(BOEHM_GC_DIR) -L$(MPS_GC_DIR) -L$(RUNTIME_DIR) \
+		-L$(LIBRARY_DIR) -L$(TRACE_DIR) -L$(BROWSER_DIR)
 
 MLFLAGS +=	$(LIB_DIR_OPTS)
 MLLIBS +=	$(LINK_LIB_OPTS)
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.17
diff -u -d -r1.17 compile_target_code.m
--- compiler/compile_target_code.m	29 Jul 2002 07:50:55 -0000	1.17
+++ compiler/compile_target_code.m	30 Jul 2002 08:14:21 -0000
@@ -405,11 +405,17 @@
 		{ CFLAGS_FOR_THREADS = "" }
 	),
 	globals__io_get_gc_method(GC_Method),
-	{ GC_Method = conservative ->
-		GC_Opt = "-DMR_CONSERVATIVE_GC "
-	; GC_Method = accurate ->
+	{
+		GC_Method = boehm,
+		GC_Opt = "-DMR_CONSERVATIVE_GC -DMR_BOEHM_GC"
+	;
+		GC_Method = mps,
+		GC_Opt = "-DMR_CONSERVATIVE_GC -DMR_MPS_GC"
+	;
+		GC_Method = accurate,
 		GC_Opt = "-DMR_NATIVE_GC "
 	;
+		GC_Method = none,
 		GC_Opt = ""
 	},
 	globals__io_lookup_bool_option(profile_calls, ProfileCalls),
Index: compiler/globals.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/globals.m,v
retrieving revision 1.50
diff -u -d -r1.50 globals.m
--- compiler/globals.m	15 Apr 2002 05:04:02 -0000	1.50
+++ compiler/globals.m	30 Jul 2002 08:12:40 -0000
@@ -51,9 +51,16 @@
 	% 
 :- type gc_method
 	--->	none
-	;	conservative
+	;	boehm
+	;	mps
 	;	accurate.
 
+	% Returns yes if the GC method is conservative,
+	% i.e. if it is `boehm' or `mps'.
+	% Conservative GC methods don't support heap
+	% reclamation on failure.
+:- func gc_is_conservative(gc_method) = bool.
+
 :- type tags_method
 	--->	none
 	;	low
@@ -242,7 +249,9 @@
 convert_foreign_language_2("il", il).
 
 convert_gc_method("none", none).
-convert_gc_method("conservative", conservative).
+convert_gc_method("conservative", boehm).
+convert_gc_method("boehm", boehm).
+convert_gc_method("mps", mps).
 convert_gc_method("accurate", accurate).
 
 convert_tags_method("none", none).
@@ -253,6 +262,11 @@
 convert_termination_norm("total", total).
 convert_termination_norm("num-data-elems", num_data_elems).
 convert_termination_norm("size-data-elems", size_data_elems).
+
+gc_is_conservative(boehm) = yes.
+gc_is_conservative(mps) = yes.
+gc_is_conservative(none) = no.
+gc_is_conservative(accurate) = no.
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.144
diff -u -d -r1.144 handle_options.m
--- compiler/handle_options.m	22 Jul 2002 07:12:57 -0000	1.144
+++ compiler/handle_options.m	30 Jul 2002 08:11:04 -0000
@@ -238,7 +238,7 @@
                     { Error = yes("Invalid tags option (must be `none', `low' or `high')") }
             )
         ;
-            { Error = yes("Invalid GC option (must be `none', `conservative' or `accurate')") }
+            { Error = yes("Invalid GC option (must be `none', `conservative', `boehm', `mps' or `accurate')") }
 	)
     ;
         { Error = yes("Invalid target option (must be `c', `asm', `il', or `java')") }
@@ -256,8 +256,8 @@
 	globals__io_init(OptionTable1, Target, GC_Method, TagsMethod,
 		TermNorm, TraceLevel, TraceSuppress),
 
-	% --gc conservative implies --no-reclaim-heap-*
-	( { GC_Method = conservative } ->
+	% Conservative GC implies --no-reclaim-heap-*
+	( { gc_is_conservative(GC_Method) = yes } ->
 		globals__io_set_option(
 			reclaim_heap_on_semidet_failure, bool(no)),
 		globals__io_set_option(
@@ -1403,7 +1403,8 @@
 grade_component_table("par", par, [parallel - bool(yes)]).
 
 	% GC components
-grade_component_table("gc", gc, [gc - string("conservative")]).
+grade_component_table("gc", gc, [gc - string("boehm")]).
+grade_component_table("mps", gc, [gc - string("mps")]).
 grade_component_table("agc", gc, [gc - string("accurate")]).
 
 	% Profiling components
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.262
diff -u -d -r1.262 mercury_compile.m
--- compiler/mercury_compile.m	24 Jul 2002 16:05:08 -0000	1.262
+++ compiler/mercury_compile.m	30 Jul 2002 12:14:05 -0000
@@ -171,6 +171,7 @@
 	[will_not_call_mercury, promise_pure, tabled_for_io],
 "
 #ifdef MR_CONSERVATIVE_GC
+  #ifndef MR_MPS_GC /* i.e. MR_BOEHM_GC */
 	/*
 	** Explicitly force the initial heap size to be at least 4 Mb.
 	**
@@ -183,6 +184,7 @@
 	** frequent garbage collection during start-up.
 	*/
 	GC_expand_hp(4 * 1024 * 1024);
+  #endif
 #endif
 ").
 
@@ -2497,7 +2499,7 @@
 		SemidetReclaim),
 	globals__io_lookup_bool_option(reclaim_heap_on_nondet_failure,
 		NondetReclaim),
-	( { GC = conservative } ->
+	( { gc_is_conservative(GC) = yes } ->
 		% we can't do heap reclamation with conservative GC
 		{ HLDS = HLDS0 }
 	; { SemidetReclaim = no, NondetReclaim = no } ->
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.378
diff -u -d -r1.378 options.m
--- compiler/options.m	29 Jul 2002 07:50:58 -0000	1.378
+++ compiler/options.m	30 Jul 2002 07:37:50 -0000
@@ -756,7 +756,7 @@
 				-	bool(no),
 	deep_profile_tail_recursion	-	bool(yes),
 		% (c) Miscellaneous optional features
-	gc			-	string("conservative"),
+	gc			-	string("boehm"),
 	parallel		-	bool(no),
 	use_trail		-	bool(no),
 	use_minimal_model	-	bool(no),
@@ -2590,16 +2590,19 @@
 	]),
 	io__write_string("      Miscellaneous optional features\n"),
 	write_tabbed_lines([
-		"--gc {none, conservative, accurate}",
-		"--garbage-collection {none, conservative, accurate}",
-		"\t\t\t\t(`.gc' grades use `--gc conservative',",
+		"--gc {none, conservative, boehm, mps, accurate}",
+		"--garbage-collection {none, conservative, boehm, mps, accurate}",
+		"\t\t\t\t(`.gc' grades use `--gc boehm',",
+		"\t\t\t\t`.mps' grades use `--gc mps',",
 		"\t\t\t\tother grades use `--gc none'.)",
 		"\tSpecify which method of garbage collection to use",
-		"\t(default: conservative).  `accurate' GC is not yet implemented.",
+		"\t(default: boehm).  `accurate' GC is not yet implemented.",
+		"\t`conservative' or `boehm' is Hans Boehm et al's conservative collector.",
+		"\t`mps' is a different conservative collector, based on",
+		"\tRavenbrook Limited's MPS (Memory Pool System) kit.",
 		"\tThis option is ignored for the IL and Java back-ends,",
 		"\twhich always use the garbage collector of the underlying",
 		"\tIL or Java implementation.",
-		"\t`--high-level-code' requires `conservative' GC.",
 		"--use-trail\t\t\t(grade modifier: `.tr')",
 		"\tEnable use of a trail.",
 		"\tThis is necessary for interfacing with constraint solvers,",
@@ -3301,7 +3304,7 @@
 		"\tInline calls to GC_malloc().",
 		"\tThis can improve performance a fair bit,",
 		"\tbut may significantly increase code size.",
-		"\tThis option has no effect if `--gc conservative'",
+		"\tThis option has no effect if `--gc boehm'",
 		"\tis not set or if the C compiler is not GNU C.",
 
 		"--cflags <options>",
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.316
diff -u -d -r1.316 user_guide.texi
--- doc/user_guide.texi	29 Jul 2002 11:15:43 -0000	1.316
+++ doc/user_guide.texi	30 Jul 2002 07:38:03 -0000
@@ -445,7 +445,7 @@
 @node Using Mmake
 @chapter Using Mmake
 @pindex mmake
- at pindex make: see Mmake
+ at pindex make --- see Mmake
 @cindex Building programs
 @cindex Recompiling
 
@@ -4488,7 +4488,10 @@
 @code{--target java --high-level-code}.
 
 @item @samp{.gc}
- at code{--gc conservative}.
+ at code{--gc boehm}.
+
+ at item @samp{.mps}
+ at code{--gc mps}
 
 @item @samp{.agc}
 @code{--gc accurate}.
@@ -4713,17 +4716,25 @@
 @end ignore
 
 @sp 1
- at item @code{--gc @{none, conservative, accurate@}}
- at itemx @code{--garbage-collection @{none, conservative, accurate@}}
+ at item @code{--gc @{none, conservative, boehm, mps, accurate@}}
+ at itemx @code{--garbage-collection @{none, conservative, boehm, mps, accurate@}}
 @cindex Garbage collection
 @cindex Conservative garbage collection
+ at cindex Boehm (et al) conservative garbage collector
+ at cindex MPS conservative garbage collector
+ at cindex Memory Pool System conservative garbage collector
 @cindex Accurate garbage collection
 @findex --gc
 @findex --garbage-collection
 Specify which method of garbage collection to use.
-Grades containing @samp{.gc} use @samp{--gc conservative},
+Grades containing @samp{.gc} use @samp{--gc boehm},
+grades containing @samp{.mps} use @samp{--gc mps},
 other grades use @samp{--gc none}.
 @samp{accurate} is not yet implemented.
+ at samp{conservative} or @samp{boehm} is Hans Boehm et al's conservative
+garbage collector.
+ at samp{mps} is another conservative collector based on Ravenbrook Limited's 
+MPS (Memory Pool System) kit.
 This option is ignored by the IL and Java back-ends, which always use
 the underlying IL or Java implementation's garbage collector.
 
@@ -5830,7 +5841,7 @@
 Inline calls to @samp{GC_malloc()}.
 This can improve performance a fair bit,
 but may significantly increase code size.
-This option has no effect if @samp{--gc conservative}
+This option has no effect if @samp{--gc boehm}
 is not set or if the C compiler is not GNU C.
 
 @sp 1
Index: library/array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.110
diff -u -d -r1.110 array.m
--- library/array.m	23 Jul 2002 08:26:22 -0000	1.110
+++ library/array.m	30 Jul 2002 11:40:57 -0000
@@ -1034,7 +1034,7 @@
 	** deallocate the storage for it
 	*/
 #ifdef MR_CONSERVATIVE_GC
-	GC_free(old_array);
+	GC_FREE(old_array);
 #endif
 }
 ").
@@ -1106,7 +1106,7 @@
 	** deallocate the storage for it
 	*/
 #ifdef MR_CONSERVATIVE_GC
-	GC_free(old_array);
+	GC_FREE(old_array);
 #endif
 }
 ").
Index: library/benchmarking.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.50
diff -u -d -r1.50 benchmarking.m
--- library/benchmarking.m	14 Jun 2002 10:18:45 -0000	1.50
+++ library/benchmarking.m	30 Jul 2002 23:56:34 -0000
@@ -220,6 +220,20 @@
 	*/
 
 #ifdef MR_CONSERVATIVE_GC
+  #ifdef MR_MPS_GC
+  	{
+		size_t committed, spare;
+
+		committed = mps_arena_committed(mercury_mps_arena);
+		spare = mps_arena_spare_committed(mercury_mps_arena);
+
+		fprintf(stderr, 
+			""\\nHeap in use: %.3fk, spare: %.3fk, total: %.3fk"",
+			(committed - spare) / 1024.0,
+			spare / 1024.0,
+			committed / 1024.0);
+	}
+  #else /* MR_BOEHM_GC */
 	fprintf(stderr, 
 		""\\n#GCs: %lu, ""
 		""Heap used since last GC: %.3fk, Total used: %.3fk"",
@@ -227,7 +241,8 @@
 		GC_get_bytes_since_gc() / 1024.0,
 		GC_get_heap_size() / 1024.0
 	);
-#else
+  #endif
+#else /* !MR_CONSERVATIVE_GC */
 	fprintf(stderr, 
 		""\\nHeap: %.3fk"",
 		((char *) MR_hp - (char *) eng->MR_eng_heap_zone->min) / 1024.0
Index: runtime/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/Mmakefile,v
retrieving revision 1.90
diff -u -d -r1.90 Mmakefile
--- runtime/Mmakefile	22 Jun 2002 19:16:08 -0000	1.90
+++ runtime/Mmakefile	30 Jul 2002 22:00:29 -0000
@@ -190,7 +190,7 @@
 
 THREADLIBS	= \
 		` case "$(GRADE)" in					\
-		    *.par*) echo "-lpthread" ;;				\
+		    *.par*|*.mps*) echo "-lpthread" ;;			\
 		  esac							\
 		`
 
Index: runtime/mercury.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury.h,v
retrieving revision 1.57
diff -u -d -r1.57 mercury.h
--- runtime/mercury.h	25 Apr 2002 09:31:56 -0000	1.57
+++ runtime/mercury.h	31 Jul 2002 00:02:13 -0000
@@ -35,9 +35,13 @@
 #include "mercury_type_tables.h"	/* for MR_register_type_ctor_info */
 
 #ifdef MR_CONSERVATIVE_GC
-  #include "gc.h"
-  #ifdef MR_INLINE_ALLOC
-    #include "gc_inl.h"
+  #ifdef MR_MPS_GC
+    #include "mercury_mps.h"
+  #else /* MR_BOEHM_GC */
+    #include "gc.h"
+    #ifdef MR_INLINE_ALLOC
+      #include "gc_inl.h"
+    #endif
   #endif
 #else
   #include "mercury_regs.h"		/* for MR_hp */
Index: runtime/mercury_conf_param.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.60
diff -u -d -r1.60 mercury_conf_param.h
--- runtime/mercury_conf_param.h	19 Jul 2002 05:39:04 -0000	1.60
+++ runtime/mercury_conf_param.h	30 Jul 2002 07:18:53 -0000
@@ -45,7 +45,9 @@
 ** MR_USE_GCC_GLOBAL_REGISTERS
 ** MR_USE_GCC_NONLOCAL_GOTOS
 ** MR_USE_ASM_LABELS
-** MR_CONSERVATIVE_GC
+** MR_CONSERVATIVE_GC (= boehm_gc *or* MPS)
+** MR_BOEHM_GC
+** MR_MPS_GC
 ** MR_NATIVE_GC		[not yet working]
 ** MR_NO_TYPE_LAYOUT
 ** MR_BOXED_FLOAT
@@ -367,6 +369,24 @@
 ** You must make sure that you don't test the value of any of these parameters
 ** before its conditional definition.
 */
+
+/*
+** Both the Boehm collector and the MPS collector are conservative.
+** (Well, actually MPS supports a wide spectrum of methods, including
+** fully conservative, partly conservative (mostly copying),
+** and fully type-accurate collection; but currently we're using
+** the conservative collector part of MPS.)
+**
+** If MR_CONSERVATIVE_GC is defined without specifying which
+** collector to use, then default to using the Boehm collector.
+*/
+#if defined(MR_BOEHM_GC) || defined(MR_MPS_GC)
+  #ifndef MR_CONSERVATIVE_GC
+  #define MR_CONSERVATIVE_GC
+  #endif
+#elif defined(MR_CONSERVATIVE_GC)
+  #define MR_BOEHM_GC
+#endif
 
 /*
 ** Static code addresses are available unless using gcc non-local gotos,
Index: runtime/mercury_context.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.h,v
retrieving revision 1.21
diff -u -d -r1.21 mercury_context.h
--- runtime/mercury_context.h	4 Jun 2002 09:12:24 -0000	1.21
+++ runtime/mercury_context.h	30 Jul 2002 05:07:02 -0000
@@ -52,6 +52,7 @@
 #include "mercury_memory.h"		/* for MR_MemoryZone */
 #include "mercury_thread.h"		/* for MercuryLock */
 #include "mercury_goto.h"		/* for MR_GOTO() */
+#include "mercury_conf.h"		/* for MR_CONSERVATIVE_GC */
 
 #ifdef	MR_THREAD_SAFE
   #define MR_IF_THREAD_SAFE(x)	x
Index: runtime/mercury_deep_copy.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy.h,v
retrieving revision 1.14
diff -u -d -r1.14 mercury_deep_copy.h
--- runtime/mercury_deep_copy.h	7 Jun 2002 00:49:00 -0000	1.14
+++ runtime/mercury_deep_copy.h	30 Jul 2002 05:07:28 -0000
@@ -11,6 +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' */
 
 /*
 ** MR_deep_copy:
Index: runtime/mercury_engine.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_engine.h,v
retrieving revision 1.24
diff -u -d -r1.24 mercury_engine.h
--- runtime/mercury_engine.h	18 Feb 2002 07:01:15 -0000	1.24
+++ runtime/mercury_engine.h	30 Jul 2002 07:19:11 -0000
@@ -27,6 +27,7 @@
 #include "mercury_goto.h"		/* for `MR_define_entry()' */
 #include "mercury_thread.h"		/* for pthread types */
 #include "mercury_context.h"		/* for MR_Context, MR_IF_USE_TRAIL */
+#include "mercury_conf.h"		/* for MR_CONSERVATIVE_GC */
 
 /*---------------------------------------------------------------------------*/
 
Index: runtime/mercury_float.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_float.h,v
retrieving revision 1.13
diff -u -d -r1.13 mercury_float.h
--- runtime/mercury_float.h	13 Feb 2002 09:56:40 -0000	1.13
+++ runtime/mercury_float.h	30 Jul 2002 05:08:47 -0000
@@ -9,7 +9,7 @@
 #ifndef MERCURY_FLOAT_H
 #define MERCURY_FLOAT_H
 
-#include "mercury_conf.h"	/* for MR_BOXED_FLOAT */
+#include "mercury_conf.h"	/* for MR_BOXED_FLOAT, MR_CONSERVATIVE_GC */
 #include "mercury_types.h"	/* for `MR_Word' */
 
 #ifdef MR_USE_SINGLE_PREC_FLOAT
Index: runtime/mercury_grade.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_grade.h,v
retrieving revision 1.37
diff -u -d -r1.37 mercury_grade.h
--- runtime/mercury_grade.h	8 May 2002 09:33:20 -0000	1.37
+++ runtime/mercury_grade.h	30 Jul 2002 05:10:59 -0000
@@ -98,7 +98,9 @@
   #define MR_GRADE_PART_3	MR_GRADE_PART_2
 #endif
 
-#ifdef MR_CONSERVATIVE_GC
+#if defined(MR_MPS_GC)
+  #define MR_GRADE_PART_4	MR_PASTE2(MR_GRADE_PART_3, _mps)
+#elif defined(MR_BOEHM_GC) || defined(MR_CONSERVATIVE_GC)
   #define MR_GRADE_PART_4	MR_PASTE2(MR_GRADE_PART_3, _gc)
 #elif defined(MR_NATIVE_GC)
   #define MR_GRADE_PART_4	MR_PASTE2(MR_GRADE_PART_3, _agc)
@@ -286,7 +288,10 @@
 #else
   #define MR_GRADE_OPT_PART_3	MR_GRADE_OPT_PART_2
 #endif
-#ifdef MR_CONSERVATIVE_GC
+
+#if defined(MR_MPS_GC)
+  #define MR_GRADE_OPT_PART_4	MR_GRADE_OPT_PART_3 ".mps"
+#elif defined(MR_BOEHM_GC) || defined(MR_CONSERVATIVE_GC)
   #define MR_GRADE_OPT_PART_4	MR_GRADE_OPT_PART_3 ".gc"
 #elif defined(MR_NATIVE_GC)
   #define MR_GRADE_OPT_PART_4	MR_GRADE_OPT_PART_3 ".agc"
Index: runtime/mercury_heap.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_heap.h,v
retrieving revision 1.25
diff -u -d -r1.25 mercury_heap.h
--- runtime/mercury_heap.h	2 Jun 2002 04:44:43 -0000	1.25
+++ runtime/mercury_heap.h	31 Jul 2002 00:06:39 -0000
@@ -9,6 +9,7 @@
 #ifndef MERCURY_HEAP_H
 #define MERCURY_HEAP_H
 
+#include "mercury_conf.h"		/* for MR_CONSERVATIVE_GC */
 #include "mercury_types.h"		/* for `MR_Word' */
 #include "mercury_context.h"		/* for min_heap_reclamation_point() */
 #include "mercury_heap_profile.h"	/* for MR_record_allocation() */
@@ -20,7 +21,11 @@
 
 #ifdef MR_CONSERVATIVE_GC
 
-  #include "gc.h"
+  #ifdef MR_MPS_GC
+    #include "mercury_mps.h"
+  #else /* MR_BOEHM_GC */
+    #include "gc.h"
+  #endif
 
   #define MR_tag_incr_hp_n(dest, tag, count) 				\
 	((dest) = (MR_Word) MR_mkword((tag),				\
Index: runtime/mercury_init.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_init.h,v
retrieving revision 1.38
diff -u -d -r1.38 mercury_init.h
--- runtime/mercury_init.h	24 Jul 2002 16:05:13 -0000	1.38
+++ runtime/mercury_init.h	30 Jul 2002 05:22:01 -0000
@@ -88,7 +88,11 @@
 #include "mercury_type_info.h"	/* for MR_TypeCtorInfo_Struct */
 
 #ifdef MR_CONSERVATIVE_GC
-  #include "gc.h"
+  #ifdef MR_MPS_GC
+    #include "mercury_mps.h"	/* XXX FIXME */
+  #else /* MR_BOEHM_GC */
+    #include "gc.h"		/* for GC_INIT(), GC_stack_bottom */
+  #endif
 #endif
 
 #ifdef MR_HIGHLEVEL_CODE
Index: runtime/mercury_memory.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory.c,v
retrieving revision 1.30
diff -u -d -r1.30 mercury_memory.c
--- runtime/mercury_memory.c	6 Mar 2002 14:34:59 -0000	1.30
+++ runtime/mercury_memory.c	30 Jul 2002 22:31:09 -0000
@@ -221,7 +221,6 @@
 #endif
 
 	MR_init_zones();
-	MR_setup_signals();
 
 	if (MR_memdebug) {
 		MR_debug_memory();
@@ -285,7 +284,7 @@
 ** These routines allocate memory that will be scanned by the
 ** conservative garbage collector.
 **
-** XXX This is inefficient.  If MR_CONSERVATIVE_GC is enabled,
+** XXX This is inefficient.  If MR_BOEHM_GC is enabled,
 ** we should set `GC_oom_fn' (see boehm_gc/gc.h) rather than
 ** testing the return value from GC_MALLOC() or GC_MALLOC_UNCOLLECTABLE().
 */
Index: runtime/mercury_memory.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory.h,v
retrieving revision 1.17
diff -u -d -r1.17 mercury_memory.h
--- runtime/mercury_memory.h	6 Mar 2002 14:34:59 -0000	1.17
+++ runtime/mercury_memory.h	31 Jul 2002 00:11:09 -0000
@@ -25,8 +25,13 @@
 #include "mercury_types.h"	/* for MR_Word */
 #include "mercury_std.h"	/* for MR_bool */
 #include "mercury_conf.h"	/* for MR_CONSERVATIVE_GC, etc. */
-#ifdef MR_CONSERVATIVE_GC
-  #include "gc.h"		/* for GC_FREE */
+
+#if defined(MR_CONSERVATIVE_GC)
+  #if defined(MR_MPS_GC)
+    #include "mercury_mps.h"	/* for GC_FREE */
+  #else /* MR_BOEHM_GC */
+    #include "gc.h"		/* for GC_FREE */
+  #endif
 #endif
 
 /*
Index: runtime/mercury_memory_handlers.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory_handlers.c,v
retrieving revision 1.26
diff -u -d -r1.26 mercury_memory_handlers.c
--- runtime/mercury_memory_handlers.c	18 Feb 2002 07:01:18 -0000	1.26
+++ runtime/mercury_memory_handlers.c	30 Jul 2002 22:36:18 -0000
@@ -110,6 +110,14 @@
 
 #define STDERR 2
 
+/*
+** Note that we cannot assume that the memory zones
+** have been initialized here, since MR_setup_signals()
+** gets called before MR_init_memory_zones().
+** However, the code here will work fine if
+** used_memory_zones is null.
+*/
+
 static MR_bool 
 try_munprotect(void *addr, void *context)
 {
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.106
diff -u -d -r1.106 mercury_wrapper.c
--- runtime/mercury_wrapper.c	9 Jun 2002 15:59:06 -0000	1.106
+++ runtime/mercury_wrapper.c	30 Jul 2002 22:39:28 -0000
@@ -340,6 +340,15 @@
 	}
 #endif
 
+	/*
+	** This must be done before MR_init_conservative_GC(),
+	** to ensure that the GC's signal handler gets installed
+	** after our signal handler.  This is needed because
+	** our signal handler assumes that signals which it can't
+	** handle are fatal.
+	*/
+	MR_setup_signals();
+
 #ifdef MR_CONSERVATIVE_GC
 	MR_init_conservative_GC();
 #endif
@@ -460,9 +469,20 @@
 } /* end runtime_mercury_init() */
 
 #ifdef MR_CONSERVATIVE_GC
+
+  #ifdef MR_MPS_GC
+    MR_bool GC_quiet = MR_TRUE;
+  #endif
+
 void
 MR_init_conservative_GC(void)
 {
+  #ifdef MR_MPS_GC
+
+	mercury_mps_init(MR_heap_size * 1024, !GC_quiet);
+
+  #else /* MR_BOEHM_GC */
+
 	/*
 	** sometimes mercury apps fail the GC_is_visible() test.
 	** dyn_load.c traverses the entire address space and registers
@@ -504,6 +524,8 @@
 			GC_REGISTER_DISPLACEMENT(i);
 		}
 	}
+
+  #endif /* MR_BOEHM_GC */
 }
 #endif /* MR_CONSERVATIVE_GC */
 
@@ -1092,7 +1114,7 @@
 			break;
 
 		case 'x':
-#ifdef MR_CONSERVATIVE_GC
+#ifdef MR_BOEHM_GC
 			GC_dont_gc = MR_TRUE;
 #endif
 
Index: runtime/mercury_wrapper.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.h,v
retrieving revision 1.52
diff -u -d -r1.52 mercury_wrapper.h
--- runtime/mercury_wrapper.h	6 Mar 2002 14:35:01 -0000	1.52
+++ runtime/mercury_wrapper.h	31 Jul 2002 00:15:44 -0000
@@ -50,11 +50,10 @@
 extern	int	MR_load_aditi_rl_code(void);
 
 /*
-** MR_init_conservative_GC() initializes the Boehm (et al)
-** conservative collector.  For the LLDS back-end, it is normally
-** called from mercury_runtime_init(), but for the MLDS
-** (--high-level-code) back-end, it may be called directly
-** from main().
+** MR_init_conservative_GC() initializes the conservative collector.
+** The conservative collector can be either the Boehm et al collector,
+** or the MPS (Memory Pool System) kit collector.  This function is normally
+** called from mercury_runtime_init().
 */
 #ifdef MR_CONSERVATIVE_GC
   extern void	MR_init_conservative_GC(void);
Index: scripts/canonical_grade.sh-subr
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/canonical_grade.sh-subr,v
retrieving revision 1.4
diff -u -d -r1.4 canonical_grade.sh-subr
--- scripts/canonical_grade.sh-subr	18 Dec 2001 05:44:17 -0000	1.4
+++ scripts/canonical_grade.sh-subr	30 Jul 2002 06:21:04 -0000
@@ -66,7 +66,9 @@
 esac
 
 case $gc_method in
-	conservative)	GRADE="$GRADE.gc" ;;
+	conservative)	GRADE="$GRADE.gc" ;;	# deprecated; alias for boehm
+	boehm)		GRADE="$GRADE.gc" ;;
+	mps)		GRADE="$GRADE.mps" ;;
 	accurate)	GRADE="$GRADE.agc" ;;
 esac
 
Index: scripts/init_grade_options.sh-subr
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/init_grade_options.sh-subr,v
retrieving revision 1.18
diff -u -d -r1.18 init_grade_options.sh-subr
--- scripts/init_grade_options.sh-subr	31 May 2001 06:00:20 -0000	1.18
+++ scripts/init_grade_options.sh-subr	30 Jul 2002 06:21:55 -0000
@@ -30,7 +30,7 @@
 	--gcc-global-registers
 	-H, --high-level-code
 	--parallel
-	--gc {conservative, accurate, none}
+	--gc {boehm, mps, accurate, none}
 	-p, --profiling
 	--profile-calls
 	--profile-time
@@ -58,7 +58,7 @@
 non_local_gotos=true
 global_regs=true
 thread_safe=false
-gc_method=conservative
+gc_method=boehm
 profile_time=false
 profile_calls=false
 profile_memory=false
Index: scripts/ml.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/ml.in,v
retrieving revision 1.96
diff -u -d -r1.96 ml.in
--- scripts/ml.in	29 Apr 2002 08:22:05 -0000	1.96
+++ scripts/ml.in	30 Jul 2002 08:17:04 -0000
@@ -208,6 +208,8 @@
 		gc_grade=gc_prof ;;
 	*.gc*)
 		gc_grade=gc ;;
+	*.mps*)
+		gc_grade=mps ;;
 	*)
 		gc_grade=nogc ;;
 esac
@@ -256,6 +258,9 @@
 	false)  STRIP_OPTS="" ;;
 esac
 
+case $gc_method in mps)
+	use_thread_libs=true ;;
+esac
 case $thread_safe in true)
 	use_thread_libs=true ;;
 esac
Index: scripts/parse_grade_options.sh-subr
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/parse_grade_options.sh-subr,v
retrieving revision 1.23
diff -u -d -r1.23 parse_grade_options.sh-subr
--- scripts/parse_grade_options.sh-subr	31 May 2001 06:00:20 -0000	1.23
+++ scripts/parse_grade_options.sh-subr	30 Jul 2002 06:22:59 -0000
@@ -73,7 +73,7 @@
 	--gc)
 		shift
 		case "$1" in
-			accurate|conservative|none)
+			accurate|conservative|boehm|mps|none)
 				gc_method=$1 ;;
 			*)
 				echo "$0: invalid gc method \`$1'" 1>&2
@@ -319,8 +319,11 @@
 				agc)
 					gc_method=accurate
 					;;
+				mps)
+					gc_method=mps
+					;;
 				gc)
-					gc_method=conservative
+					gc_method=boehm
 					;;
 				nogc)
 					gc_method=none
-- 
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