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

ruby-changes:31387

From: ko1 <ko1@a...>
Date: Tue, 29 Oct 2013 20:17:09 +0900 (JST)
Subject: [ruby-changes:31387] ko1:r43466 (trunk): * add RUBY_TYPED_FREE_IMMEDIATELY to data types which only use

ko1	2013-10-29 20:16:54 +0900 (Tue, 29 Oct 2013)

  New Revision: 43466

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

  Log:
    * add RUBY_TYPED_FREE_IMMEDIATELY to data types which only use
      safe functions during garbage collection such as xfree().
      On default, T_DATA objects are freed at same points as fianlizers.
      This approach protects issues such as reported by [ruby-dev:35578].
      However, freeing T_DATA objects immediately helps heap usage.
      Most of T_DATA (in other words, most of dfree functions) are safe.
      However, we turned off RUBY_TYPED_FREE_IMMEDIATELY by default
      for safety.
    * cont.c: ditto.
    * dir.c: ditto.
    * encoding.c: ditto.
    * enumerator.c: ditto.
    * error.c: ditto.
    * file.c: ditto.
    * gc.c: ditto.
    * io.c: ditto.
    * iseq.c: ditto.
    * marshal.c: ditto.
    * parse.y: ditto.
    * proc.c: ditto.
    * process.c: ditto.
    * random.c: ditto.
    * thread.c: ditto.
    * time.c: ditto.
    * transcode.c: ditto.
    * variable.c: ditto.
    * vm.c: ditto.
    * vm_backtrace.c: ditto.
    * vm_trace.c: ditto.
    * ext/bigdecimal/bigdecimal.c: ditto.
    * ext/objspace/objspace.c: ditto.
    * ext/stringio/stringio.c: ditto.
    * ext/strscan/strscan.c: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/cont.c
    trunk/dir.c
    trunk/encoding.c
    trunk/enumerator.c
    trunk/error.c
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/ext/objspace/objspace.c
    trunk/ext/stringio/stringio.c
    trunk/ext/strscan/strscan.c
    trunk/file.c
    trunk/gc.c
    trunk/io.c
    trunk/iseq.c
    trunk/marshal.c
    trunk/parse.y
    trunk/proc.c
    trunk/process.c
    trunk/random.c
    trunk/thread.c
    trunk/time.c
    trunk/transcode.c
    trunk/variable.c
    trunk/vm.c
    trunk/vm_backtrace.c
    trunk/vm_trace.c
Index: encoding.c
===================================================================
--- encoding.c	(revision 43465)
+++ encoding.c	(revision 43466)
@@ -71,6 +71,7 @@ enc_memsize(const void *p) https://github.com/ruby/ruby/blob/trunk/encoding.c#L71
 static const rb_data_type_t encoding_data_type = {
     "encoding",
     {0, 0, enc_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 #define is_data_encoding(obj) (RTYPEDDATA_P(obj) && RTYPEDDATA_TYPE(obj) == &encoding_data_type)
Index: time.c
===================================================================
--- time.c	(revision 43465)
+++ time.c	(revision 43466)
@@ -1796,6 +1796,7 @@ time_memsize(const void *tobj) https://github.com/ruby/ruby/blob/trunk/time.c#L1796
 static const rb_data_type_t time_data_type = {
     "time",
     {time_mark, time_free, time_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43465)
+++ ChangeLog	(revision 43466)
@@ -1,3 +1,66 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Oct 29 20:01:58 2013  Koichi Sasada  <ko1@a...>
+
+	* add RUBY_TYPED_FREE_IMMEDIATELY to data types which only use
+	  safe functions during garbage collection such as xfree().
+
+	  On default, T_DATA objects are freed at same points as fianlizers.
+	  This approach protects issues such as reported by [ruby-dev:35578].
+	  However, freeing T_DATA objects immediately helps heap usage.
+
+	  Most of T_DATA (in other words, most of dfree functions) are safe.
+	  However, we turned off RUBY_TYPED_FREE_IMMEDIATELY by default
+	  for safety.
+
+	* cont.c: ditto.
+
+	* dir.c: ditto.
+
+	* encoding.c: ditto.
+
+	* enumerator.c: ditto.
+
+	* error.c: ditto.
+
+	* file.c: ditto.
+
+	* gc.c: ditto.
+
+	* io.c: ditto.
+
+	* iseq.c: ditto.
+
+	* marshal.c: ditto.
+
+	* parse.y: ditto.
+
+	* proc.c: ditto.
+
+	* process.c: ditto.
+
+	* random.c: ditto.
+
+	* thread.c: ditto.
+
+	* time.c: ditto.
+
+	* transcode.c: ditto.
+
+	* variable.c: ditto.
+
+	* vm.c: ditto.
+
+	* vm_backtrace.c: ditto.
+
+	* vm_trace.c: ditto.
+
+	* ext/bigdecimal/bigdecimal.c: ditto.
+
+	* ext/objspace/objspace.c: ditto.
+
+	* ext/stringio/stringio.c: ditto.
+
+	* ext/strscan/strscan.c: ditto.
+
 Tue Oct 29 19:48:33 2013  Koichi Sasada  <ko1@a...>
 
 	* include/ruby/ruby.h: fix typo (FL_WB_PROTECT -> FL_WB_PROTECTED).
Index: enumerator.c
===================================================================
--- enumerator.c	(revision 43465)
+++ enumerator.c	(revision 43466)
@@ -168,6 +168,7 @@ static const rb_data_type_t enumerator_d https://github.com/ruby/ruby/blob/trunk/enumerator.c#L168
 	enumerator_free,
 	enumerator_memsize,
     },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static struct enumerator *
@@ -1076,6 +1077,7 @@ static const rb_data_type_t yielder_data https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1077
 	yielder_free,
 	yielder_memsize,
     },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static struct yielder *
@@ -1181,6 +1183,7 @@ static const rb_data_type_t generator_da https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1183
 	generator_free,
 	generator_memsize,
     },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static struct generator *
