Move object processing in Process.warmup to gc.c

This commit is contained in:
Peter Zhu 2024-10-16 09:20:32 -04:00
parent 9a98b70a50
commit 3ddaf24cd2
Notes: git 2024-10-18 13:07:05 +00:00
3 changed files with 16 additions and 5 deletions

14
gc.c
View File

@ -3007,6 +3007,20 @@ rb_gc_location(VALUE value)
return rb_gc_impl_location(rb_gc_get_objspace(), value);
}
void
rb_gc_prepare_heap_process_object(VALUE obj)
{
switch (BUILTIN_TYPE(obj)) {
case T_STRING:
// Precompute the string coderange. This both save time for when it will be
// eventually needed, and avoid mutating heap pages after a potential fork.
rb_enc_str_coderange(obj);
break;
default:
break;
}
}
void
rb_gc_prepare_heap(void)
{

View File

@ -6763,12 +6763,8 @@ gc_set_candidate_object_i(void *vstart, void *vend, size_t stride, void *data)
case T_NONE:
case T_ZOMBIE:
break;
case T_STRING:
// precompute the string coderange. This both save time for when it will be
// eventually needed, and avoid mutating heap pages after a potential fork.
rb_enc_str_coderange(v);
// fall through
default:
rb_gc_prepare_heap_process_object(v);
if (!RVALUE_OLD_P(objspace, v) && !RVALUE_WB_UNPROTECTED(objspace, v)) {
RVALUE_AGE_SET_CANDIDATE(objspace, v);
}

View File

@ -42,6 +42,7 @@ uint32_t rb_gc_get_shape(VALUE obj);
void rb_gc_set_shape(VALUE obj, uint32_t shape_id);
uint32_t rb_gc_rebuild_shape(VALUE obj, size_t heap_id);
size_t rb_obj_memsize_of(VALUE obj);
void rb_gc_prepare_heap_process_object(VALUE obj);
RUBY_SYMBOL_EXPORT_END
void rb_ractor_finish_marking(void);