From 264e4cd04fbcdcb739a1ff9a84e19afe66005cb2 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Mon, 10 Aug 2020 18:19:17 -0400 Subject: Remove write barrier exemption for T_ICLASS Before this commit, iclasses were "shady", or not protected by write barriers. Because of that, the GC needs to spend more time marking these objects than otherwise. Applications that make heavy use of modules should see reduction in GC time as they have a significant number of live iclasses on the heap. - Put logic for iclass method table ownership into a function - Remove calls to WB_UNPROTECT and insert write barriers for iclasses This commit relies on the following invariant: for any non oirigin iclass `I`, `RCLASS_M_TBL(I) == RCLASS_M_TBL(RBasic(I)->klass)`. This invariant did not hold prior to 98286e9 for classes and modules that have prepended modules. [Feature #16984] --- class.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'class.c') diff --git a/class.c b/class.c index 0d97603821..9876e996c8 100644 --- a/class.c +++ b/class.c @@ -911,8 +911,7 @@ rb_include_class_new(VALUE module, VALUE super) { VALUE klass = class_alloc(T_ICLASS, rb_cClass); - RCLASS_M_TBL(OBJ_WB_UNPROTECT(klass)) = - RCLASS_M_TBL(OBJ_WB_UNPROTECT(module)); /* TODO: unprotected? */ + RCLASS_M_TBL(klass) = RCLASS_M_TBL(module); RCLASS_SET_ORIGIN(klass, klass); if (BUILTIN_TYPE(module) == T_ICLASS) { @@ -1098,13 +1097,12 @@ move_refined_method(ID key, VALUE value, void *data) const rb_method_entry_t *orig_me = me->def->body.refined.orig_me, *new_me; RB_OBJ_WRITE(me, &me->def->body.refined.orig_me, NULL); new_me = rb_method_entry_clone(me); - rb_id_table_insert(tbl, key, (VALUE)new_me); - RB_OBJ_WRITTEN(klass, Qundef, new_me); + rb_method_table_insert(klass, tbl, key, new_me); rb_method_entry_copy(me, orig_me); return ID_TABLE_CONTINUE; } else { - rb_id_table_insert(tbl, key, (VALUE)me); + rb_method_table_insert(klass, tbl, key, me); return ID_TABLE_DELETE; } } @@ -1119,7 +1117,6 @@ ensure_origin(VALUE klass) VALUE origin = RCLASS_ORIGIN(klass); if (origin == klass) { origin = class_alloc(T_ICLASS, klass); - OBJ_WB_UNPROTECT(origin); /* TODO: conservative shading. Need more survey. */ RCLASS_SET_SUPER(origin, RCLASS_SUPER(klass)); RCLASS_SET_SUPER(klass, origin); RCLASS_SET_ORIGIN(klass, origin); -- cgit v1.2.3