Index: variable.c
===================================================================
--- variable.c	(revision 43465)
+++ variable.c	(revision 43466)
@@ -1535,6 +1535,7 @@ autoload_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/variable.c#L1535
 static const rb_data_type_t autoload_data_type = {
     "autoload",
     {autoload_mark, autoload_free, autoload_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 #define check_autoload_table(av) \
@@ -1585,6 +1586,7 @@ autoload_i_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/variable.c#L1586
 static const rb_data_type_t autoload_data_i_type = {
     "autoload_i",
     {autoload_i_mark, autoload_i_free, autoload_i_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 #define check_autoload_data(av) \
Index: iseq.c
===================================================================
--- iseq.c	(revision 43465)
+++ iseq.c	(revision 43466)
@@ -168,9 +168,8 @@ static const rb_data_type_t iseq_data_ty https://github.com/ruby/ruby/blob/trunk/iseq.c#L168
 	iseq_free,
 	iseq_memsize,
     },              /* functions */
-    0,              /* parent */
-    0,              /* data */
-    FL_WB_PROTECTED /* flags */
+    NULL, NULL,
+    RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
 };
 
 static VALUE
Index: io.c
===================================================================
--- io.c	(revision 43465)
+++ io.c	(revision 43466)
@@ -7583,6 +7583,7 @@ argf_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/io.c#L7583
 static const rb_data_type_t argf_type = {
     "ARGF",
     {argf_mark, argf_free, argf_memsize},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static inline void
Index: proc.c
===================================================================
--- proc.c	(revision 43465)
+++ proc.c	(revision 43466)
@@ -78,6 +78,7 @@ static const rb_data_type_t proc_data_ty https://github.com/ruby/ruby/blob/trunk/proc.c#L78
 	proc_free,
 	proc_memsize,
     },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 VALUE
@@ -276,6 +277,7 @@ const rb_data_type_t ruby_binding_data_t https://github.com/ruby/ruby/blob/trunk/proc.c#L277
 	binding_free,
 	binding_memsize,
     },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE
@@ -1104,6 +1106,7 @@ static const rb_data_type_t method_data_ https://github.com/ruby/ruby/blob/trunk/proc.c#L1106
 	bm_free,
 	bm_memsize,
     },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 VALUE
