[m-dev.] For review: revised changes to runtime for global heap

Warwick Harvey wharvey at cs.monash.edu.au
Wed Jun 17 15:17:35 AEST 1998


Fergus Henderson <fjh at cs.mu.OZ.AU> writes:
> On 17-Jun-1998, Warwick Harvey <wharvey at cs.monash.edu.au> wrote:
> > I'm thinking it might be worth defining MR_heap_zone, etc.:
> > 
> > #define MR_heap_zone		MR_ENGINE(heap_zone)
> > #define MR_solutions_heap_zone	MR_ENGINE(solutions_heap_zone)
> > #define MR_global_heap_zone	MR_ENGINE(global_heap_zone)
> > 
> > Does this seem useful?
> 
> Yes.

Done.  (Nobody else seems to refer to them after they're allocated though).

> >  #define MR_NUM_SPECIAL_REG	10
> 
> You need to change that to 11 now.
...
> However, the existing definition of MR_NUM_SPECIAL_REG is wrong in the
> `defined(MR_THREAD_SAFE) && NUM_REAL_REGS > 0' case -- it should
> be 11 before your addition of global_hp and 12 after it.
> You might as well fix that one while you're at it.

I don't understand this (I can't see what MR_NUM_SPECIAL_REG is for), but 
done.

> Also please copy the documentation at the top of the non-thread-safe

Done.

> (I'd fix these two myself, but it's probably easier for you to do it
> yourself rather than to try to merge in my changes.)

I dunno, I'm getting pretty good at that.  ;-)

> Otherwise, everything looks fine.  Please mail around another diff,
> but the changes suggested above are pretty straightforward, so
> if it passes the bootcheck then go ahead and commit it without
> waiting for another review.

OK, here's the new diff.  The last one passed a bootcheck last night, the 
current one (plus updates from the repository) passes a make install and my 
tests of the new code.  I'm running a bootcheck on it now, but don't expect 
the result until tomorrow (well, after I leave work tonight anyway), so you 
have plenty of time to review this diff.  :-)


runtime/mercury_engine.c:
runtime/mercury_engine.h:
	Added fields global_heap_zone and e_global_hp (for the global heap
	and its heap pointer) to the MR_mercury_engine_struct, along with
	appropriate initialisation, etc.
+	Defined MR_heap_zone, MR_solutions_heap_zone, and MR_global_heap_zone
+	for convenient access to the corresponding field of the relevant
+	Mercury engine.


Index: runtime/mercury_deep_copy.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy.c,v
retrieving revision 1.8
diff -u -r1.8 mercury_deep_copy.c
--- mercury_deep_copy.c	1998/06/10 06:56:01	1.8
+++ mercury_deep_copy.c	1998/06/17 04:51:53
@@ -11,6 +11,7 @@
 #include "mercury_imp.h"
 #include "mercury_deep_copy.h"
 #include "mercury_type_info.h"
+#include "mercury_memory.h"
 
 #define in_range(X)	((X) >= lower_limit && (X) <= upper_limit)
 
@@ -342,3 +343,49 @@
 		return type_info;
 	}
 }
+
+
+#define SWAP(val1, val2, type)		\
+	do {				\
+		type swap_tmp;		\
+		swap_tmp = (val1);	\
+		(val1) = (val2);	\
+		(val2) = swap_tmp;	\
+	} while (0)
+
+#ifndef CONSERVATIVE_GC
+/*
+** MR_make_long_lived(): see mercury_deep_copy.h for documentation.
+*/
+Word
+MR_make_long_lived(Word term, Word *type_info, Word *lower_limit)
+{
+	Word result;
+
+	restore_transient_registers();	/* Because we play with MR_hp */
+
+	if (lower_limit < MR_heap_zone->bottom ||
+			lower_limit > MR_heap_zone->top) {
+		lower_limit = MR_heap_zone->bottom;
+	}
+
+	/* temporarily swap the heap with the global heap */
+	SWAP(MR_heap_zone, MR_global_heap_zone, MemoryZone *);
+	SWAP(MR_hp, MR_global_hp, Word *);
+
+	/* copy values from the heap to the global heap */
+	save_transient_registers();
+	result = deep_copy(term, type_info, lower_limit,
+			MR_global_heap_zone->top);
+	restore_transient_registers();
+
+	/* swap the heap and global heap back again */
+	SWAP(MR_heap_zone, MR_global_heap_zone, MemoryZone *);
+	SWAP(MR_hp, MR_global_hp, Word *);
+
+	save_transient_registers();	/* Because we played with MR_hp */
+
+	return result;
+}
+#endif	/* not CONSERVATIVE_GC */
+
Index: runtime/mercury_deep_copy.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy.h,v
retrieving revision 1.4
diff -u -r1.4 mercury_deep_copy.h
--- mercury_deep_copy.h	1998/06/10 06:56:04	1.4
+++ mercury_deep_copy.h	1998/06/17 04:51:53
@@ -11,7 +11,8 @@
 
 #include "mercury_types.h"	/* for `Word' */
 
-/* Deep Copy:
+/*
+** Deep Copy:
 **
 ** 	Copy a data item, completely.
 **
@@ -68,5 +69,43 @@
 
 Word deep_copy(Word data, Word *type_info, Word *lower_limit, 
 	Word *upper_limit);
+
+/*
+** MR_make_permanent:
+**
+**	Returns a copy of term that can be accessed safely even after
+**	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
+**	hence the term is just returned.
+**
+**	When not using a conservative GC grade, save_transient_registers()
+**	and restore_transient_registers() need to be used around this
+**	function.
+*/
+
+#define MR_make_permanent(term, type_info)			\
+	MR_make_long_lived((term), (type_info), NULL)
+
+/*
+** MR_make_long_lived:
+**
+**	This is the same as MR_make_permanent, except that if limit is an
+**	address on the heap, parts of term that are "older" than limit will
+**	not be copied.  This is useful when you know that the permanent copy
+**	of term will not be accessed after the heap pointer has backtracked
+**	beyond limit.  Naturally, this always occurs when the permanent term
+**	is to be stored in *limit.
+**
+**	I'd like to describe the limit argument without referring to the
+**	"heap," but don't see how to.
+*/
+
+#ifdef CONSERVATIVE_GC
+  #define MR_make_long_lived(term, type_info, lower_limit) (term)
+#else
+  Word MR_make_long_lived(Word term, Word *type_info, Word *lower_limit);
+#endif
 
 #endif /* not MERCURY_DEEP_COPY_H */
Index: runtime/mercury_engine.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_engine.c,v
retrieving revision 1.8
diff -u -r1.8 mercury_engine.c
--- mercury_engine.c	1998/06/15 07:00:07	1.8
+++ mercury_engine.c	1998/06/17 04:51:53
@@ -84,6 +84,11 @@
 			solutions_heap_size, next_offset(),
 			solutions_heap_zone_size, default_handler);
 	eng->e_sol_hp = eng->solutions_heap_zone->min;
