summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2022-02-02 15:32:38 -0500
committerPeter Zhu <[email protected]>2022-02-03 09:22:24 -0500
commit424374d3302d8d25165007e7afedf14b1a76d23e (patch)
tree609bc7c495191093f5dfd1cc5e13b5267b1683e6 /gc.c
parent8f3a36fb6e40f9259cc2fcd182cddb7472f3be14 (diff)
Fix case when gc_marks_continue does not yield slots
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5521
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/gc.c b/gc.c
index 4eaceef807..0309559481 100644
--- a/gc.c
+++ b/gc.c
@@ -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) {