Index: thread.c
===================================================================
--- thread.c	(revision 43465)
+++ thread.c	(revision 43466)
@@ -3957,6 +3957,7 @@ thgroup_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/thread.c#L3957
 static const rb_data_type_t thgroup_data_type = {
     "thgroup",
     {NULL, RUBY_TYPED_DEFAULT_FREE, thgroup_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 /*
@@ -4195,6 +4196,7 @@ mutex_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/thread.c#L4196
 static const rb_data_type_t mutex_data_type = {
     "mutex",
     {mutex_mark, mutex_free, mutex_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 VALUE
@@ -4644,6 +4646,7 @@ thread_shield_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/thread.c#L4646
 static const rb_data_type_t thread_shield_data_type = {
     "thread_shield",
     {thread_shield_mark, 0, 0,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE
Index: dir.c
===================================================================
--- dir.c	(revision 43465)
+++ dir.c	(revision 43466)
@@ -381,6 +381,7 @@ dir_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/dir.c#L381
 static const rb_data_type_t dir_data_type = {
     "dir",
     {dir_mark, dir_free, dir_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE dir_close(VALUE);
Index: vm_backtrace.c
===================================================================
--- vm_backtrace.c	(revision 43465)
+++ vm_backtrace.c	(revision 43466)
@@ -112,6 +112,7 @@ location_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L112
 static const rb_data_type_t location_data_type = {
     "frame_info",
     {location_mark, location_free, location_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static inline rb_backtrace_location_t *
@@ -407,6 +408,7 @@ backtrace_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L408
 static const rb_data_type_t backtrace_data_type = {
     "backtrace",
     {backtrace_mark, backtrace_free, backtrace_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 int
Index: gc.c
===================================================================
--- gc.c	(revision 43465)
+++ gc.c	(revision 43466)
@@ -1378,6 +1378,8 @@ obj_free(rb_objspace_t *objspace, VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L1378
 	    if (RTYPEDDATA_P(obj)) {
 		free_immediately = RANY(obj)->as.typeddata.type->flags & RUBY_TYPED_FREE_IMMEDIATELY;
 		RDATA(obj)->dfree = RANY(obj)->as.typeddata.type->function.dfree;
+		if (0 && free_immediately == 0) /* to expose non-free-immediate T_DATA */
+		  fprintf(stderr, "not immediate -> %s\n", RANY(obj)->as.typeddata.type->wrap_struct_name);
 	    }
 	    if (RANY(obj)->as.data.dfree == RUBY_DEFAULT_FREE) {
 		xfree(DATA_PTR(obj));
@@ -5369,7 +5371,8 @@ static const rb_data_type_t weakmap_type https://github.com/ruby/ruby/blob/trunk/gc.c#L5371
 	wmap_mark,
 	wmap_free,
 	wmap_memsize,
-    }
+    },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE
Index: parse.y
===================================================================
--- parse.y	(revision 43465)
+++ parse.y	(revision 43466)
@@ -11018,6 +11018,7 @@ rb_data_type_t parser_data_type = { https://github.com/ruby/ruby/blob/trunk/parse.y#L11018
 	parser_free,
 	parser_memsize,
     },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 #ifndef RIPPER
