~ chicken-core (chicken-5) 3890bdc762726cf0418a28d42143a39c34e7a009


commit 3890bdc762726cf0418a28d42143a39c34e7a009
Author:     Peter Bex <peter.bex@xs4all.nl>
AuthorDate: Sat Apr 5 21:04:54 2014 +0200
Commit:     Mario Domenech Goulart <mario.goulart@gmail.com>
CommitDate: Wed Apr 9 19:52:18 2014 -0300

    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.
    
    Signed-off-by: Mario Domenech Goulart <mario.goulart@gmail.com>

diff --git a/library.scm b/library.scm
index 31eda652..59ddc36e 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 8d2284d6..f68cd092 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);
 }
Trap