summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-26 07:56:44 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-26 07:56:44 +0000
commit1939d097e650a60557eafbd89a6684f4626e0ad5 (patch)
tree62a3065ee36528808c6dd58a23011df911fc3820
parent043523adc5275b640f5bb33bd05513194dabf61d (diff)
move several fields from rb_thread_t to rb_execution_context_t.
* vm_core.h (rb_thread_t): move several fields which are copied at cont.c to rb_execution_context_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--cont.c21
-rw-r--r--eval.c8
-rw-r--r--eval_error.c2
-rw-r--r--eval_intern.h26
-rw-r--r--process.c2
-rw-r--r--safe.c14
-rw-r--r--signal.c4
-rw-r--r--thread.c12
-rw-r--r--vm.c16
-rw-r--r--vm_core.h12
-rw-r--r--vm_eval.c6
-rw-r--r--vm_insnhelper.c12
-rw-r--r--vm_trace.c2
13 files changed, 68 insertions, 69 deletions
diff --git a/cont.c b/cont.c
index 16c8297fe6..b8572b495a 100644
--- a/cont.c
+++ b/cont.c
@@ -164,7 +164,7 @@ static VALUE rb_eFiberError;
NOINLINE(static VALUE cont_capture(volatile int *volatile stat));
#define THREAD_MUST_BE_RUNNING(th) do { \
- if (!(th)->tag) rb_raise(rb_eThreadError, "not running thread"); \
+ if (!(th)->ec.tag) rb_raise(rb_eThreadError, "not running thread"); \
} while (0)
static void
@@ -410,12 +410,9 @@ cont_save_thread(rb_context_t *cont, rb_thread_t *th)
/* save thread context */
sth->ec = th->ec;
+
sth->local_storage = th->local_storage;
- sth->safe_level = th->safe_level;
- sth->raised_flag = th->raised_flag;
VM_ASSERT(th->status == THREAD_RUNNABLE);
- sth->tag = th->tag;
- sth->protect_tag = th->protect_tag;
sth->errinfo = th->errinfo;
sth->first_proc = th->first_proc;
sth->root_lep = th->root_lep;
@@ -548,6 +545,10 @@ cont_restore_thread(rb_context_t *cont)
/* other members of ec */
th->ec.cfp = sth->ec.cfp;
+ th->ec.safe_level = sth->ec.safe_level;
+ th->ec.raised_flag = sth->ec.raised_flag;
+ th->ec.tag = sth->ec.tag;
+ th->ec.protect_tag = sth->ec.protect_tag;
}
else {
/* fiber */
@@ -561,10 +562,6 @@ cont_restore_thread(rb_context_t *cont)
th->fiber = (rb_fiber_t*)cont;
}
- th->safe_level = sth->safe_level;
- th->raised_flag = sth->raised_flag;
- th->tag = sth->tag;
- th->protect_tag = sth->protect_tag;
th->errinfo = sth->errinfo;
th->first_proc = sth->first_proc;
th->root_lep = sth->root_lep;
@@ -1066,7 +1063,7 @@ rb_cont_call(int argc, VALUE *argv, VALUE contval)
if (cont->saved_thread.self != th->self) {
rb_raise(rb_eRuntimeError, "continuation called across threads");
}
- if (cont->saved_thread.protect_tag != th->protect_tag) {
+ if (cont->saved_thread.ec.protect_tag != th->ec.protect_tag) {
rb_raise(rb_eRuntimeError, "continuation called across stack rewinding barrier");
}
if (cont->saved_thread.fiber) {
@@ -1228,7 +1225,7 @@ fiber_init(VALUE fibval, VALUE proc)
0, /* local_size */
0);
- th->tag = 0;
+ th->ec.tag = 0;
th->local_storage = st_init_numtable();
th->local_storage_recursive_hash = Qnil;
th->local_storage_recursive_hash_for_trace = Qnil;
@@ -1432,7 +1429,7 @@ fiber_switch(rb_fiber_t *fib, int argc, const VALUE *argv, int is_resume)
if (cont->saved_thread.self != th->self) {
rb_raise(rb_eFiberError, "fiber called across threads");
}
- else if (cont->saved_thread.protect_tag != th->protect_tag) {
+ else if (cont->saved_thread.ec.protect_tag != th->ec.protect_tag) {
rb_raise(rb_eFiberError, "fiber called across stack rewinding barrier");
}
else if (fib->status == FIBER_TERMINATED) {
diff --git a/eval.c b/eval.c
index 6cc6c7b5a0..916e88d74b 100644
--- a/eval.c
+++ b/eval.c
@@ -173,7 +173,7 @@ ruby_cleanup(volatile int ex)
step_0: step++;
errs[1] = th->errinfo;
- th->safe_level = 0;
+ th->ec.safe_level = 0;
ruby_init_stack(&errs[STACK_UPPER(errs, 0, 1)]);
SAVE_ROOT_JMPBUF(th, ruby_finalize_0());
@@ -865,10 +865,10 @@ rb_protect(VALUE (* proc) (VALUE), VALUE data, int *pstate)
struct rb_vm_protect_tag protect_tag;
rb_jmpbuf_t org_jmpbuf;
- protect_tag.prev = th->protect_tag;
+ protect_tag.prev = th->ec.protect_tag;
TH_PUSH_TAG(th);
- th->protect_tag = &protect_tag;
+ th->ec.protect_tag = &protect_tag;
MEMCPY(&org_jmpbuf, &(th)->root_jmpbuf, rb_jmpbuf_t, 1);
if ((state = TH_EXEC_TAG()) == TAG_NONE) {
SAVE_ROOT_JMPBUF(th, result = (*proc) (data));
@@ -877,7 +877,7 @@ rb_protect(VALUE (* proc) (VALUE), VALUE data, int *pstate)
rb_vm_rewind_cfp(th, cfp);
}
MEMCPY(&(th)->root_jmpbuf, &org_jmpbuf, rb_jmpbuf_t, 1);
- th->protect_tag = protect_tag.prev;
+ th->ec.protect_tag = protect_tag.prev;
TH_POP_TAG();
if (pstate != NULL) *pstate = state;
diff --git a/eval_error.c b/eval_error.c
index ba3f9708ac..4340f60676 100644
--- a/eval_error.c
+++ b/eval_error.c
@@ -167,7 +167,7 @@ void
rb_threadptr_error_print(rb_thread_t *volatile th, volatile VALUE errinfo)
{
volatile VALUE errat = Qundef;
- volatile int raised_flag = th->raised_flag;
+ volatile int raised_flag = th->ec.raised_flag;
volatile VALUE eclass = Qundef, emesg = Qundef;
if (NIL_P(errinfo))
diff --git a/eval_intern.h b/eval_intern.h
index 7a5dfa185c..fb28a31829 100644
--- a/eval_intern.h
+++ b/eval_intern.h
@@ -133,16 +133,16 @@ LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *);
struct rb_vm_tag _tag; \
_tag.state = TAG_NONE; \
_tag.tag = Qundef; \
- _tag.prev = _th->tag;
+ _tag.prev = _th->ec.tag;
#define TH_POP_TAG() \
- _th->tag = _tag.prev; \
+ _th->ec.tag = _tag.prev; \
} while (0)
#define TH_TMPPOP_TAG() \
- _th->tag = _tag.prev
+ _th->ec.tag = _tag.prev
-#define TH_REPUSH_TAG() (void)(_th->tag = &_tag)
+#define TH_REPUSH_TAG() (void)(_th->ec.tag = &_tag)
#define PUSH_TAG() TH_PUSH_TAG(GET_THREAD())
#define POP_TAG() TH_POP_TAG()
@@ -157,12 +157,12 @@ LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *);
# define VAR_NOCLOBBERED(var) var
#endif
-/* clear th->tag->state, and return the value */
+/* clear th->ec.tag->state, and return the value */
static inline int
rb_threadptr_tag_state(rb_thread_t *th)
{
- enum ruby_tag_type state = th->tag->state;
- th->tag->state = TAG_NONE;
+ enum ruby_tag_type state = th->ec.tag->state;
+ th->ec.tag->state = TAG_NONE;
return state;
}
@@ -170,8 +170,8 @@ NORETURN(static inline void rb_threadptr_tag_jump(rb_thread_t *, enum ruby_tag_t
static inline void
rb_threadptr_tag_jump(rb_thread_t *th, enum ruby_tag_type st)
{
- th->tag->state = st;
- ruby_longjmp(th->tag->buf, 1);
+ th->ec.tag->state = st;
+ ruby_longjmp(th->ec.tag->buf, 1);
}
/*
@@ -265,10 +265,10 @@ enum {
};
int rb_threadptr_set_raised(rb_thread_t *th);
int rb_threadptr_reset_raised(rb_thread_t *th);
-#define rb_thread_raised_set(th, f) ((th)->raised_flag |= (f))
-#define rb_thread_raised_reset(th, f) ((th)->raised_flag &= ~(f))
-#define rb_thread_raised_p(th, f) (((th)->raised_flag & (f)) != 0)
-#define rb_thread_raised_clear(th) ((th)->raised_flag = 0)
+#define rb_thread_raised_set(th, f) ((th)->ec.raised_flag |= (f))
+#define rb_thread_raised_reset(th, f) ((th)->ec.raised_flag &= ~(f))
+#define rb_thread_raised_p(th, f) (((th)->ec.raised_flag & (f)) != 0)
+#define rb_thread_raised_clear(th) ((th)->ec.raised_flag = 0)
int rb_threadptr_stack_check(rb_thread_t *th);
VALUE rb_f_eval(int argc, const VALUE *argv, VALUE self);
diff --git a/process.c b/process.c
index 7f5c641852..a167562f00 100644
--- a/process.c
+++ b/process.c
@@ -3772,7 +3772,7 @@ rb_f_exit_bang(int argc, VALUE *argv, VALUE obj)
void
rb_exit(int status)
{
- if (GET_THREAD()->tag) {
+ if (GET_THREAD()->ec.tag) {
VALUE args[2];
args[0] = INT2NUM(status);
diff --git a/safe.c b/safe.c
index 7aae978272..d938082d64 100644
--- a/safe.c
+++ b/safe.c
@@ -34,13 +34,13 @@ ruby_safe_level_2_warning(void)
int
rb_safe_level(void)
{
- return GET_THREAD()->safe_level;
+ return GET_THREAD()->ec.safe_level;
}
void
rb_set_safe_level_force(int safe)
{
- GET_THREAD()->safe_level = safe;
+ GET_THREAD()->ec.safe_level = safe;
}
void
@@ -48,11 +48,11 @@ rb_set_safe_level(int level)
{
rb_thread_t *th = GET_THREAD();
- if (level > th->safe_level) {
+ if (level > th->ec.safe_level) {
if (level > SAFE_LEVEL_MAX) {
rb_raise(rb_eArgError, "$SAFE=2 to 4 are obsolete");
}
- th->safe_level = level;
+ th->ec.safe_level = level;
}
}
@@ -68,15 +68,15 @@ safe_setter(VALUE val)
int level = NUM2INT(val);
rb_thread_t *th = GET_THREAD();
- if (level < th->safe_level) {
+ if (level < th->ec.safe_level) {
rb_raise(rb_eSecurityError,
"tried to downgrade safe level from %d to %d",
- th->safe_level, level);
+ th->ec.safe_level, level);
}
if (level > SAFE_LEVEL_MAX) {
rb_raise(rb_eArgError, "$SAFE=2 to 4 are obsolete");
}
- th->safe_level = level;
+ th->ec.safe_level = level;
}
void
diff --git a/signal.c b/signal.c
index f2fd0575d7..2e69cf08ac 100644
--- a/signal.c
+++ b/signal.c
@@ -845,11 +845,11 @@ check_stack_overflow(int sig, const uintptr_t addr, const ucontext_t *ctx)
if (sp_page == fault_page || sp_page == fault_page + 1 ||
sp_page <= fault_page && fault_page <= bp_page) {
rb_thread_t *th = ruby_current_thread;
- if ((uintptr_t)th->tag->buf / pagesize <= fault_page + 1) {
+ if ((uintptr_t)th->ec.tag->buf / pagesize <= fault_page + 1) {
/* drop the last tag if it is close to the fault,
* otherwise it can cause stack overflow again at the same
* place. */
- th->tag = th->tag->prev;
+ th->ec.tag = th->ec.tag->prev;
}
raise_stack_overflow(sig, th);
}
diff --git a/thread.c b/thread.c
index edae43e50c..8fb7ac0f4d 100644
--- a/thread.c
+++ b/thread.c
@@ -2038,7 +2038,7 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing)
rb_atomic_t interrupt;
int postponed_job_interrupt = 0;
- if (th->raised_flag) return;
+ if (th->ec.raised_flag) return;
while ((interrupt = threadptr_get_interrupts(th)) != 0) {
int sig;
@@ -2181,20 +2181,20 @@ rb_threadptr_signal_exit(rb_thread_t *th)
int
rb_threadptr_set_raised(rb_thread_t *th)
{
- if (th->raised_flag & RAISED_EXCEPTION) {
+ if (th->ec.raised_flag & RAISED_EXCEPTION) {
return 1;
}
- th->raised_flag |= RAISED_EXCEPTION;
+ th->ec.raised_flag |= RAISED_EXCEPTION;
return 0;
}
int
rb_threadptr_reset_raised(rb_thread_t *th)
{
- if (!(th->raised_flag & RAISED_EXCEPTION)) {
+ if (!(th->ec.raised_flag & RAISED_EXCEPTION)) {
return 0;
}
- th->raised_flag &= ~RAISED_EXCEPTION;
+ th->ec.raised_flag &= ~RAISED_EXCEPTION;
return 1;
}
@@ -2935,7 +2935,7 @@ rb_thread_safe_level(VALUE thread)
rb_thread_t *th;
GetThreadPtr(thread, th);
- return INT2NUM(th->safe_level);
+ return INT2NUM(th->ec.safe_level);
}
/*
diff --git a/vm.c b/vm.c
index 4979f9ce97..203d962938 100644
--- a/vm.c
+++ b/vm.c
@@ -882,7 +882,7 @@ rb_vm_make_proc_lambda(rb_thread_t *th, const struct rb_captured_block *captured
procval = rb_proc_create_from_captured(klass, captured,
imemo_type(captured->code.val) == imemo_iseq ? block_type_iseq : block_type_ifunc,
- (int8_t)th->safe_level, FALSE, is_lambda);
+ (int8_t)th->ec.safe_level, FALSE, is_lambda);
return procval;
}
@@ -1139,16 +1139,16 @@ vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self,
{
VALUE val = Qundef;
enum ruby_tag_type state;
- volatile int stored_safe = th->safe_level;
+ volatile int stored_safe = th->ec.safe_level;
TH_PUSH_TAG(th);
if ((state = EXEC_TAG()) == TAG_NONE) {
- th->safe_level = proc->safe_level;
+ th->ec.safe_level = proc->safe_level;
val = invoke_block_from_c_proc(th, proc, self, argc, argv, passed_block_handler, proc->is_lambda);
}
TH_POP_TAG();
- th->safe_level = stored_safe;
+ th->ec.safe_level = stored_safe;
if (state) {
TH_JUMP_TAG(th, state);
@@ -1418,7 +1418,7 @@ rb_vm_make_jump_tag_but_local_jump(int state, VALUE val)
VALUE result = Qnil;
if (val == Qundef) {
- val = GET_THREAD()->tag->retval;
+ val = GET_THREAD()->ec.tag->retval;
}
switch (state) {
case 0:
@@ -1786,7 +1786,7 @@ vm_exec(rb_thread_t *th)
if ((state = EXEC_TAG()) == TAG_NONE) {
vm_loop_start:
result = vm_exec_core(th, initial);
- VM_ASSERT(th->tag == &_tag);
+ VM_ASSERT(th->ec.tag == &_tag);
if ((state = _tag.state) != TAG_NONE) {
err = (struct vm_throw_data *)result;
_tag.state = TAG_NONE;
@@ -1939,7 +1939,7 @@ vm_exec(rb_thread_t *th)
#endif
}
th->errinfo = Qnil;
- VM_ASSERT(th->tag->state == TAG_NONE);
+ VM_ASSERT(th->ec.tag->state == TAG_NONE);
goto vm_loop_start;
}
}
@@ -1989,7 +1989,7 @@ vm_exec(rb_thread_t *th)
catch_iseq->body->stack_max);
state = 0;
- th->tag->state = TAG_NONE;
+ th->ec.tag->state = TAG_NONE;
th->errinfo = Qnil;
goto vm_loop_start;
}
diff --git a/vm_core.h b/vm_core.h
index 028d9c3177..dc9043497f 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -737,6 +737,12 @@ typedef struct rb_thread_context_struct {
VALUE *stack; /* must free, must mark */
size_t stack_size; /* size in word (byte size / sizeof(VALUE)) */
rb_control_frame_t *cfp;
+
+ struct rb_vm_tag *tag;
+ struct rb_vm_protect_tag *protect_tag;
+
+ int safe_level;
+ int raised_flag;
} rb_execution_context_t;
typedef struct rb_thread_struct {
@@ -745,8 +751,7 @@ typedef struct rb_thread_struct {
rb_vm_t *vm;
rb_execution_context_t ec;
- int safe_level;
- int raised_flag;
+
VALUE last_status; /* $? */
/* for rb_iterate */
@@ -801,9 +806,6 @@ typedef struct rb_thread_struct {
VALUE locking_mutex;
struct rb_mutex_struct *keeping_mutexes;
- struct rb_vm_tag *tag;
- struct rb_vm_protect_tag *protect_tag;
-
/* storage */
st_table *local_storage;
VALUE local_storage_recursive_hash;
diff --git a/vm_eval.c b/vm_eval.c
index 3a595c0f2a..a3482d15b6 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1136,7 +1136,7 @@ rb_iterate0(VALUE (* it_proc) (VALUE), VALUE data1,
rb_vm_rewind_cfp(th, cfp);
state = 0;
- th->tag->state = TAG_NONE;
+ th->ec.tag->state = TAG_NONE;
th->errinfo = Qnil;
if (state == TAG_RETRY) goto iter_retry;
@@ -1853,7 +1853,7 @@ void
rb_throw_obj(VALUE tag, VALUE value)
{
rb_thread_t *th = GET_THREAD();
- struct rb_vm_tag *tt = th->tag;
+ struct rb_vm_tag *tt = th->ec.tag;
while (tt) {
if (tt->tag == tag) {
@@ -1976,7 +1976,7 @@ vm_catch_protect(VALUE tag, rb_block_call_func *func, VALUE data,
}
else if (state == TAG_THROW && THROW_DATA_VAL((struct vm_throw_data *)th->errinfo) == tag) {
rb_vm_rewind_cfp(th, saved_cfp);
- val = th->tag->retval;
+ val = th->ec.tag->retval;
th->errinfo = Qnil;
state = 0;
}
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 2370545acb..35684e6ed1 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -35,7 +35,7 @@ static void
threadptr_stack_overflow(rb_thread_t *th, int setup)
{
VALUE mesg = th->vm->special_exceptions[ruby_error_sysstack];
- th->raised_flag = 0;
+ th->ec.raised_flag = 0;
if (setup) {
VALUE at = rb_threadptr_backtrace_object(th);
mesg = ruby_vm_special_exception_copy(mesg);
@@ -1029,16 +1029,16 @@ vm_throw_continue(rb_thread_t *th, VALUE err)
/* continue throw */
if (FIXNUM_P(err)) {
- th->tag->state = FIX2INT(err);
+ th->ec.tag->state = FIX2INT(err);
}
else if (SYMBOL_P(err)) {
- th->tag->state = TAG_THROW;
+ th->ec.tag->state = TAG_THROW;
}
else if (THROW_DATA_P(err)) {
- th->tag->state = THROW_DATA_STATE((struct vm_throw_data *)err);
+ th->ec.tag->state = THROW_DATA_STATE((struct vm_throw_data *)err);
}
else {
- th->tag->state = TAG_RAISE;
+ th->ec.tag->state = TAG_RAISE;
}
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");
}
- th->tag->state = state;
+ th->ec.tag->state = state;
return (VALUE)THROW_DATA_NEW(throwobj, escape_cfp, state);
}
diff --git a/vm_trace.c b/vm_trace.c
index 75c4693bc3..76728e21ed 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -358,7 +358,7 @@ rb_threadptr_exec_event_hooks_orig(rb_trace_arg_t *trace_arg, int pop_p)
if (state) {
if (pop_p) {
if (VM_FRAME_FINISHED_P(th->ec.cfp)) {
- th->tag = th->tag->prev;
+ th->ec.tag = th->ec.tag->prev;
}
rb_vm_pop_frame(th);
}