Index: process.c
===================================================================
--- process.c	(revision 43465)
+++ process.c	(revision 43466)
@@ -1366,6 +1366,7 @@ memsize_exec_arg(const void *ptr) https://github.com/ruby/ruby/blob/trunk/process.c#L1366
 static const rb_data_type_t exec_arg_data_type = {
     "exec_arg",
     {mark_exec_arg, free_exec_arg, memsize_exec_arg},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 #ifdef _WIN32
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 43465)
+++ ext/bigdecimal/bigdecimal.c	(revision 43466)
@@ -146,6 +146,7 @@ BigDecimal_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L146
 static const rb_data_type_t BigDecimal_data_type = {
     "BigDecimal",
     { 0, BigDecimal_delete, BigDecimal_memsize, },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static inline int
Index: ext/objspace/objspace.c
===================================================================
--- ext/objspace/objspace.c	(revision 43465)
+++ ext/objspace/objspace.c	(revision 43466)
@@ -643,6 +643,7 @@ iow_size(const void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L643
 static const rb_data_type_t iow_data_type = {
     "ObjectSpace::InternalObjectWrapper",
     {iow_mark, 0, iow_size,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE rb_mInternalObjectWrapper;
Index: ext/stringio/stringio.c
===================================================================
--- ext/stringio/stringio.c	(revision 43465)
+++ ext/stringio/stringio.c	(revision 43466)
@@ -78,6 +78,7 @@ static const rb_data_type_t strio_data_t https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L78
 	strio_free,
 	strio_memsize,
     },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 #define check_strio(self) ((struct StringIO*)rb_check_typeddata((self), &strio_data_type))
Index: ext/strscan/strscan.c
===================================================================
--- ext/strscan/strscan.c	(revision 43465)
+++ ext/strscan/strscan.c	(revision 43466)
@@ -190,7 +190,8 @@ strscan_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/strscan/strscan.c#L190
 
 static const rb_data_type_t strscanner_type = {
     "StringScanner",
-    {strscan_mark, strscan_free, strscan_memsize}
+    {strscan_mark, strscan_free, strscan_memsize},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE
Index: error.c
===================================================================
--- error.c	(revision 43465)
+++ error.c	(revision 43466)
@@ -1033,6 +1033,7 @@ static const rb_data_type_t name_err_mes https://github.com/ruby/ruby/blob/trunk/error.c#L1033
 	name_err_mesg_free,
 	name_err_mesg_memsize,
     },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 /* :nodoc: */
Index: vm_trace.c
===================================================================
--- vm_trace.c	(revision 43465)
+++ vm_trace.c	(revision 43466)
@@ -630,6 +630,7 @@ tp_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L630
 static const rb_data_type_t tp_data_type = {
     "tracepoint",
     {tp_mark, RUBY_TYPED_NEVER_FREE, tp_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE
Index: cont.c
===================================================================
--- cont.c	(revision 43465)
+++ cont.c	(revision 43466)
@@ -417,6 +417,7 @@ cont_save_machine_stack(rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/cont.c#L417
 static const rb_data_type_t cont_data_type = {
     "continuation",
     {cont_mark, cont_free, cont_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static void
@@ -1032,6 +1033,7 @@ rb_cont_call(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/cont.c#L1033
 static const rb_data_type_t fiber_data_type = {
     "fiber",
     {fiber_mark, fiber_free, fiber_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE
Index: vm.c
===================================================================
--- vm.c	(revision 43465)
+++ vm.c	(revision 43466)
@@ -305,6 +305,7 @@ env_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L305
 static const rb_data_type_t env_data_type = {
     "VM/env",
     {env_mark, env_free, env_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE
@@ -1686,6 +1687,7 @@ vm_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L1687
 static const rb_data_type_t vm_data_type = {
     "VM",
     {rb_vm_mark, vm_free, vm_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 
@@ -1963,6 +1965,7 @@ const rb_data_type_t ruby_threadptr_data https://github.com/ruby/ruby/blob/trunk/vm.c#L1965
 	thread_free,
 	thread_memsize,
     },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 VALUE
Index: marshal.c
===================================================================
--- marshal.c	(revision 43465)
+++ marshal.c	(revision 43466)
@@ -186,6 +186,7 @@ memsize_dump_arg(const void *ptr) https://github.com/ruby/ruby/blob/trunk/marshal.c#L186
 static const rb_data_type_t dump_arg_data = {
     "dump_arg",
     {mark_dump_arg, free_dump_arg, memsize_dump_arg,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static const char *
@@ -1021,6 +1022,7 @@ memsize_load_arg(const void *ptr) https://github.com/ruby/ruby/blob/trunk/marshal.c#L1022
 static const rb_data_type_t load_arg_data = {
     "load_arg",
     {mark_load_arg, free_load_arg, memsize_load_arg,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 #define r_entry(v, arg) r_entry0((v), (arg)->data->num_entries, (arg))
Index: file.c
===================================================================
--- file.c	(revision 43465)
+++ file.c	(revision 43466)
@@ -362,6 +362,7 @@ stat_memsize(const void *p) https://github.com/ruby/ruby/blob/trunk/file.c#L362
 static const rb_data_type_t stat_data_type = {
     "stat",
     {NULL, RUBY_TYPED_DEFAULT_FREE, stat_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE
Index: random.c
===================================================================
--- random.c	(revision 43465)
+++ random.c	(revision 43466)
@@ -335,6 +335,7 @@ static const rb_data_type_t random_data_ https://github.com/ruby/ruby/blob/trunk/random.c#L335
 	random_free,
 	random_memsize,
     },
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static rb_random_t *
Index: transcode.c
===================================================================
--- transcode.c	(revision 43465)
+++ transcode.c	(revision 43466)
@@ -2921,6 +2921,7 @@ econv_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/transcode.c#L2921
 static const rb_data_type_t econv_data_type = {
     "econv",
     {NULL, econv_free, econv_memsize,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
 static VALUE

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

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