summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-05 22:20:14 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-05 22:20:14 +0000
commit8f88ff4e37a5374e49025076905c57941379336a (patch)
tree91d54c45a4325f786b484bdbf6ffc9f61dc28527 /gc.c
parent908c25341ecfceb822b2b15288a8a3f53cf6add3 (diff)
* internal.h: remove struct method_table_wrapper.
struct method_table_wrapper was introduced to avoid duplicate marking for method tables. For example, `module M1; def foo; end; end` make one method table (mtbl) contains a method `foo`. M1 (T_MODULE) points mtbl. Classes C1 and C2 includes M1, then two T_ICLASS objects are created and they points mtbl too. In this case, three objects (one T_MODULE and two T_ICLASS objects) points same mtbl. On marking phase, these three objects mark same mtbl. To avoid such duplication, struct method_table_wrapper was introduced. However, created two T_ICLASS objects have same or shorter lifetime than M1 (T_MODULE) object. So that we only need to mark mtbl from M1, not from T_ICLASS objects. This patch tries marking only from M1. Note that one `Module#prepend` call creates two T_ICLASS objects. One for refering to a prepending Module object, same as `Module#include`. We don't nedd to care this T_ICLASS. One for moving original mtbl from a prepending class. We need to mark such mtbl from this T_ICLASS object. To mark the mtbl, we need to use `RCLASS_ORIGIN(klass)` on marking from a prepended class `klass`. * class.c: ditto. * eval.c (rb_using_refinement): ditto. * gc.c: ditto. * include/ruby/ruby.h: define m_tbl directly. The definition of struct RClass should be moved to (srcdir)/internal.h. * method.h: remove decl of rb_free_m_tbl_wrapper(). * object.c: use RCLASS_M_TBL() directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c42
1 files changed, 13 insertions, 29 deletions
diff --git a/gc.c b/gc.c
index b843e7bb73..c123f670cd 100644
--- a/gc.c
+++ b/gc.c
@@ -1801,17 +1801,10 @@ free_method_entry_i(st_data_t key, st_data_t value, st_data_t data)
static void
rb_free_m_tbl(st_table *tbl)
{
- st_foreach(tbl, free_method_entry_i, 0);
- st_free_table(tbl);
-}
-
-void
-rb_free_m_tbl_wrapper(struct method_table_wrapper *wrapper)
-{
- if (wrapper->tbl) {
- rb_free_m_tbl(wrapper->tbl);
+ if (tbl) {
+ st_foreach(tbl, free_method_entry_i, 0);
+ st_free_table(tbl);
}
- xfree(wrapper);
}
static int
@@ -1888,9 +1881,8 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
break;
case T_MODULE:
case T_CLASS:
- if (RCLASS_M_TBL_WRAPPER(obj)) {
- rb_free_m_tbl_wrapper(RCLASS_M_TBL_WRAPPER(obj));
- }
+ rb_free_m_tbl(RCLASS_M_TBL(obj));
+
if (RCLASS_IV_TBL(obj)) {
st_free_table(RCLASS_IV_TBL(obj));
}
@@ -2863,9 +2855,6 @@ obj_memsize_of(VALUE obj, int use_all_types)
break;
case T_MODULE:
case T_CLASS:
- if (RCLASS_M_TBL_WRAPPER(obj)) {
- size += sizeof(struct method_table_wrapper);
- }
if (RCLASS_M_TBL(obj)) {
size += st_memsize(RCLASS_M_TBL(obj));
}
@@ -3837,19 +3826,13 @@ mark_method_entry_i(st_data_t key, st_data_t value, st_data_t data)
}
static void
-mark_m_tbl_wrapper(rb_objspace_t *objspace, struct method_table_wrapper *wrapper)
+mark_m_tbl(rb_objspace_t *objspace, struct st_table *tbl)
{
- struct mark_tbl_arg arg;
- if (!wrapper || !wrapper->tbl) return;
- if (LIKELY(objspace->mark_func_data == 0) && !is_incremental_marking(objspace)) {
- /* prevent multiple marking during same GC cycle,
- * since m_tbl is shared between several T_ICLASS */
- size_t serial = rb_gc_count();
- if (wrapper->serial == serial) return;
- wrapper->serial = serial;
+ if (tbl) {
+ struct mark_tbl_arg arg;
+ arg.objspace = objspace;
+ st_foreach(tbl, mark_method_entry_i, (st_data_t)&arg);
}
- arg.objspace = objspace;
- st_foreach(wrapper->tbl, mark_method_entry_i, (st_data_t)&arg);
}
static int
@@ -4147,10 +4130,11 @@ gc_mark_children(rb_objspace_t *objspace, VALUE obj)
gc_mark(objspace, any->as.basic.klass);
switch (BUILTIN_TYPE(obj)) {
- case T_ICLASS:
case T_CLASS:
case T_MODULE:
- mark_m_tbl_wrapper(objspace, RCLASS_M_TBL_WRAPPER(obj));
+ if (!RCLASS_EXT(obj)) break;
+ mark_m_tbl(objspace, RCLASS_M_TBL(RCLASS_ORIGIN(obj)));
+ case T_ICLASS:
if (!RCLASS_EXT(obj)) break;
mark_tbl(objspace, RCLASS_IV_TBL(obj));
mark_const_tbl(objspace, RCLASS_CONST_TBL(obj));