Skip to content

Commit 0a2d6fc

Browse files
authored
Don't use exchange in the hot path of the GC (#50021)
* Don't use exchange in the hot path of the GC and save one extra load
1 parent 2c80455 commit 0a2d6fc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/gc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ STATIC_INLINE void gc_queue_big_marked(jl_ptls_t ptls, bigval_t *hdr,
804804
FORCE_INLINE int gc_try_setmark_tag(jl_taggedvalue_t *o, uint8_t mark_mode) JL_NOTSAFEPOINT
805805
{
806806
assert(gc_marked(mark_mode));
807-
uintptr_t tag = o->header;
807+
uintptr_t tag = jl_atomic_load_relaxed((_Atomic(uintptr_t)*)&o->header);
808808
if (gc_marked(tag))
809809
return 0;
810810
if (mark_reset_age) {
@@ -818,9 +818,9 @@ FORCE_INLINE int gc_try_setmark_tag(jl_taggedvalue_t *o, uint8_t mark_mode) JL_N
818818
tag = tag | mark_mode;
819819
assert((tag & 0x3) == mark_mode);
820820
}
821-
tag = jl_atomic_exchange_relaxed((_Atomic(uintptr_t)*)&o->header, tag);
822-
verify_val(jl_valueof(o));
823-
return !gc_marked(tag);
821+
jl_atomic_store_relaxed((_Atomic(uintptr_t)*)&o->header, tag); //xchg here was slower than
822+
verify_val(jl_valueof(o)); //potentially redoing work because of a stale tag.
823+
return 1;
824824
}
825825

826826
// This function should be called exactly once during marking for each big

0 commit comments

Comments
 (0)