summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-07-27 14:05:31 -0400
committerPeter Zhu <peter@peterzhu.ca>2022-07-28 10:02:12 -0400
commit229cf263df8ae5020b959724b26ac7ecc5e7e122 (patch)
treeaac1a2a242cfd1fac9f16dc661db09bbeaa96f0c /gc.c
parent1c16645216b6db04ccb1144e6f7e085e1e0a6132 (diff)
Lock the VM for rb_gc_writebarrier_unprotect
When using Ractors, rb_gc_writebarrier_unprotect requries a VM lock since it modifies the bitmaps.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6192
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/gc.c b/gc.c
index cd48c47a94..df4c99b15b 100644
--- a/gc.c
+++ b/gc.c
@@ -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();
}
}