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

ruby-changes:9813

From: nobu <ko1@a...>
Date: Tue, 6 Jan 2009 18:43:29 +0900 (JST)
Subject: [ruby-changes:9813] Ruby:r21354 (ruby_1_8): * eval.c (stack_extend): streamlined rb_thread_restore_context()

nobu	2009-01-06 18:34:55 +0900 (Tue, 06 Jan 2009)

  New Revision: 21354

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

  Log:
    * eval.c (stack_extend): streamlined rb_thread_restore_context()
      to ensure O(1) time.  based on a patch by Brent Roman <brent AT
      mbari.org>.

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/eval.c

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 21353)
+++ ruby_1_8/ChangeLog	(revision 21354)
@@ -1,3 +1,9 @@
+Tue Jan  6 18:34:53 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* eval.c (stack_extend): streamlined rb_thread_restore_context()
+	  to ensure O(1) time.  based on a patch by Brent Roman <brent AT
+	  mbari.org>.
+
 Tue Jan  6 13:39:18 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* eval.c (cc_mark): frees the continuation's stack if its thread
Index: ruby_1_8/eval.c
===================================================================
--- ruby_1_8/eval.c	(revision 21353)
+++ ruby_1_8/eval.c	(revision 21354)
@@ -10633,9 +10633,8 @@
     th->safe = ruby_safe_level;
 
     th->node = ruby_current_node;
-    if (ruby_sandbox_save != NULL)
-    {
-      ruby_sandbox_save(th);
+    if (ruby_sandbox_save != NULL) {
+	ruby_sandbox_save(th);
     }
 }
 
@@ -10683,20 +10682,19 @@
     (rb_thread_switch(ruby_setjmp(rb_thread_save_context(th), (th)->context)))
 
 NORETURN(static void rb_thread_restore_context _((rb_thread_t,int)));
-NORETURN(NOINLINE(static void rb_thread_restore_context_0(rb_thread_t,int,void*)));
-NORETURN(NOINLINE(static void stack_extend(rb_thread_t, int, VALUE *)));
+NORETURN(NOINLINE(static void rb_thread_restore_context_0(rb_thread_t,int)));
+NORETURN(NOINLINE(static void stack_extend(rb_thread_t, int)));
 
 static void
-rb_thread_restore_context_0(rb_thread_t th, int exit, void *vp)
+rb_thread_restore_context_0(rb_thread_t th, int exit)
 {
     static rb_thread_t tmp;
     static int ex;
     static VALUE tval;
 
     rb_trap_immediate = 0;	/* inhibit interrupts from here */
-    if (ruby_sandbox_restore != NULL)
-    {
-      ruby_sandbox_restore(th);
+    if (ruby_sandbox_restore != NULL) {
+	ruby_sandbox_restore(th);
     }
     ruby_frame = th->frame;
     ruby_scope = th->scope;
@@ -10744,9 +10742,9 @@
 static volatile int C(k), C(l), C(m), C(n), C(o);
 static volatile int C(p), C(q), C(r), C(s), C(t);
 int rb_dummy_false = 0;
-NORETURN(NOINLINE(static void register_stack_extend(rb_thread_t, int, void *, VALUE *)));
+NORETURN(NOINLINE(static void register_stack_extend(rb_thread_t, int, VALUE *)));
 static void
-register_stack_extend(rb_thread_t th, int exit, void *vp, VALUE *curr_bsp)
+register_stack_extend(rb_thread_t th, int exit, VALUE *curr_bsp)
 {
     if (rb_dummy_false) {
         /* use registers as much as possible */
@@ -10760,52 +10758,63 @@
         E(p) = E(q) = E(r) = E(s) = E(t) = 0;
     }
     if (curr_bsp < th->bstr_pos+th->bstr_len) {
-        register_stack_extend(th, exit, &exit, (VALUE*)rb_ia64_bsp());
+        register_stack_extend(th, exit, (VALUE*)rb_ia64_bsp());
     }
-    rb_thread_restore_context_0(th, exit, &exit);
+    stack_extend(th, exit);
 }
 #undef C
 #undef E
 #endif
 
-# if defined(_MSC_VER) && _MSC_VER >= 1300
-__declspec(noinline) static void stack_extend(rb_thread_t, int, VALUE*);
-# endif
 static void
-stack_extend(rb_thread_t th, int exit, VALUE *addr_in_prev_frame)
+stack_extend(rb_thread_t th, int exit)
 {
 #define STACK_PAD_SIZE 1024
-    VALUE space[STACK_PAD_SIZE];
+    volatile VALUE space[STACK_PAD_SIZE], *sp = space;
 
-#if STACK_GROW_DIRECTION < 0
-    if (addr_in_prev_frame > th->stk_pos) stack_extend(th, exit, &space[0]);
-#elif STACK_GROW_DIRECTION > 0
-    if (addr_in_prev_frame < th->stk_pos + th->stk_len) stack_extend(th, exit, &space[STACK_PAD_SIZE-1]);
-#else
-    if (addr_in_prev_frame < rb_gc_stack_start) {
+#if !STACK_GROW_DIRECTION
+    if (space < rb_gc_stack_start) {
         /* Stack grows downward */
-        if (addr_in_prev_frame > th->stk_pos) stack_extend(th, exit, &space[0]);
+#endif
+#if STACK_GROW_DIRECTION <= 0
+	if (space > th->stk_pos) {
+# ifdef HAVE_ALLOCA
+	    sp = ALLOCA_N(VALUE, &space[0] - th->stk_pos);
+# else
+	    stack_extend(th, exit);
+# endif
+	}
+#endif
+#if !STACK_GROW_DIRECTION
     }
     else {
         /* Stack grows upward */
-        if (addr_in_prev_frame < th->stk_pos + th->stk_len) stack_extend(th, exit, &space[STACK_PAD_SIZE-1]);
+#endif
+#if STACK_GROW_DIRECTION >= 0
+	if (&space[STACK_PAD_SIZE] < th->stk_pos + th->stk_len) {
+# ifdef HAVE_ALLOCA
+	    sp = ALLOCA_N(VALUE, th->stk_pos + th->stk_len - &space[STACK_PAD_SIZE]);
+# else
+	    stack_extend(th, exit);
+# endif
+	}
+#endif
+#if !STACK_GROW_DIRECTION
     }
 #endif
+    rb_thread_restore_context_0(th, exit);
+}
 #ifdef __ia64
-    register_stack_extend(th, exit, space, (VALUE*)rb_ia64_bsp());
-#else
-    rb_thread_restore_context_0(th, exit, space);
+#define stack_extend(th, exit) register_stack_extend(th, exit, (VALUE*)rb_ia64_bsp())
 #endif
-}
 
 static void
 rb_thread_restore_context(th, exit)
     rb_thread_t th;
     int exit;
 {
-    VALUE v;
     if (!th->stk_ptr) rb_bug("unsaved context");
-    stack_extend(th, exit, &v);
+    stack_extend(th, exit);
 }
 
 static void
@@ -12121,9 +12130,9 @@
     th->locals = 0;\
     th->thread = 0;\
     if (curr_thread == 0) {\
-      th->sandbox = Qnil;\
+	th->sandbox = Qnil;\
     } else {\
-      th->sandbox = curr_thread->sandbox;\
+	th->sandbox = curr_thread->sandbox;\
     }\
 } while (0)
 

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

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