>From 1abf96ecb879d406e0b7032e819578e81e631f3f Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sat, 5 Apr 2014 21:04:54 +0200 Subject: [PATCH] Improve GC performance by avoiding tracking of nursery->nursery or heap->heap mutations. Instead, we only track mutations pointing *into* the nursery, and only on objects *not* in the nursery. --- library.scm | 11 +++++++---- runtime.c | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/library.scm b/library.scm index 31eda65..59ddc36 100644 --- a/library.scm +++ b/library.scm @@ -5079,13 +5079,16 @@ EOF (pstr ", ") (pnum gctime) (pstr "s GC time (major)"))) - (let ((mut (##sys#slot info 2))) + (let ((mut (##sys#slot info 2)) + (umut (##sys#slot info 3))) (when (fx> mut 0) (pstr ", ") (pnum mut) - (pstr " mutations"))) - (let ((minor (##sys#slot info 3)) - (major (##sys#slot info 4))) + (pchr #\/) + (pnum umut) + (pstr " mutations (total/tracked)"))) + (let ((minor (##sys#slot info 4)) + (major (##sys#slot info 5))) (when (or (fx> minor 0) (fx> major 0)) (pstr ", ") (pnum major) diff --git a/runtime.c b/runtime.c index 8d2284d..f68cd09 100644 --- a/runtime.c +++ b/runtime.c @@ -441,6 +441,7 @@ static C_TLS int static volatile C_TLS int serious_signal_occurred = 0; static C_TLS unsigned int mutation_count, + tracked_mutation_count, stack_size; static C_TLS int chicken_is_initialized; #ifdef HAVE_SIGSETJMP @@ -751,7 +752,7 @@ int CHICKEN_initialize(int heap, int stack, int symbols, void *toplevel) #endif } - mutation_count = gc_count_1 = gc_count_1_total = gc_count_2 = 0; + tracked_mutation_count = mutation_count = gc_count_1 = gc_count_1_total = gc_count_2 = 0; lf_list = NULL; C_register_lf2(NULL, 0, create_initial_ptable()); C_restart_address = toplevel; @@ -2713,6 +2714,14 @@ C_mutate_slot(C_word *slot, C_word val) { unsigned int mssize, newmssize, bytes; + ++mutation_count; + /* Mutation stack exists to track mutations pointing from elsewhere + * into nursery. Stuff pointing anywhere else can be skipped, as + * well as mutations on nursery objects. + */ + if(!C_in_stackp(val) || C_in_stackp((C_word)slot)) + return *slot = val; + #ifdef C_GC_HOOKS if(C_gc_mutation_hook != NULL && C_gc_mutation_hook(slot, val)) return val; #endif @@ -2737,7 +2746,7 @@ C_mutate_slot(C_word *slot, C_word val) } *(mutation_stack_top++) = slot; - ++mutation_count; + ++tracked_mutation_count; return *slot = val; } @@ -4080,6 +4089,7 @@ C_regparm C_word C_fcall C_set_gc_report(C_word flag) C_regparm C_word C_fcall C_start_timer(void) { + tracked_mutation_count = 0; mutation_count = 0; gc_count_1_total = 0; gc_count_2 = 0; @@ -4093,13 +4103,14 @@ void C_ccall C_stop_timer(C_word c, C_word closure, C_word k) { double t0 = C_cpu_milliseconds() - timer_start_ms; C_word - ab[ WORDS_PER_FLONUM * 2 + 6 ], /* 2 flonums, 1 vector of 5 elements */ + ab[ WORDS_PER_FLONUM * 2 + 7 ], /* 2 flonums, 1 vector of 6 elements */ *a = ab, elapsed = C_flonum(&a, t0 / 1000.0), gc_time = C_flonum(&a, gc_ms / 1000.0), info; - info = C_vector(&a, 5, elapsed, gc_time, C_fix(mutation_count), C_fix(gc_count_1_total), + info = C_vector(&a, 6, elapsed, gc_time, C_fix(mutation_count), + C_fix(tracked_mutation_count), C_fix(gc_count_1_total), C_fix(gc_count_2)); C_kontinue(k, info); } -- 1.7.9.5