From 607585e7f03e9264b47c1e97086e3e9c9c11b2d5 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Tue, 16 Aug 2022 10:25:23 +0200 Subject: [PATCH] Add whippet-inline.h --- whippet-inline.h | 56 ++++++++++++++++++++++++++++++++ whippet.h | 84 ++++++++++-------------------------------------- 2 files changed, 73 insertions(+), 67 deletions(-) create mode 100644 whippet-inline.h diff --git a/whippet-inline.h b/whippet-inline.h new file mode 100644 index 000000000..b61724cfa --- /dev/null +++ b/whippet-inline.h @@ -0,0 +1,56 @@ +#ifndef WHIPPET_INLINE_H +#define WHIPPET_INLINE_H + +#include "gc-config.h" +#include "gc-api.h" + +static inline enum gc_allocator_kind gc_allocator_kind(void) { + return GC_ALLOCATOR_INLINE_BUMP_POINTER; +} +static inline size_t gc_allocator_small_granule_size(void) { + return 16; +} +static inline size_t gc_allocator_large_threshold(void) { + return 8192; +} + +static inline size_t gc_allocator_allocation_pointer_offset(void) { + return sizeof(uintptr_t) * 0; +} +static inline size_t gc_allocator_allocation_limit_offset(void) { + return sizeof(uintptr_t) * 1; +} + +static inline size_t gc_allocator_freelist_offset(size_t size) { + abort(); +} + +static inline size_t gc_allocator_alloc_table_alignment(void) { + return 4 * 1024 * 1024; +} +static inline uint8_t gc_allocator_alloc_table_begin_pattern(void) { + return 1; +} +static inline uint8_t gc_allocator_alloc_table_end_pattern(void) { + return 16; +} + +static inline int gc_allocator_needs_clear(void) { + return 0; +} + +static inline enum gc_write_barrier_kind gc_small_write_barrier_kind(void) { + if (GC_GENERATIONAL) + return GC_WRITE_BARRIER_CARD; + return GC_WRITE_BARRIER_NONE; +} +static inline size_t gc_small_write_barrier_card_table_alignment(void) { + GC_ASSERT(GC_GENERATIONAL); + return 4 * 1024 * 1024; +} +static inline size_t gc_small_write_barrier_card_size(void) { + GC_ASSERT(GC_GENERATIONAL); + return 256; +} + +#endif // WHIPPET_INLINE_H diff --git a/whippet.h b/whippet.h index a070c0cb1..6ac499635 100644 --- a/whippet.h +++ b/whippet.h @@ -25,6 +25,7 @@ #include "serial-tracer.h" #endif #include "spin.h" +#include "whippet-inline.h" #define GRANULE_SIZE 16 #define GRANULE_SIZE_LOG_2 4 @@ -369,44 +370,6 @@ static inline struct heap* mutator_heap(struct mutator *mutator) { return mutator->heap; } -static inline enum gc_allocator_kind gc_allocator_kind(void) { - return GC_ALLOCATOR_INLINE_BUMP_POINTER; -} -static inline size_t gc_allocator_small_granule_size(void) { - return GRANULE_SIZE; -} -static inline size_t gc_allocator_large_threshold(void) { - return LARGE_OBJECT_THRESHOLD; -} - -static inline size_t gc_allocator_allocation_pointer_offset(void) { - return offsetof(struct mutator, alloc); -} -static inline size_t gc_allocator_allocation_limit_offset(void) { - return offsetof(struct mutator, sweep); -} - -static inline size_t gc_allocator_freelist_offset(size_t size) { - abort(); -} - -static inline void gc_allocator_inline_success(struct mutator *mut, - struct gc_ref obj, - uintptr_t aligned_size) { - uint8_t *metadata = object_metadata_byte(gc_ref_heap_object(obj)); - size_t granules = aligned_size >> GRANULE_SIZE_LOG_2; - if (granules == 1) { - metadata[0] = METADATA_BYTE_YOUNG | METADATA_BYTE_END; - } else { - metadata[0] = METADATA_BYTE_YOUNG; - if (granules > 2) - memset(metadata + 1, 0, granules - 2); - metadata[granules - 1] = METADATA_BYTE_END; - } -} -static inline void gc_allocator_inline_failure(struct mutator *mut, - uintptr_t aligned_size) {} - static inline void clear_memory(uintptr_t addr, size_t size) { memset((char*)addr, 0, size); } @@ -1844,7 +1807,7 @@ static void* gc_allocate_small(struct mutator *mut, size_t size) { obj = (struct gcobj*)mut->alloc; mut->alloc += size; } - gc_allocator_inline_success(mut, gc_ref_from_heap_object(obj), size); + gc_update_alloc_table(mut, gc_ref_from_heap_object(obj), size); return obj; } @@ -1852,34 +1815,6 @@ static inline void* gc_allocate_pointerless(struct mutator *mut, size_t size) { return gc_allocate(mut, size); } -static inline enum gc_write_barrier_kind gc_small_write_barrier_kind(void) { - if (GC_GENERATIONAL) - return GC_WRITE_BARRIER_CARD; - return GC_WRITE_BARRIER_NONE; -} -static inline size_t gc_small_write_barrier_card_table_alignment(void) { - GC_ASSERT(GC_GENERATIONAL); - return SLAB_SIZE; -} -static inline size_t gc_small_write_barrier_card_size(void) { - GC_ASSERT(GC_GENERATIONAL); - return GRANULES_PER_REMSET_BYTE * GRANULE_SIZE; -} - -static inline size_t gc_allocator_alloc_table_alignment(void) { - return SLAB_SIZE; -} -static inline uint8_t gc_allocator_alloc_table_begin_pattern(void) { - return METADATA_BYTE_YOUNG; -} -static inline uint8_t gc_allocator_alloc_table_end_pattern(void) { - return METADATA_BYTE_END; -} - -static inline int gc_allocator_needs_clear(void) { - return 0; -} - #define FOR_EACH_GC_OPTION(M) \ M(GC_OPTION_FIXED_HEAP_SIZE, "fixed-heap-size") \ M(GC_OPTION_PARALLELISM, "parallelism") @@ -2022,6 +1957,21 @@ static int mark_space_init(struct mark_space *space, struct heap *heap) { static int gc_init(int argc, struct gc_option argv[], struct heap **heap, struct mutator **mut) { + GC_ASSERT_EQ(gc_allocator_small_granule_size(), GRANULE_SIZE); + GC_ASSERT_EQ(gc_allocator_large_threshold(), LARGE_OBJECT_THRESHOLD); + GC_ASSERT_EQ(gc_allocator_allocation_pointer_offset(), + offsetof(struct mutator, alloc)); + GC_ASSERT_EQ(gc_allocator_allocation_limit_offset(), + offsetof(struct mutator, sweep)); + GC_ASSERT_EQ(gc_allocator_alloc_table_alignment(), SLAB_SIZE); + GC_ASSERT_EQ(gc_allocator_alloc_table_begin_pattern(), METADATA_BYTE_YOUNG); + GC_ASSERT_EQ(gc_allocator_alloc_table_end_pattern(), METADATA_BYTE_END); + if (GC_GENERATIONAL) { + GC_ASSERT_EQ(gc_small_write_barrier_card_table_alignment(), SLAB_SIZE); + GC_ASSERT_EQ(gc_small_write_barrier_card_size(), + BLOCK_SIZE / REMSET_BYTES_PER_BLOCK); + } + struct options options = { 0, }; if (!parse_options(argc, argv, &options)) return 0;