diff --git a/gc.c b/gc.c index 85fd2869ff7a29..5a64d2d59c49e3 100644 --- a/gc.c +++ b/gc.c @@ -11210,19 +11210,26 @@ gc_set_flags_start(rb_objspace_t *objspace, unsigned int reason, unsigned int *d objspace->flags.immediate_sweep = !!(reason & GPR_FLAG_IMMEDIATE_SWEEP); objspace->flags.during_global_gc = !!(reason & GPR_FLAG_GLOBAL); - - /* 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); - } } static void gc_set_flags_finish(rb_objspace_t *objspace, unsigned int reason, unsigned int *do_full_mark, unsigned int *immediate_mark) { + 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 */ + + GC_ASSERT(gc_mode(objspace) == gc_mode_none); + GC_ASSERT(!is_lazy_sweeping(objspace)); + GC_ASSERT(!is_incremental_marking(objspace)); + + unsigned int lock_lev; + gc_enter(objspace, gc_enter_event_start, &lock_lev); + +#if RGENGC_CHECK_MODE >= 2 + gc_verify_internal_consistency(objspace); +#endif + +>>>>>>> 7835ebce97a6e6132d2bc7bdbef115f3f47cc6c2 if (ruby_gc_stressful) { int flag = FIXNUM_P(ruby_gc_stress_mode) ? FIX2INT(ruby_gc_stress_mode) : 0; @@ -11256,6 +11263,14 @@ gc_set_flags_finish(rb_objspace_t *objspace, unsigned int reason, unsigned int * 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; }