Skip to content

Commit

Permalink
use atomic-fetch-and in write barrier slow-path (JuliaLang#54744)
Browse files Browse the repository at this point in the history
Not sure why we're not using it, but we probably should.
  • Loading branch information
d-netto committed Jun 28, 2024
1 parent 0ed80bd commit e0726dc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1891,13 +1891,15 @@ JL_DLLEXPORT void jl_gc_queue_root(const jl_value_t *ptr)
{
jl_ptls_t ptls = jl_current_task->ptls;
jl_taggedvalue_t *o = jl_astaggedvalue(ptr);
// The modification of the `gc_bits` is not atomic but it
// should be safe here since GC is not allowed to run here and we only
// write GC_OLD to the GC bits outside GC. This could cause
// duplicated objects in the remset but that shouldn't be a problem.
o->bits.gc = GC_MARKED;
arraylist_push(ptls->heap.remset, (jl_value_t*)ptr);
ptls->heap.remset_nptr++; // conservative
// The modification of the `gc_bits` needs to be atomic.
// We need to ensure that objects are in the remset at
// most once, since the mark phase may update page metadata,
// which is not idempotent. See comments in https://github.com/JuliaLang/julia/issues/50419
uintptr_t header = jl_atomic_fetch_and_relaxed((_Atomic(uintptr_t) *)&o->header, ~GC_OLD);
if (header & GC_OLD) { // write barrier has not been triggered in this object yet
arraylist_push(ptls->heap.remset, (jl_value_t*)ptr);
ptls->heap.remset_nptr++; // conservative
}
}

void jl_gc_queue_multiroot(const jl_value_t *parent, const jl_value_t *ptr) JL_NOTSAFEPOINT
Expand Down

0 comments on commit e0726dc

Please sign in to comment.