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

commit 4f8c7bef613f045492990bd6f841c31a06c78825
Author: Andy Wingo <wi...@igalia.com>
AuthorDate: Tue Dec 10 09:40:49 2024 +0100

    Refactor copy_space_forward to take src and dst spaces
---
 src/copy-space.h | 21 +++++++++++----------
 src/pcc.c        |  4 ++--
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/copy-space.h b/src/copy-space.h
index 920235707..a6382e741 100644
--- a/src/copy-space.h
+++ b/src/copy-space.h
@@ -483,7 +483,6 @@ static inline int
 copy_space_forward_atomic(struct copy_space *space, struct gc_edge edge,
                           struct gc_ref old_ref,
                           struct copy_space_allocator *alloc) {
-  GC_ASSERT(copy_space_object_region(old_ref) != space->active_region);
   struct gc_atomic_forward fwd = gc_atomic_forward_begin(old_ref);
 
   if (fwd.state == GC_FORWARDING_STATE_NOT_FORWARDED)
@@ -532,7 +531,6 @@ static int
 copy_space_forward_if_traced_atomic(struct copy_space *space,
                                     struct gc_edge edge,
                                     struct gc_ref old_ref) {
-  GC_ASSERT(copy_space_object_region(old_ref) != space->active_region);
   struct gc_atomic_forward fwd = gc_atomic_forward_begin(old_ref);
   switch (fwd.state) {
   case GC_FORWARDING_STATE_NOT_FORWARDED:
@@ -559,8 +557,6 @@ static inline int
 copy_space_forward_nonatomic(struct copy_space *space, struct gc_edge edge,
                              struct gc_ref old_ref,
                              struct copy_space_allocator *alloc) {
-  GC_ASSERT(copy_space_object_region(old_ref) != space->active_region);
-
   uintptr_t forwarded = gc_object_forwarded_nonatomic(old_ref);
   if (forwarded) {
     gc_edge_update(edge, gc_ref(forwarded));
@@ -582,7 +578,6 @@ static int
 copy_space_forward_if_traced_nonatomic(struct copy_space *space,
                                        struct gc_edge edge,
                                        struct gc_ref old_ref) {
-  GC_ASSERT(copy_space_object_region(old_ref) != space->active_region);
   uintptr_t forwarded = gc_object_forwarded_nonatomic(old_ref);
   if (forwarded) {
     gc_edge_update(edge, gc_ref(forwarded));
@@ -592,17 +587,23 @@ copy_space_forward_if_traced_nonatomic(struct copy_space 
*space,
 }
 
 static inline int
-copy_space_forward(struct copy_space *space, struct gc_edge edge,
+copy_space_forward(struct copy_space *src_space, struct copy_space *dst_space,
+                   struct gc_edge edge,
                    struct gc_ref old_ref,
-                   struct copy_space_allocator *alloc) {
-  if (GC_PARALLEL && space->atomic_forward)
-    return copy_space_forward_atomic(space, edge, old_ref, alloc);
-  return copy_space_forward_nonatomic(space, edge, old_ref, alloc);
+                   struct copy_space_allocator *dst_alloc) {
+  GC_ASSERT(copy_space_contains(src_space, old_ref));
+  GC_ASSERT(src_space != dst_space
+            || copy_space_object_region(old_ref) != src_space->active_region);
+  if (GC_PARALLEL && src_space->atomic_forward)
+    return copy_space_forward_atomic(dst_space, edge, old_ref, dst_alloc);
+  return copy_space_forward_nonatomic(dst_space, edge, old_ref, dst_alloc);
 }
 
 static inline int
 copy_space_forward_if_traced(struct copy_space *space, struct gc_edge edge,
                              struct gc_ref old_ref) {
+  GC_ASSERT(copy_space_contains(space, old_ref));
+  GC_ASSERT(copy_space_object_region(old_ref) != space->active_region);
   if (GC_PARALLEL && space->atomic_forward)
     return copy_space_forward_if_traced_atomic(space, edge, old_ref);
   return copy_space_forward_if_traced_nonatomic(space, edge, old_ref);
diff --git a/src/pcc.c b/src/pcc.c
index 0b5b92236..847297407 100644
--- a/src/pcc.c
+++ b/src/pcc.c
@@ -115,8 +115,8 @@ static inline int do_trace(struct gc_heap *heap, struct 
gc_edge edge,
                            struct gc_ref ref,
                            struct gc_trace_worker_data *data) {
   if (GC_LIKELY(copy_space_contains(heap_copy_space(heap), ref)))
-    return copy_space_forward(heap_copy_space(heap), edge, ref,
-                              &data->allocator);
+    return copy_space_forward(heap_copy_space(heap), heap_copy_space(heap),
+                              edge, ref, &data->allocator);
   else if (large_object_space_contains(heap_large_object_space(heap), ref))
     return large_object_space_mark_object(heap_large_object_space(heap), ref);
   else

Reply via email to