1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

Initialize BDW-GC using Whippet API

* libguile/gc.c (scm_storage_prehistory): Use Whippet API instead of
BDW-GC API.
This commit is contained in:
Andy Wingo 2025-04-17 09:31:48 +02:00
parent 2d5d9f6ba9
commit 57e8686cea

View file

@ -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)
void
scm_storage_prehistory ()
{
GC_set_all_interior_pointers (0);
GC_set_finalize_on_demand (1);
static struct gc_heap *the_gc_heap;
static struct gc_basic_stats the_gc_stats;
#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
void
scm_storage_prehistory (void)
{
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);
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))