From 6d48e12f788e946feba8777f8c0431ed9ede5aad Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 4 Oct 2024 13:51:17 +0200 Subject: [PATCH] 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