Skip to content

Commit

Permalink
relax synchronization on WB
Browse files Browse the repository at this point in the history
Current synchronization is too much on write barriers.
  • Loading branch information
ko1 committed Dec 17, 2020
1 parent 44fba19 commit 99b9145
Showing 1 changed file with 10 additions and 29 deletions.
39 changes: 10 additions & 29 deletions gc.c
Expand Up @@ -7689,7 +7689,11 @@ gc_writebarrier_generational(VALUE a, VALUE b, rb_objspace_t *objspace)
#if 1
/* mark `a' and remember (default behavior) */
if (!rgengc_remembered(objspace, a)) {
rgengc_remember(objspace, a);
RB_VM_LOCK_ENTER_NO_BARRIER();
{
rgengc_remember(objspace, a);
}
RB_VM_LOCK_LEAVE_NO_BARRIER();
gc_report(1, objspace, "gc_writebarrier_generational: %s (remembered) -> %s\n", obj_info(a), obj_info(b));
}
#else
Expand Down Expand Up @@ -7763,49 +7767,26 @@ void
rb_gc_writebarrier(VALUE a, VALUE b)
{
rb_objspace_t *objspace = &rb_objspace;
bool retry;

if (RGENGC_CHECK_MODE && SPECIAL_CONST_P(a)) rb_bug("rb_gc_writebarrier: a is special const");
if (RGENGC_CHECK_MODE && SPECIAL_CONST_P(b)) rb_bug("rb_gc_writebarrier: b is special const");

retry_:
retry = false;
if (!is_incremental_marking(objspace)) {
if (!RVALUE_OLD_P(a) || RVALUE_OLD_P(b)) {
// do nothing
}
else {
RB_VM_LOCK_ENTER_NO_BARRIER(); // can change GC state
{
if (!is_incremental_marking(objspace)) {
if (!RVALUE_OLD_P(a) || RVALUE_OLD_P(b)) {
// do nothing
}
else {
gc_writebarrier_generational(a, b, objspace);
}
}
else {
retry = true;
}
}
RB_VM_LOCK_LEAVE_NO_BARRIER();
gc_writebarrier_generational(a, b, objspace);
}
}
else { /* slow path */
RB_VM_LOCK_ENTER_NO_BARRIER(); // can change GC state
else {
/* slow path */
RB_VM_LOCK_ENTER_NO_BARRIER();
{
if (is_incremental_marking(objspace)) {
gc_writebarrier_incremental(a, b, objspace);
}
else {
retry = true;
}
gc_writebarrier_incremental(a, b, objspace);
}
RB_VM_LOCK_LEAVE_NO_BARRIER();
}
if (retry) goto retry_;

return;
}

Expand Down

0 comments on commit 99b9145

Please sign in to comment.