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

ruby-changes:34646

From: ko1 <ko1@a...>
Date: Mon, 7 Jul 2014 10:54:13 +0900 (JST)
Subject: [ruby-changes:34646] ko1:r46729 (trunk): * parse.y: do not use rb_gc_resurrect(), but create a new dynamic

ko1	2014-07-07 10:53:54 +0900 (Mon, 07 Jul 2014)

  New Revision: 46729

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

  Log:
    * parse.y: do not use rb_gc_resurrect(), but create a new dynamic
      symbol for garbage dynamic symbol.
    * common.mk: use gc.h by parse.y.

  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/parse.y
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46728)
+++ ChangeLog	(revision 46729)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jul  7 10:52:03 2014  Koichi Sasada  <ko1@a...>
+
+	* parse.y: do not use rb_gc_resurrect(), but create a new dynamic
+	  symbol for garbage dynamic symbol.
+
+	* common.mk: use gc.h by parse.y.
+
 Mon Jul  7 02:18:42 2014  Koichi Sasada  <ko1@a...>
 
 	* string.c (fstr_update_callback): do not use rb_gc_resurrect()
Index: common.mk
===================================================================
--- common.mk	(revision 46728)
+++ common.mk	(revision 46729)
@@ -722,7 +722,7 @@ parse.$(OBJEXT): {$(VPATH)}parse.c $(RUB https://github.com/ruby/ruby/blob/trunk/common.mk#L722
   $(ENCODING_H_INCLUDES) {$(VPATH)}id.h {$(VPATH)}regenc.h \
   {$(VPATH)}regex.h {$(VPATH)}util.h {$(VPATH)}lex.c \
   {$(VPATH)}defs/keywords {$(VPATH)}id.c {$(VPATH)}parse.y \
-  {$(VPATH)}parse.h {$(VPATH)}internal.h $(PROBES_H_INCLUDES) {$(VPATH)}vm_opts.h
+  {$(VPATH)}parse.h {$(VPATH)}internal.h $(PROBES_H_INCLUDES) {$(VPATH)}vm_opts.h {$(VPATH)}gc.h
 proc.$(OBJEXT): {$(VPATH)}proc.c {$(VPATH)}eval_intern.h \
   $(RUBY_H_INCLUDES) {$(VPATH)}gc.h $(VM_CORE_H_INCLUDES) \
   {$(VPATH)}internal.h {$(VPATH)}iseq.h {$(VPATH)}vm_opts.h
Index: parse.y
===================================================================
--- parse.y	(revision 46728)
+++ parse.y	(revision 46729)
@@ -25,6 +25,7 @@ https://github.com/ruby/ruby/blob/trunk/parse.y#L25
 #include "node.h"
 #include "parse.h"
 #include "id.h"
+#include "gc.h"
 #include "regenc.h"
 #include <stdio.h>
 #include <errno.h>
@@ -10445,11 +10446,46 @@ setup_fake_str(struct RString *fake_str, https://github.com/ruby/ruby/blob/trunk/parse.y#L10446
     return (VALUE)fake_str;
 }
 
+static VALUE
+dsymbol_alloc(const VALUE klass, const VALUE str, rb_encoding * const enc)
+{
+    const VALUE dsym = rb_newobj_of(klass, T_SYMBOL | FL_WB_PROTECTED);
+    const ID type = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
+
+    rb_enc_associate(dsym, enc);
+    OBJ_FREEZE(dsym);
+    RB_OBJ_WRITE(dsym, &RSYMBOL(dsym)->fstr, str);
+    RSYMBOL(dsym)->type = type;
+
+    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);
+
+    if (RUBY_DTRACE_SYMBOL_CREATE_ENABLED()) {
+	RUBY_DTRACE_SYMBOL_CREATE(RSTRING_PTR(RSYMBOL(dsym)->fstr), rb_sourcefile(), rb_sourceline());
+    }
+
+    return dsym;
+}
+
+static inline VALUE
+dsymbol_check(const VALUE sym)
+{
+    if (UNLIKELY(rb_objspace_garbage_object_p(sym))) {
+	const VALUE fstr = RSYMBOL(sym)->fstr;
+	st_delete(global_symbols.str_id, (st_data_t *)&fstr, NULL);
+	st_delete(global_symbols.id_str, (st_data_t *)&sym, NULL);
+	return dsymbol_alloc(rb_cSymbol, fstr, rb_enc_get(fstr));
+    }
+    else {
+	return sym;
+    }
+}
+
 static ID
 rb_pin_dynamic_symbol(VALUE sym)
 {
     must_be_dynamic_symbol(sym);
-    rb_gc_resurrect(sym);
+    sym = dsymbol_check(sym);
     /* stick dynamic symbol */
     if (!st_insert(global_symbols.pinned_dsym, sym, (st_data_t)sym)) {
 	global_symbols.pinned_dsym_minor_marked = 0;
@@ -10688,15 +10724,14 @@ rb_str_dynamic_intern(VALUE str) https://github.com/ruby/ruby/blob/trunk/parse.y#L10724
 {
 #if USE_SYMBOL_GC
     rb_encoding *enc, *ascii;
-    VALUE dsym;
-    ID id, type;
+    ID id;
 
     if (st_lookup(global_symbols.str_id, str, &id)) {
 	VALUE sym = ID2SYM(id);
 	if (ID_DYNAMIC_SYM_P(id)) {
 	    /* because of lazy sweep, dynamic symbol may be unmarked already and swept
 	     * at next time */
-	    rb_gc_resurrect(sym);
+	    sym = dsymbol_check(sym);
 	}
 	return sym;
     }
@@ -10712,24 +10747,7 @@ rb_str_dynamic_intern(VALUE str) https://github.com/ruby/ruby/blob/trunk/parse.y#L10747
 	}
     }
 
-    type = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
-    str = rb_fstring(str);
-    dsym = rb_newobj_of(rb_cSymbol, T_SYMBOL);
-    rb_enc_associate(dsym, enc);
-    OBJ_FREEZE(dsym);
-    RSYMBOL(dsym)->fstr = str;
-    RSYMBOL(dsym)->type = type;
-
-    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;
-
-    if (RUBY_DTRACE_SYMBOL_CREATE_ENABLED()) {
-	RUBY_DTRACE_SYMBOL_CREATE(RSTRING_PTR(str), rb_sourcefile(), rb_sourceline());
-	RB_GC_GUARD(str);
-    }
-
-    return dsym;
+    return dsymbol_alloc(rb_cSymbol, rb_fstring(str), enc);
 #else
     return rb_str_intern(str);
 #endif
@@ -10739,8 +10757,7 @@ static int https://github.com/ruby/ruby/blob/trunk/parse.y#L10757
 lookup_id_str(ID id, st_data_t *data)
 {
     if (ID_DYNAMIC_SYM_P(id)) {
-	rb_gc_resurrect((VALUE)id);
-	rb_gc_resurrect(RSYMBOL(id)->fstr);
+	id = (ID)dsymbol_check((VALUE)id);
 	*data = RSYMBOL(id)->fstr;
 	return TRUE;
     }
@@ -10866,7 +10883,7 @@ symbols_i(VALUE key, ID value, VALUE ary https://github.com/ruby/ruby/blob/trunk/parse.y#L10883
 {
     VALUE sym = ID2SYM(value);
     if (ID_DYNAMIC_SYM_P(value)) {
-	rb_gc_resurrect(sym);
+	sym = dsymbol_check(sym);
     }
     rb_ary_push(ary, sym);
     return ST_CONTINUE;

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

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