For review: revised changes to runtime for global heap
Warwick Harvey
wharvey at cs.monash.edu.au
Wed Jun 17 11:53:04 AEST 1998
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? If so, where should they be defined?
mercury_engine.h? It seems to me to be appropriate to put them with MR_hp,
MR_sol_hp, etc., except that these are defined in mercury_regorder.h, which
doesn't seem appropriate for the above.
Anyway, the real point of this mail is the revised changes to the runtime
for adding the global heap:
runtime/mercury_deep_copy.c:
runtime/mercury_deep_copy.h:
Added two functions, MR_make_permanent() and
MR_make_partially_permanent(), which essentially do a deep copy of a
term to the global heap.
(In conservative GC grades, these functions actually do nothing).
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.
runtime/mercury_memory.c:
Added code for handling the size and zone size of the global heap.
runtime/mercury_regorder.h:
runtime/mercury_regs.h:
Defined MR_global_hp (the global heap pointer for general use),
along with corresponding other changes.
runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
Added declarations and initialisation of the size and zone_size of
the global_heap.
Added an entry for MR_GLOBAL_HP_RN to print_register_usage_counts()
(plus missing entries for MR_SOL_HP_RN, MR_MIN_HP_REC and
MR_MIN_SOL_HP_REC).
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 01:42:40
@@ -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,51 @@
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_ENGINE(heap_zone)->bottom ||
+ lower_limit > MR_ENGINE(heap_zone)->top) {
+ lower_limit = MR_ENGINE(heap_zone)->bottom;
+ }
+
+ /* temporarily swap the heap with the global heap */
+ SWAP(MR_ENGINE(heap_zone), MR_ENGINE(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_ENGINE(global_heap_zone)->top);
+ restore_transient_registers();
+
+ /* swap the heap and global heap back again */
+ SWAP(MR_ENGINE(heap_zone), MR_ENGINE(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 01:42:40
@@ -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 01:42:40
@@ -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 01:42:40
@@ -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,12 +253,14 @@
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)
/*
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 01:42:40
@@ -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 01:42:40
@@ -78,6 +78,8 @@
#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 \
@@ -87,7 +89,7 @@
#define MR_NUM_SPECIAL_REG 10
/* 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 +105,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,6 +191,8 @@
#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)
@@ -196,7 +201,7 @@
#define MR_NUM_SPECIAL_REG 10
/* 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 +217,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 01:42:40
@@ -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 01:42:41
@@ -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 01:42:41
@@ -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