diff --git a/ChangeLog b/ChangeLog index 6e90ade3b3..75433de66b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +Thu Jul 10 01:09:57 2014 Koichi Sasada + + * symbol.c: remove rb_gc_mark_symbols(). + + fstrings refered by static symbols and pinned dynamic symbols + are registerd by rb_gc_register_mark_object(). + + frstring refered by dynamic symbols (not pinned symbols) + are refered from global_symbols.dsymbol_fstr_hash (Hash object). + + Note that fstrings refered from dynamic symbols must live loger + than symbol objects themselves because rb_gc_free_dsymbol() uses + fstring to remove from symbol tables. + This is why we can not mark fstrings from dynamic symbols. + + This technique reduces root objects for GC marking. + + * gc.c (gc_mark_roots): ditto. + + * internal.h: ditto. + Thu Jul 10 00:24:18 2014 Naohisa Goto * common.mk (DTRACE_DEPENDENT_OBJS): fix build failure on Solaris diff --git a/gc.c b/gc.c index fd84749dd5..23b1e075f4 100644 --- a/gc.c +++ b/gc.c @@ -4230,15 +4230,6 @@ gc_mark_roots(rb_objspace_t *objspace, int full_mark, const char **categoryp) MARK_CHECKPOINT("machine_context"); mark_current_machine_context(objspace, th); - MARK_CHECKPOINT("symbols"); -#if USE_RGENGC - objspace->rgengc.parent_object_is_old = TRUE; - rb_gc_mark_symbols(full_mark); - objspace->rgengc.parent_object_is_old = FALSE; -#else - rb_gc_mark_symbols(full_mark); -#endif - MARK_CHECKPOINT("encodings"); rb_gc_mark_encodings(); diff --git a/internal.h b/internal.h index e3ab0dec8b..c91670a388 100644 --- a/internal.h +++ b/internal.h @@ -805,7 +805,6 @@ int rb_is_attrset_name(VALUE name); int rb_is_local_name(VALUE name); int rb_is_method_name(VALUE name); int rb_is_junk_name(VALUE name); -void rb_gc_mark_symbols(int full_mark); ID rb_make_internal_id(void); void rb_gc_free_dsymbol(VALUE); VALUE rb_str_dynamic_intern(VALUE); diff --git a/symbol.c b/symbol.c index 338c6e9d28..342768b8fb 100644 --- a/symbol.c +++ b/symbol.c @@ -59,7 +59,7 @@ static struct symbols { ID last_id; st_table *str_id; st_table *id_str; - int minor_marked; + VALUE dsymbol_fstr_hash; } global_symbols = {tLAST_TOKEN}; static const struct st_hash_type symhash = { @@ -70,21 +70,17 @@ static const struct st_hash_type symhash = { void Init_sym(void) { + VALUE dsym_fstrs = rb_hash_new(); + global_symbols.dsymbol_fstr_hash = dsym_fstrs; + rb_gc_register_mark_object(dsym_fstrs); + rb_obj_hide(dsym_fstrs); + global_symbols.str_id = st_init_table_with_size(&symhash, 1000); global_symbols.id_str = st_init_numtable_with_size(1000); Init_id(); } -void -rb_gc_mark_symbols(int full_mark) -{ - if (full_mark || global_symbols.minor_marked == 0) { - rb_mark_tbl(global_symbols.id_str); - if (!full_mark) global_symbols.minor_marked = 1; - } -} - static ID attrsetname_to_attr(VALUE name); static int lookup_id_str(ID id, st_data_t *data); @@ -316,7 +312,8 @@ register_static_symid_str(ID id, VALUE str) st_add_direct(global_symbols.str_id, (st_data_t)str, id); st_add_direct(global_symbols.id_str, id, (st_data_t)str); - global_symbols.minor_marked = 0; + rb_gc_register_mark_object(str); + return id; } @@ -384,7 +381,7 @@ dsymbol_alloc(const VALUE klass, const VALUE str, rb_encoding * const enc) st_add_direct(global_symbols.str_id, (st_data_t)str, (st_data_t)dsym); st_add_direct(global_symbols.id_str, (ID)dsym, (st_data_t)str); - global_symbols.minor_marked = 0; + rb_hash_aset(global_symbols.dsymbol_fstr_hash, str, Qtrue); if (RUBY_DTRACE_SYMBOL_CREATE_ENABLED()) { RUBY_DTRACE_SYMBOL_CREATE(RSTRING_PTR(RSYMBOL(dsym)->fstr), rb_sourcefile(), rb_sourceline()); @@ -419,11 +416,14 @@ dsymbol_pindown(VALUE sym) must_be_dynamic_symbol(sym); if (UNLIKELY(SYMBOL_PINNED_P(sym) == 0)) { + VALUE fstr = RSYMBOL(sym)->fstr; sym = dsymbol_check(sym); FL_SET(sym, SYMBOL_PINNED); /* make it permanent object */ rb_gc_register_mark_object(sym); + rb_gc_register_mark_object(fstr); + rb_hash_delete(global_symbols.dsymbol_fstr_hash, fstr); } return (ID)sym;