1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-29 06:20:30 +02:00

Fix embarrassing bugs in write buffer fast path

Check edge address, not object address, and reverse the sense of the
check!
This commit is contained in:
Andy Wingo 2024-10-04 13:50:01 +02:00
parent e1ae9819cf
commit 15a51c8a85

View file

@ -237,14 +237,14 @@ static inline int gc_write_barrier_fast(struct gc_mutator *mut, struct gc_ref ob
size_t fields_per_byte = gc_write_barrier_field_fields_per_byte();
uint8_t first_bit_pattern = gc_write_barrier_field_first_bit_pattern();
uintptr_t addr = gc_ref_value(obj);
uintptr_t addr = gc_edge_address(edge);
uintptr_t base = addr & ~(field_table_alignment - 1);
uintptr_t field = (addr & (field_table_alignment - 1)) / sizeof(uintptr_t);
uintptr_t log_byte = field / fields_per_byte;
uint8_t log_bit = first_bit_pattern << (field % fields_per_byte);
uint8_t *byte_loc = (uint8_t*)(base + log_byte);
uint8_t byte = atomic_load_explicit(byte_loc, memory_order_relaxed);
return byte & log_bit;
return !(byte & log_bit);
}
case GC_WRITE_BARRIER_SLOW:
return 1;