+
+	eng->global_heap_zone = create_zone("global_heap", 1,
+			global_heap_size, next_offset(),
+			global_heap_zone_size, default_handler);
+	eng->e_global_hp = eng->global_heap_zone->min;
 #endif
 
 #ifdef MR_LOWLEVEL_DEBUG
Index: runtime/mercury_engine.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_engine.h,v
retrieving revision 1.5
diff -u -r1.5 mercury_engine.h
--- mercury_engine.h	1998/06/15 07:00:08	1.5
+++ mercury_engine.h	1998/06/17 04:51:53
@@ -164,6 +164,8 @@
 		/* The heap pointer for this engine */
 	Word		*e_sol_hp;
 		/* The solutions heap pointer for this engine */
+	Word		*e_global_hp;
+		/* The global heap pointer for this engine */
 #endif
 	MR_Context	*this_context;
 		/*
@@ -197,6 +199,7 @@
 #ifndef	CONSERVATIVE_GC
 	MemoryZone	*heap_zone;
 	MemoryZone	*solutions_heap_zone;
+	MemoryZone	*global_heap_zone;
 #endif
 #ifndef	SPEED
 	MemoryZone	*dumpstack_zone;
@@ -250,13 +253,24 @@
   	do {								\
 		IF_NOT_CONSERVATIVE_GC(MR_hp = (eng)->e_hp;)		\
 		IF_NOT_CONSERVATIVE_GC(MR_sol_hp = (eng)->e_sol_hp;)	\
+		IF_NOT_CONSERVATIVE_GC(MR_global_hp = (eng)->e_global_hp;) \
 	} while (0)
 
 #define save_engine_regs(eng)						\
   	do {								\
 		IF_NOT_CONSERVATIVE_GC((eng)->e_hp = MR_hp;)		\
 		IF_NOT_CONSERVATIVE_GC((eng)->e_sol_hp = MR_sol_hp;)	\
+		IF_NOT_CONSERVATIVE_GC((eng)->e_global_hp = MR_global_hp;) \
 	} while (0)
+
+/*
+** Macros for easy access to heap zones
+*/
+#ifndef	CONSERVATIVE_GC
+  #define MR_heap_zone			MR_ENGINE(heap_zone)
+  #define MR_solutions_heap_zone	MR_ENGINE(solutions_heap_zone)
+  #define MR_global_heap_zone		MR_ENGINE(global_heap_zone)
+#endif
 
 /*
 ** Functions for creating/destroying a MercuryEngine.
Index: runtime/mercury_memory.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory.c,v
retrieving revision 1.10
diff -u -r1.10 mercury_memory.c
--- mercury_memory.c	1998/06/09 07:25:01	1.10
+++ mercury_memory.c	1998/06/17 04:51:53
@@ -142,12 +142,16 @@
 	heap_size	    = 0;
 	solutions_heap_zone_size = 0;
 	solutions_heap_size = 0;
+	global_heap_zone_size = 0;
+	global_heap_size    = 0;
 #else
 	heap_zone_size      = round_up(heap_zone_size * 1024, unit);
 	heap_size           = round_up(heap_size * 1024, unit);
 	solutions_heap_zone_size = round_up(solutions_heap_zone_size * 1024, 
 		unit);
 	solutions_heap_size = round_up(solutions_heap_size * 1024, unit);
+	global_heap_zone_size = round_up(global_heap_zone_size * 1024, unit);
+	global_heap_size    = round_up(global_heap_size * 1024, unit);
 #endif
 
 	detstack_size       = round_up(detstack_size * 1024, unit);
@@ -174,6 +178,9 @@
 	}
 	if (solutions_heap_zone_size >= solutions_heap_size) {
 		solutions_heap_zone_size = unit;
+	}
+	if (global_heap_zone_size >= global_heap_size) {
+		global_heap_zone_size = unit;
 	}
 #endif
 
Index: runtime/mercury_regorder.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_regorder.h,v
retrieving revision 1.7
diff -u -r1.7 mercury_regorder.h
--- mercury_regorder.h	1998/06/15 07:00:12	1.7
+++ mercury_regorder.h	1998/06/17 04:51:54
@@ -69,6 +69,11 @@
 
 #define MR_engine_base	LVALUE_CAST(Word *, count_usage(MR_SP_RN, mr0))
 
+/*
+** If you modify the following block, make sure that you update
+** the definitions of MR_NUM_SPECIAL_REG, MR_MAX_SPECIAL_REG_MR,
+** and MR_saved_*.
+*/
 #define MR_succip	LVALUE_CAST(Code *, count_usage(MR_SI_RN, mr2))
 #define MR_hp		LVALUE_CAST(Word *, count_usage(MR_HP_RN, mr6))
 #define MR_sp		LVALUE_CAST(Word *, count_usage(MR_SP_RN, mr1))
