1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-03 18:50:19 +02:00

Add gc_heap_contains API

This commit is contained in:
Andy Wingo 2025-05-04 12:10:03 +02:00
parent c9063b8027
commit c7fe77de0e
5 changed files with 29 additions and 0 deletions

View file

@ -59,6 +59,8 @@ GC_API_ void* gc_call_without_gc(struct gc_mutator *mut, void* (*f)(void*),
GC_API_ void gc_collect(struct gc_mutator *mut,
enum gc_collection_kind requested_kind);
GC_API_ int gc_heap_contains(struct gc_heap *heap, struct gc_ref ref);
static inline void gc_update_alloc_table(struct gc_ref obj, size_t size,
enum gc_allocation_kind kind) GC_ALWAYS_INLINE;
static inline void gc_update_alloc_table(struct gc_ref obj, size_t size,

View file

@ -187,6 +187,11 @@ void gc_collect(struct gc_mutator *mut,
}
}
int gc_heap_contains(struct gc_heap *heap, struct gc_ref ref) {
GC_ASSERT(gc_ref_is_heap_object(ref));
return GC_base(gc_ref_heap_object(ref)) != 0;
}
int gc_object_is_old_generation_slow(struct gc_mutator *mut,
struct gc_ref obj) {
return 0;

View file

@ -844,6 +844,13 @@ gc_collect(struct gc_mutator *mut, enum gc_collection_kind kind) {
trigger_collection(mut, kind);
}
int
gc_heap_contains(struct gc_heap *heap, struct gc_ref ref) {
GC_ASSERT(gc_ref_is_heap_object(ref));
return nofl_space_contains(heap_nofl_space(heap), ref)
|| large_object_space_contains(heap_large_object_space(heap), ref);
}
int*
gc_safepoint_flag_loc(struct gc_mutator *mut) {
return &mutator_heap(mut)->collecting;

View file

@ -965,6 +965,14 @@ void gc_collect(struct gc_mutator *mut, enum gc_collection_kind kind) {
trigger_collection(mut, kind);
}
int gc_heap_contains(struct gc_heap *heap, struct gc_ref ref) {
GC_ASSERT(gc_ref_is_heap_object(ref));
return (GC_GENERATIONAL
? (new_space_contains(heap, ref) || old_space_contains(heap, ref))
: copy_space_contains(heap_mono_space(heap), ref))
|| large_object_space_contains(heap_large_object_space(heap), ref);
}
static void* allocate_large(struct gc_mutator *mut, size_t size) {
struct gc_heap *heap = mutator_heap(mut);
struct large_object_space *space = heap_large_object_space(heap);

View file

@ -468,6 +468,13 @@ void gc_collect(struct gc_mutator *mut,
collect(mut);
}
int
gc_heap_contains(struct gc_heap *heap, struct gc_ref ref) {
GC_ASSERT(gc_ref_is_heap_object(ref));
return semi_space_contains(heap_semi_space(heap), ref)
|| large_object_space_contains(heap_large_object_space(heap), ref);
}
int gc_object_is_old_generation_slow(struct gc_mutator *mut,
struct gc_ref obj) {
return 0;