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

ruby-changes:34751

From: ko1 <ko1@a...>
Date: Wed, 16 Jul 2014 18:39:18 +0900 (JST)
Subject: [ruby-changes:34751] ko1:r46834 (trunk): * vm_core.h: remove rb_vm_t::trap_list[RUBY_NSIG], but add

ko1	2014-07-16 18:39:09 +0900 (Wed, 16 Jul 2014)

  New Revision: 46834

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

  Log:
    * vm_core.h: remove rb_vm_t::trap_list[RUBY_NSIG], but add
      rb_vm_t::trap_list_cmds (an array) and
      rb_vm_t::trap_list_safes[RUBY_NSIG]
      (separate to two different array).
      This modification reduce root objects.
    * signal.c: ditto.
    * vm.c (rb_vm_mark): remove marking code for rb_vm_t::trap_list.

  Modified files:
    trunk/ChangeLog
    trunk/signal.c
    trunk/vm.c
    trunk/vm_core.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46833)
+++ ChangeLog	(revision 46834)
@@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 16 18:34:47 2014  Koichi Sasada  <ko1@a...>
+
+	* vm_core.h: remove rb_vm_t::trap_list[RUBY_NSIG], but add
+	  rb_vm_t::trap_list_cmds (an array) and
+	  rb_vm_t::trap_list_safes[RUBY_NSIG]
+	  (separate to two different array).
+
+	  This modification reduce root objects.
+
+	* signal.c: ditto.
+
+	* vm.c (rb_vm_mark): remove marking code for rb_vm_t::trap_list.
+
 Wed Jul 16 18:08:47 2014  Koichi Sasada  <ko1@a...>
 
 	* iseq.c (rb_iseq_defined_string): use rb_gc_mark_object() instead of
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 46833)
+++ vm_core.h	(revision 46834)
@@ -364,10 +364,8 @@ typedef struct rb_vm_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L364
     struct st_table *loading_table;
 
     /* signal */
-    struct {
-	VALUE cmd;
-	int safe;
-    } trap_list[RUBY_NSIG];
+    VALUE trap_list_cmds; /* an Array object */
+    int trap_list_safes[RUBY_NSIG];
 
     /* hook */
     rb_hook_list_t event_hooks;
Index: vm.c
===================================================================
--- vm.c	(revision 46833)
+++ vm.c	(revision 46834)
@@ -1737,8 +1737,6 @@ void rb_vm_trace_mark_event_hooks(rb_hoo https://github.com/ruby/ruby/blob/trunk/vm.c#L1737
 void
 rb_vm_mark(void *ptr)
 {
-    int i;
-
     RUBY_MARK_ENTER("vm");
     RUBY_GC_INFO("-------------------------------------------------\n");
     if (ptr) {
@@ -1766,11 +1764,6 @@ rb_vm_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L1764
 	}
 
 	rb_vm_trace_mark_event_hooks(&vm->event_hooks);
-
-	for (i = 0; i < RUBY_NSIG; i++) {
-	    if (vm->trap_list[i].cmd)
-		rb_gc_mark(vm->trap_list[i].cmd);
-	}
     }
 
     RUBY_MARK_LEAVE("vm");
Index: signal.c
===================================================================
--- signal.c	(revision 46833)
+++ signal.c	(revision 46834)
@@ -861,15 +861,17 @@ signal_exec(VALUE cmd, int safe, int sig https://github.com/ruby/ruby/blob/trunk/signal.c#L861
     }
 }
 
+#define TRAP_LIST_CMD(vm, sig) RARRAY_AREF((vm)->trap_list_cmds, (sig))
+#define TRAP_LIST_SAFE(vm, sig) ((vm)->trap_list_safes[sig])
 void
 rb_trap_exit(void)
 {
     rb_vm_t *vm = GET_VM();
-    VALUE trap_exit = vm->trap_list[0].cmd;
+    VALUE trap_exit = TRAP_LIST_CMD(vm, 0);
 
     if (trap_exit) {
-	vm->trap_list[0].cmd = 0;
-	signal_exec(trap_exit, vm->trap_list[0].safe, 0);
+	RARRAY_ASET(vm->trap_list_cmds, 0, Qfalse);
+	signal_exec(trap_exit, TRAP_LIST_SAFE(vm, 0), 0);
     }
 }
 
@@ -877,8 +879,8 @@ void https://github.com/ruby/ruby/blob/trunk/signal.c#L879
 rb_signal_exec(rb_thread_t *th, int sig)
 {
     rb_vm_t *vm = GET_VM();
-    VALUE cmd = vm->trap_list[sig].cmd;
-    int safe = vm->trap_list[sig].safe;
+    VALUE cmd = TRAP_LIST_CMD(vm, sig);
+    int safe = TRAP_LIST_SAFE(vm, sig);
 
     if (cmd == 0) {
 	switch (sig) {
@@ -1074,7 +1076,7 @@ trap(int sig, sighandler_t func, VALUE c https://github.com/ruby/ruby/blob/trunk/signal.c#L1076
      * RUBY_VM_CHECK_INTS().
      */
     oldfunc = ruby_signal(sig, func);
-    oldcmd = vm->trap_list[sig].cmd;
+    oldcmd = TRAP_LIST_CMD(vm, sig);
     switch (oldcmd) {
       case 0:
       case Qtrue:
@@ -1090,8 +1092,8 @@ trap(int sig, sighandler_t func, VALUE c https://github.com/ruby/ruby/blob/trunk/signal.c#L1092
 	break;
     }
 
-    vm->trap_list[sig].cmd = command;
-    vm->trap_list[sig].safe = rb_safe_level();
+    RARRAY_ASET(vm->trap_list_cmds, sig, command);
+    vm->trap_list_safes[sig] = rb_safe_level();
 
     return oldcmd;
 }
@@ -1240,7 +1242,7 @@ init_sigchld(int sig) https://github.com/ruby/ruby/blob/trunk/signal.c#L1242
 	ruby_signal(sig, oldfunc);
     }
     else {
-	GET_VM()->trap_list[sig].cmd = 0;
+	RARRAY_ASET(GET_VM()->trap_list_cmds, sig, Qfalse);
     }
     rb_enable_interrupt();
 }
@@ -1304,6 +1306,13 @@ void https://github.com/ruby/ruby/blob/trunk/signal.c#L1306
 Init_signal(void)
 {
     VALUE mSignal = rb_define_module("Signal");
+    int i;
+    VALUE cmds = GET_VM()->trap_list_cmds = rb_ary_tmp_new(RUBY_NSIG);
+
+    rb_gc_register_mark_object(cmds);
+    for (i=0; i<RUBY_NSIG; i++) {
+	RARRAY_ASET(cmds, i, Qfalse);
+    }
 
     rb_define_global_function("trap", sig_trap, -1);
     rb_define_module_function(mSignal, "trap", sig_trap, -1);

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

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