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

commit 6d48e12f788e946feba8777f8c0431ed9ede5aad
Author: Andy Wingo <wi...@igalia.com>
AuthorDate: Fri Oct 4 13:51:17 2024 +0200

    Add assertions when forgetting nofl edges
---
 src/nofl-space.h | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/nofl-space.h b/src/nofl-space.h
index 7bf818cbe..817c10461 100644
--- a/src/nofl-space.h
+++ b/src/nofl-space.h
@@ -972,10 +972,18 @@ nofl_space_forget_edge(struct nofl_space *space, struct 
gc_edge edge) {
   GC_ASSERT(nofl_space_contains_edge(space, edge));
   GC_ASSERT(GC_GENERATIONAL);
   uint8_t* loc = nofl_field_logged_byte(edge);
-  // Clear both logged bits.
-  uint8_t bits = NOFL_METADATA_BYTE_LOGGED_0 | NOFL_METADATA_BYTE_LOGGED_1;
-  uint8_t byte = atomic_load_explicit(loc, memory_order_acquire);
-  atomic_store_explicit(loc, byte & ~bits, memory_order_release);
+  if (GC_DEBUG) {
+    pthread_mutex_lock(&space->lock);
+    uint8_t bit = nofl_field_logged_bit(edge);
+    GC_ASSERT(*loc & bit);
+    *loc &= ~bit;
+    pthread_mutex_unlock(&space->lock);
+  } else {
+    // In release mode, race to clear both bits at once.
+    uint8_t byte = atomic_load_explicit(loc, memory_order_relaxed);
+    byte &= ~(NOFL_METADATA_BYTE_LOGGED_0 | NOFL_METADATA_BYTE_LOGGED_1);
+    atomic_store_explicit(loc, byte, memory_order_relaxed);
+  }
 }
 
 static void

Reply via email to