1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-13 17:20:21 +02:00

Refactor handling of precise and conservative roots

This commit is contained in:
Andy Wingo 2022-03-04 15:27:22 +01:00
parent 2a619ba67d
commit 283721b39a
5 changed files with 31 additions and 37 deletions

View file

@ -8,10 +8,10 @@ ALL_TESTS=$(foreach COLLECTOR,$(COLLECTORS),$(addprefix $(COLLECTOR)-,$(TESTS)))
all: $(ALL_TESTS) all: $(ALL_TESTS)
bdw-%: bdw.h %.c bdw-%: bdw.h conservative-roots.h %.c
$(CC) $(CFLAGS) -lpthread `pkg-config --libs --cflags bdw-gc` -I. -DGC_BDW -o $@ $*.c $(CC) $(CFLAGS) -lpthread `pkg-config --libs --cflags bdw-gc` -I. -DGC_BDW -o $@ $*.c
semi-%: semi.h %.c semi-%: semi.h precise-roots.h %.c
$(CC) $(CFLAGS) -I. -DGC_SEMI -o $@ $*.c $(CC) $(CFLAGS) -I. -DGC_SEMI -o $@ $*.c
check: $(addprefix test-$(TARGET),$(TARGETS)) check: $(addprefix test-$(TARGET),$(TARGETS))

18
bdw.h
View file

@ -1,3 +1,5 @@
#include "conservative-roots.h"
// When pthreads are used, let `libgc' know about it and redirect // When pthreads are used, let `libgc' know about it and redirect
// allocation calls such as `GC_MALLOC ()' to (contention-free, faster) // allocation calls such as `GC_MALLOC ()' to (contention-free, faster)
// thread-local allocation. // thread-local allocation.
@ -32,22 +34,6 @@ static inline void* allocate(struct context *cx, enum alloc_kind kind,
abort(); abort();
} }
struct handle {
void *v;
};
#define HANDLE_TO(T) union { T* v; struct handle handle; }
#define HANDLE_REF(h) h.v
#define HANDLE_SET(h,val) do { h.v = val; } while (0)
#define PUSH_HANDLE(cx, h) push_handle(cx, &h.handle)
#define POP_HANDLE(cx, h) pop_handle(cx, &h.handle)
static inline void push_handle(struct context *cx, struct handle *handle) {
}
static inline void pop_handle(struct context *cx, struct handle *handle) {
}
static inline void init_field(void **addr, void *val) { static inline void init_field(void **addr, void *val) {
*addr = val; *addr = val;
} }

7
conservative-roots.h Normal file
View file

@ -0,0 +1,7 @@
struct handle { void *unused; };
#define HANDLE_TO(T) union { T* v; struct handle handle; }
#define HANDLE_REF(h) h.v
#define HANDLE_SET(h,val) do { h.v = val; } while (0)
#define PUSH_HANDLE(cx, h) do { (void) &h; } while (0)
#define POP_HANDLE(cx, h) do { (void) &h; } while (0)

19
precise-roots.h Normal file
View file

@ -0,0 +1,19 @@
struct handle {
void *v;
struct handle *next;
};
#define HANDLE_TO(T) union { T* v; struct handle handle; }
#define HANDLE_REF(h) h.v
#define HANDLE_SET(h,val) do { h.v = val; } while (0)
#define PUSH_HANDLE(cx, h) push_handle(&cx->roots, &h.handle)
#define POP_HANDLE(cx, h) pop_handle(&cx->roots, &h.handle)
static inline void push_handle(struct handle **roots, struct handle *handle) {
handle->next = *roots;
*roots = handle;
}
static inline void pop_handle(struct handle **roots, struct handle *handle) {
*roots = handle->next;
}

20
semi.h
View file

@ -4,10 +4,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
struct handle { #include "precise-roots.h"
void *v;
struct handle *next;
};
struct context { struct context {
uintptr_t hp; uintptr_t hp;
@ -143,21 +140,6 @@ static inline void* allocate(struct context *cx, enum alloc_kind kind,
} }
} }
#define HANDLE_TO(T) union { T* v; struct handle handle; }
#define HANDLE_REF(h) h.v
#define HANDLE_SET(h,val) do { h.v = val; } while (0)
#define PUSH_HANDLE(cx, h) push_handle(cx, &h.handle)
#define POP_HANDLE(cx, h) pop_handle(cx, &h.handle)
static inline void push_handle(struct context *cx, struct handle *handle) {
handle->next = cx->roots;
cx->roots = handle;
}
static inline void pop_handle(struct context *cx, struct handle *handle) {
cx->roots = handle->next;
}
static inline void init_field(void **addr, void *val) { static inline void init_field(void **addr, void *val) {
*addr = val; *addr = val;
} }