summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authortmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-03 08:11:07 +0000
committertmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-03 08:11:07 +0000
commit084b602d9a52b62a04d17f65ba1a9b8a767d1e3e (patch)
tree397a5f2e6ec8b546fc44ae5f16e212be20c5d577 /class.c
parentee7fa8b227a43f2e0af34c73bbdbf549bfaeb189 (diff)
* include/ruby/ruby.h (struct RClass): Add wrapper struct around
RClass->m_tbl with serial. This prevents double marking method tables, since many classes/modules can share the same method table. This improves minor mark time in a large application by 30%. * internal.h (struct method_table_wrapper): Define new wrapper struct with additional serial. * internal.h (RCLASS_M_TBL_INIT): New macro for initializing method table wrapper and st_table. * method.h (void rb_sweep_method_entry): Rename rb_free_m_table to rb_free_m_tbl for consistentcy * .gdbinit (define rb_method_entry): Update rb_method_entry gdb helper for new method table structure. * class.c: Use RCLASS_M_TBL_WRAPPER and RCLASS_M_TBL_INIT macros. * class.c (rb_include_class_new): Share WRAPPER between module and iclass, so serial can prevent double marking. * eval.c (rb_prepend_module): ditto. * eval.c (rb_using_refinement): ditto. * gc.c: Mark and free new wrapper struct. * gc.c (obj_memsize_of): Count size of additional wrapper struct. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/class.c b/class.c
index 2bd6bb3..eebb46c 100644
--- a/class.c
+++ b/class.c
@@ -158,7 +158,7 @@ class_alloc(VALUE flags, VALUE klass)
obj->ptr = ALLOC(rb_classext_t);
RCLASS_IV_TBL(obj) = 0;
RCLASS_CONST_TBL(obj) = 0;
- RCLASS_M_TBL(obj) = 0;
+ RCLASS_M_TBL_WRAPPER(obj) = 0;
RCLASS_SET_SUPER((VALUE)obj, 0);
RCLASS_ORIGIN(obj) = (VALUE)obj;
RCLASS_IV_INDEX_TBL(obj) = 0;
@@ -189,7 +189,7 @@ rb_class_boot(VALUE super)
VALUE klass = class_alloc(T_CLASS, rb_cClass);
RCLASS_SET_SUPER(klass, super);
- RCLASS_M_TBL(klass) = st_init_numtable();
+ RCLASS_M_TBL_INIT(klass);
OBJ_INFECT(klass, super);
return (VALUE)klass;
@@ -353,10 +353,10 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)&arg);
}
if (RCLASS_M_TBL(orig)) {
- if (RCLASS_M_TBL(clone)) {
- rb_free_m_table(RCLASS_M_TBL(clone));
+ if (RCLASS_M_TBL_WRAPPER(clone)) {
+ rb_free_m_tbl_wrapper(RCLASS_M_TBL_WRAPPER(clone));
}
- RCLASS_M_TBL(clone) = st_init_numtable();
+ RCLASS_M_TBL_INIT(clone);
st_foreach(RCLASS_M_TBL(orig), clone_method_i, (st_data_t)clone);
}
@@ -402,7 +402,7 @@ rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
if (attach != Qundef) {
rb_singleton_class_attached(clone, attach);
}
- RCLASS_M_TBL(clone) = st_init_numtable();
+ RCLASS_M_TBL_INIT(clone);
st_foreach(RCLASS_M_TBL(klass), clone_method_i, (st_data_t)clone);
rb_singleton_class_attached(RBASIC(clone)->klass, clone);
FL_SET(clone, FL_SINGLETON);
@@ -723,9 +723,7 @@ VALUE
rb_module_new(void)
{
VALUE mdl = class_alloc(T_MODULE, rb_cModule);
-
- RCLASS_M_TBL(mdl) = st_init_numtable();
-
+ RCLASS_M_TBL_INIT(mdl);
return (VALUE)mdl;
}
@@ -803,7 +801,8 @@ rb_include_class_new(VALUE module, VALUE super)
RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
RCLASS_CONST_TBL(klass) = RCLASS_CONST_TBL(module);
- RCLASS_M_TBL(OBJ_WB_UNPROTECT(klass)) = RCLASS_M_TBL(OBJ_WB_UNPROTECT(RCLASS_ORIGIN(module)));
+ RCLASS_M_TBL_WRAPPER(OBJ_WB_UNPROTECT(klass)) =
+ RCLASS_M_TBL_WRAPPER(OBJ_WB_UNPROTECT(RCLASS_ORIGIN(module)));
RCLASS_SET_SUPER(klass, super);
if (RB_TYPE_P(module, T_ICLASS)) {
@@ -953,8 +952,8 @@ rb_prepend_module(VALUE klass, VALUE module)
RCLASS_SET_SUPER(origin, RCLASS_SUPER(klass));
RCLASS_SET_SUPER(klass, origin);
RCLASS_ORIGIN(klass) = origin;
- RCLASS_M_TBL(origin) = RCLASS_M_TBL(klass);
- RCLASS_M_TBL(klass) = st_init_numtable();
+ RCLASS_M_TBL_WRAPPER(origin) = RCLASS_M_TBL_WRAPPER(klass);
+ RCLASS_M_TBL_INIT(klass);
st_foreach(RCLASS_M_TBL(origin), move_refined_method,
(st_data_t) RCLASS_M_TBL(klass));
}