diff --git a/bdw.h b/bdw.h index 2d30fb3b6..142e5bccb 100644 --- a/bdw.h +++ b/bdw.h @@ -211,8 +211,8 @@ static int gc_init(int argc, struct gc_option argv[], return 1; } -static struct mutator* initialize_gc_for_thread(uintptr_t *stack_base, - struct heap *heap) { +static struct mutator* gc_init_for_thread(uintptr_t *stack_base, + struct heap *heap) { pthread_mutex_lock(&heap->lock); if (!heap->multithreaded) { GC_allow_register_threads(); @@ -224,15 +224,13 @@ static struct mutator* initialize_gc_for_thread(uintptr_t *stack_base, GC_register_my_thread(&base); return add_mutator(heap); } -static void finish_gc_for_thread(struct mutator *mut) { +static void gc_finish_for_thread(struct mutator *mut) { GC_unregister_my_thread(); } -static void* call_without_gc(struct mutator *mut, void* (*f)(void*), - void *data) NEVER_INLINE; -static void* call_without_gc(struct mutator *mut, - void* (*f)(void*), - void *data) { +static void* gc_call_without_gc(struct mutator *mut, + void* (*f)(void*), + void *data) { return GC_do_blocking(f, data); } diff --git a/gc-api.h b/gc-api.h index 7d6eead51..c88fcde7b 100644 --- a/gc-api.h +++ b/gc-api.h @@ -7,6 +7,9 @@ #define GC_DEBUG 0 #endif +#define GC_ALWAYS_INLINE __attribute__((always_inline)) +#define GC_NEVER_INLINE __attribute__((noinline)) + #define GC_UNLIKELY(e) __builtin_expect(e, 0) #define GC_LIKELY(e) __builtin_expect(e, 1) @@ -52,7 +55,7 @@ struct gc_edge { static inline struct gc_edge gc_edge(void* addr) { return (struct gc_edge){addr}; } -static struct gc_ref gc_edge_ref(struct gc_edge edge) { +static inline struct gc_ref gc_edge_ref(struct gc_edge edge) { return *edge.dst; } static inline void gc_edge_update(struct gc_edge edge, struct gc_ref ref) { @@ -82,4 +85,10 @@ GC_API_ int gc_option_from_string(const char *str); GC_API_ int gc_init(int argc, struct gc_option argv[], struct heap **heap, struct mutator **mutator); +GC_API_ struct mutator* gc_init_for_thread(uintptr_t *stack_base, + struct heap *heap); +GC_API_ void gc_finish_for_thread(struct mutator *mut); +GC_API_ void* gc_call_without_gc(struct mutator *mut, void* (*f)(void*), + void *data) GC_NEVER_INLINE; + #endif // GC_API_H_ diff --git a/mt-gcbench.c b/mt-gcbench.c index 23fb235c2..c3d92fef0 100644 --- a/mt-gcbench.c +++ b/mt-gcbench.c @@ -307,9 +307,9 @@ struct call_with_gc_data { }; static void* call_with_gc_inner(uintptr_t *stack_base, void *arg) { struct call_with_gc_data *data = arg; - struct mutator *mut = initialize_gc_for_thread(stack_base, data->heap); + struct mutator *mut = gc_init_for_thread(stack_base, data->heap); void *ret = data->f(mut); - finish_gc_for_thread(mut); + gc_finish_for_thread(mut); return ret; } static void* call_with_gc(void* (*f)(struct mutator *), @@ -434,7 +434,7 @@ int main(int argc, char *argv[]) { run_one_test(mut); for (size_t i = 1; i < nthreads; i++) { struct join_data data = { 0, threads[i] }; - call_without_gc(mut, join_thread, &data); + gc_call_without_gc(mut, join_thread, &data); if (data.status) { errno = data.status; perror("Failed to join thread"); diff --git a/semi.h b/semi.h index 0f6071266..944ab88f0 100644 --- a/semi.h +++ b/semi.h @@ -370,17 +370,17 @@ static int gc_init(int argc, struct gc_option argv[], return 1; } -static struct mutator* initialize_gc_for_thread(uintptr_t *stack_base, - struct heap *heap) { +static struct mutator* gc_init_for_thread(uintptr_t *stack_base, + struct heap *heap) { fprintf(stderr, "Semispace copying collector not appropriate for multithreaded use.\n"); exit(1); } -static void finish_gc_for_thread(struct mutator *space) { +static void gc_finish_for_thread(struct mutator *space) { } -static void* call_without_gc(struct mutator *mut, void* (*f)(void*), - void *data) { +static void* gc_call_without_gc(struct mutator *mut, void* (*f)(void*), + void *data) { // Can't be threads, then there won't be collection. return f(data); } diff --git a/whippet.h b/whippet.h index b100ca04f..db59bc2db 100644 --- a/whippet.h +++ b/whippet.h @@ -2079,8 +2079,8 @@ static int gc_init(int argc, struct gc_option argv[], return 1; } -static struct mutator* initialize_gc_for_thread(uintptr_t *stack_base, - struct heap *heap) { +static struct mutator* gc_init_for_thread(uintptr_t *stack_base, + struct heap *heap) { struct mutator *ret = calloc(1, sizeof(struct mutator)); if (!ret) abort(); @@ -2088,7 +2088,7 @@ static struct mutator* initialize_gc_for_thread(uintptr_t *stack_base, return ret; } -static void finish_gc_for_thread(struct mutator *mut) { +static void gc_finish_for_thread(struct mutator *mut) { remove_mutator(mutator_heap(mut), mut); mutator_mark_buf_destroy(&mut->mark_buf); free(mut); @@ -2118,11 +2118,9 @@ static void reactivate_mutator(struct heap *heap, struct mutator *mut) { heap_unlock(heap); } -static void* call_without_gc(struct mutator *mut, void* (*f)(void*), - void *data) NEVER_INLINE; -static void* call_without_gc(struct mutator *mut, - void* (*f)(void*), - void *data) { +static void* gc_call_without_gc(struct mutator *mut, + void* (*f)(void*), + void *data) { struct heap *heap = mutator_heap(mut); deactivate_mutator(heap, mut); void *ret = f(data);