@@ -78,16 +83,18 @@
 #define MR_min_hp_rec	LVALUE_CAST(Word *, count_usage(MR_MIN_HP_REC, 
mr(39)))
 #define MR_min_sol_hp_rec	LVALUE_CAST(Word *,	\
 			count_usage(MR_MIN_HP_REC, mr40))
+#define MR_global_hp	LVALUE_CAST(Word *,	\
+			count_usage(MR_GLOBAL_HP_RN, mr(41)))
 
 #define MR_trail_ptr	count_usage(MR_TRAIL_PTR_RN, MR_trail_ptr_var)
 #define MR_ticket_counter	 \
 		count_usage(MR_TICKET_COUNTER_RN, MR_ticket_counter_var)
 
 /* the number of special, non rN registers */
-#define MR_NUM_SPECIAL_REG	10
+#define MR_NUM_SPECIAL_REG	12
 
 /* the maximum mrN number of special, non rN registers */
-#define	MR_MAX_SPECIAL_REG_MR	40
+#define	MR_MAX_SPECIAL_REG_MR	41
 
 /*
 ** The MR_saved_foo macros are like MR_foo except that
@@ -103,6 +110,7 @@
 #define MR_saved_sol_hp(save_area)	LVALUE_CAST(Word *, save_area[38])
 #define MR_saved_min_hp_rec(save_area)	LVALUE_CAST(Word *, save_area[39])
 #define MR_saved_min_sol_hp_rec(save_area) LVALUE_CAST(Word *, 
save_area[40])
+#define MR_saved_global_hp(save_area)	LVALUE_CAST(Word *, save_area[41])
 
 #define VIRTUAL_REG_MAP_BODY	{ \
 	3, \
@@ -188,15 +196,17 @@
 #define MR_min_hp_rec	LVALUE_CAST(Word *, count_usage(MR_MIN_HP_REC, 
mr(38)))
 #define MR_min_sol_hp_rec	LVALUE_CAST(Word *,	\
 			count_usage(MR_MIN_HP_REC, mr39))
+#define MR_global_hp	LVALUE_CAST(Word *,	\
+			count_usage(MR_GLOBAL_HP_RN, mr(40)))
 #define MR_trail_ptr	count_usage(MR_TRAIL_PTR_RN, MR_trail_ptr_var)
 #define MR_ticket_counter	 \
 		count_usage(MR_TICKET_COUNTER_RN, MR_ticket_counter_var)
 
 /* the number of special, non rN registers */
