Skip garbage check for special consts in concurrent set

rb_objspace_garbage_object_p expects only GC managed objects to be passed
in. We should skip the check if curr_key is a special constant.
This commit is contained in:
Peter Zhu 2025-07-02 10:00:48 -04:00
parent 038129175b
commit 5d44f2917f

View File

@ -119,7 +119,7 @@ concurrent_set_try_resize_without_locking(VALUE old_set_obj, VALUE *set_obj_ptr)
RUBY_ASSERT(key != CONCURRENT_SET_MOVED);
if (key < CONCURRENT_SET_SPECIAL_VALUE_COUNT) continue;
if (rb_objspace_garbage_object_p(key)) continue;
if (!RB_SPECIAL_CONST_P(key) && rb_objspace_garbage_object_p(key)) continue;
VALUE hash = RUBY_ATOMIC_VALUE_LOAD(entry->hash);
if (hash == 0) {
@ -231,7 +231,7 @@ rb_concurrent_set_find_or_insert(VALUE *set_obj_ptr, VALUE key, void *data)
VALUE curr_hash = RUBY_ATOMIC_VALUE_LOAD(entry->hash);
if ((curr_hash == hash || curr_hash == 0) && set->funcs->cmp(key, curr_key)) {
// We've found a match.
if (UNLIKELY(rb_objspace_garbage_object_p(curr_key))) {
if (UNLIKELY(!RB_SPECIAL_CONST_P(curr_key) && rb_objspace_garbage_object_p(curr_key))) {
// This is a weakref set, so after marking but before sweeping is complete we may find a matching garbage object.
// Skip it and mark it as deleted.
RUBY_ATOMIC_VALUE_CAS(entry->key, curr_key, CONCURRENT_SET_DELETED);