summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorJean Boussier <byroot@ruby-lang.org>2023-04-05 08:40:07 +0200
committerJean Boussier <jean.boussier@gmail.com>2023-07-17 11:20:15 +0200
commitfa30b99c34291cde7b17cc709552bc5681729a12 (patch)
tree84add14f8a2b05fcd00ca0ee3b6b1980b52e9540 /gc.c
parentd3bcff01583abce2fb095fc67f47e86fa7005755 (diff)
Implement Process.warmup
[Feature #18885] For now, the optimizations performed are: - Run a major GC - Compact the heap - Promote all surviving objects to oldgen Other optimizations may follow.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7662
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/gc.c b/gc.c
index f72818906f..8658660faf 100644
--- a/gc.c
+++ b/gc.c
@@ -9590,6 +9590,26 @@ garbage_collect_with_gvl(rb_objspace_t *objspace, unsigned int reason)
}
}
+static int
+gc_set_candidate_object_i(void *vstart, void *vend, size_t stride, void *data)
+{
+ rb_objspace_t *objspace = &rb_objspace;
+ VALUE v = (VALUE)vstart;
+ for (; v != (VALUE)vend; v += stride) {
+ switch (BUILTIN_TYPE(v)) {
+ case T_NONE:
+ case T_ZOMBIE:
+ break;
+ default:
+ if (!RVALUE_OLD_P(v) && !RVALUE_WB_UNPROTECTED(v)) {
+ RVALUE_AGE_SET_CANDIDATE(objspace, v);
+ }
+ }
+ }
+
+ return 0;
+}
+
static VALUE
gc_start_internal(rb_execution_context_t *ec, VALUE self, VALUE full_mark, VALUE immediate_mark, VALUE immediate_sweep, VALUE compact)
{
@@ -9617,6 +9637,13 @@ gc_start_internal(rb_execution_context_t *ec, VALUE self, VALUE full_mark, VALUE
return Qnil;
}
+void
+rb_gc_prepare_heap(void)
+{
+ rb_objspace_each_objects(gc_set_candidate_object_i, NULL);
+ gc_start_internal(NULL, Qtrue, Qtrue, Qtrue, Qtrue, Qtrue);
+}
+
static int
gc_is_moveable_obj(rb_objspace_t *objspace, VALUE obj)
{