-#define MR_NUM_SPECIAL_REG	10
+#define MR_NUM_SPECIAL_REG	11
 
 /* the maximum mrN number of special, non rN registers */
-#define	MR_MAX_SPECIAL_REG_MR	39
+#define	MR_MAX_SPECIAL_REG_MR	40
 
 /*
 ** The MR_saved_foo macros are like MR_foo except that
@@ -212,6 +222,7 @@
 #define MR_saved_sol_hp(save_area)	LVALUE_CAST(Word *, save_area[37])
 #define MR_saved_min_hp_rec(save_area)	LVALUE_CAST(Word *, save_area[38])
 #define MR_saved_min_sol_hp_rec(save_area) LVALUE_CAST(Word *, 
save_area[39])
+#define MR_saved_global_hp(save_area)	LVALUE_CAST(Word *, save_area[40])
 
 #define VIRTUAL_REG_MAP_BODY	{ \
 	2, \
Index: runtime/mercury_regs.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_regs.h,v
retrieving revision 1.8
diff -u -r1.8 mercury_regs.h
--- mercury_regs.h	1998/06/15 07:00:13	1.8
+++ mercury_regs.h	1998/06/17 04:51:54
@@ -205,6 +205,7 @@
 #define MR_virtual_sol_hp 		MR_saved_sol_hp(MR_fake_reg)
 #define MR_virtual_min_hp_rec 		MR_saved_min_hp_rec(MR_fake_reg)
 #define MR_virtual_min_sol_hp_rec 	MR_saved_min_sol_hp_rec(MR_fake_reg)
+#define MR_virtual_global_hp 		MR_saved_global_hp(MR_fake_reg)
 
 /*
 ** get_reg() and set_reg() provide a different way of addressing
@@ -238,6 +239,7 @@
 #define	MR_SOL_HP_RN		(MR_ORD_RN + 7)
 #define	MR_MIN_HP_REC		(MR_ORD_RN + 8)
 #define	MR_MIN_SOL_HP_REC	(MR_ORD_RN + 9)
-#define MAX_RN			(MR_ORD_RN + 10)
+#define	MR_GLOBAL_HP_RN		(MR_ORD_RN + 10)
+#define	MAX_RN			(MR_ORD_RN + 11)
 
 #endif /* not MERCURY_REGS_H */
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.13
diff -u -r1.13 mercury_wrapper.c
--- mercury_wrapper.c	1998/06/09 02:08:25	1.13
+++ mercury_wrapper.c	1998/06/17 04:51:54
@@ -49,6 +49,7 @@
 size_t		detstack_size =  	2048;
 size_t		nondstack_size =  	128;
 size_t		solutions_heap_size =	1024;
+size_t		global_heap_size =	1024;
 size_t		trail_size =		128;
 
 /* size of the redzones at the end of data areas, in kilobytes */
@@ -57,6 +58,7 @@
 size_t		detstack_zone_size =	16;
 size_t		nondstack_zone_size =	16;
 size_t		solutions_heap_zone_size = 16;
+size_t		global_heap_zone_size =	16;
 size_t		trail_zone_size =	16;
 
 /* primary cache size to optimize for, in kilobytes */
@@ -893,6 +895,18 @@
 				break;
 			case MR_TICKET_COUNTER_RN:
 				printf("MR_ticket_counter");
+				break;
+			case MR_SOL_HP_RN:
+				printf("MR_sol_hp");
+				break;
+			case MR_MIN_HP_REC:
+				printf("MR_min_hp_rec");
+				break;
+			case MR_MIN_SOL_HP_REC:
+				printf("MR_min_sol_hp_rec");
+				break;
+			case MR_GLOBAL_HP_RN:
+				printf("MR_global_hp");
 				break;
 			default:
 				printf("UNKNOWN%d", i);
Index: runtime/mercury_wrapper.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.h,v
retrieving revision 1.7
diff -u -r1.7 mercury_wrapper.h
--- mercury_wrapper.h	1998/04/08 11:34:17	1.7
+++ mercury_wrapper.h	1998/06/17 04:51:54
@@ -80,6 +80,7 @@
 extern	size_t		nondstack_size;
 extern	size_t		solutions_heap_size;
 extern	size_t		trail_size;
+extern	size_t		global_heap_size;
 
 /* sizes of the red zones */
 extern	size_t		heap_zone_size;
@@ -87,6 +88,7 @@
 extern	size_t		nondstack_zone_size;
 extern	size_t		solutions_heap_zone_size;
 extern	size_t		trail_zone_size;
+extern	size_t		global_heap_zone_size;
 
 /* size of the primary cache */
 extern	size_t		pcache_size;





More information about the developers mailing list