diff --git a/debug.c b/debug.c index 546ffc440f..4717a0bc9c 100644 --- a/debug.c +++ b/debug.c @@ -226,7 +226,7 @@ ruby_env_debug_option(const char *str, int len, void *arg) } if (NAME_MATCH("gc_stress")) { - rb_gc_stress_set(Qtrue); + rb_gc_initial_stress_set(Qtrue); return 1; } SET_WHEN("core", ruby_enable_coredump, 1); diff --git a/gc.c b/gc.c index 8812c0fea5..04df9dc71b 100644 --- a/gc.c +++ b/gc.c @@ -1876,10 +1876,22 @@ calloc1(size_t n) return calloc(1, n); } +static VALUE initial_stress = Qfalse; + +void +rb_gc_initial_stress_set(VALUE flag) +{ + initial_stress = flag; +} + rb_objspace_t * rb_objspace_alloc(void) { rb_objspace_t *objspace = calloc1(sizeof(rb_objspace_t)); + + objspace->flags.gc_stressful = RTEST(initial_stress); + objspace->gc_stress_mode = initial_stress; + objspace->flags.measure_gc = 1; malloc_limit = gc_params.malloc_limit_min; objspace->finalize_deferred_pjob = rb_postponed_job_preregister(0, gc_finalize_deferred, objspace); @@ -1898,8 +1910,6 @@ rb_objspace_alloc(void) rb_darray_make_without_gc(&objspace->weak_references, 0); - dont_gc_on(); - return objspace; } @@ -8951,7 +8961,7 @@ 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); - if (!heap_allocated_pages) return FALSE; /* heap is not ready */ + if (!heap_allocated_pages) return TRUE; /* 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); @@ -11147,20 +11157,14 @@ gc_stress_get(rb_execution_context_t *ec, VALUE self) return ruby_gc_stress_mode; } -void -rb_gc_stress_set(VALUE flag) +static VALUE +gc_stress_set_m(rb_execution_context_t *ec, VALUE self, VALUE flag) { rb_objspace_t *objspace = &rb_objspace; objspace->flags.gc_stressful = RTEST(flag); objspace->gc_stress_mode = flag; -} -static VALUE -gc_stress_set_m(rb_execution_context_t *ec, VALUE self, VALUE flag) -{ - - rb_gc_stress_set(flag); return flag; } diff --git a/internal/gc.h b/internal/gc.h index 82a1b901f8..5b1180fd91 100644 --- a/internal/gc.h +++ b/internal/gc.h @@ -223,7 +223,7 @@ void rb_gc_remove_weak(VALUE parent_obj, VALUE *ptr); void rb_gc_ref_update_table_values_only(st_table *tbl); -void rb_gc_stress_set(VALUE flag); +void rb_gc_initial_stress_set(VALUE flag); #define rb_gc_mark_and_move_ptr(ptr) do { \ VALUE _obj = (VALUE)*(ptr); \