wingo pushed a commit to branch wip-whippet in repository guile. commit 57e8686ceaec796ffdfddbff675872aed4547cf1 Author: Andy Wingo <wi...@pobox.com> AuthorDate: Thu Apr 17 09:31:48 2025 +0200
Initialize BDW-GC using Whippet API * libguile/gc.c (scm_storage_prehistory): Use Whippet API instead of BDW-GC API. --- libguile/gc.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/libguile/gc.c b/libguile/gc.c index e94ad3c42..e10ef54f0 100644 --- a/libguile/gc.c +++ b/libguile/gc.c @@ -60,6 +60,7 @@ #include "gc.h" #include "gc-internal.h" +#include "gc-basic-stats.h" /* For GC_set_start_callback. */ @@ -444,38 +445,33 @@ scm_gc_unregister_roots (SCM *b, unsigned long n) +static struct gc_heap *the_gc_heap; +static struct gc_basic_stats the_gc_stats; + void -scm_storage_prehistory () +scm_storage_prehistory (void) { - GC_set_all_interior_pointers (0); - GC_set_finalize_on_demand (1); + struct gc_options *options = gc_allocate_options (); + gc_options_set_int(options, GC_OPTION_HEAP_SIZE_POLICY, GC_HEAP_SIZE_GROWABLE); + gc_options_set_size(options, GC_OPTION_HEAP_SIZE, DEFAULT_INITIAL_HEAP_SIZE); -#if (GC_VERSION_MAJOR == 7 && GC_VERSION_MINOR == 4 \ - && GC_VERSION_MICRO == 0) - /* BDW-GC 7.4.0 has a bug making it loop indefinitely when using more - than one marker thread: <https://github.com/ivmai/bdwgc/pull/30>. - Work around it by asking for one marker thread. */ - setenv ("GC_MARKERS", "1", 1); -#endif + char *options_str = getenv ("GUILE_GC_OPTIONS"); + if (options_str && !gc_options_parse_and_set_many (options, options_str)) + fprintf (stderr, "warning: failed to set GC options from string: \"%s\"\n", + options_str); #if SCM_I_GSC_USE_NULL_THREADS /* If we have disabled threads in Guile, ensure that the GC doesn't spawn any marker threads. */ - setenv ("GC_MARKERS", "1", 1); + gc_options_set_int (options, GC_OPTION_PARALLELISM, 1) #endif - GC_INIT (); - - size_t heap_size = GC_get_heap_size (); - if (heap_size < DEFAULT_INITIAL_HEAP_SIZE) - GC_expand_hp (DEFAULT_INITIAL_HEAP_SIZE - heap_size); - - /* We only need to register a displacement for those types for which the - higher bits of the type tag are used to store a pointer (that is, a - pointer to an 8-octet aligned region). */ - GC_REGISTER_DISPLACEMENT (scm_tc3_cons); - GC_REGISTER_DISPLACEMENT (scm_tc3_struct); - /* GC_REGISTER_DISPLACEMENT (scm_tc3_unused); */ + struct gc_mutator *mut; + if (!gc_init (options, NULL, &the_gc_heap, &mut, + GC_BASIC_STATS, &the_gc_stats)) { + fprintf (stderr, "Failed to initialize GC\n"); + abort (); + } /* Sanity check. */ if (!GC_is_visible (&scm_protects))