ruby-changes:48425
From: ko1 <ko1@a...>
Date: Sun, 29 Oct 2017 22:19:19 +0900 (JST)
Subject: [ruby-changes:48425] ko1:r60539 (trunk): EXEC_EVENT_HOOK(ec, ...)
ko1 2017-10-29 22:19:14 +0900 (Sun, 29 Oct 2017) New Revision: 60539 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60539 Log: EXEC_EVENT_HOOK(ec, ...) * vm_core.h (EXEC_EVENT_HOOK): accepts `ec` instead of `th`. Modified files: trunk/cont.c trunk/error.c trunk/eval.c trunk/gc.c trunk/insns.def trunk/thread.c trunk/vm.c trunk/vm_core.h trunk/vm_eval.c trunk/vm_insnhelper.c Index: vm_eval.c =================================================================== --- vm_eval.c (revision 60538) +++ vm_eval.c (revision 60539) @@ -71,7 +71,7 @@ vm_call0_cfunc_with_frame(rb_execution_c https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L71 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_c https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L88 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; Index: error.c =================================================================== --- error.c (revision 60538) +++ error.c (revision 60539) @@ -1015,12 +1015,12 @@ rb_get_backtrace(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L1015 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); Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 60538) +++ vm_insnhelper.c (revision 60539) @@ -1911,7 +1911,7 @@ vm_call_cfunc_with_frame(rb_execution_co https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1911 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_co https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1927 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; Index: thread.c =================================================================== --- thread.c (revision 60538) +++ thread.c (revision 60539) @@ -584,11 +584,11 @@ thread_do_start(rb_thread_t *th, VALUE a https://github.com/ruby/ruby/blob/trunk/thread.c#L584 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_threa https://github.com/ruby/ruby/blob/trunk/thread.c#L2094 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); Index: eval.c =================================================================== --- eval.c (revision 60538) +++ eval.c (revision 60539) @@ -577,7 +577,7 @@ setup_exception(rb_execution_context_t * https://github.com/ruby/ruby/blob/trunk/eval.c#L577 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 https://github.com/ruby/ruby/blob/trunk/eval.c#L796 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); } /*! Index: gc.c =================================================================== --- gc.c (revision 60538) +++ gc.c (revision 60539) @@ -1811,9 +1811,9 @@ rb_objspace_set_event_hook(const rb_even https://github.com/ruby/ruby/blob/trunk/gc.c#L1811 } 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_o https://github.com/ruby/ruby/blob/trunk/gc.c#L1821 #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) Index: cont.c =================================================================== --- cont.c (revision 60538) +++ cont.c (revision 60539) @@ -1414,7 +1414,7 @@ rb_fiber_start(void) https://github.com/ruby/ruby/blob/trunk/cont.c#L1414 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, https://github.com/ruby/ruby/blob/trunk/cont.c#L1671 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; } Index: insns.def =================================================================== --- insns.def (revision 60538) +++ insns.def (revision 60539) @@ -790,7 +790,7 @@ trace https://github.com/ruby/ruby/blob/trunk/insns.def#L790 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 https://github.com/ruby/ruby/blob/trunk/insns.def#L808 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); } /**********************************************************/ Index: vm.c =================================================================== --- vm.c (revision 60538) +++ vm.c (revision 60539) @@ -532,13 +532,13 @@ vm_get_ruby_level_caller_cfp(const rb_ex https://github.com/ruby/ruby/blob/trunk/vm.c#L532 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 *e https://github.com/ruby/ruby/blob/trunk/vm.c#L1000 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 https://github.com/ruby/ruby/blob/trunk/vm.c#L1665 #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) https://github.com/ruby/ruby/blob/trunk/vm.c#L1821 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) https://github.com/ruby/ruby/blob/trunk/vm.c#L1862 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) https://github.com/ruby/ruby/blob/trunk/vm.c#L2004 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); Index: vm_core.h =================================================================== --- vm_core.h (revision 60538) +++ vm_core.h (revision 60539) @@ -1712,18 +1712,19 @@ struct rb_trace_arg_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L1712 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 *c https://github.com/ruby/ruby/blob/trunk/vm_core.h#L1742 } } -#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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/