Project

General

Profile

Feature #2294 ยป ruby_bind_stack_after_refactoring.patch

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

View differences:

ChangeLog
337 337

  
338 338
Mon Oct 25 13:28:00 2009  Suraj N. Kurapati <sunaku@gmail.com>
339 339

  
340
	* include/ruby/ruby.h: declare ruby_bind_stack(). [ruby-core:26361]
341

  
342
	* gc.c: implement ruby_bind_stack().  restrict GC marking
343
	  region to ruby_bind_stack() boundaries for main thread.
344

  
345
Mon Oct 25 13:28:00 2009  Suraj N. Kurapati <sunaku@gmail.com>
346

  
340 347
	* gc.c: refactor common code from mark_current_machine_context()
341 348
	  and rb_gc_mark_machine_stack() into get_machine_stack_bounds().
342 349

  
gc.c
19 19
#include "eval_intern.h"
20 20
#include "vm_core.h"
21 21
#include "gc.h"
22
#include <assert.h>
22 23
#include <stdio.h>
23 24
#include <setjmp.h>
24 25
#include <sys/types.h>
......
2089 2090

  
2090 2091
void rb_vm_mark(void *ptr);
2091 2092

  
2093
static VALUE *ruby_stack_lower_bound = 0, *ruby_stack_upper_bound = 0;
2094
static char ruby_stack_is_bound = 0;
2095

  
2096
void
2097
ruby_bind_stack(void *lower_boundary, void *upper_boundary)
2098
{
2099
    assert(upper_boundary > lower_boundary && lower_boundary > 0);
2100
    ruby_stack_lower_bound = lower_boundary;
2101
    ruby_stack_upper_bound = upper_boundary;
2102
    ruby_stack_is_bound = 1;
2103
}
2104

  
2092 2105
static void
2093 2106
get_machine_stack_bounds(rb_thread_t *th, VALUE **stack_start, VALUE **stack_end, unsigned stack_end_increment)
2094 2107
{
......
2108 2121
        *stack_end = th->machine_stack_end + stack_end_increment;
2109 2122
    }
2110 2123
#endif
2124
    if (ruby_stack_is_bound && th == th->vm->main_thread) {
2125
        if (*stack_start < ruby_stack_lower_bound) {
2126
          *stack_start = ruby_stack_lower_bound;
2127
        }
2128

  
2129
        if (*stack_end > ruby_stack_upper_bound) {
2130
          *stack_end = ruby_stack_upper_bound;
2131
        }
2132
    }
2111 2133
}
2112 2134

  
2113 2135
static void
include/ruby/ruby.h
1143 1143
#define RUBY_INIT_STACK \
1144 1144
    VALUE variable_in_this_stack_frame; \
1145 1145
    ruby_init_stack(&variable_in_this_stack_frame);
1146
/*
1147
 *  Binds the stack of Ruby's main thread to the region of memory that spans
1148
 *  inclusively from the given lower boundary to the given upper boundary:
1149
 *
1150
 *    lower boundary <= stack pointer of Ruby's main thread <= upper boundary
1151
 *
1152
 *  These boundaries *do not* protect Ruby's main thread against stack
1153
 *  overflow and they *do not* apply to non-main Ruby threads (whose stacks
1154
 *  are dynamically allocated and managed by the native Operating System).
1155
 */
1156
void ruby_bind_stack(void *lower_boundary, void *upper_boundary);
1146 1157
void ruby_init(void);
1147 1158
void *ruby_options(int, char**);
1148 1159
int ruby_run_node(void *);
1149
-