summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog23
-rw-r--r--gc.c41
-rw-r--r--thread_pthread.ci10
-rw-r--r--thread_win32.ci2
-rw-r--r--vm.c4
-rw-r--r--vm_core.h2
6 files changed, 58 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index e869f57380..2218eea1cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+Sat Dec 15 13:04:30 2007 Tanaka Akira <akr@fsij.org>
+
+ * 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@ruby-lang.org>
* encoding.c (rb_enc_register, rb_enc_replicate, rb_enc_alias): check
diff --git a/gc.c b/gc.c
index 68d3fa9ffc..c539b59ec0 100644
--- a/gc.c
+++ b/gc.c
@@ -171,15 +171,9 @@ unsigned int _stklen = 0x180000; /* 1.5 kB */
#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 @@ rb_data_object_alloc(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_F
#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 @@ stack_grow_direction(VALUE *addr)
#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 @@ ruby_stack_length(VALUE **p)
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 @@ rb_gc_start(void)
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 @@ Init_stack(VALUE *addr)
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 @@ void ruby_init_stack(VALUE *addr
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 @@ void ruby_init_stack(VALUE *addr
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
diff --git a/thread_pthread.ci b/thread_pthread.ci
index 9d5a7d3d79..6cf43dbeb3 100644
--- a/thread_pthread.ci
+++ b/thread_pthread.ci
@@ -280,13 +280,21 @@ native_thread_create(rb_thread_t *th)
}
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));
diff --git a/thread_win32.ci b/thread_win32.ci
index d71040836b..9c5ef7f33c 100644
--- a/thread_win32.ci
+++ b/thread_win32.ci
@@ -429,6 +429,8 @@ native_thread_create(rb_thread_t *th)
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);
diff --git a/vm.c b/vm.c
index 673026214d..79404a3fa4 100644
--- a/vm.c
+++ b/vm.c
@@ -1738,6 +1738,7 @@ rb_thread_alloc(VALUE klass)
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 @@ Init_BareVM(void)
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);
}
diff --git a/vm_core.h b/vm_core.h
index c2c1420df5..a104778b44 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -431,9 +431,11 @@ struct rb_thread_struct
/* 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;