wingo pushed a commit to branch wip-whippet
in repository guile.

commit 274cf438649fd920417634a9214e66edf4bfc9ee
Author: Andy Wingo <wi...@igalia.com>
AuthorDate: Mon Dec 9 14:28:19 2024 +0100

    Add new old-gen predicate method: check a range of addresses
---
 api/gc-api.h   | 16 ++++++++++++++++
 api/gc-attrs.h |  1 +
 src/bdw.c      | 10 ++++++++++
 src/mmc.c      | 10 ++++++++++
 src/pcc.c      | 11 +++++++++++
 src/semi.c     | 10 ++++++++++
 6 files changed, 58 insertions(+)

diff --git a/api/gc-api.h b/api/gc-api.h
index 2efd16ecd..4b23bb543 100644
--- a/api/gc-api.h
+++ b/api/gc-api.h
@@ -30,6 +30,11 @@ GC_API_ int gc_init(const struct gc_options *options,
                     struct gc_event_listener event_listener,
                     void *event_listener_data);
 
+GC_API_ struct gc_heap* gc_mutator_heap(struct gc_mutator *mut);
+
+GC_API_ uintptr_t gc_small_object_nursery_low_address(struct gc_heap *heap);
+GC_API_ uintptr_t gc_small_object_nursery_high_address(struct gc_heap *heap);
+
 struct gc_mutator_roots;
 GC_API_ void gc_mutator_set_roots(struct gc_mutator *mut,
                                   struct gc_mutator_roots *roots);
@@ -200,6 +205,17 @@ static inline int gc_object_is_old_generation(struct 
gc_mutator *mut,
     uint8_t byte = atomic_load_explicit(byte_loc, memory_order_relaxed);
     return byte & gc_old_generation_check_alloc_table_bit_pattern();
   }
+  case GC_OLD_GENERATION_CHECK_SMALL_OBJECT_NURSERY: {
+    struct gc_heap *heap = gc_mutator_heap(mut);
+    // Note that these addresses are fixed and that the embedder might
+    // want to store them somewhere or inline them into the output of
+    // JIT-generated code.  They may also be power-of-two aligned.
+    uintptr_t low_addr = gc_small_object_nursery_low_address(heap);
+    uintptr_t high_addr = gc_small_object_nursery_high_address(heap);
+    uintptr_t size = high_addr - low_addr;
+    uintptr_t addr = gc_ref_value(obj);
+    return addr - low_addr < size;
+  }
   case GC_OLD_GENERATION_CHECK_SLOW:
     return gc_object_is_old_generation_slow(mut, obj);
   default:
diff --git a/api/gc-attrs.h b/api/gc-attrs.h
index d7fc77682..344c24c27 100644
--- a/api/gc-attrs.h
+++ b/api/gc-attrs.h
@@ -30,6 +30,7 @@ static inline int gc_allocator_needs_clear(void) 
GC_ALWAYS_INLINE;
 enum gc_old_generation_check_kind {
   GC_OLD_GENERATION_CHECK_NONE,
   GC_OLD_GENERATION_CHECK_ALLOC_TABLE,
+  GC_OLD_GENERATION_CHECK_SMALL_OBJECT_NURSERY,
   GC_OLD_GENERATION_CHECK_SLOW
 };
 
diff --git a/src/bdw.c b/src/bdw.c
index d1478d805..72b13012e 100644
--- a/src/bdw.c
+++ b/src/bdw.c
@@ -82,6 +82,16 @@ static inline size_t gc_inline_freelist_object_size(size_t 
idx) {
   return (idx + 1U) * GC_INLINE_GRANULE_BYTES;
 }
 
+struct gc_heap* gc_mutator_heap(struct gc_mutator *mutator) {
+  return __the_bdw_gc_heap;
+}
+uintptr_t gc_small_object_nursery_low_address(struct gc_heap *heap) {
+  GC_CRASH();
+}
+uintptr_t gc_small_object_nursery_high_address(struct gc_heap *heap) {
+  GC_CRASH();
+}
+
 // The values of these must match the internal POINTERLESS and NORMAL
 // definitions in libgc, for which unfortunately there are no external
 // definitions.  Alack.
diff --git a/src/mmc.c b/src/mmc.c
index d123c4793..0af725138 100644
--- a/src/mmc.c
+++ b/src/mmc.c
@@ -104,6 +104,16 @@ mutator_heap(struct gc_mutator *mutator) {
   return mutator->heap;
 }
 
+struct gc_heap* gc_mutator_heap(struct gc_mutator *mutator) {
+  return mutator_heap(mutator);
+}
+uintptr_t gc_small_object_nursery_low_address(struct gc_heap *heap) {
+  GC_CRASH();
+}
+uintptr_t gc_small_object_nursery_high_address(struct gc_heap *heap) {
+  GC_CRASH();
+}
+
 static void
 gc_trace_worker_call_with_data(void (*f)(struct gc_tracer *tracer,
                                          struct gc_heap *heap,
diff --git a/src/pcc.c b/src/pcc.c
index 0ca94327e..0b5b92236 100644
--- a/src/pcc.c
+++ b/src/pcc.c
@@ -86,6 +86,17 @@ static inline struct gc_heap* mutator_heap(struct gc_mutator 
*mutator) {
   return mutator->heap;
 }
 
+struct gc_heap* gc_mutator_heap(struct gc_mutator *mutator) {
+  return mutator_heap(mutator);
+}
+
+uintptr_t gc_small_object_nursery_low_address(struct gc_heap *heap) {
+  GC_CRASH();
+}
+uintptr_t gc_small_object_nursery_high_address(struct gc_heap *heap) {
+  GC_CRASH();
+}
+
 static void
 gc_trace_worker_call_with_data(void (*f)(struct gc_tracer *tracer,
                                          struct gc_heap *heap,
diff --git a/src/semi.c b/src/semi.c
index 29cb0c92f..c16cecabd 100644
--- a/src/semi.c
+++ b/src/semi.c
@@ -81,6 +81,16 @@ static inline struct semi_space* mutator_semi_space(struct 
gc_mutator *mut) {
   return heap_semi_space(mutator_heap(mut));
 }
 
+struct gc_heap* gc_mutator_heap(struct gc_mutator *mutator) {
+  return mutator_heap(mutator);
+}
+uintptr_t gc_small_object_nursery_low_address(struct gc_heap *heap) {
+  GC_CRASH();
+}
+uintptr_t gc_small_object_nursery_high_address(struct gc_heap *heap) {
+  GC_CRASH();
+}
+
 static uintptr_t align_up(uintptr_t addr, size_t align) {
   return (addr + align - 1) & ~(align-1);
 }

Reply via email to