Skip to content

Commit 2168fdb

Browse files
Move class pre-aging out of the allocation path
Previously classes and modules were pre-aged. Ie. as soon as they're allocated they are aged to old_age - 1. This was done with the assumption that classes are generally always long lived, so we should assume that any that survive a single GC can be considered old. This commit keeps the same semantics, but moves the logic out of the allocation path, in order to simplify allocation. Classes and modules are now set to old-age the first time they are marked.
1 parent b52cb82 commit 2168fdb

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

gc/default/default.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,10 +2175,6 @@ newobj_init(VALUE klass, VALUE flags, int wb_protected, rb_objspace_t *objspace,
21752175
RBASIC(obj)->shape_id = 0;
21762176
#endif
21772177

2178-
int t = flags & RUBY_T_MASK;
2179-
if (t == T_CLASS || t == T_MODULE || t == T_ICLASS) {
2180-
RVALUE_AGE_SET_CANDIDATE(objspace, obj);
2181-
}
21822178

21832179
#if RACTOR_CHECK_MODE
21842180
void rb_ractor_setup_belonging(VALUE obj);
@@ -4407,8 +4403,16 @@ gc_aging(rb_objspace_t *objspace, VALUE obj)
44074403

44084404
if (!RVALUE_PAGE_WB_UNPROTECTED(page, obj)) {
44094405
if (!RVALUE_OLD_P(objspace, obj)) {
4410-
gc_report(3, objspace, "gc_aging: YOUNG: %s\n", rb_obj_info(obj));
4411-
RVALUE_AGE_INC(objspace, obj);
4406+
int t = BUILTIN_TYPE(obj);
4407+
if (t == T_CLASS || t == T_MODULE || t == T_ICLASS) {
4408+
gc_report(3, objspace, "gc_aging: YOUNG class: %s\n", rb_obj_info(obj));
4409+
RVALUE_AGE_SET(obj, RVALUE_OLD_AGE);
4410+
RVALUE_OLD_UNCOLLECTIBLE_SET(objspace, obj);
4411+
}
4412+
else {
4413+
gc_report(3, objspace, "gc_aging: YOUNG: %s\n", rb_obj_info(obj));
4414+
RVALUE_AGE_INC(objspace, obj);
4415+
}
44124416
}
44134417
else if (is_full_marking(objspace)) {
44144418
GC_ASSERT(RVALUE_PAGE_UNCOLLECTIBLE(page, obj) == FALSE);

0 commit comments

Comments
 (0)