* compile.c, compile.h (DECL_ANCHOR, INIT_ANCHOR): split not to

initialize aggregations with dynamic values.  [ruby-talk:259306]

* eval.c (rb_protect): not to initialize aggregations with dynamic
  values.  [ruby-talk:259306]

* gc.c (mark_current_machine_context): ditto.

* thread.c (thgroup_list, call_trace_func): ditto.

* vm.c (vm_init_redefined_flag): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-07-20 07:11:35 +00:00
parent 98a54d46f7
commit 39c56c3349
7 changed files with 102 additions and 74 deletions

View File

@ -1,3 +1,17 @@
Fri Jul 20 16:11:33 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c, compile.h (DECL_ANCHOR, INIT_ANCHOR): split not to
initialize aggregations with dynamic values. [ruby-talk:259306]
* eval.c (rb_protect): not to initialize aggregations with dynamic
values. [ruby-talk:259306]
* gc.c (mark_current_machine_context): ditto.
* thread.c (thgroup_list, call_trace_func): ditto.
* vm.c (vm_init_redefined_flag): ditto.
Fri Jul 20 15:22:51 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Jul 20 15:22:51 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/openssl/ossl_config.c (ossl_config_set_section): do not * ext/openssl/ossl_config.c (ossl_config_set_section): do not

View File

