Skip to content

Commit

Permalink
Fix case when gc_marks_continue does not yield slots
Browse files Browse the repository at this point in the history
gc_marks_continue will start sweeping when it finishes marking. However,
if the heap we are trying to allocate into is full, then the sweeping
may not yield any free slots. If we don't call gc_sweep_continue
immediate after this, then another GC will be started halfway during
lazy sweeping. gc_sweep_continue will either grow the heap or finish
sweeping.
  • Loading branch information
peterzhu2118 committed Feb 3, 2022
1 parent 8f3a36f commit 424374d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gc.c
Expand Up @@ -2204,13 +2204,14 @@ heap_prepare(rb_objspace_t *objspace, rb_size_pool_t *size_pool, rb_heap_t *heap
{
GC_ASSERT(heap->free_pages == NULL);

if (is_lazy_sweeping(objspace)) {
gc_sweep_continue(objspace, size_pool, heap);
}
else if (is_incremental_marking(objspace)) {
if (is_incremental_marking(objspace)) {
gc_marks_continue(objspace, size_pool, heap);
}

if (heap->free_pages == NULL && is_lazy_sweeping(objspace)) {
gc_sweep_continue(objspace, size_pool, heap);
}

if (heap->free_pages == NULL &&
(will_be_incremental_marking(objspace) || heap_increment(objspace, size_pool, heap) == FALSE) &&
gc_start(objspace, GPR_FLAG_NEWOBJ) == FALSE) {
Expand Down

0 comments on commit 424374d

Please sign in to comment.