diff options
Diffstat (limited to 'libguile/gc.c')
-rw-r--r-- | libguile/gc.c | 74 |
1 files changed, 25 insertions, 49 deletions
diff --git a/libguile/gc.c b/libguile/gc.c index 91250ba57..8816a61a6 100644 --- a/libguile/gc.c +++ b/libguile/gc.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2006, 2008, 2009, 2010 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -69,10 +69,6 @@ extern unsigned long * __libc_ia64_register_backing_store_base; #include <unistd.h> #endif -/* Lock this mutex before doing lazy sweeping. - */ -scm_i_pthread_mutex_t scm_i_sweep_mutex = SCM_I_PTHREAD_MUTEX_INITIALIZER; - /* Set this to != 0 if every cell that is accessed shall be checked: */ int scm_debug_cell_accesses_p = 0; @@ -206,23 +202,13 @@ unsigned long scm_gc_ports_collected = 0; static unsigned long protected_obj_count = 0; -SCM_SYMBOL (sym_cells_allocated, "cells-allocated"); +SCM_SYMBOL (sym_gc_time_taken, "gc-time-taken"); SCM_SYMBOL (sym_heap_size, "heap-size"); SCM_SYMBOL (sym_heap_free_size, "heap-free-size"); SCM_SYMBOL (sym_heap_total_allocated, "heap-total-allocated"); -SCM_SYMBOL (sym_mallocated, "bytes-malloced"); -SCM_SYMBOL (sym_mtrigger, "gc-malloc-threshold"); -SCM_SYMBOL (sym_heap_segments, "cell-heap-segments"); -SCM_SYMBOL (sym_gc_time_taken, "gc-time-taken"); -SCM_SYMBOL (sym_gc_mark_time_taken, "gc-mark-time-taken"); -SCM_SYMBOL (sym_times, "gc-times"); -SCM_SYMBOL (sym_cells_marked, "cells-marked"); -SCM_SYMBOL (sym_cells_marked_conservatively, "cells-marked-conservatively"); -SCM_SYMBOL (sym_cells_swept, "cells-swept"); -SCM_SYMBOL (sym_malloc_yield, "malloc-yield"); -SCM_SYMBOL (sym_cell_yield, "cell-yield"); +SCM_SYMBOL (sym_heap_allocated_since_gc, "heap-allocated-since-gc"); SCM_SYMBOL (sym_protected_objects, "protected-objects"); -SCM_SYMBOL (sym_total_cells_allocated, "total-cells-allocated"); +SCM_SYMBOL (sym_times, "gc-times"); /* Number of calls to SCM_NEWCELL since startup. */ @@ -287,33 +273,14 @@ SCM_DEFINE (scm_gc_stats, "gc-stats", 0, 0, 0, total_bytes = GC_get_total_bytes (); gc_times = GC_gc_no; - /* njrev: can any of these scm_cons's or scm_list_n signal a memory - error? If so we need a frame here. */ answer = scm_list_n (scm_cons (sym_gc_time_taken, SCM_INUM0), -#if 0 - scm_cons (sym_cells_allocated, - scm_from_ulong (local_scm_cells_allocated)), - scm_cons (sym_mallocated, - scm_from_ulong (local_scm_mallocated)), - scm_cons (sym_mtrigger, - scm_from_ulong (local_scm_mtrigger)), - scm_cons (sym_gc_mark_time_taken, - scm_from_ulong (local_scm_gc_mark_time_taken)), - scm_cons (sym_cells_marked, - scm_from_double (local_scm_gc_cells_marked)), - scm_cons (sym_cells_swept, - scm_from_double (local_scm_gc_cells_swept)), - scm_cons (sym_malloc_yield, - scm_from_long (local_scm_gc_malloc_yield_percentage)), - scm_cons (sym_cell_yield, - scm_from_long (local_scm_gc_cell_yield_percentage)), - scm_cons (sym_heap_segments, heap_segs), -#endif scm_cons (sym_heap_size, scm_from_size_t (heap_size)), scm_cons (sym_heap_free_size, scm_from_size_t (free_bytes)), scm_cons (sym_heap_total_allocated, scm_from_size_t (total_bytes)), + scm_cons (sym_heap_allocated_since_gc, + scm_from_size_t (bytes_since_gc)), scm_cons (sym_protected_objects, scm_from_ulong (protected_obj_count)), scm_cons (sym_times, scm_from_size_t (gc_times)), @@ -377,17 +344,7 @@ SCM_DEFINE (scm_gc, "gc", 0, 0, 0, "no longer accessible.") #define FUNC_NAME s_scm_gc { - scm_i_scm_pthread_mutex_lock (&scm_i_sweep_mutex); scm_i_gc ("call"); - /* njrev: It looks as though other places, e.g. scm_realloc, - can call scm_i_gc without acquiring the sweep mutex. Does this - matter? Also scm_i_gc (or its descendants) touch the - scm_sys_protects, which are protected in some cases - (e.g. scm_permobjs above in scm_gc_stats) by a critical section, - not by the sweep mutex. Shouldn't all the GC-relevant objects be - protected in the same way? */ - scm_i_pthread_mutex_unlock (&scm_i_sweep_mutex); - scm_c_hook_run (&scm_after_gc_c_hook, 0); return SCM_UNSPECIFIED; } #undef FUNC_NAME @@ -587,6 +544,23 @@ scm_gc_unregister_roots (SCM *b, unsigned long n) scm_gc_unregister_root (p); } +static void +scm_c_register_gc_callback (void *key, void (*func) (void *, void *), + void *data) +{ + if (!key) + key = GC_MALLOC_ATOMIC (sizeof (void*)); + + GC_REGISTER_FINALIZER_NO_ORDER (key, func, data, NULL, NULL); +} + +static void +system_gc_callback (void *key, void *data) +{ + scm_c_register_gc_callback (key, system_gc_callback, data); + scm_c_hook_run (&scm_after_gc_c_hook, NULL); +} + @@ -642,6 +616,8 @@ scm_storage_prehistory () scm_c_hook_init (&scm_before_sweep_c_hook, 0, SCM_C_HOOK_NORMAL); scm_c_hook_init (&scm_after_sweep_c_hook, 0, SCM_C_HOOK_NORMAL); scm_c_hook_init (&scm_after_gc_c_hook, 0, SCM_C_HOOK_NORMAL); + + scm_c_register_gc_callback (NULL, system_gc_callback, NULL); } scm_i_pthread_mutex_t scm_i_gc_admin_mutex = SCM_I_PTHREAD_MUTEX_INITIALIZER; |