[m-rev.] diff: make AGC debugging a run-time option
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Aug 2 18:13:02 AEST 2002
Estimated hours taken: 1
Branches: main
Make the accurate GC debugging code a run-time option
rather than a compile-time option.
The run-time cost of this is very small -- just a few `if' statements
per garbage collection -- and it is more convenient if agc debugging
can be enabled by setting MERCURY_OPTIONS rather than by having to
recompile the Mercury runtime.
runtime/mercury_engine.h:
Add a new debug flag `MR_agc_debug', for debugging accurate GC.
runtime/mercury_wrapper.c:
Set the flag if the -dA or -dG options are
specified in MERCURY_OPTIONS.
runtime/mercury_accurate_gc.c:
Change the code which was using `#ifdef MR_AGC_DEBUG_COLLECTION'
to instead use `if (MR_agc_debug)'.
runtime/mercury_conf_param.h:
Delete the documentation of the now unused configuration macro
MR_AGC_DEBUG_COLLECTION, and add a mention of the -dG option.
Workspace: /home/ceres/fjh/mercury
Index: runtime/mercury_accurate_gc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_accurate_gc.c,v
retrieving revision 1.21
diff -u -d -r1.21 mercury_accurate_gc.c
--- runtime/mercury_accurate_gc.c 7 Jun 2002 00:48:59 -0000 1.21
+++ runtime/mercury_accurate_gc.c 2 Aug 2002 07:55:26 -0000
@@ -84,16 +84,19 @@
old_heap = MR_ENGINE(MR_eng_heap_zone);
new_heap = MR_ENGINE(MR_eng_heap_zone2);
-#ifdef MR_DEBUG_AGC_COLLECTION
- fprintf(stderr, "\ngarbage_collect() called.\n");
+ /*
+ ** Print some debugging messages.
+ */
+ if (MR_agc_debug) {
+ fprintf(stderr, "\ngarbage_collect() called.\n");
- fprintf(stderr, "old_heap->min: %lx \t old_heap->hardmax: %lx\n",
- (long) old_heap->min, (long) old_heap->hardmax);
+ fprintf(stderr, "old_heap->min: %lx \t old_heap->hardmax: %lx\n",
+ (long) old_heap->min, (long) old_heap->hardmax);
fprintf(stderr, "new_heap->min: %lx \t new_heap->hardmax: %lx\n",
- (long) new_heap->min, (long) new_heap->hardmax);
+ (long) new_heap->min, (long) new_heap->hardmax);
- fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
-#endif
+ fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+ }
old_hp = MR_virtual_hp;
@@ -128,10 +131,10 @@
MR_ENGINE(MR_eng_heap_zone) = tmp;
}
-#ifdef MR_DEBUG_AGC_COLLECTION
- fprintf(stderr, "Swapped heaps\n");
- fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
-#endif
+ if (MR_agc_debug) {
+ fprintf(stderr, "Swapped heaps\n");
+ fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+ }
/*
** Copy any roots on the stack
@@ -143,41 +146,42 @@
*/
garbage_collect_roots();
-#ifdef MR_DEBUG_AGC_COLLECTION
- fprintf(stderr, "Clearing old heap:\n");
+ /*
+ ** Print some more debugging messages,
+ ** and clear out the old heap.
+ */
+ if (MR_agc_debug) {
+ fprintf(stderr, "Clearing old heap:\n");
- {
- MR_Word *tmp_hp;
+ {
+ MR_Word *tmp_hp;
- for (tmp_hp = old_heap->min; tmp_hp <= old_hp; tmp_hp++) {
+ for (tmp_hp = old_heap->min; tmp_hp <= old_hp; tmp_hp++) {
*tmp_hp = 0xDEADBEAF;
- }
- }
+ }
+ }
- fprintf(stderr, "AFTER:\n");
+ fprintf(stderr, "AFTER:\n");
/* XXX save this, it appears to get clobbered */
- new_hp = MR_virtual_hp;
+ new_hp = MR_virtual_hp;
- MR_agc_dump_roots(root_list);
+ MR_agc_dump_roots(root_list);
/* XXX restore this, it appears to get clobbered */
- fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
- MR_virtual_hp = new_hp;
- fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
-
- fprintf(stderr, "old heap: %ld bytes, new heap: %ld bytes\n",
- (long) ((char *) old_hp - (char *) old_heap->min),
- (long) ((char *) MR_virtual_hp - (char *) new_heap->min));
- fprintf(stderr, "%ld bytes recovered\n",
- (long) ((char *) old_hp - (char *) old_heap->min) -
- ((char *) MR_virtual_hp - (char *) new_heap->min));
+ fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+ MR_virtual_hp = new_hp;
+ fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
-#endif
+ fprintf(stderr, "old heap: %ld bytes, new heap: %ld bytes\n",
+ (long) ((char *) old_hp - (char *) old_heap->min),
+ (long) ((char *) MR_virtual_hp - (char *) new_heap->min));
+ fprintf(stderr, "%ld bytes recovered\n",
+ (long) ((char *) old_hp - (char *) old_heap->min) -
+ ((char *) MR_virtual_hp - (char *) new_heap->min));
-#ifdef MR_DEBUG_AGC_COLLECTION
- fprintf(stderr, "garbage_collect() done.\n\n");
-#endif
+ fprintf(stderr, "garbage_collect() done.\n\n");
+ }
}
static void
@@ -403,16 +407,16 @@
old_heap = MR_ENGINE(MR_eng_heap_zone);
new_heap = MR_ENGINE(MR_eng_heap_zone2);
-#ifdef MR_DEBUG_AGC_COLLECTION
- fprintf(stderr, "\ngarbage_collect() called.\n");
+ if (MR_agc_debug) {
+ fprintf(stderr, "\ngarbage_collect() called.\n");
- fprintf(stderr, "old_heap->min: %lx \t old_heap->hardmax: %lx\n",
- (long) old_heap->min, (long) old_heap->hardmax);
+ fprintf(stderr, "old_heap->min: %lx \t old_heap->hardmax: %lx\n",
+ (long) old_heap->min, (long) old_heap->hardmax);
fprintf(stderr, "new_heap->min: %lx \t new_heap->hardmax: %lx\n",
- (long) new_heap->min, (long) new_heap->hardmax);
+ (long) new_heap->min, (long) new_heap->hardmax);
- fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
-#endif
+ fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+ }
old_hp = MR_virtual_hp;
@@ -432,34 +436,34 @@
MR_ENGINE(MR_eng_heap_zone) = tmp;
}
-#ifdef MR_DEBUG_AGC_COLLECTION
- fprintf(stderr, "Swapped heaps\n");
- fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
-#endif
+ if (MR_agc_debug) {
+ fprintf(stderr, "Swapped heaps\n");
+ fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+ }
label = MR_lookup_internal_by_addr(success_ip);
label_layout = label->i_layout;
-#ifdef MR_DEBUG_AGC_COLLECTION
- first_label = label;
- first_stack_pointer = stack_pointer;
- first_current_frame = current_frame;
- first_max_frame = max_frame;
- fprintf(stderr, "BEFORE:\n");
- MR_agc_dump_stack_frames(first_label, old_heap, first_stack_pointer,
- first_current_frame);
- MR_agc_dump_nondet_stack_frames(first_label, old_heap, first_stack_pointer,
- first_current_frame, first_max_frame);
- MR_agc_dump_roots(root_list);
+ if (MR_agc_debug) {
+ first_label = label;
+ first_stack_pointer = stack_pointer;
+ first_current_frame = current_frame;
+ first_max_frame = max_frame;
+ fprintf(stderr, "BEFORE:\n");
+ MR_agc_dump_stack_frames(first_label, old_heap, first_stack_pointer,
+ first_current_frame);
+ MR_agc_dump_nondet_stack_frames(first_label, old_heap,
+ first_stack_pointer, first_current_frame, first_max_frame);
+ MR_agc_dump_roots(root_list);
- /*
- ** XXX the debug code seems to be messing up the heap pointer.
- ** easier to reset it than debug the problem at the moment
- */
- fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
- MR_virtual_hp = new_heap->min;
- fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
-#endif
+ /*
+ ** XXX the debug code seems to be messing up the heap pointer.
+ ** easier to reset it than debug the problem at the moment
+ */
+ fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+ MR_virtual_hp = new_heap->min;
+ fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+ }
/*
** For each stack frame ...
@@ -470,10 +474,10 @@
const MR_Label_Layout *return_label_layout;
int short_var_count, long_var_count;
-#ifdef MR_DEBUG_AGC_COLLECTION
- printlabel((MR_Code *) (Word) label->i_addr);
- fflush(NULL);
-#endif
+ if (MR_agc_debug) {
+ printlabel((MR_Code *) (Word) label->i_addr);
+ fflush(NULL);
+ }
short_var_count = MR_short_desc_var_count(label_layout);
long_var_count = MR_long_desc_var_count(label_layout);
@@ -574,21 +578,21 @@
frame_size = max_frame - MR_prevfr_slot(max_frame);
if (frame_size == MR_NONDET_TEMP_SIZE) {
-#ifdef MR_DEBUG_AGC_COLLECTION
+ if (MR_agc_debug) {
printlabel(MR_redoip_slot(max_frame));
fflush(NULL);
-#endif
+ }
} else if (frame_size == MR_DET_TEMP_SIZE) {
-#ifdef MR_DEBUG_AGC_COLLECTION
+ if (MR_agc_debug) {
printlabel(MR_redoip_slot(max_frame));
fflush(NULL);
-#endif
- stack_pointer = MR_detfr_slot(max_frame); /* XXX ??? */
+ }
+ stack_pointer = MR_detfr_slot(max_frame); /* XXX ??? */
} else {
-#ifdef MR_DEBUG_AGC_COLLECTION
+ if (MR_agc_debug) {
printlabel(MR_redoip_slot(max_frame));
fflush(NULL);
-#endif
+ }
}
label = MR_lookup_internal_by_addr(MR_redoip_slot(max_frame));
@@ -649,48 +653,47 @@
*/
garbage_collect_roots();
-#ifdef MR_DEBUG_AGC_COLLECTION
- fprintf(stderr, "Clearing old heap:\n");
+ if (MR_agc_debug) {
+ fprintf(stderr, "Clearing old heap:\n");
- {
- Word *tmp_hp;
+ {
+ Word *tmp_hp;
- for (tmp_hp = old_heap->min; tmp_hp <= old_hp; tmp_hp++) {
- *tmp_hp = 1;
- }
- }
+ for (tmp_hp = old_heap->min; tmp_hp <= old_hp; tmp_hp++) {
+ *tmp_hp = 0xDEADBEAF;
+ }
+ }
- fprintf(stderr, "AFTER:\n");
+ fprintf(stderr, "AFTER:\n");
/* XXX save this, it appears to get clobbered */
- new_hp = MR_virtual_hp;
+ new_hp = MR_virtual_hp;
- MR_agc_dump_stack_frames(first_label, new_heap, first_stack_pointer,
- first_current_frame);
- MR_agc_dump_roots(root_list);
- MR_agc_dump_nondet_stack_frames(first_label, new_heap, first_stack_pointer,
- first_current_frame, first_max_frame);
+ MR_agc_dump_stack_frames(first_label, new_heap, first_stack_pointer,
+ first_current_frame);
+ MR_agc_dump_roots(root_list);
+ MR_agc_dump_nondet_stack_frames(first_label, new_heap,
+ first_stack_pointer, first_current_frame, first_max_frame);
/* XXX restore this, it appears to get clobbered */
- fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
- MR_virtual_hp = new_hp;
- fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
-
- fprintf(stderr, "old heap: %ld bytes, new heap: %ld bytes\n",
- (long) ((char *) old_hp - (char *) old_heap->min),
- (long) ((char *) MR_virtual_hp - (char *) new_heap->min));
- fprintf(stderr, "%ld bytes recovered\n",
- (long) ((char *) old_hp - (char *) old_heap->min) -
- ((char *) MR_virtual_hp - (char *) new_heap->min));
+ fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
+ MR_virtual_hp = new_hp;
+ fprintf(stderr, "MR_virtual_hp: %lx\n", (long) MR_virtual_hp);
-#endif
+ fprintf(stderr, "old heap: %ld bytes, new heap: %ld bytes\n",
+ (long) ((char *) old_hp - (char *) old_heap->min),
+ (long) ((char *) MR_virtual_hp - (char *) new_heap->min));
+ fprintf(stderr, "%ld bytes recovered\n",
+ (long) ((char *) old_hp - (char *) old_heap->min) -
+ ((char *) MR_virtual_hp - (char *) new_heap->min));
+ }
/* Reset the redzone on the old heap */
MR_reset_redzone(old_heap);
-#ifdef MR_DEBUG_AGC_COLLECTION
- fprintf(stderr, "garbage_collect() done.\n\n");
-#endif
+ if (MR_agc_debug) {
+ fprintf(stderr, "garbage_collect() done.\n\n");
+ }
}
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 23 Jul 2002 13:08:43 -0000
@@ -166,11 +166,7 @@
**
** MR_DEBUG_AGC_SCHEDULING
** Display debugging information while scheduling accurate garbage
-** collection.
-**
-** MR_DEBUG_AGC_COLLECTION
-** Display debugging information while collecting garbage using the
-** accurate garbage collector.
+** collection (for the low-level back-end).
**
** MR_DEBUG_AGC_FORWARDING
** Display debugging information when leaving or finding forwarding
@@ -185,11 +181,16 @@
** collection.
**
** MR_DEBUG_AGC_SMALL_HEAP
-** Use a small heap to trigger garbage collection more often.
+** Use a small heap (52k) to trigger garbage collection more often.
+** This is the same as setting MERCURY_OPTIONS="--heap-size 52".
**
** MR_DEBUG_AGC_ALL
** Turn on all debugging information for accurate garbage
** collection. (Equivalent to all MR_DEBUG_AGC_* macros above).
+**
+** Note that general debugging information about accurate
+** garbage collection is printed if -dG is included in MERCURY_OPTIONS.
+** This works even if none of the MR_DEBUG_AGC_* macros are enabled.
**
** MR_TABLE_DEBUG
** Enables low-level debugging messages from the tabling system.
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 7 Jun 2002 15:14:27 -0000
@@ -50,8 +50,9 @@
#define MR_TABLEHASHFLAG 11
#define MR_TABLESTACKFLAG 12
#define MR_UNBUFFLAG 13
-#define MR_DETAILFLAG 14
-#define MR_MAXFLAG 15
+#define MR_AGC_FLAG 14
+#define MR_DETAILFLAG 15
+#define MR_MAXFLAG 16
/* MR_DETAILFLAG should be the last real flag */
#define MR_progdebug MR_debugflag[MR_PROGFLAG]
@@ -69,6 +70,7 @@
#define MR_tablestackdebug MR_debugflag[MR_TABLESTACKFLAG]
#define MR_unbufdebug MR_debugflag[MR_UNBUFFLAG]
#define MR_detaildebug MR_debugflag[MR_DETAILFLAG]
+#define MR_agc_debug MR_debugflag[MR_AGC_FLAG]
/*
** MR_setjmp and MR_longjmp are wrappers around setjmp and longjmp
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 23 Jul 2002 13:08:48 -0000
@@ -947,6 +947,9 @@
#ifdef MR_CONSERVATIVE_GC
GC_quiet = MR_FALSE;
#endif
+#ifdef MR_NATIVE_GC
+ MR_agc_debug = MR_TRUE;
+#endif
} else if (MR_streq(MR_optarg, "b")) {
MR_nondstackdebug = MR_TRUE;
} else if (MR_streq(MR_optarg, "c")) {
@@ -960,6 +963,8 @@
} else if (MR_streq(MR_optarg, "G")) {
#ifdef MR_CONSERVATIVE_GC
GC_quiet = MR_FALSE;
+#elif defined(MR_NATIVE_GC)
+ MR_agc_debug = MR_TRUE;
#else
; /* ignore inapplicable option */
#endif
--
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