@ -139,6 +139,7 @@ iseq_compile(VALUE self, NODE *node)
{ {
DECL_ANCHOR(ret); DECL_ANCHOR(ret);
rb_iseq_t *iseq; rb_iseq_t *iseq;
INIT_ANCHOR(ret);
GetISeqPtr(self, iseq); GetISeqPtr(self, iseq);
if (node == 0) { if (node == 0) {
@ -1827,6 +1828,7 @@ compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root,
int len = node->nd_alen, line = nd_line(node), i=0; int len = node->nd_alen, line = nd_line(node), i=0;
DECL_ANCHOR(anchor); DECL_ANCHOR(anchor);
INIT_ANCHOR(anchor);
if (nd_type(node) != NODE_ZARRAY) { if (nd_type(node) != NODE_ZARRAY) {
while (node) { while (node) {
if (nd_type(node) != NODE_ARRAY) { if (nd_type(node) != NODE_ARRAY) {
@ -1951,6 +1953,7 @@ make_masgn_lhs(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node)
} }
default: { default: {
DECL_ANCHOR(anchor); DECL_ANCHOR(anchor);
INIT_ANCHOR(anchor);
COMPILE_POPED(anchor, "masgn lhs", node); COMPILE_POPED(anchor, "masgn lhs", node);
/* dump_disasm_list(FIRST_ELEMENT(anchor)); */ /* dump_disasm_list(FIRST_ELEMENT(anchor)); */
REMOVE_ELEM(FIRST_ELEMENT(anchor)); REMOVE_ELEM(FIRST_ELEMENT(anchor));
@ -2060,6 +2063,7 @@ compile_massign(rb_iseq_t *iseq, LINK_ANCHOR *ret,
while (n) { while (n) {
DECL_ANCHOR(lhs); DECL_ANCHOR(lhs);
INIT_ANCHOR(lhs);
COMPILE_POPED(lhs, "post", n->nd_head); COMPILE_POPED(lhs, "post", n->nd_head);
if (nd_type(n->nd_head) != NODE_MASGN) { if (nd_type(n->nd_head) != NODE_MASGN) {
@ -2416,10 +2420,13 @@ add_ensure_iseq(LINK_ANCHOR *ret, rb_iseq_t *iseq)
struct iseq_compile_data_ensure_node_stack *prev_enlp = enlp; struct iseq_compile_data_ensure_node_stack *prev_enlp = enlp;
DECL_ANCHOR(ensure); DECL_ANCHOR(ensure);
INIT_ANCHOR(ensure);
while (enlp) { while (enlp) {
DECL_ANCHOR(ensure_part); DECL_ANCHOR(ensure_part);
LABEL *lstart = NEW_LABEL(0); LABEL *lstart = NEW_LABEL(0);
LABEL *lend = NEW_LABEL(0); LABEL *lend = NEW_LABEL(0);
INIT_ANCHOR(ensure_part);
add_ensure_range(iseq, enlp->erange, lstart, lend); add_ensure_range(iseq, enlp->erange, lstart, lend);
iseq->compile_data->ensure_node_stack = enlp->prev; iseq->compile_data->ensure_node_stack = enlp->prev;
@ -2442,6 +2449,8 @@ setup_args(rb_iseq_t *iseq, LINK_ANCHOR *args, NODE *argn, unsigned long *flag)
DECL_ANCHOR(arg_block); DECL_ANCHOR(arg_block);
DECL_ANCHOR(args_splat); DECL_ANCHOR(args_splat);
INIT_ANCHOR(arg_block);
INIT_ANCHOR(args_splat);
if (argn && nd_type(argn) == NODE_BLOCK_PASS) { if (argn && nd_type(argn) == NODE_BLOCK_PASS) {
COMPILE(arg_block, "block", argn->nd_body); COMPILE(arg_block, "block", argn->nd_body);
*flag |= VM_CALL_ARGS_BLOCKARG_BIT; *flag |= VM_CALL_ARGS_BLOCKARG_BIT;
@ -2463,6 +2472,7 @@ setup_args(rb_iseq_t *iseq, LINK_ANCHOR *args, NODE *argn, unsigned long *flag)
int next_is_array = (nd_type(argn->nd_head) == NODE_ARRAY); int next_is_array = (nd_type(argn->nd_head) == NODE_ARRAY);
DECL_ANCHOR(tmp); DECL_ANCHOR(tmp);
INIT_ANCHOR(tmp);
COMPILE(tmp, "args (cat: splat)", argn->nd_body); COMPILE(tmp, "args (cat: splat)", argn->nd_body);
if (next_is_array && nsplat == 0) { if (next_is_array && nsplat == 0) {
/* none */ /* none */
@ -2565,6 +2575,9 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
DECL_ANCHOR(else_seq); DECL_ANCHOR(else_seq);
LABEL *then_label, *else_label, *end_label; LABEL *then_label, *else_label, *end_label;
INIT_ANCHOR(cond_seq);
INIT_ANCHOR(then_seq);
INIT_ANCHOR(else_seq);
then_label = NEW_LABEL(nd_line(node)); then_label = NEW_LABEL(nd_line(node));
else_label = NEW_LABEL(nd_line(node)); else_label = NEW_LABEL(nd_line(node));
end_label = NEW_LABEL(nd_line(node)); end_label = NEW_LABEL(nd_line(node));
@ -2596,6 +2609,9 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
DECL_ANCHOR(cond_seq); DECL_ANCHOR(cond_seq);
VALUE special_literals = rb_ary_new(); VALUE special_literals = rb_ary_new();
INIT_ANCHOR(head);
INIT_ANCHOR(body_seq);
INIT_ANCHOR(cond_seq);
if (node->nd_head == 0) { if (node->nd_head == 0) {
COMPILE_(ret, "when", node->nd_body, poped); COMPILE_(ret, "when", node->nd_body, poped);
break; break;
@ -2692,6 +2708,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
LABEL *endlabel; LABEL *endlabel;
DECL_ANCHOR(body_seq); DECL_ANCHOR(body_seq);
INIT_ANCHOR(body_seq);
endlabel = NEW_LABEL(nd_line(node)); endlabel = NEW_LABEL(nd_line(node));
while (node && nd_type(node) == NODE_WHEN) { while (node && nd_type(node) == NODE_WHEN) {
@ -3075,14 +3092,16 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
LABEL *lstart = NEW_LABEL(nd_line(node)); LABEL *lstart = NEW_LABEL(nd_line(node));
LABEL *lend = NEW_LABEL(nd_line(node)); LABEL *lend = NEW_LABEL(nd_line(node));
LABEL *lcont = NEW_LABEL(nd_line(node)); LABEL *lcont = NEW_LABEL(nd_line(node));
struct ensure_range er = { lstart, lend, 0 }; struct ensure_range er = { 0 };
struct iseq_compile_data_ensure_node_stack enl = { struct iseq_compile_data_ensure_node_stack enl;
node->nd_ensr,
iseq->compile_data->ensure_node_stack, /* prev */
&er,
};
struct ensure_range *erange; struct ensure_range *erange;
INIT_ANCHOR(ensr);
er.begin = lstart;
er.end = lend;
enl.ensure_node = node->nd_ensr;
enl.prev = iseq->compile_data->ensure_node_stack; /* prev */
enl.erange = &er;
COMPILE_POPED(ensr, "ensure ensr", node->nd_ensr); COMPILE_POPED(ensr, "ensure ensr", node->nd_ensr);
iseq->compile_data->ensure_node_stack = &enl; iseq->compile_data->ensure_node_stack = &enl;
@ -3256,6 +3275,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
* nd_mid * nd_mid
*/ */
INIT_ANCHOR(args);
COMPILE(ret, "NODE_OP_ASGN1 recv", node->nd_recv); COMPILE(ret, "NODE_OP_ASGN1 recv", node->nd_recv);
argc = compile_array(iseq, args, node->nd_args->nd_body, Qfalse); argc = compile_array(iseq, args, node->nd_args->nd_body, Qfalse);
POP_ELEMENT(args); POP_ELEMENT(args);
@ -3448,6 +3468,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
VALUE parent_block = iseq->compile_data->current_block; VALUE parent_block = iseq->compile_data->current_block;
iseq->compile_data->current_block = Qfalse; iseq->compile_data->current_block = Qfalse;
INIT_ANCHOR(recv);
INIT_ANCHOR(args);
#if SUPPORT_JOKE #if SUPPORT_JOKE
if (nd_type(node) == NODE_VCALL) { if (nd_type(node) == NODE_VCALL) {
if (mid == idBitblt) { if (mid == idBitblt) {
@ -3543,8 +3565,9 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
VALUE argc; VALUE argc;
unsigned long flag = 0; unsigned long flag = 0;
VALUE parent_block = iseq->compile_data->current_block; VALUE parent_block = iseq->compile_data->current_block;
iseq->compile_data->current_block = Qfalse;
INIT_ANCHOR(args);
iseq->compile_data->current_block = Qfalse;
if (nd_type(node) == NODE_SUPER) { if (nd_type(node) == NODE_SUPER) {
argc = setup_args(iseq, args, node->nd_args, &flag); argc = setup_args(iseq, args, node->nd_args, &flag);
} }
@ -3647,6 +3670,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
VALUE size = 0; VALUE size = 0;
int type = node->nd_head ? nd_type(node->nd_head) : NODE_ZARRAY; int type = node->nd_head ? nd_type(node->nd_head) : NODE_ZARRAY;
INIT_ANCHOR(list);
switch (type) { switch (type) {
case NODE_ARRAY:{ case NODE_ARRAY:{
compile_array(iseq, list, node->nd_head, Qfalse); compile_array(iseq, list, node->nd_head, Qfalse);
@ -3704,6 +3728,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
VALUE argc; VALUE argc;
unsigned long flag = 0; unsigned long flag = 0;
INIT_ANCHOR(args);
if (iseq->type == ISEQ_TYPE_TOP || iseq->type == ISEQ_TYPE_CLASS) { if (iseq->type == ISEQ_TYPE_TOP || iseq->type == ISEQ_TYPE_CLASS) {
COMPILE_ERROR((ERROR_ARGS "Illegal yield")); COMPILE_ERROR((ERROR_ARGS "Illegal yield"));
} }
@ -3813,6 +3838,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
DECL_ANCHOR(recv); DECL_ANCHOR(recv);
DECL_ANCHOR(val); DECL_ANCHOR(val);
INIT_ANCHOR(recv);
INIT_ANCHOR(val);
switch(nd_type(node)) { switch(nd_type(node)) {
case NODE_MATCH: case NODE_MATCH:
ADD_INSN1(recv, nd_line(node), putobject, node->nd_lit); ADD_INSN1(recv, nd_line(node), putobject, node->nd_lit);
@ -4081,6 +4108,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
DECL_ANCHOR(pref); DECL_ANCHOR(pref);
DECL_ANCHOR(body); DECL_ANCHOR(body);
INIT_ANCHOR(pref);
INIT_ANCHOR(body);
compile_colon2(iseq, node, pref, body); compile_colon2(iseq, node, pref, body);
if (LIST_SIZE_ZERO(pref)) { if (LIST_SIZE_ZERO(pref)) {
if (iseq->compile_data->option->inline_const_cache) { if (iseq->compile_data->option->inline_const_cache) {
@ -4278,6 +4307,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
unsigned long flag = 0; unsigned long flag = 0;
VALUE argc; VALUE argc;
INIT_ANCHOR(recv);
INIT_ANCHOR(args);
argc = setup_args(iseq, args, node->nd_args, &flag); argc = setup_args(iseq, args, node->nd_args, &flag);
if (node->nd_recv == (NODE *) 1) { if (node->nd_recv == (NODE *) 1) {
@ -4717,6 +4748,7 @@ iseq_build_from_ary(rb_iseq_t *iseq, VALUE locals, VALUE args,
DECL_ANCHOR(anchor); DECL_ANCHOR(anchor);
INIT_ANCHOR(anchor);
if (iseq->type == ISEQ_TYPE_METHOD || if (iseq->type == ISEQ_TYPE_METHOD ||
iseq->type == ISEQ_TYPE_TOP || iseq->type == ISEQ_TYPE_TOP ||
iseq->type == ISEQ_TYPE_CLASS) { iseq->type == ISEQ_TYPE_CLASS) {

View File

@ -211,8 +211,12 @@ r_value(VALUE value)
#define COMPILE_OK 1 #define COMPILE_OK 1
#define COMPILE_NG 0 #define COMPILE_NG 0
/* leave name uninitialized so that compiler warn if INIT_ANCHOR is
* missing */
#define DECL_ANCHOR(name) \ #define DECL_ANCHOR(name) \
LINK_ANCHOR name##_body__ = {{0,}, &name##_body__.anchor}; \ LINK_ANCHOR *name, name##_body__ = {{0,},}
LINK_ANCHOR *name = & name##_body__ #define INIT_ANCHOR(name) \
(name##_body__.last = &name##_body__.anchor, name = &name##_body__)
#endif /* RUBY_COMPILE_H */ #endif /* RUBY_COMPILE_H */

6
eval.c
View File

@ -1146,9 +1146,9 @@ rb_protect(VALUE (*proc) (VALUE), VALUE data, int *state)
int status; int status;
rb_thread_t *th = GET_THREAD(); rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp = th->cfp; rb_control_frame_t *cfp = th->cfp;
struct rb_vm_trap_tag trap_tag = { struct rb_vm_trap_tag trap_tag;
th->trap_tag,
}; trap_tag.prev = th->trap_tag;
PUSH_TAG(); PUSH_TAG();
th->trap_tag = &trap_tag; th->trap_tag = &trap_tag;

37
gc.c
View File

@ -1403,41 +1403,18 @@ mark_current_machine_context(rb_thread_t *th)
FLUSH_REGISTER_WINDOWS; FLUSH_REGISTER_WINDOWS;
/* This assumes that all registers are saved into the jmp_buf (and stack) */ /* This assumes that all registers are saved into the jmp_buf (and stack) */
setjmp(save_regs_gc_mark); setjmp(save_regs_gc_mark);
mark_locations_array((VALUE*)save_regs_gc_mark,
sizeof(save_regs_gc_mark) / sizeof(VALUE));
{ mark_locations_array(stack_start, stack_end - stack_start);
struct { VALUE *start; VALUE *end; } regions[] = {
{ (VALUE*)save_regs_gc_mark,
(VALUE*)save_regs_gc_mark +
sizeof(save_regs_gc_mark) / sizeof(VALUE *) },
{ stack_start, stack_end }
#ifdef __ia64 #ifdef __ia64
, { th->machine_register_stack_start, mark_locations_array(th->machine_register_stack_start,
th->machine_register_stack_end } th->machine_register_stack_end - th->machine_register_stack_start);
#endif #endif
#if defined(__human68k__) || defined(__mc68000__) #if defined(__human68k__) || defined(__mc68000__)
, { (VALUE*)((char*)STACK_END + 2), mark_locations_array((VALUE*)((char*)STACK_END + 2),
(VALUE*)((char*)STACK_START + 2) } (STACK_START - STACK_END));
#endif #endif
};
int i;
for (i = 0; i < sizeof(regions)/sizeof(*regions); i++) {
/* stack scanning code is inlined here
* because function call grows stack.
* don't call mark_locations_array,
* rb_gc_mark_locations, etc. */
VALUE *x, n, v;
x = regions[i].start;
n = regions[i].end - x;
while (n--) {
v = *x;
VALGRIND_MAKE_MEM_DEFINED(&v, sizeof(v));
if (is_pointer_to_heap((void *)v)) {
gc_mark(v, 0);
}
x++;
}
}
}
} }
static int static int

View File

@ -1964,9 +1964,10 @@ static VALUE
thgroup_list(VALUE group) thgroup_list(VALUE group)
{ {
VALUE ary = rb_ary_new(); VALUE ary = rb_ary_new();
struct thgroup_list_params param = { struct thgroup_list_params param;
ary, group,
}; param.ary = ary;
param.group = group;
st_foreach(GET_THREAD()->vm->living_threads, thgroup_list_i, (st_data_t) & param); st_foreach(GET_THREAD()->vm->living_threads, thgroup_list_i, (st_data_t) & param);
return ary; return ary;
} }
@ -2808,7 +2809,13 @@ call_trace_proc(VALUE args)
static void static void
call_trace_func(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass) call_trace_func(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass)
{ {
struct call_trace_func_args args = {event, proc, self, id, klass}; struct call_trace_func_args args;
args.event = event;
args.proc = proc;
args.self = self;
args.id = id;
args.klass = klass;
ruby_suppress_tracing(call_trace_proc, (VALUE)&args); ruby_suppress_tracing(call_trace_proc, (VALUE)&args);
} }

50
vm.c
View File

@ -1009,36 +1009,30 @@ add_opt_method(VALUE klass, ID mid, VALUE bop)
static void static void
vm_init_redefined_flag(void) vm_init_redefined_flag(void)
{ {
const VALUE register_info[] = { ID mid;
idPLUS, BOP_PLUS, rb_cFixnum, rb_cFloat, rb_cString, rb_cArray, 0, VALUE bop;
idMINUS, BOP_MINUS, rb_cFixnum, 0,
idMULT, BOP_MULT, rb_cFixnum, rb_cFloat, 0,
idDIV, BOP_DIV, rb_cFixnum, rb_cFloat, 0,
idMOD, BOP_MOD, rb_cFixnum, rb_cFloat, 0,
idEq, BOP_EQ, rb_cFixnum, rb_cFloat, rb_cString, 0,
idLT, BOP_LT, rb_cFixnum, 0,
idLE, BOP_LE, rb_cFixnum, 0,
idLTLT, BOP_LTLT, rb_cString, rb_cArray, 0,
idAREF, BOP_AREF, rb_cArray, rb_cHash, 0,
idASET, BOP_ASET, rb_cArray, rb_cHash, 0,
idLength, BOP_LENGTH, rb_cArray, rb_cString, rb_cHash, 0,
idSucc, BOP_SUCC, rb_cFixnum, rb_cString, rb_cTime, 0,
idGT, BOP_GT, rb_cFixnum, 0,
idGE, BOP_GE, rb_cFixnum, 0,
0,
};
const VALUE *ptr = register_info;
vm_opt_method_table = st_init_numtable(); vm_opt_method_table = st_init_numtable();
while (*ptr) { #define OP(mid_, bop_) (mid = id##mid_, bop = BOP_##bop_)
ID mid = *ptr++; #define C(k) add_opt_method(rb_c##k, mid, bop)
VALUE bop = *ptr++; OP(PLUS, PLUS), (C(Fixnum), C(Float), C(String), C(Array));
while(*ptr) { OP(MINUS, MINUS), (C(Fixnum));
VALUE klass = *ptr++; OP(MULT, MULT), (C(Fixnum), C(Float));
add_opt_method(klass, mid, bop); OP(DIV, DIV), (C(Fixnum), C(Float));
} OP(MOD, MOD), (C(Fixnum), C(Float));
ptr++; OP(Eq, EQ), (C(Fixnum), C(Float), C(String));
} OP(LT, LT), (C(Fixnum));
OP(LE, LE), (C(Fixnum));
OP(LTLT, LTLT), (C(String), C(Array));
OP(AREF, AREF), (C(Array), C(Hash));
OP(ASET, ASET), (C(Array), C(Hash));
OP(Length, LENGTH), (C(Array), C(String), C(Hash));
OP(Succ, SUCC), (C(Fixnum), C(String), C(Time));
OP(GT, GT), (C(Fixnum));
OP(GE, GE), (C(Fixnum));
#undef C
#undef OP
} }
/* evaluator body */ /* evaluator body */