The attached patch adds debug-output when the mutation-stack is resized (and debug-mode is enabled). The m-stack grows by twice its current size instead of growing by a fixed rate. Also, some variables (incorrectly) reported by gcc/valgrind as being uninitialized in C_reclaim are set to appropriate values. Thanks to Joerg Wittenberger for his help in locating these warnings.
cheers, felix
>From 44d6eedc809899b6eb520daf463c7f48697b5d25 Mon Sep 17 00:00:00 2001 From: felix <fe...@call-with-current-continuation.org> Date: Tue, 25 Oct 2011 13:26:28 +0200 Subject: [PATCH] cleaning up uninitialized variables in C_reclaim, add debug output to C_mutate on m-stack resize, grow m-stack at higher rate --- runtime.c | 25 +++++++++++++++---------- 1 files changed, 15 insertions(+), 10 deletions(-) diff --git a/runtime.c b/runtime.c index 05bf39c..5e4f755 100644 --- a/runtime.c +++ b/runtime.c @@ -156,7 +156,6 @@ extern void _C_do_apply_hack(void *proc, C_word *args, int count) C_noret; #define TEMPORARY_STACK_SIZE 2048 #define STRING_BUFFER_SIZE 4096 #define DEFAULT_MUTATION_STACK_SIZE 1024 -#define MUTATION_STACK_GROWTH 1024 #define FILE_INFO_SIZE 7 @@ -2605,7 +2604,7 @@ C_word C_h_structure(int n, ...) C_regparm C_word C_fcall C_mutate(C_word *slot, C_word val) { - int mssize; + unsigned int mssize, newmssize, bytes; if(!C_immediatep(val)) { #ifdef C_GC_HOOKS @@ -2615,14 +2614,19 @@ C_regparm C_word C_fcall C_mutate(C_word *slot, C_word val) if(mutation_stack_top >= mutation_stack_limit) { assert(mutation_stack_top == mutation_stack_limit); mssize = mutation_stack_top - mutation_stack_bottom; - mutation_stack_bottom = - (C_word **)realloc(mutation_stack_bottom, - (mssize + MUTATION_STACK_GROWTH) * sizeof(C_word *)); + newmssize = mssize * 2; + bytes = newmssize * sizeof(C_word *); + + if(debug_mode) + C_dbg(C_text("debug"), C_text("resizing mutation-stack from " UWORD_COUNT_FORMAT_STRING "k to " UWORD_COUNT_FORMAT_STRING "k ...\n"), + (mssize * sizeof(C_word *)) / 1024, bytes / 1024); + + mutation_stack_bottom = (C_word **)realloc(mutation_stack_bottom, bytes); if(mutation_stack_bottom == NULL) panic(C_text("out of memory - cannot re-allocate mutation stack")); - mutation_stack_limit = mutation_stack_bottom + mssize + MUTATION_STACK_GROWTH; + mutation_stack_limit = mutation_stack_bottom + newmssize; mutation_stack_top = mutation_stack_bottom + mssize; } @@ -2666,7 +2670,7 @@ static void mark(C_word *x) { \ C_regparm void C_fcall C_reclaim(void *trampoline, void *proc) { - int i, j, n, fcount, weakn; + int i, j, n, fcount, weakn = 0; C_uword count, bytes; C_word *p, **msp, bucket, last, item, container; C_header h; @@ -2675,7 +2679,7 @@ C_regparm void C_fcall C_reclaim(void *trampoline, void *proc) C_SCHEME_BLOCK *bp; C_GC_ROOT *gcrp; WEAK_TABLE_ENTRY *wep; - double tgc; + double tgc = 0; C_SYMBOL_TABLE *stp; volatile int finalizers_checked; FINALIZER_NODE *flist; @@ -2694,9 +2698,10 @@ C_regparm void C_fcall C_reclaim(void *trampoline, void *proc) C_restart_address = proc; heap_scan_top = (C_byte *)C_align((C_uword)C_fromspace_top); gc_mode = GC_MINOR; + start = C_fromspace_top; /* Entry point for second-level GC (on explicit request or because of full fromspace): */ - if(C_setjmp(gc_restart) || (start = C_fromspace_top) >= C_fromspace_limit) { + if(C_setjmp(gc_restart) || start >= C_fromspace_limit) { if(gc_bell) { C_putchar(7); C_fflush(stdout); @@ -3173,7 +3178,7 @@ C_regparm void C_fcall C_rereclaim2(C_uword size, int double_plus) if(debug_mode) C_dbg(C_text("debug"), C_text("resizing heap dynamically from " UWORD_COUNT_FORMAT_STRING "k to " UWORD_COUNT_FORMAT_STRING "k ...\n"), - (C_uword)heap_size / 1000, size / 1000); + (C_uword)heap_size / 1024, size / 1024); if(gc_report_flag) { C_dbg(C_text("GC"), C_text("(old) fromspace: \tstart=" UWORD_FORMAT_STRING -- 1.6.0.4
_______________________________________________ Chicken-hackers mailing list Chicken-hackers@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-hackers