[m-dev.] diff: improve documentation about -DNO_SIGNALS

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Sep 21 16:00:50 AEDT 2000


Estimated hours taken: 0.25

runtime/mercury_prof_mem.h:
runtime/mercury_prof_mem.c:
	Improve the documentation about the use of -DNO_SIGNALS and
	the use of malloc/GC_malloc in the profiling signal handler.

boehm_gc/Makefile:
scripts/mgnuc.in:
	Add pointers to the documentation in runtime/mercury_prof_mem.h.

Workspace: /home/pgrad/fjh/ws/hg2
Index: boehm_gc/Makefile
===================================================================
RCS file: /home/mercury1/repository/mercury/boehm_gc/Makefile,v
retrieving revision 1.42
diff -u -d -r1.42 Makefile
--- boehm_gc/Makefile	2000/09/18 11:08:47	1.42
+++ boehm_gc/Makefile	2000/09/21 04:58:11
@@ -49,7 +49,7 @@
 CFLAGS= -DSILENT -DDONT_DEFINE_READ -DNO_DEBUGGING -DNO_EXECUTE_PERMISSION \
 	$(CFLAGS_FOR_PIC) $(DLL_CFLAGS) $(EXTRA_CFLAGS)
 # Note that the `mgnuc' script also passes -DNO_SIGNALS, unless
-# profiling was enabled.
+# profiling was enabled (see comments in runtime/mercury_prof_mem.h for why).
 # We need $(CFLAGS_FOR_PIC) because we might be building a shared library.
 
 # Setjmp_test may yield overly optimistic results when compiled
Index: runtime/mercury_prof_mem.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_prof_mem.c,v
retrieving revision 1.8
diff -u -d -r1.8 mercury_prof_mem.c
--- runtime/mercury_prof_mem.c	2000/08/03 06:18:52	1.8
+++ runtime/mercury_prof_mem.c	2000/09/21 04:51:11
@@ -12,7 +12,11 @@
 ** This module is needed to get around the problem that when a signal occurs
 ** it may be in a malloc.  The handling routine may also do a malloc which 
 ** stuffs up the internal state of malloc and cause a seg fault.
-** To avoid this problem, we use our own version of malloc() which
+** If we're using the conservative GC, that doesn't cause a problem,
+** since the Boehm et al collector is signal safe if compiled without
+** -DNO_SIGNALS, which we do for profiling grades.  But if we're not
+** using the conservative GC, then the handler will need to call malloc().
+** To minimize this problem, we use our own version of malloc() which
 ** allocates memory in large chunks, reducing the chance of this
 ** problem occurring.
 */
@@ -71,6 +75,11 @@
 
 	/* Here we waste a bit of space but hopefully not to much */
 	if (mem_left < size) {
+		/*
+		** XXX For the conservative GC, it would be better to
+		** allocate this memory with GC_malloc_atomic_uncollectable(),
+		** so that the collector doesn't scan it.
+		*/
 		next = MR_GC_malloc(MEMORY_BLOCK * size);
 		mem_left = MEMORY_BLOCK * size;
 	}
Index: runtime/mercury_prof_mem.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_prof_mem.h,v
retrieving revision 1.6
diff -u -d -r1.6 mercury_prof_mem.h
--- runtime/mercury_prof_mem.h	2000/08/03 06:18:52	1.6
+++ runtime/mercury_prof_mem.h	2000/09/21 04:45:12
@@ -21,7 +21,13 @@
 ** and then doles out portions of these chunks one at a time.
 ** We use MR_prof_malloc() to reduce the chance of calling MR_GC_malloc()
 ** from a profiling interrupt that interrupted another call to MR_GC_malloc().
-** Doing that is bad news, because MR_GC_malloc() is not re-entrant.
+** Doing that is bad news, because MR_GC_malloc() is not guaranteed to be
+** re-entrant.
+** (If conservative GC is enabled, then MR_GC_malloc() _is_ re-entrant,
+** since for profiling grades we compile the conservative collector without
+** -DNO_SIGNALS [see boehm_gc/README for documentation about -DNO_SIGNALS].
+** But if conservative GC is not enabled, then MR_GC_malloc() just
+** calls malloc(), which is not guaranteed to be re-entrant.)
 **
 ** Note that the current implementation of MR_prof_malloc only guarantees
 ** that the memory will be MR_Word-aligned; if you want to allocate types
Index: scripts/mgnuc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mgnuc.in,v
retrieving revision 1.72
diff -u -d -r1.72 mgnuc.in
--- scripts/mgnuc.in	2000/09/14 14:31:27	1.72
+++ scripts/mgnuc.in	2000/09/21 04:57:34
@@ -279,6 +279,8 @@
 case $profile_time in
 	true)		PROF_TIME_OPTS="-DPROFILE_TIME" ;;
 	false)		PROF_TIME_OPTS="-DNO_SIGNALS" ;;
+			# We pass -DNO_SIGNALS unless profiling is enabled.
+			# See comments in runtime/mercury_prof_mem.h for why.
 esac
 
 case $profile_calls in

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list