Project

General

Profile

Feature #2294 » ruby_bind_stack.patch

reduce runtime overhead - sunaku (Suraj Kurapati), 11/01/2009 04:12 AM

View differences:

ChangeLog
* io.c (io_cntl): F_DUPFD is platform dependent.
Mon Oct 25 13:28:00 2009 Suraj N. Kurapati <sunaku@gmail.com>
* include/ruby/ruby.h: declare ruby_bind_stack(). [ruby-core:26361]
* gc.c: implement ruby_bind_stack(). restrict GC marking
region to ruby_bind_stack() boundaries for main thread.
refactor common code from mark_current_machine_context()
and rb_gc_mark_machine_stack() into get_machine_stack_bounds().
Sun Oct 25 10:19:09 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/dl/handle.c (rb_dlhandle_close): fixed an invalid local
gc.c
#include "eval_intern.h"
#include "vm_core.h"
#include "gc.h"
#include <assert.h>
#include <stdio.h>
#include <setjmp.h>
#include <sys/types.h>
......
void rb_vm_mark(void *ptr);
static VALUE *ruby_stack_lower_bound = 0, *ruby_stack_upper_bound = 0;
static char ruby_stack_is_bound = 0;
void
ruby_bind_stack(void *lower_boundary, void *upper_boundary)
{
assert(upper_boundary > lower_boundary && lower_boundary > 0);
ruby_stack_lower_bound = lower_boundary;
ruby_stack_upper_bound = upper_boundary;
ruby_stack_is_bound = 1;
}
static void
get_machine_stack_bounds(rb_thread_t *th, VALUE **stack_start, VALUE **stack_end, unsigned stack_end_increment)
{
#if STACK_GROW_DIRECTION < 0
*stack_start = th->machine_stack_end;
*stack_end = th->machine_stack_start;
#elif STACK_GROW_DIRECTION > 0
*stack_start = th->machine_stack_start;
*stack_end = th->machine_stack_end + stack_end_increment;
#else
if (th->machine_stack_end < th->machine_stack_start) {
*stack_start = th->machine_stack_end;
*stack_end = th->machine_stack_start;
}
else {
*stack_start = th->machine_stack_start;
*stack_end = th->machine_stack_end + stack_end_increment;
}
#endif
if (ruby_stack_is_bound && th == th->vm->main_thread) {
if (*stack_start < ruby_stack_lower_bound) {
*stack_start = ruby_stack_lower_bound;
}
if (*stack_end > ruby_stack_upper_bound) {
*stack_end = ruby_stack_upper_bound;
}
}
}
static void
mark_current_machine_context(rb_objspace_t *objspace, rb_thread_t *th)
{
......
rb_setjmp(save_regs_gc_mark);
SET_STACK_END;
#if STACK_GROW_DIRECTION < 0
stack_start = th->machine_stack_end;
stack_end = th->machine_stack_start;
#elif STACK_GROW_DIRECTION > 0
stack_start = th->machine_stack_start;
stack_end = th->machine_stack_end + 1;
#else
if (th->machine_stack_end < th->machine_stack_start) {
stack_start = th->machine_stack_end;
stack_end = th->machine_stack_start;
}
else {
stack_start = th->machine_stack_start;
stack_end = th->machine_stack_end + 1;
}
#endif
get_machine_stack_bounds(th, &stack_start, &stack_end, 1);
mark_locations_array(objspace,
(VALUE*)save_regs_gc_mark,
......
void
rb_gc_mark_machine_stack(rb_thread_t *th)
{
VALUE *stack_start, *stack_end;
get_machine_stack_bounds(th, &stack_start, &stack_end, 0);
rb_objspace_t *objspace = &rb_objspace;
#if STACK_GROW_DIRECTION < 0
rb_gc_mark_locations(th->machine_stack_end, th->machine_stack_start);
#elif STACK_GROW_DIRECTION > 0
rb_gc_mark_locations(th->machine_stack_start, th->machine_stack_end);
#else
if (th->machine_stack_start < th->machine_stack_end) {
rb_gc_mark_locations(th->machine_stack_start, th->machine_stack_end);
}
else {
rb_gc_mark_locations(th->machine_stack_end, th->machine_stack_start);
}
#endif
rb_gc_mark_locations(stack_start, stack_end);
#ifdef __ia64
rb_gc_mark_locations(th->machine_register_stack_start, th->machine_register_stack_end);
#endif
include/ruby/ruby.h
#define RUBY_INIT_STACK \
VALUE variable_in_this_stack_frame; \
ruby_init_stack(&variable_in_this_stack_frame);
/*
* Binds the stack of Ruby's main thread to the region of memory that spans
* inclusively from the given lower boundary to the given upper boundary:
*
* lower boundary <= stack pointer of Ruby's main thread <= upper boundary
*
* These boundaries *do not* protect Ruby's main thread against stack
* overflow and they *do not* apply to non-main Ruby threads (whose stacks
* are dynamically allocated and managed by the native Operating System).
*/
void ruby_bind_stack(void *lower_boundary, void *upper_boundary);
void ruby_init(void);
void *ruby_options(int, char**);
int ruby_run_node(void *);
(18-18/26)