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

ruby-changes:2744

From: ko1@a...
Date: 15 Dec 2007 13:32:44 +0900
Subject: [ruby-changes:2744] akr - Ruby:r14235 (trunk): * vm_core.h (rb_thread_t): new member machine_stack_maxsize and

akr	2007-12-15 13:09:24 +0900 (Sat, 15 Dec 2007)

  New Revision: 14235

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
    trunk/thread_pthread.ci
    trunk/thread_win32.ci
    trunk/vm.c
    trunk/vm_core.h

  Log:
    * vm_core.h (rb_thread_t): new member machine_stack_maxsize and
      machine_register_stack_maxsize.
    
    * gc.c (rb_gc_stack_maxsize): new global variable for the thread size
      of the main thread.
      (STACK_LEVEL_MAX): use machine_stack_maxsize of current thread.
      (ruby_stack_check): check IA64 register stack.
      (ruby_set_stack_size): set rb_gc_stack_maxsize.
      (Init_stack): set rb_gc_stack_maxsize.
    
    * thread_pthread.ci (native_thread_create): initialize
      th->machine_stack_maxsize and th->machine_register_stack_maxsize.
    
    * vm.c (Init_BareVM): initialize th->machine_stack_maxsize and
      th->machine_register_stack_maxsize.
    
    * thread_win32.ci (native_thread_create): initialize
      th->machine_stack_maxsize.  not tested.  just a guess at all.
    
    [ruby-dev:32604]
    


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/thread_win32.ci?r1=14235&r2=14234
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/thread_pthread.ci?r1=14235&r2=14234
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14235&r2=14234
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/gc.c?r1=14235&r2=14234
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/vm_core.h?r1=14235&r2=14234
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/vm.c?r1=14235&r2=14234

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14234)
+++ ChangeLog	(revision 14235)
@@ -1,3 +1,26 @@
+Sat Dec 15 13:04:30 2007  Tanaka Akira  <akr@f...>
+
+	* vm_core.h (rb_thread_t): new member machine_stack_maxsize and
+	  machine_register_stack_maxsize.
+
+	* gc.c (rb_gc_stack_maxsize): new global variable for the thread size
+	  of the main thread.
+	  (STACK_LEVEL_MAX): use machine_stack_maxsize of current thread.
+	  (ruby_stack_check): check IA64 register stack.
+	  (ruby_set_stack_size): set rb_gc_stack_maxsize.
+	  (Init_stack): set rb_gc_stack_maxsize.
+
+	* thread_pthread.ci (native_thread_create): initialize
+	  th->machine_stack_maxsize and th->machine_register_stack_maxsize.
+
+	* vm.c (Init_BareVM): initialize th->machine_stack_maxsize and
+	  th->machine_register_stack_maxsize.
+
+	* thread_win32.ci (native_thread_create): initialize
+	  th->machine_stack_maxsize.  not tested.  just a guess at all.
+
+	[ruby-dev:32604]
+
 Sat Dec 15 12:58:00 2007  Nobuyoshi Nakada  <nobu@r...>
 
 	* encoding.c (rb_enc_register, rb_enc_replicate, rb_enc_alias): check
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 14234)
+++ vm_core.h	(revision 14235)
@@ -431,9 +431,11 @@
     /* for GC */
     VALUE *machine_stack_start;
     VALUE *machine_stack_end;
+    size_t machine_stack_maxsize;
 #ifdef __ia64
     VALUE *machine_register_stack_start;
     VALUE *machine_register_stack_end;
+    size_t machine_register_stack_maxsize;
 #endif
     jmp_buf machine_regs;
     int mark_stack_len;
Index: gc.c
===================================================================
--- gc.c	(revision 14234)
+++ gc.c	(revision 14235)
@@ -171,15 +171,9 @@
 #endif
 
 #if defined(DJGPP) || defined(_WIN32_WCE)
-static unsigned int STACK_LEVEL_MAX = 65535;
-#elif defined(__human68k__)
-unsigned int _stacksize = 262144;
-# define STACK_LEVEL_MAX (_stacksize - 4096)
-# undef HAVE_GETRLIMIT
-#elif defined(HAVE_GETRLIMIT) || defined(_WIN32)
-static unsigned int STACK_LEVEL_MAX = 655300;
+size_t rb_gc_stack_maxsize = 65535*sizeof(VALUE);
 #else
-# define STACK_LEVEL_MAX 655300
+size_t rb_gc_stack_maxsize = 655300*sizeof(VALUE);
 #endif
 
 
@@ -579,6 +573,7 @@
 
 #define STACK_START (th->machine_stack_start)
 #define STACK_END (th->machine_stack_end)
+#define STACK_LEVEL_MAX (th->machine_stack_maxsize/sizeof(VALUE))
 
 #if defined(sparc) || defined(__sparc__)
 # define STACK_LENGTH  (STACK_START - STACK_END + 0x80)
@@ -611,11 +606,6 @@
 
 #define GC_WATER_MARK 512
 
