move "state" to rb_vm_tag.

* vm_core.h (rb_thread_t::tag_state): move to "rb_vm_tag::state".
  Lifetime of "state" should be same as current tag.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2017-06-23 09:43:52 +00:00
parent a64801c1e9
commit 4a4627fb0d
7 changed files with 18 additions and 28 deletions

2
cont.c
View File

@ -413,7 +413,6 @@ cont_save_thread(rb_context_t *cont, rb_thread_t *th)
sth->local_storage = th->local_storage; sth->local_storage = th->local_storage;
sth->safe_level = th->safe_level; sth->safe_level = th->safe_level;
sth->raised_flag = th->raised_flag; sth->raised_flag = th->raised_flag;
sth->tag_state = th->tag_state;
sth->status = th->status; sth->status = th->status;
sth->tag = th->tag; sth->tag = th->tag;
sth->protect_tag = th->protect_tag; sth->protect_tag = th->protect_tag;
@ -561,7 +560,6 @@ cont_restore_thread(rb_context_t *cont)
th->ec.cfp = sth->ec.cfp; th->ec.cfp = sth->ec.cfp;
th->safe_level = sth->safe_level; th->safe_level = sth->safe_level;
th->raised_flag = sth->raised_flag; th->raised_flag = sth->raised_flag;
th->tag_state = sth->tag_state;
th->status = sth->status; th->status = sth->status;
th->tag = sth->tag; th->tag = sth->tag;
th->protect_tag = sth->protect_tag; th->protect_tag = sth->protect_tag;

View File

@ -131,6 +131,7 @@ LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *);
#define TH_PUSH_TAG(th) do { \ #define TH_PUSH_TAG(th) do { \
rb_thread_t * const _th = (th); \ rb_thread_t * const _th = (th); \
struct rb_vm_tag _tag; \ struct rb_vm_tag _tag; \
_tag.state = TAG_NONE; \
_tag.tag = Qundef; \ _tag.tag = Qundef; \
_tag.prev = _th->tag; _tag.prev = _th->tag;
@ -156,12 +157,12 @@ LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *);
# define VAR_NOCLOBBERED(var) var # define VAR_NOCLOBBERED(var) var
#endif #endif
/* clear th->tag_state, and return the value */ /* clear th->tag->state, and return the value */
static inline int static inline int
rb_threadptr_tag_state(rb_thread_t *th) rb_threadptr_tag_state(rb_thread_t *th)
{ {
enum ruby_tag_type state = th->tag_state; enum ruby_tag_type state = th->tag->state;
th->tag_state = TAG_NONE; th->tag->state = TAG_NONE;
return state; return state;
} }
@ -169,7 +170,7 @@ NORETURN(static inline void rb_threadptr_tag_jump(rb_thread_t *, enum ruby_tag_t
static inline void static inline void
rb_threadptr_tag_jump(rb_thread_t *th, enum ruby_tag_type st) rb_threadptr_tag_jump(rb_thread_t *th, enum ruby_tag_type st)
{ {
th->tag_state = st; th->tag->state = st;
ruby_longjmp(th->tag->buf, 1); ruby_longjmp(th->tag->buf, 1);
} }

10
vm.c
View File

@ -1476,7 +1476,6 @@ vm_iter_break(rb_thread_t *th, VALUE val)
} }
#endif #endif
th->tag_state = TAG_BREAK;
th->errinfo = (VALUE)THROW_DATA_NEW(val, target_cfp, TAG_BREAK); th->errinfo = (VALUE)THROW_DATA_NEW(val, target_cfp, TAG_BREAK);
TH_JUMP_TAG(th, TAG_BREAK); TH_JUMP_TAG(th, TAG_BREAK);
} }
@ -1787,9 +1786,10 @@ vm_exec(rb_thread_t *th)
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
vm_loop_start: vm_loop_start:
result = vm_exec_core(th, initial); result = vm_exec_core(th, initial);
if ((state = th->tag_state) != TAG_NONE) { VM_ASSERT(th->tag == &_tag);
if ((state = _tag.state) != TAG_NONE) {
err = (struct vm_throw_data *)result; err = (struct vm_throw_data *)result;
th->tag_state = TAG_NONE; _tag.state = TAG_NONE;
goto exception_handler; goto exception_handler;
} }
} }
@ -1939,7 +1939,7 @@ vm_exec(rb_thread_t *th)
#endif #endif
} }
th->errinfo = Qnil; th->errinfo = Qnil;
th->tag_state = TAG_NONE; VM_ASSERT(th->tag->state == TAG_NONE);
goto vm_loop_start; goto vm_loop_start;
} }
} }
@ -1989,7 +1989,7 @@ vm_exec(rb_thread_t *th)
catch_iseq->body->stack_max); catch_iseq->body->stack_max);
state = 0; state = 0;
th->tag_state = TAG_NONE; th->tag->state = TAG_NONE;
th->errinfo = Qnil; th->errinfo = Qnil;
goto vm_loop_start; goto vm_loop_start;
} }

View File

