diff --git a/cont.c b/cont.c index 853787567f..b4f9fce241 100644 --- a/cont.c +++ b/cont.c @@ -1414,7 +1414,7 @@ rb_fiber_start(void) th->ec->root_lep = rb_vm_proc_local_ep(fib->first_proc); th->ec->root_svar = Qfalse; - EXEC_EVENT_HOOK(th, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, 0, Qnil); + EXEC_EVENT_HOOK(th->ec, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, 0, Qnil); cont->value = rb_vm_invoke_proc(th->ec, proc, argc, argv, VM_BLOCK_HANDLER_NONE); } EC_POP_TAG(); @@ -1671,7 +1671,7 @@ fiber_switch(rb_fiber_t *fib, int argc, const VALUE *argv, int is_resume) value = fiber_store(fib, th); RUBY_VM_CHECK_INTS(th); - EXEC_EVENT_HOOK(th, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, 0, Qnil); + EXEC_EVENT_HOOK(th->ec, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, 0, Qnil); return value; } diff --git a/error.c b/error.c index 176659b8ee..420539e4a4 100644 --- a/error.c +++ b/error.c @@ -1015,12 +1015,12 @@ rb_get_backtrace(VALUE exc) ID mid = id_backtrace; if (rb_method_basic_definition_p(CLASS_OF(exc), id_backtrace)) { VALUE info, klass = rb_eException; - rb_thread_t *th = GET_THREAD(); + rb_execution_context_t *ec = GET_EC(); if (NIL_P(exc)) return Qnil; - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, exc, mid, mid, klass, Qundef); + EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, exc, mid, mid, klass, Qundef); info = exc_backtrace(exc); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, exc, mid, mid, klass, info); + EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, exc, mid, mid, klass, info); if (NIL_P(info)) return Qnil; return rb_check_backtrace(info); diff --git a/eval.c b/eval.c index 419e1d31a6..fa97b9d973 100644 --- a/eval.c +++ b/eval.c @@ -577,7 +577,7 @@ setup_exception(rb_execution_context_t *ec, int tag, volatile VALUE mesg, VALUE if (tag != TAG_FATAL) { RUBY_DTRACE_HOOK(RAISE, rb_obj_classname(ec->errinfo)); - EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), RUBY_EVENT_RAISE, ec->cfp->self, 0, 0, 0, mesg); + EXEC_EVENT_HOOK(ec, RUBY_EVENT_RAISE, ec->cfp->self, 0, 0, 0, mesg); } } @@ -796,17 +796,17 @@ rb_make_exception(int argc, const VALUE *argv) void rb_raise_jump(VALUE mesg, VALUE cause) { - rb_thread_t *th = GET_THREAD(); - const rb_control_frame_t *cfp = th->ec->cfp; + rb_execution_context_t *ec = GET_EC(); + const rb_control_frame_t *cfp = ec->cfp; const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp); VALUE klass = me->owner; VALUE self = cfp->self; ID mid = me->called_id; - rb_vm_pop_frame(th->ec); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, self, me->def->original_id, mid, klass, Qnil); + rb_vm_pop_frame(ec); + EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, self, me->def->original_id, mid, klass, Qnil); - rb_longjmp(th->ec, TAG_RAISE, mesg, cause); + rb_longjmp(ec, TAG_RAISE, mesg, cause); } /*! diff --git a/gc.c b/gc.c index 48053b66c5..17d2a09769 100644 --- a/gc.c +++ b/gc.c @@ -1811,9 +1811,9 @@ rb_objspace_set_event_hook(const rb_event_flag_t event) } static void -gc_event_hook_body(rb_thread_t *th, rb_objspace_t *objspace, const rb_event_flag_t event, VALUE data) +gc_event_hook_body(rb_execution_context_t *ec, rb_objspace_t *objspace, const rb_event_flag_t event, VALUE data) { - EXEC_EVENT_HOOK(th, event, th->ec->cfp->self, 0, 0, 0, data); + EXEC_EVENT_HOOK(ec, event, ec->cfp->self, 0, 0, 0, data); } #define gc_event_hook_available_p(objspace) ((objspace)->flags.has_hook) @@ -1821,7 +1821,7 @@ gc_event_hook_body(rb_thread_t *th, rb_objspace_t *objspace, const rb_event_flag #define gc_event_hook(objspace, event, data) do { \ if (UNLIKELY(gc_event_hook_needed_p(objspace, event))) { \ - gc_event_hook_body(GET_THREAD(), (objspace), (event), (data)); \ + gc_event_hook_body(GET_EC(), (objspace), (event), (data)); \ } \ } while (0) diff --git a/insns.def b/insns.def index 61b61f6187..b254193a4c 100644 --- a/insns.def +++ b/insns.def @@ -790,7 +790,7 @@ trace rb_event_flag_t flag = (rb_event_flag_t)nf; vm_dtrace(flag, rb_ec_thread_ptr(ec)); - EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), flag, GET_SELF(), 0, 0, 0 /* id and klass are resolved at callee */, + EXEC_EVENT_HOOK(ec, flag, GET_SELF(), 0, 0, 0 /* id and klass are resolved at callee */, (flag & (RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN)) ? TOPN(0) : Qundef); } @@ -808,7 +808,7 @@ trace2 rb_event_flag_t flag = (rb_event_flag_t)nf; vm_dtrace(flag, rb_ec_thread_ptr(ec)); - EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), flag, GET_SELF(), 0, 0, 0 /* id and klass are resolved at callee */, data); + EXEC_EVENT_HOOK(ec, flag, GET_SELF(), 0, 0, 0 /* id and klass are resolved at callee */, data); } /**********************************************************/ diff --git a/thread.c b/thread.c index e3330cab4a..5a98a19cf3 100644 --- a/thread.c +++ b/thread.c @@ -584,11 +584,11 @@ thread_do_start(rb_thread_t *th, VALUE args) th->ec->errinfo = Qnil; th->ec->root_lep = rb_vm_proc_local_ep(th->first_proc); th->ec->root_svar = Qfalse; - EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_BEGIN, th->self, 0, 0, 0, Qundef); + EXEC_EVENT_HOOK(th->ec, RUBY_EVENT_THREAD_BEGIN, th->self, 0, 0, 0, Qundef); th->value = rb_vm_invoke_proc(th->ec, proc, (int)RARRAY_LEN(args), RARRAY_CONST_PTR(args), VM_BLOCK_HANDLER_NONE); - EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_END, th->self, 0, 0, 0, Qundef); + EXEC_EVENT_HOOK(th->ec, RUBY_EVENT_THREAD_END, th->self, 0, 0, 0, Qundef); } else { th->value = (*th->first_func)((void *)args); @@ -2094,7 +2094,7 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing) if (th->status == THREAD_RUNNABLE) th->running_time_us += TIME_QUANTUM_USEC; - EXEC_EVENT_HOOK(th, RUBY_INTERNAL_EVENT_SWITCH, th->ec->cfp->self, + EXEC_EVENT_HOOK(th->ec, RUBY_INTERNAL_EVENT_SWITCH, th->ec->cfp->self, 0, 0, 0, Qundef); rb_thread_schedule_limits(limits_us); diff --git a/vm.c b/vm.c index 95949765b2..146a255e99 100644 --- a/vm.c +++ b/vm.c @@ -532,13 +532,13 @@ vm_get_ruby_level_caller_cfp(const rb_execution_context_t *ec, const rb_control_ void rb_vm_pop_cfunc_frame(void) { - rb_thread_t *th = GET_THREAD(); - rb_control_frame_t *cfp = th->ec->cfp; + rb_execution_context_t *ec = GET_EC(); + rb_control_frame_t *cfp = ec->cfp; const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, cfp->self, me->def->original_id, me->called_id, me->owner, Qnil); - RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, me->owner, me->def->original_id); - vm_pop_frame(th->ec, cfp, cfp->ep); + EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, cfp->self, me->def->original_id, me->called_id, me->owner, Qnil); + RUBY_DTRACE_CMETHOD_RETURN_HOOK(rb_ec_thread_ptr(ec), me->owner, me->def->original_id); + vm_pop_frame(ec, cfp, cfp->ep); } void @@ -1000,10 +1000,10 @@ invoke_bmethod(rb_execution_context_t *ec, const rb_iseq_t *iseq, VALUE self, co iseq->body->stack_max); RUBY_DTRACE_METHOD_ENTRY_HOOK(rb_ec_thread_ptr(ec), me->owner, me->def->original_id); - EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), RUBY_EVENT_CALL, self, me->def->original_id, me->called_id, me->owner, Qnil); + EXEC_EVENT_HOOK(ec, RUBY_EVENT_CALL, self, me->def->original_id, me->called_id, me->owner, Qnil); VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH); ret = vm_exec(ec); - EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), RUBY_EVENT_RETURN, self, me->def->original_id, me->called_id, me->owner, ret); + EXEC_EVENT_HOOK(ec, RUBY_EVENT_RETURN, self, me->def->original_id, me->called_id, me->owner, ret); RUBY_DTRACE_METHOD_RETURN_HOOK(rb_ec_thread_ptr(ec), me->owner, me->def->original_id); return ret; } @@ -1665,38 +1665,38 @@ frame_name(const rb_control_frame_t *cfp) #endif static void -hook_before_rewind(rb_thread_t *th, const rb_control_frame_t *cfp, int will_finish_vm_exec, int state, struct vm_throw_data *err) +hook_before_rewind(rb_execution_context_t *ec, const rb_control_frame_t *cfp, int will_finish_vm_exec, int state, struct vm_throw_data *err) { if (state == TAG_RAISE && RBASIC_CLASS(err) == rb_eSysStackError) { return; } - switch (VM_FRAME_TYPE(th->ec->cfp)) { + switch (VM_FRAME_TYPE(ec->cfp)) { case VM_FRAME_MAGIC_METHOD: - RUBY_DTRACE_METHOD_RETURN_HOOK(th, 0, 0); - EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->ec->cfp->self, 0, 0, 0, frame_return_value(err)); + RUBY_DTRACE_METHOD_RETURN_HOOK(rb_ec_thread_ptr(ec), 0, 0); + EXEC_EVENT_HOOK_AND_POP_FRAME(ec, RUBY_EVENT_RETURN, ec->cfp->self, 0, 0, 0, frame_return_value(err)); THROW_DATA_CONSUMED_SET(err); break; case VM_FRAME_MAGIC_BLOCK: - if (VM_FRAME_BMETHOD_P(th->ec->cfp)) { - EXEC_EVENT_HOOK(th, RUBY_EVENT_B_RETURN, th->ec->cfp->self, 0, 0, 0, frame_return_value(err)); + if (VM_FRAME_BMETHOD_P(ec->cfp)) { + EXEC_EVENT_HOOK(ec, RUBY_EVENT_B_RETURN, ec->cfp->self, 0, 0, 0, frame_return_value(err)); if (!will_finish_vm_exec) { /* kick RUBY_EVENT_RETURN at invoke_block_from_c() for bmethod */ - EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->ec->cfp->self, - rb_vm_frame_method_entry(th->ec->cfp)->def->original_id, - rb_vm_frame_method_entry(th->ec->cfp)->called_id, - rb_vm_frame_method_entry(th->ec->cfp)->owner, + EXEC_EVENT_HOOK_AND_POP_FRAME(ec, RUBY_EVENT_RETURN, ec->cfp->self, + rb_vm_frame_method_entry(ec->cfp)->def->original_id, + rb_vm_frame_method_entry(ec->cfp)->called_id, + rb_vm_frame_method_entry(ec->cfp)->owner, frame_return_value(err)); } THROW_DATA_CONSUMED_SET(err); } else { - EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->ec->cfp->self, 0, 0, 0, frame_return_value(err)); + EXEC_EVENT_HOOK_AND_POP_FRAME(ec, RUBY_EVENT_B_RETURN, ec->cfp->self, 0, 0, 0, frame_return_value(err)); THROW_DATA_CONSUMED_SET(err); } break; case VM_FRAME_MAGIC_CLASS: - EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_END, th->ec->cfp->self, 0, 0, 0, Qnil); + EXEC_EVENT_HOOK_AND_POP_FRAME(ec, RUBY_EVENT_END, ec->cfp->self, 0, 0, 0, Qnil); break; } } @@ -1821,7 +1821,7 @@ vm_exec(rb_execution_context_t *ec) while (ec->cfp->pc == 0 || ec->cfp->iseq == 0) { if (UNLIKELY(VM_FRAME_TYPE(ec->cfp) == VM_FRAME_MAGIC_CFUNC)) { - EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), RUBY_EVENT_C_RETURN, ec->cfp->self, + EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, ec->cfp->self, rb_vm_frame_method_entry(ec->cfp)->def->original_id, rb_vm_frame_method_entry(ec->cfp)->called_id, rb_vm_frame_method_entry(ec->cfp)->owner, Qnil); @@ -1862,7 +1862,7 @@ vm_exec(rb_execution_context_t *ec) ec->errinfo = Qnil; result = THROW_DATA_VAL(err); THROW_DATA_CATCH_FRAME_SET(err, cfp + 1); - hook_before_rewind(rb_ec_thread_ptr(ec), ec->cfp, TRUE, state, err); + hook_before_rewind(ec, ec->cfp, TRUE, state, err); rb_vm_pop_frame(ec); goto finish_vme; } @@ -2004,7 +2004,7 @@ vm_exec(rb_execution_context_t *ec) goto vm_loop_start; } else { - hook_before_rewind(rb_ec_thread_ptr(ec), ec->cfp, FALSE, state, err); + hook_before_rewind(ec, ec->cfp, FALSE, state, err); if (VM_FRAME_FINISHED_P(ec->cfp)) { rb_vm_pop_frame(ec); diff --git a/vm_core.h b/vm_core.h index e54cf5c6f8..11ee962fc7 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1712,18 +1712,19 @@ struct rb_trace_arg_struct { void rb_threadptr_exec_event_hooks(struct rb_trace_arg_struct *trace_arg); void rb_threadptr_exec_event_hooks_and_pop_frame(struct rb_trace_arg_struct *trace_arg); -#define EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, called_id_, klass_, data_, pop_p_) do { \ +#define EXEC_EVENT_HOOK_ORIG(ec_, flag_, self_, id_, called_id_, klass_, data_, pop_p_) do { \ const rb_event_flag_t flag_arg_ = (flag_); \ if (UNLIKELY(ruby_vm_event_flags & (flag_arg_))) { \ /* defer evaluating the other arguments */ \ - ruby_exec_event_hook_orig(th_, flag_arg_, self_, id_, called_id_, klass_, data_, pop_p_); \ + ruby_exec_event_hook_orig(ec_, flag_arg_, self_, id_, called_id_, klass_, data_, pop_p_); \ } \ } while (0) static inline void -ruby_exec_event_hook_orig(rb_thread_t *const th, const rb_event_flag_t flag, +ruby_exec_event_hook_orig(rb_execution_context_t *ec, const rb_event_flag_t flag, VALUE self, ID id, ID called_id, VALUE klass, VALUE data, int pop_p) { + const rb_thread_t *th = rb_ec_thread_ptr(ec); if ((th->event_hooks.events | th->vm->event_hooks.events) & flag) { struct rb_trace_arg_struct trace_arg; trace_arg.event = flag; @@ -1741,11 +1742,11 @@ ruby_exec_event_hook_orig(rb_thread_t *const th, const rb_event_flag_t flag, } } -#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, called_id_, klass_, data_) \ - EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, called_id_, klass_, data_, 0) +#define EXEC_EVENT_HOOK(ec_, flag_, self_, id_, called_id_, klass_, data_) \ + EXEC_EVENT_HOOK_ORIG(ec_, flag_, self_, id_, called_id_, klass_, data_, 0) -#define EXEC_EVENT_HOOK_AND_POP_FRAME(th_, flag_, self_, id_, called_id_, klass_, data_) \ - EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, called_id_, klass_, data_, 1) +#define EXEC_EVENT_HOOK_AND_POP_FRAME(ec_, flag_, self_, id_, called_id_, klass_, data_) \ + EXEC_EVENT_HOOK_ORIG(ec_, flag_, self_, id_, called_id_, klass_, data_, 1) RUBY_SYMBOL_EXPORT_BEGIN diff --git a/vm_eval.c b/vm_eval.c index 15cdce77cc..4d4ac4dc02 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -71,7 +71,7 @@ vm_call0_cfunc_with_frame(rb_execution_context_t* ec, struct rb_calling_info *ca VALUE block_handler = calling->block_handler; RUBY_DTRACE_CMETHOD_ENTRY_HOOK(rb_ec_thread_ptr(ec), me->owner, me->def->original_id); - EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), RUBY_EVENT_C_CALL, recv, me->def->original_id, mid, me->owner, Qnil); + EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, recv, me->def->original_id, mid, me->owner, Qnil); { rb_control_frame_t *reg_cfp = ec->cfp; @@ -88,7 +88,7 @@ vm_call0_cfunc_with_frame(rb_execution_context_t* ec, struct rb_calling_info *ca VM_PROFILE_UP(C2C_POPF); rb_vm_pop_frame(ec); } - EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), RUBY_EVENT_C_RETURN, recv, me->def->original_id, mid, me->owner, val); + EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, recv, me->def->original_id, mid, me->owner, val); RUBY_DTRACE_CMETHOD_RETURN_HOOK(rb_ec_thread_ptr(ec), me->owner, me->def->original_id); return val; diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 92d7490e86..6d82b1cc01 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1911,7 +1911,7 @@ vm_call_cfunc_with_frame(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp int argc = calling->argc; RUBY_DTRACE_CMETHOD_ENTRY_HOOK(rb_ec_thread_ptr(ec), me->owner, me->def->original_id); - EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), RUBY_EVENT_C_CALL, recv, me->def->original_id, ci->mid, me->owner, Qundef); + EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, recv, me->def->original_id, ci->mid, me->owner, Qundef); vm_push_frame(ec, NULL, VM_FRAME_MAGIC_CFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL, recv, block_handler, (VALUE)me, @@ -1927,7 +1927,7 @@ vm_call_cfunc_with_frame(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp rb_vm_pop_frame(ec); - EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), RUBY_EVENT_C_RETURN, recv, me->def->original_id, ci->mid, me->owner, val); + EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, recv, me->def->original_id, ci->mid, me->owner, val); RUBY_DTRACE_CMETHOD_RETURN_HOOK(rb_ec_thread_ptr(ec), me->owner, me->def->original_id); return val;