[前][次][番号順一覧][スレッド一覧]

ruby-changes:34689

From: ko1 <ko1@a...>
Date: Thu, 10 Jul 2014 01:19:28 +0900 (JST)
Subject: [ruby-changes:34689] ko1:r46772 (trunk): * symbol.c: remove rb_gc_mark_symbols().

ko1	2014-07-10 01:19:13 +0900 (Thu, 10 Jul 2014)

  New Revision: 46772

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46772

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
    trunk/internal.h
    trunk/symbol.c
Index: symbol.c
===================================================================
--- symbol.c	(revision 46771)
+++ symbol.c	(revision 46772)
@@ -59,7 +59,7 @@ static struct symbols { https://github.com/ruby/ruby/blob/trunk/symbol.c#L59
     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 https://github.com/ruby/ruby/blob/trunk/symbol.c#L70
 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 s https://github.com/ruby/ruby/blob/trunk/symbol.c#L312
 
     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 V https://github.com/ruby/ruby/blob/trunk/symbol.c#L381
 
     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) https://github.com/ruby/ruby/blob/trunk/symbol.c#L416
     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;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46771)
+++ ChangeLog	(revision 46772)
@@ -1,3 +1,24 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jul 10 01:09:57 2014  Koichi Sasada  <ko1@a...>
+
+	* 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  <ngotogenome@g...>
 
 	* common.mk (DTRACE_DEPENDENT_OBJS): fix build failure on Solaris
Index: gc.c
===================================================================
--- gc.c	(revision 46771)
+++ gc.c	(revision 46772)
@@ -4230,15 +4230,6 @@ gc_mark_roots(rb_objspace_t *objspace, i https://github.com/ruby/ruby/blob/trunk/gc.c#L4230
     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();
 
Index: internal.h
===================================================================
--- internal.h	(revision 46771)
+++ internal.h	(revision 46772)
@@ -805,7 +805,6 @@ int rb_is_attrset_name(VALUE name); https://github.com/ruby/ruby/blob/trunk/internal.h#L805
 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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]