@ -691,8 +691,9 @@ typedef RUBY_JMP_BUF rb_jmpbuf_t;
struct rb_vm_tag { struct rb_vm_tag {
VALUE tag; VALUE tag;
VALUE retval; VALUE retval;
rb_jmpbuf_t buf;
struct rb_vm_tag *prev; struct rb_vm_tag *prev;
enum ruby_tag_type state;
rb_jmpbuf_t buf;
}; };
struct rb_vm_protect_tag { struct rb_vm_protect_tag {
@ -743,9 +744,6 @@ typedef struct rb_thread_struct {
int raised_flag; int raised_flag;
VALUE last_status; /* $? */ VALUE last_status; /* $? */
/* passing state */
enum ruby_tag_type tag_state;
/* for rb_iterate */ /* for rb_iterate */
VALUE passed_block_handler; VALUE passed_block_handler;

View File

@ -1136,7 +1136,7 @@ rb_iterate0(VALUE (* it_proc) (VALUE), VALUE data1,
rb_vm_rewind_cfp(th, cfp); rb_vm_rewind_cfp(th, cfp);
state = 0; state = 0;
th->tag_state = TAG_NONE; th->tag->state = TAG_NONE;
th->errinfo = Qnil; th->errinfo = Qnil;
if (state == TAG_RETRY) goto iter_retry; if (state == TAG_RETRY) goto iter_retry;

View File

@ -1029,16 +1029,16 @@ vm_throw_continue(rb_thread_t *th, VALUE err)
/* continue throw */ /* continue throw */
if (FIXNUM_P(err)) { if (FIXNUM_P(err)) {
th->tag_state = FIX2INT(err); th->tag->state = FIX2INT(err);
} }
else if (SYMBOL_P(err)) { else if (SYMBOL_P(err)) {
th->tag_state = TAG_THROW; th->tag->state = TAG_THROW;
} }
else if (THROW_DATA_P(err)) { else if (THROW_DATA_P(err)) {
th->tag_state = THROW_DATA_STATE((struct vm_throw_data *)err); th->tag->state = THROW_DATA_STATE((struct vm_throw_data *)err);
} }
else { else {
th->tag_state = TAG_RAISE; th->tag->state = TAG_RAISE;
} }
return err; return err;
} }
@ -1177,7 +1177,7 @@ vm_throw_start(rb_thread_t *const th, rb_control_frame_t *const reg_cfp, enum ru
rb_bug("isns(throw): unsupport throw type"); rb_bug("isns(throw): unsupport throw type");
} }
th->tag_state = state; th->tag->state = state;
return (VALUE)THROW_DATA_NEW(throwobj, escape_cfp, state); return (VALUE)THROW_DATA_NEW(throwobj, escape_cfp, state);
} }

View File

@ -329,12 +329,10 @@ rb_threadptr_exec_event_hooks_orig(rb_trace_arg_t *trace_arg, int pop_p)
if (th->trace_arg == 0 && /* check reentrant */ if (th->trace_arg == 0 && /* check reentrant */
trace_arg->self != rb_mRubyVMFrozenCore /* skip special methods. TODO: remove it. */) { trace_arg->self != rb_mRubyVMFrozenCore /* skip special methods. TODO: remove it. */) {
const VALUE errinfo = th->errinfo; const VALUE errinfo = th->errinfo;
const enum ruby_tag_type outer_state = th->tag_state;
const VALUE old_recursive = th->local_storage_recursive_hash; const VALUE old_recursive = th->local_storage_recursive_hash;
int state = 0; int state = 0;
th->local_storage_recursive_hash = th->local_storage_recursive_hash_for_trace; th->local_storage_recursive_hash = th->local_storage_recursive_hash_for_trace;
th->tag_state = TAG_NONE;
th->errinfo = Qnil; th->errinfo = Qnil;
th->vm->trace_running++; th->vm->trace_running++;
@ -366,7 +364,6 @@ rb_threadptr_exec_event_hooks_orig(rb_trace_arg_t *trace_arg, int pop_p)
} }
TH_JUMP_TAG(th, state); TH_JUMP_TAG(th, state);
} }
th->tag_state = outer_state;
} }
} }
} }
@ -387,7 +384,6 @@ VALUE
rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg) rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg)
{ {
volatile int raised; volatile int raised;
volatile enum ruby_tag_type outer_state;
VALUE result = Qnil; VALUE result = Qnil;
rb_thread_t *volatile th = GET_THREAD(); rb_thread_t *volatile th = GET_THREAD();
enum ruby_tag_type state; enum ruby_tag_type state;
@ -399,8 +395,6 @@ rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg)
if (!th->trace_arg) th->trace_arg = &dummy_trace_arg; if (!th->trace_arg) th->trace_arg = &dummy_trace_arg;
raised = rb_threadptr_reset_raised(th); raised = rb_threadptr_reset_raised(th);
outer_state = th->tag_state;
th->tag_state = TAG_NONE;
TH_PUSH_TAG(th); TH_PUSH_TAG(th);
if ((state = TH_EXEC_TAG()) == TAG_NONE) { if ((state = TH_EXEC_TAG()) == TAG_NONE) {
@ -419,7 +413,6 @@ rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg)
TH_JUMP_TAG(th, state); TH_JUMP_TAG(th, state);
} }
th->tag_state = outer_state;
return result; return result;
} }