1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

Inline freelist vectors into scm_thread

* libguile/gc-inline.h:
* libguile/threads.h (SCM_INLINE_GC_GRANULE_WORDS)
  (SCM_INLINE_GC_GRANULE_BYTES, SCM_INLINE_GC_FREELIST_COUNT): Move
  definitions here, from gc-inline.h.
  (struct scm_thread): Inline freelist vectors.
* libguile/threads.c (thread_mark): Update marker for pointerless
  freelists.
  (on_thread_exit): Clear individual freelist entries, instead of the
  vector as a whole.
  (guilify_self_2): No need to alloc freelist vectors.
This commit is contained in:
Andy Wingo 2019-06-20 13:44:47 +02:00
parent 117bb3bade
commit 33aecf48b0
3 changed files with 27 additions and 35 deletions

View file

@ -1,7 +1,7 @@
#ifndef SCM_GC_INLINE_H
#define SCM_GC_INLINE_H
/* Copyright 1995-1996,1998-2004,2006-2014,2018
/* Copyright 1995-1996,1998-2004,2006-2014,2018-2019
Free Software Foundation, Inc.
This file is part of Guile.
@ -47,17 +47,6 @@
#define SCM_INLINE_GC_GRANULE_WORDS 2
#define SCM_INLINE_GC_GRANULE_BYTES \
(sizeof(void *) * SCM_INLINE_GC_GRANULE_WORDS)
/* A freelist set contains SCM_INLINE_GC_FREELIST_COUNT pointers to
singly linked lists of objects of different sizes, the ith one
containing objects i + 1 granules in size. This setting of
SCM_INLINE_GC_FREELIST_COUNT will hold freelists for allocations of
up to 256 bytes. */
#define SCM_INLINE_GC_FREELIST_COUNT (256U / SCM_INLINE_GC_GRANULE_BYTES)
static inline size_t
scm_inline_gc_bytes_to_freelist_index (size_t bytes)
{

View file

@ -1,4 +1,4 @@
/* Copyright 1995-1998,2000-2014,2018
/* Copyright 1995-1998,2000-2014,2018-2019
Free Software Foundation, Inc.
This file is part of Guile.
@ -99,20 +99,16 @@ thread_mark (GC_word *addr, struct GC_ms_entry *mark_stack_ptr,
but GC doesn't know to trace them (as they are pointerless), so we
need to do that here. See the comments at the top of libgc's
gc_inline.h. */
if (t->pointerless_freelists)
for (size_t n = 0; n < SCM_INLINE_GC_FREELIST_COUNT; n++)
{
size_t n;
for (n = 0; n < SCM_INLINE_GC_FREELIST_COUNT; n++)
void *chain = t->pointerless_freelists[n];
if (chain)
{
void *chain = t->pointerless_freelists[n];
if (chain)
{
/* The first link is already marked by the freelist vector,
so we just have to mark the tail. */
while ((chain = *(void **)chain))
mark_stack_ptr = GC_mark_and_push (chain, mark_stack_ptr,
mark_stack_limit, NULL);
}
/* The first link is already marked by the thread itsel, so we
just have to mark the tail. */
while ((chain = *(void **)chain))
mark_stack_ptr = GC_mark_and_push (chain, mark_stack_ptr,
mark_stack_limit, NULL);
}
}
@ -443,12 +439,6 @@ guilify_self_2 (SCM dynamic_state)
t->continuation_root = scm_cons (t->handle, SCM_EOL);
t->continuation_base = t->base;
{
size_t size = SCM_INLINE_GC_FREELIST_COUNT * sizeof (void *);
t->freelists = scm_gc_malloc (size, "freelists");
t->pointerless_freelists = scm_gc_malloc (size, "atomic freelists");
}
t->dynamic_state = scm_gc_typed_calloc (scm_t_dynamic_state);
t->dynamic_state->thread_local_values = scm_c_make_hash_table (0);
scm_set_current_dynamic_state (dynamic_state);
@ -508,8 +498,8 @@ on_thread_exit (void *v)
/* Although this thread has exited, the thread object might still be
alive. Release unused memory. */
t->freelists = NULL;
t->pointerless_freelists = NULL;
for (size_t n = 0; n < SCM_INLINE_GC_FREELIST_COUNT; n++)
t->freelists[n] = t->pointerless_freelists[n] = NULL;
t->dynamic_state = NULL;
t->dynstack.base = NULL;
t->dynstack.top = NULL;

View file

@ -39,6 +39,19 @@
#define SCM_INLINE_GC_GRANULE_WORDS 2
#define SCM_INLINE_GC_GRANULE_BYTES \
(sizeof(void *) * SCM_INLINE_GC_GRANULE_WORDS)
/* A freelist set contains SCM_INLINE_GC_FREELIST_COUNT pointers to
singly linked lists of objects of different sizes, the ith one
containing objects i + 1 granules in size. This setting of
SCM_INLINE_GC_FREELIST_COUNT will hold freelists for allocations of
up to 256 bytes. */
#define SCM_INLINE_GC_FREELIST_COUNT (256U / SCM_INLINE_GC_GRANULE_BYTES)
/* smob tags for the thread datatypes */
SCM_API scm_t_bits scm_tc16_thread;
SCM_API scm_t_bits scm_tc16_mutex;
@ -60,8 +73,8 @@ struct scm_thread {
not be run. */
/* Thread-local freelists; see gc-inline.h. */
void **freelists;
void **pointerless_freelists;
void *freelists[SCM_INLINE_GC_FREELIST_COUNT];
void *pointerless_freelists[SCM_INLINE_GC_FREELIST_COUNT];
SCM handle;
scm_i_pthread_t pthread;