-#define CHECK_STACK(ret) do {\
-    SET_STACK_END;\
-    (ret) = (STACK_LENGTH > STACK_LEVEL_MAX + GC_WATER_MARK);\
-} while (0)
-
 int
 ruby_stack_length(VALUE **p)
 {
@@ -628,10 +618,17 @@
 int
 ruby_stack_check(void)
 {
-  int ret;
-  rb_thread_t *th = GET_THREAD();
-  CHECK_STACK(ret);
-  return ret;
+    int ret;
+    rb_thread_t *th = GET_THREAD();
+    SET_STACK_END;
+    ret = STACK_LENGTH > STACK_LEVEL_MAX + GC_WATER_MARK;
+#ifdef __ia64
+    if (!ret) {
+        ret = (VALUE*)rb_ia64_bsp() - th->machine_register_stack_start >
+              th->machine_register_stack_maxsize/sizeof(VALUE) + GC_WATER_MARK;
+    }
+#endif
+    return ret;
 }
 
 static void
@@ -1576,9 +1573,7 @@
 void
 ruby_set_stack_size(size_t size)
 {
-#ifndef STACK_LEVEL_MAX
-    STACK_LEVEL_MAX = size/sizeof(VALUE);
-#endif
+    rb_gc_stack_maxsize = size;
 }
 
 void
@@ -1638,7 +1633,7 @@
 	    unsigned int space = rlim.rlim_cur/5;
 
 	    if (space > 1024*1024) space = 1024*1024;
-	    STACK_LEVEL_MAX = (rlim.rlim_cur - space) / sizeof(VALUE);
+	    rb_gc_stack_maxsize = rlim.rlim_cur - space;
 	}
     }
 #endif
@@ -1670,7 +1665,7 @@
 	    unsigned int space = rlim.rlim_cur/5;
 
 	    if (space > 1024*1024) space = 1024*1024;
-	    STACK_LEVEL_MAX = (rlim.rlim_cur - space) / sizeof(VALUE);
+	    rb_gc_stack_maxsize = rlim.rlim_cur - space;
 	}
     }
 #elif defined _WIN32
@@ -1683,7 +1678,7 @@
 	    size = (char *)mi.BaseAddress - (char *)mi.AllocationBase;
 	    space = size / 5;
 	    if (space > 1024*1024) space = 1024*1024;
-	    STACK_LEVEL_MAX = (size - space) / sizeof(VALUE);
+            rb_gc_stack_maxsize = size - space;
 	}
     }
 #endif
Index: thread_pthread.ci
===================================================================
--- thread_pthread.ci	(revision 14234)
+++ thread_pthread.ci	(revision 14235)
@@ -280,13 +280,21 @@
     }
     else {
 	pthread_attr_t attr;
-	size_t stack_size = 1024 * 1024; /* 1024KB */
+	size_t stack_size = 512 * 1024; /* 512KB */
+        size_t space;
 
 #ifdef PTHREAD_STACK_MIN
 	if (stack_size < PTHREAD_STACK_MIN) {
 	    stack_size = PTHREAD_STACK_MIN * 2;
 	}
 #endif
+        space = stack_size/5;
+        if (space > 1024*1024) space = 1024*1024;
+        th->machine_stack_maxsize = stack_size - space;
+#ifdef __ia64
+        th->machine_stack_maxsize /= 2;
+        th->machine_register_stack_maxsize = th->machine_stack_maxsize;
+#endif
 
 	CHECK_ERR(pthread_attr_init(&attr));
 
Index: vm.c
===================================================================
--- vm.c	(revision 14234)
+++ vm.c	(revision 14235)
@@ -1738,6 +1738,7 @@
 
 VALUE insns_name_array(void);
 extern VALUE *rb_gc_stack_start;
+extern size_t rb_gc_stack_maxsize;
 #ifdef __ia64
 extern VALUE *rb_gc_register_stack_start;
 #endif
@@ -1872,8 +1873,11 @@
     th_init2(th);
     th->vm = vm;
     th->machine_stack_start = rb_gc_stack_start;
+    th->machine_stack_maxsize = rb_gc_stack_maxsize;
 #ifdef __ia64
     th->machine_register_stack_start = rb_gc_register_stack_start;
+    th->machine_stack_maxsize /= 2;
+    th->machine_register_stack_maxsize = th->machine_stack_maxsize;
 #endif
     rb_thread_set_current_raw(th);
 }
Index: thread_win32.ci
===================================================================
--- thread_win32.ci	(revision 14234)
+++ thread_win32.ci	(revision 14235)
@@ -429,6 +429,8 @@
     size_t stack_size = 4 * 1024; /* 4KB */
     th->thread_id = w32_create_thread(stack_size, thread_start_func_1, th);
 
+    th->machine_stack_maxsize = 64 * 1024; /* not tested.  just a guess at all. */
+
     if ((th->thread_id) == 0) {
 	st_delete_wrap(th->vm->living_threads, th->self);
 	rb_raise(rb_eThreadError, "can't create Thread (%d)", errno);

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

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