diff options
author | Peter Zhu <peter@peterzhu.ca> | 2022-07-27 14:05:31 -0400 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2022-07-28 10:02:12 -0400 |
commit | 229cf263df8ae5020b959724b26ac7ecc5e7e122 (patch) | |
tree | aac1a2a242cfd1fac9f16dc661db09bbeaa96f0c | |
parent | 1c16645216b6db04ccb1144e6f7e085e1e0a6132 (diff) | |
download | ruby-229cf263df8ae5020b959724b26ac7ecc5e7e122.tar.gz |
Lock the VM for rb_gc_writebarrier_unprotect
When using Ractors, rb_gc_writebarrier_unprotect requries a VM lock
since it modifies the bitmaps.
-rw-r--r-- | gc.c | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -8964,25 +8964,29 @@ rb_gc_writebarrier_unprotect(VALUE obj) gc_report(2, objspace, "rb_gc_writebarrier_unprotect: %s %s\n", obj_info(obj), rgengc_remembered(objspace, obj) ? " (already remembered)" : ""); - if (RVALUE_OLD_P(obj)) { - gc_report(1, objspace, "rb_gc_writebarrier_unprotect: %s\n", obj_info(obj)); - RVALUE_DEMOTE(objspace, obj); - gc_mark_set(objspace, obj); - gc_remember_unprotected(objspace, obj); + RB_VM_LOCK_ENTER_NO_BARRIER(); + { + if (RVALUE_OLD_P(obj)) { + gc_report(1, objspace, "rb_gc_writebarrier_unprotect: %s\n", obj_info(obj)); + RVALUE_DEMOTE(objspace, obj); + gc_mark_set(objspace, obj); + gc_remember_unprotected(objspace, obj); #if RGENGC_PROFILE - objspace->profile.total_shade_operation_count++; + objspace->profile.total_shade_operation_count++; #if RGENGC_PROFILE >= 2 - objspace->profile.shade_operation_count_types[BUILTIN_TYPE(obj)]++; + objspace->profile.shade_operation_count_types[BUILTIN_TYPE(obj)]++; #endif /* RGENGC_PROFILE >= 2 */ #endif /* RGENGC_PROFILE */ - } - else { - RVALUE_AGE_RESET(obj); - } + } + else { + RVALUE_AGE_RESET(obj); + } - RB_DEBUG_COUNTER_INC(obj_wb_unprotect); - MARK_IN_BITMAP(GET_HEAP_WB_UNPROTECTED_BITS(obj), obj); + RB_DEBUG_COUNTER_INC(obj_wb_unprotect); + MARK_IN_BITMAP(GET_HEAP_WB_UNPROTECTED_BITS(obj), obj); + } + RB_VM_LOCK_LEAVE_NO_BARRIER(); } } |