From 7835ebce97a6e6132d2bc7bdbef115f3f47cc6c2 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 27 Nov 2023 10:23:31 -0500 Subject: [PATCH] Set compaction after major GC has been determined do_full_mark can change in gc_start, so we want to set auto-compaction only after do_full_mark has been properly set. --- gc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gc.c b/gc.c index 2d7eb4de93..7daddd5364 100644 --- a/gc.c +++ b/gc.c @@ -9409,14 +9409,6 @@ gc_start(rb_objspace_t *objspace, unsigned int reason) /* reason may be clobbered, later, so keep set immediate_sweep here */ objspace->flags.immediate_sweep = !!(reason & GPR_FLAG_IMMEDIATE_SWEEP); - /* Explicitly enable compaction (GC.compact) */ - if (do_full_mark && ruby_enable_autocompact) { - objspace->flags.during_compacting = TRUE; - } - else { - objspace->flags.during_compacting = !!(reason & GPR_FLAG_COMPACT); - } - if (!heap_allocated_pages) return FALSE; /* heap is not ready */ if (!(reason & GPR_FLAG_METHOD) && !ready_to_gc(objspace)) return TRUE; /* GC is not allowed */ @@ -9464,6 +9456,14 @@ gc_start(rb_objspace_t *objspace, unsigned int reason) objspace->flags.during_incremental_marking = do_full_mark; } + /* Explicitly enable compaction (GC.compact) */ + if (do_full_mark && ruby_enable_autocompact) { + objspace->flags.during_compacting = TRUE; + } + else { + objspace->flags.during_compacting = !!(reason & GPR_FLAG_COMPACT); + } + if (!GC_ENABLE_LAZY_SWEEP || objspace->flags.dont_incremental) { objspace->flags.immediate_sweep = TRUE; }