1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

Merge remote-tracking branch 'whippet/main' into wip-whippet

This commit is contained in:
Andy Wingo 2025-04-23 17:30:27 +02:00
commit 975860e5e2
7 changed files with 54 additions and 65 deletions

View file

@ -4,8 +4,15 @@
#include "gc-attrs.h"
#include "gc-assert.h"
static inline enum gc_allocator_kind gc_allocator_kind(void) {
return GC_ALLOCATOR_INLINE_FREELIST;
static inline enum gc_inline_allocator_kind
gc_inline_allocator_kind(enum gc_allocation_kind kind) {
switch (kind) {
case GC_ALLOCATION_TAGGED:
case GC_ALLOCATION_UNTAGGED_CONSERVATIVE:
return GC_INLINE_ALLOCATOR_FREELIST;
default:
return GC_INLINE_ALLOCATOR_NONE;
}
}
static inline size_t gc_allocator_small_granule_size(void) {
return 2 * sizeof(void *);
@ -30,11 +37,8 @@ static inline size_t gc_allocator_freelist_offset(size_t size,
case GC_ALLOCATION_UNTAGGED_CONSERVATIVE:
base = 0;
break;
case GC_ALLOCATION_UNTAGGED_POINTERLESS:
case GC_ALLOCATION_TAGGED_POINTERLESS:
base = (sizeof(void*) * gc_allocator_large_threshold() /
gc_allocator_small_granule_size());
break;
default:
GC_CRASH();
}
size_t bucket = (size - 1) / gc_allocator_small_granule_size();
return base + sizeof(void*) * bucket;

View file

@ -140,6 +140,7 @@ static inline void* gc_allocate_small_fast_freelist(struct gc_mutator *mut,
return NULL;
*freelist_loc = *(void**)head;
*(void**)head = NULL;
gc_update_alloc_table(gc_ref_from_heap_object(head), size, kind);
@ -153,12 +154,12 @@ static inline void* gc_allocate_small_fast(struct gc_mutator *mut, size_t size,
GC_ASSERT(size != 0);
GC_ASSERT(size <= gc_allocator_large_threshold());
switch (gc_allocator_kind()) {
case GC_ALLOCATOR_INLINE_BUMP_POINTER:
switch (gc_inline_allocator_kind(kind)) {
case GC_INLINE_ALLOCATOR_BUMP_POINTER:
return gc_allocate_small_fast_bump_pointer(mut, size, kind);
case GC_ALLOCATOR_INLINE_FREELIST:
case GC_INLINE_ALLOCATOR_FREELIST:
return gc_allocate_small_fast_freelist(mut, size, kind);
case GC_ALLOCATOR_INLINE_NONE:
case GC_INLINE_ALLOCATOR_NONE:
return NULL;
default:
GC_CRASH();

View file

@ -7,13 +7,13 @@
#include <stddef.h>
#include <stdint.h>
enum gc_allocator_kind {
GC_ALLOCATOR_INLINE_BUMP_POINTER,
GC_ALLOCATOR_INLINE_FREELIST,
GC_ALLOCATOR_INLINE_NONE
enum gc_inline_allocator_kind {
GC_INLINE_ALLOCATOR_BUMP_POINTER,
GC_INLINE_ALLOCATOR_FREELIST,
GC_INLINE_ALLOCATOR_NONE
};
static inline enum gc_allocator_kind gc_allocator_kind(void) GC_ALWAYS_INLINE;
static inline enum gc_inline_allocator_kind gc_inline_allocator_kind(enum gc_allocation_kind) GC_ALWAYS_INLINE;
static inline size_t gc_allocator_large_threshold(void) GC_ALWAYS_INLINE;
static inline size_t gc_allocator_small_granule_size(void) GC_ALWAYS_INLINE;

View file

@ -5,8 +5,8 @@
#include "gc-assert.h"
#include "gc-attrs.h"
static inline enum gc_allocator_kind gc_allocator_kind(void) {
return GC_ALLOCATOR_INLINE_BUMP_POINTER;
static inline enum gc_inline_allocator_kind gc_inline_allocator_kind(enum gc_allocation_kind kind) {
return GC_INLINE_ALLOCATOR_BUMP_POINTER;
}
static inline size_t gc_allocator_small_granule_size(void) {
return 16;

View file

@ -8,8 +8,8 @@
static const uintptr_t GC_ALIGNMENT = 8;
static const size_t GC_LARGE_OBJECT_THRESHOLD = 8192;
static inline enum gc_allocator_kind gc_allocator_kind(void) {
return GC_ALLOCATOR_INLINE_BUMP_POINTER;
static inline enum gc_inline_allocator_kind gc_inline_allocator_kind(enum gc_allocation_kind kind) {
return GC_INLINE_ALLOCATOR_BUMP_POINTER;
}
static inline size_t gc_allocator_small_granule_size(void) {
return GC_ALIGNMENT;

View file

@ -7,8 +7,9 @@
static const uintptr_t GC_ALIGNMENT = 8;
static const size_t GC_LARGE_OBJECT_THRESHOLD = 8192;
static inline enum gc_allocator_kind gc_allocator_kind(void) {
return GC_ALLOCATOR_INLINE_BUMP_POINTER;
static inline enum gc_inline_allocator_kind
gc_inline_allocator_kind(enum gc_allocation_kind kind) {
return GC_INLINE_ALLOCATOR_BUMP_POINTER;
}
static inline size_t gc_allocator_small_granule_size(void) {
return GC_ALIGNMENT;

View file

@ -65,7 +65,6 @@ struct gc_heap {
struct gc_mutator {
void *freelists[GC_INLINE_FREELIST_COUNT];
void *pointerless_freelists[GC_INLINE_FREELIST_COUNT];
struct gc_heap *heap;
struct gc_mutator_roots *roots;
struct gc_mutator *next; // with heap lock
@ -122,9 +121,7 @@ allocate_small(void **freelist, size_t idx, enum gc_inline_kind kind) {
}
*freelist = *(void **)(head);
if (kind == GC_INLINE_KIND_POINTERLESS)
memset(head, 0, gc_inline_freelist_object_size(idx));
*(void**)head = NULL;
return head;
}
@ -133,21 +130,19 @@ void* gc_allocate_slow(struct gc_mutator *mut, size_t size,
enum gc_allocation_kind kind) {
GC_ASSERT(size != 0);
if (size <= gc_allocator_large_threshold()) {
size_t idx = gc_inline_bytes_to_freelist_index(size);
void **freelists;
enum gc_inline_kind freelist_kind;
switch (kind) {
case GC_ALLOCATION_TAGGED:
case GC_ALLOCATION_UNTAGGED_CONSERVATIVE:
case GC_ALLOCATION_UNTAGGED_CONSERVATIVE: {
size_t idx = gc_inline_bytes_to_freelist_index(size);
return allocate_small(&mut->freelists[idx], idx, GC_INLINE_KIND_NORMAL);
}
case GC_ALLOCATION_TAGGED_POINTERLESS:
case GC_ALLOCATION_UNTAGGED_POINTERLESS:
return allocate_small(&mut->pointerless_freelists[idx], idx,
GC_INLINE_KIND_POINTERLESS);
break;
default:
GC_CRASH();
}
} else {
}
switch (kind) {
case GC_ALLOCATION_TAGGED:
case GC_ALLOCATION_UNTAGGED_CONSERVATIVE: {
@ -168,7 +163,6 @@ void* gc_allocate_slow(struct gc_mutator *mut, size_t size,
default:
GC_CRASH();
}
}
}
void gc_pin_object(struct gc_mutator *mut, struct gc_ref ref) {
@ -399,18 +393,7 @@ mark_mutator(GC_word *addr, struct GC_ms_entry *mark_stack_ptr,
return state.mark_stack_ptr;
}
for (int i = 0; i < GC_INLINE_FREELIST_COUNT; i++)
state.mark_stack_ptr = GC_MARK_AND_PUSH (mut->freelists[i],
state.mark_stack_ptr,
state.mark_stack_limit,
NULL);
for (int i = 0; i < GC_INLINE_FREELIST_COUNT; i++)
for (void *head = mut->pointerless_freelists[i]; head; head = *(void**)head)
state.mark_stack_ptr = GC_MARK_AND_PUSH (head,
state.mark_stack_ptr,
state.mark_stack_limit,
NULL);
memset(mut->freelists, 0, sizeof(void*) * GC_INLINE_FREELIST_COUNT);
if (mut->roots)
gc_trace_mutator_roots(mut->roots, bdw_mark_edge, mut->heap, &state);