From e7bca22779c68b800c75fdad8841440dfeb32f8d Mon Sep 17 00:00:00 2001 From: Ludovic Courtes Date: Sun, 3 Dec 2006 21:59:02 +0000 Subject: [PATCH] Use thread-local allocation (significant perf. improvement!); added the `boehm-gc.h' header. * libguile/Makefile.am (modinclude_HEADERS): Added `boehm-gc.h'. * libguile/coop-defs.h: Use "libguile/boehm-gc.h" instead of . * libguile/coop-threads.h: Likewise. * libguile/coop.c: Likewise. * libguile/gc.c: Likewise. (scm_storage_prehistory): Invoke `GC_init ()'. * libguile/guardians.c: Use "libguile/boehm-gc.h" instead of . * libguile/inline.h: Likewise. (scm_double_cell): Use `GC_MALLOC' instead of `GC_malloc'. * libguile/pthread-threads.h: Use "libguile/boehm-gc.h" instead of . * libguile/smob.c: Likewise. * libguile/smob.h: Likewise. * libguile/struct.c: Likewise. * libguile/threads.c: Likewise. * libguile/weaks.c: Likewise. git-archimport-id: lcourtes@laas.fr--2005-libre/guile-core--boehm-gc--1.9--patch-51 --- libguile/Makefile.am | 1 + libguile/boehm-gc.h | 39 ++++++++++++++++++++++++++++++++++++++ libguile/coop-defs.h | 5 ++--- libguile/coop-pthreads.h | 3 +-- libguile/coop.c | 2 ++ libguile/gc.c | 11 ++++++++++- libguile/guardians.c | 2 +- libguile/inline.h | 4 ++-- libguile/pthread-threads.h | 3 +-- libguile/smob.c | 2 +- libguile/smob.h | 2 +- libguile/struct.c | 2 +- libguile/threads.c | 1 + libguile/vectors.c | 2 +- libguile/weaks.c | 2 +- 15 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 libguile/boehm-gc.h diff --git a/libguile/Makefile.am b/libguile/Makefile.am index 531390183..34b747324 100644 --- a/libguile/Makefile.am +++ b/libguile/Makefile.am @@ -183,6 +183,7 @@ pkginclude_HEADERS = gh.h # These are headers visible as . modincludedir = $(includedir)/libguile modinclude_HEADERS = __scm.h alist.h arbiters.h async.h backtrace.h \ + boehm-gc.h \ boolean.h chars.h continuations.h convert.h debug.h debug-malloc.h \ deprecation.h deprecated.h discouraged.h dynl.h dynwind.h \ environments.h eq.h error.h eval.h evalext.h extensions.h \ diff --git a/libguile/boehm-gc.h b/libguile/boehm-gc.h new file mode 100644 index 000000000..49a369596 --- /dev/null +++ b/libguile/boehm-gc.h @@ -0,0 +1,39 @@ +#ifndef SCM_BOEHM_GC_H +#define SCM_BOEHM_GC_H + +/* Copyright (C) 2006 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 as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* Correct header inclusion. */ + +#include "libguile/gen-scmconfig.h" + +#ifdef SCM_I_GSC_USE_PTHREAD_THREADS + +/* When pthreads are used, let `libgc' know about it and redirect allocation + calls such as `GC_MALLOC ()' to (contention-free, faster) thread-local + allocation. */ + +# define GC_THREADS 1 +# define GC_REDIRECT_TO_LOCAL 1 + +#endif + +#include +#include + +#endif /* SCM_BOEHM_GC_H */ diff --git a/libguile/coop-defs.h b/libguile/coop-defs.h index 7b06ccefe..9ce80358b 100644 --- a/libguile/coop-defs.h +++ b/libguile/coop-defs.h @@ -31,11 +31,10 @@ #ifdef GUILE_PTHREAD_COMPAT # include - -# define GC_THREADS 1 -# include #endif +#include "libguile/boehm-gc.h" + /* This file is included by threads.h, which, in turn, is included by libguile.h while coop-threads.h only is included by coop-threads.c. */ diff --git a/libguile/coop-pthreads.h b/libguile/coop-pthreads.h index a82f1249a..57b53ede4 100644 --- a/libguile/coop-pthreads.h +++ b/libguile/coop-pthreads.h @@ -29,8 +29,7 @@ #include -#define GC_THREADS 1 -#include +#include "libguile/boehm-gc.h" #include "libguile/iselect.h" diff --git a/libguile/coop.c b/libguile/coop.c index 133c3d470..a8dca12c5 100644 --- a/libguile/coop.c +++ b/libguile/coop.c @@ -511,6 +511,8 @@ coop_condition_variable_destroy (coop_c *c) #ifdef GUILE_PTHREAD_COMPAT +#include "libguile/boehm-gc.h" + /* 1K room for the cond wait routine */ #if SCM_STACK_GROWS_UP # define COOP_STACK_ROOM (256) diff --git a/libguile/gc.c b/libguile/gc.c index 142fd0be9..d8b27d2f5 100644 --- a/libguile/gc.c +++ b/libguile/gc.c @@ -23,6 +23,8 @@ # include #endif +#include "libguile/gen-scmconfig.h" + #include #include #include @@ -55,7 +57,7 @@ extern unsigned long * __libc_ia64_register_backing_store_base; #include "libguile/gc.h" #include "libguile/dynwind.h" -#include +#include "libguile/boehm-gc.h" #ifdef GUILE_DEBUG_MALLOC #include "libguile/debug-malloc.h" @@ -641,6 +643,13 @@ scm_storage_prehistory () GC_all_interior_pointers = 0; GC_INIT (); + +#ifdef SCM_I_GSC_USE_PTHREAD_THREADS + /* When using GC 6.8, this call is required to initialize thread-local + freelists (shouldn't be necessary with GC 7.0). */ + GC_init (); +#endif + GC_expand_hp (SCM_DEFAULT_INIT_HEAP_SIZE_2); /* We only need to register a displacement for those types for which the diff --git a/libguile/guardians.c b/libguile/guardians.c index 7ca11c407..879462a73 100644 --- a/libguile/guardians.c +++ b/libguile/guardians.c @@ -55,7 +55,7 @@ #include "libguile/eval.h" #include "libguile/guardians.h" -#include +#include "libguile/boehm-gc.h" diff --git a/libguile/inline.h b/libguile/inline.h index 8d6c41717..75a7cc95c 100644 --- a/libguile/inline.h +++ b/libguile/inline.h @@ -38,7 +38,7 @@ #include "libguile/pairs.h" -#include +#include "libguile/boehm-gc.h" SCM_API SCM scm_cell (scm_t_bits car, scm_t_bits cdr); @@ -98,7 +98,7 @@ scm_double_cell (scm_t_bits car, scm_t_bits cbr, { SCM z; - z = SCM_PACK ((scm_t_bits) (GC_malloc (2 * sizeof (scm_t_cell)))); + z = SCM_PACK ((scm_t_bits) (GC_MALLOC (2 * sizeof (scm_t_cell)))); /* Initialize the type slot last so that the cell is ignored by the GC until it is completely initialized. This is only relevant when the GC can actually run during this code, which it can't diff --git a/libguile/pthread-threads.h b/libguile/pthread-threads.h index e2ee7b2fa..64b56e197 100644 --- a/libguile/pthread-threads.h +++ b/libguile/pthread-threads.h @@ -29,8 +29,7 @@ #include /* `libgc' intercepts pthread calls by defining wrapping macros. */ -#define GC_THREADS 1 -#include +#include "libguile/boehm-gc.h" /* Threads */ diff --git a/libguile/smob.c b/libguile/smob.c index 901942c8e..718442237 100644 --- a/libguile/smob.c +++ b/libguile/smob.c @@ -37,7 +37,7 @@ #include "libguile/smob.h" -#include +#include "libguile/boehm-gc.h" #include diff --git a/libguile/smob.h b/libguile/smob.h index 05617933b..2bf508e28 100644 --- a/libguile/smob.h +++ b/libguile/smob.h @@ -25,7 +25,7 @@ #include "libguile/__scm.h" #include "libguile/print.h" -#include +#include "libguile/boehm-gc.h" diff --git a/libguile/struct.c b/libguile/struct.c index 38331dd0f..181b3d32c 100644 --- a/libguile/struct.c +++ b/libguile/struct.c @@ -39,7 +39,7 @@ #include #endif -#include +#include "libguile/boehm-gc.h" diff --git a/libguile/threads.c b/libguile/threads.c index ec1360585..5f5218019 100644 --- a/libguile/threads.c +++ b/libguile/threads.c @@ -20,6 +20,7 @@ #define _GNU_SOURCE +#include "libguile/boehm-gc.h" #include "libguile/_scm.h" #if HAVE_UNISTD_H diff --git a/libguile/vectors.c b/libguile/vectors.c index afc74b7da..4bc5ce611 100644 --- a/libguile/vectors.c +++ b/libguile/vectors.c @@ -34,7 +34,7 @@ #include "libguile/dynwind.h" #include "libguile/deprecation.h" -#include /* disappearing links (aka. weak pointers) */ +#include "libguile/boehm-gc.h" diff --git a/libguile/weaks.c b/libguile/weaks.c index efb2d13ae..5883dec1f 100644 --- a/libguile/weaks.c +++ b/libguile/weaks.c @@ -52,7 +52,7 @@ #include "libguile/validate.h" #include "libguile/weaks.h" -#include +#include "libguile/boehm-gc.h" #include -- 2.20.1