diff options
Diffstat (limited to 'vm_trace.c')
| -rw-r--r-- | vm_trace.c | 794 |
1 files changed, 522 insertions, 272 deletions
diff --git a/vm_trace.c b/vm_trace.c index 20fade5fd9..0090541275 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -23,14 +23,20 @@ #include "eval_intern.h" #include "internal.h" +#include "internal/bits.h" +#include "internal/class.h" +#include "internal/gc.h" #include "internal/hash.h" #include "internal/symbol.h" +#include "internal/thread.h" #include "iseq.h" -#include "mjit.h" +#include "ruby/atomic.h" #include "ruby/debug.h" #include "vm_core.h" #include "ruby/ractor.h" +#include "ractor_core.h" #include "yjit.h" +#include "zjit.h" #include "builtin.h" @@ -66,7 +72,22 @@ rb_hook_list_mark(rb_hook_list_t *hooks) } } -static void clean_hooks(const rb_execution_context_t *ec, rb_hook_list_t *list); +void +rb_hook_list_mark_and_move(rb_hook_list_t *hooks) +{ + if (!rb_gc_checking_shareable()) { + // hooks can be unshareable + + rb_event_hook_t *hook = hooks->hooks; + + while (hook) { + rb_gc_mark_and_move(&hook->data); + hook = hook->next; + } + } +} + +static void clean_hooks(rb_hook_list_t *list); void rb_hook_list_free(rb_hook_list_t *hooks) @@ -74,47 +95,98 @@ rb_hook_list_free(rb_hook_list_t *hooks) hooks->need_clean = true; if (hooks->running == 0) { - clean_hooks(GET_EC(), hooks); + clean_hooks(hooks); } } /* ruby_vm_event_flags management */ void rb_clear_attr_ccs(void); +void rb_clear_bf_ccs(void); -static void -update_global_event_hook(rb_event_flag_t prev_events, rb_event_flag_t new_events) +static bool iseq_trace_set_all_needed(rb_event_flag_t new_events) { rb_event_flag_t new_iseq_events = new_events & ISEQ_TRACE_EVENTS; rb_event_flag_t enabled_iseq_events = ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS; - bool first_time_iseq_events_p = new_iseq_events & ~enabled_iseq_events; - bool enable_c_call = (prev_events & RUBY_EVENT_C_CALL) == 0 && (new_events & RUBY_EVENT_C_CALL); + return new_iseq_events & ~enabled_iseq_events; + +} + +static bool clear_attr_ccs_needed(rb_event_flag_t prev_events, rb_event_flag_t new_events) +{ + bool enable_c_call = (prev_events & RUBY_EVENT_C_CALL) == 0 && (new_events & RUBY_EVENT_C_CALL); bool enable_c_return = (prev_events & RUBY_EVENT_C_RETURN) == 0 && (new_events & RUBY_EVENT_C_RETURN); + return enable_c_call || enable_c_return; +} + +/* If the events are internal events (e.g. gc hooks), it updates them globally for all ractors. Otherwise + * they are ractor local. You cannot listen to internal events through set_trace_func or TracePoint. + * Some ractor-local tracepoint events cause global level iseq changes, so are still called `global events`. + */ +static void +update_global_event_hooks(rb_hook_list_t *list, rb_event_flag_t prev_events, rb_event_flag_t new_events, int change_iseq_events, int change_c_events) +{ + rb_execution_context_t *ec = rb_current_execution_context(false); + unsigned int lev; + + // Can't enter VM lock during freeing of ractor hook list on MMTK, where ec == NULL. + if (ec) { + RB_VM_LOCK_ENTER_LEV(&lev); + rb_vm_barrier(); + } + + rb_event_flag_t new_iseq_events = new_events & ISEQ_TRACE_EVENTS; + rb_event_flag_t enabled_iseq_events = ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS; + bool new_iseq_events_p = iseq_trace_set_all_needed(new_events); + bool enable_call = (prev_events & RUBY_EVENT_CALL) == 0 && (new_events & RUBY_EVENT_CALL); + bool enable_return = (prev_events & RUBY_EVENT_RETURN) == 0 && (new_events & RUBY_EVENT_RETURN); + bool clear_attr_ccs_p = clear_attr_ccs_needed(prev_events, new_events); + + // FIXME: `ruby_vm_event_flags` should have the global list of event flags for internal events as well + // as for all ractors. That's not how it works right now, so we shouldn't rely on it apart from the + // internal events. Since it doesn't work like this, we have to track more state with `ruby_vm_iseq_events_enabled`, + // `ruby_vm_c_events_enabled`, etc. + rb_event_flag_t new_events_global = (ruby_vm_event_flags & ~prev_events) | new_events; + ruby_vm_event_flags = new_events_global; // Modify ISEQs or CCs to enable tracing - if (first_time_iseq_events_p) { + if (new_iseq_events_p) { // write all ISeqs only when new events are added for the first time rb_iseq_trace_set_all(new_iseq_events | enabled_iseq_events); } - // if c_call or c_return is activated - else if (enable_c_call || enable_c_return) { + else if (clear_attr_ccs_p) { // turn on C_CALL or C_RETURN ractor locally rb_clear_attr_ccs(); } + else if (enable_call || enable_return) { // turn on CALL or RETURN ractor locally + rb_clear_bf_ccs(); + } + + if (change_iseq_events < 0) { + RUBY_ASSERT(ruby_vm_iseq_events_enabled >= (unsigned int)(-change_iseq_events)); + } + ruby_vm_iseq_events_enabled += change_iseq_events; + if (change_c_events < 0) { + RUBY_ASSERT(ruby_vm_c_events_enabled >= (unsigned int)(-change_iseq_events)); + } + ruby_vm_c_events_enabled += change_c_events; - ruby_vm_event_flags = new_events; - ruby_vm_event_enabled_global_flags |= new_events; - rb_objspace_set_event_hook(new_events); + ruby_vm_event_enabled_global_flags |= new_events; // NOTE: this is only ever added to + if (new_events_global & RUBY_INTERNAL_EVENT_MASK) { + rb_objspace_set_event_hook(new_events_global); + } // Invalidate JIT code as needed - if (first_time_iseq_events_p || enable_c_call || enable_c_return) { + if (new_iseq_events_p || clear_attr_ccs_p) { // Invalidate all code when ISEQs are modified to use trace_* insns above. // Also invalidate when enabling c_call or c_return because generated code // never fires these events. // Internal events fire inside C routines so don't need special handling. - // Do this after event flags updates so other ractors see updated vm events - // when they wake up. rb_yjit_tracing_invalidate_all(); - rb_mjit_tracing_invalidate_all(new_iseq_events); + rb_zjit_tracing_invalidate_all(); + } + + if (ec) { + RB_VM_LOCK_LEAVE_LEV(&lev); } } @@ -142,28 +214,43 @@ alloc_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, return hook; } +// Connect a hook onto a ractor, an iseq or a method definition's hook list static void -hook_list_connect(VALUE list_owner, rb_hook_list_t *list, rb_event_hook_t *hook, int global_p) +hook_list_connect(rb_hook_list_t *list, rb_event_hook_t *hook, int global_p) { rb_event_flag_t prev_events = list->events; + int change_iseq_events = 0; + int change_c_events = 0; hook->next = list->hooks; list->hooks = hook; list->events |= hook->events; if (global_p) { - /* global hooks are root objects at GC mark. */ - update_global_event_hook(prev_events, list->events); - } - else { - RB_OBJ_WRITTEN(list_owner, Qundef, hook->data); + if (hook->events & ISEQ_TRACE_EVENTS) { + change_iseq_events++; + } + if ((hook->events & RUBY_EVENT_C_CALL) || (hook->events & RUBY_EVENT_C_RETURN)) { + change_c_events++; + } + update_global_event_hooks(list, prev_events, list->events, change_iseq_events, change_c_events); } } static void -connect_event_hook(const rb_execution_context_t *ec, rb_event_hook_t *hook) +connect_non_targeted_event_hook(const rb_execution_context_t *ec, rb_event_hook_t *hook) { - rb_hook_list_t *list = rb_ec_ractor_hooks(ec); - hook_list_connect(Qundef, list, hook, TRUE); + rb_hook_list_t *list; + + /* internal events are VM-global, non-internal are ractor-local */ + VM_ASSERT(!(hook->events & RUBY_INTERNAL_EVENT_OBJSPACE_MASK) || !(hook->events & ~RUBY_INTERNAL_EVENT_OBJSPACE_MASK)); + + if (hook->events & RUBY_INTERNAL_EVENT_OBJSPACE_MASK) { + list = rb_vm_global_hooks(ec); + } + else { + list = rb_ec_ractor_hooks(ec); + } + hook_list_connect(list, hook, TRUE); } static void @@ -172,7 +259,7 @@ rb_threadptr_add_event_hook(const rb_execution_context_t *ec, rb_thread_t *th, { rb_event_hook_t *hook = alloc_event_hook(func, events, data, hook_flags); hook->filter.th = th; - connect_event_hook(ec, hook); + connect_non_targeted_event_hook(ec, hook); } void @@ -197,14 +284,44 @@ void rb_add_event_hook2(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flags) { rb_event_hook_t *hook = alloc_event_hook(func, events, data, hook_flags); - connect_event_hook(GET_EC(), hook); + connect_non_targeted_event_hook(GET_EC(), hook); +} + +static bool +hook_list_targeted_p(rb_hook_list_t *list) +{ + switch (list->type) { + case hook_list_type_targeted_iseq: + case hook_list_type_targeted_def: + return true; + default: + return false; + } +} + +unsigned int +rb_hook_list_count(rb_hook_list_t *list) +{ + rb_event_hook_t *hook = list->hooks; + unsigned int count = 0; + + while (hook) { + if (!(hook->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED)) { + count++; + } + hook = hook->next; + } + + return count; } static void -clean_hooks(const rb_execution_context_t *ec, rb_hook_list_t *list) +clean_hooks(rb_hook_list_t *list) { rb_event_hook_t *hook, **nextp = &list->hooks; rb_event_flag_t prev_events = list->events; + int change_iseq_events = 0; + int change_c_events = 0; VM_ASSERT(list->running == 0); VM_ASSERT(list->need_clean == true); @@ -215,6 +332,14 @@ clean_hooks(const rb_execution_context_t *ec, rb_hook_list_t *list) while ((hook = *nextp) != 0) { if (hook->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED) { *nextp = hook->next; + if (!hook_list_targeted_p(list)) { + if (hook->events & ISEQ_TRACE_EVENTS) { + change_iseq_events--; + } + if ((hook->events & RUBY_EVENT_C_CALL) || (hook->events & RUBY_EVENT_C_RETURN)) { + change_c_events--; + } + } xfree(hook); } else { @@ -223,34 +348,31 @@ clean_hooks(const rb_execution_context_t *ec, rb_hook_list_t *list) } } - if (list->is_local) { + if (hook_list_targeted_p(list)) { if (list->events == 0) { - /* local events */ ruby_xfree(list); } } else { - update_global_event_hook(prev_events, list->events); + update_global_event_hooks(list, prev_events, list->events, change_iseq_events, change_c_events); } } static void -clean_hooks_check(const rb_execution_context_t *ec, rb_hook_list_t *list) +clean_hooks_check(rb_hook_list_t *list) { if (UNLIKELY(list->need_clean)) { if (list->running == 0) { - clean_hooks(ec, list); + clean_hooks(list); } } } #define MATCH_ANY_FILTER_TH ((rb_thread_t *)1) -/* if func is 0, then clear all funcs */ static int -remove_event_hook(const rb_execution_context_t *ec, const rb_thread_t *filter_th, rb_event_hook_func_t func, VALUE data) +remove_event_hook_from_list(rb_hook_list_t *list, const rb_thread_t *filter_th, rb_event_hook_func_t func, VALUE data) { - rb_hook_list_t *list = rb_ec_ractor_hooks(ec); int ret = 0; rb_event_hook_t *hook = list->hooks; @@ -259,15 +381,27 @@ remove_event_hook(const rb_execution_context_t *ec, const rb_thread_t *filter_th if (hook->filter.th == filter_th || filter_th == MATCH_ANY_FILTER_TH) { if (UNDEF_P(data) || hook->data == data) { hook->hook_flags |= RUBY_EVENT_HOOK_FLAG_DELETED; - ret+=1; list->need_clean = true; + ret+=1; } } } hook = hook->next; } - clean_hooks_check(ec, list); + clean_hooks_check(list); + return ret; +} + +/* if func is 0, then clear all funcs */ +static int +remove_event_hook(const rb_execution_context_t *ec, const rb_thread_t *filter_th, rb_event_hook_func_t func, VALUE data) +{ + int ret = 0; + + ret += remove_event_hook_from_list(rb_ec_ractor_hooks(ec), filter_th, func, data); + ret += remove_event_hook_from_list(rb_vm_global_hooks(ec), filter_th, func, data); + return ret; } @@ -351,7 +485,7 @@ static void exec_hooks_postcheck(const rb_execution_context_t *ec, rb_hook_list_t *list) { list->running--; - clean_hooks_check(ec, list); + clean_hooks_check(list); } static void @@ -390,13 +524,15 @@ exec_hooks_protected(rb_execution_context_t *ec, rb_hook_list_t *list, const rb_ } // pop_p: Whether to pop the frame for the TracePoint when it throws. -MJIT_FUNC_EXPORTED void +void rb_exec_event_hooks(rb_trace_arg_t *trace_arg, rb_hook_list_t *hooks, int pop_p) { rb_execution_context_t *ec = trace_arg->ec; - if (UNLIKELY(trace_arg->event & RUBY_INTERNAL_EVENT_MASK)) { - if (ec->trace_arg && (ec->trace_arg->event & RUBY_INTERNAL_EVENT_MASK)) { + if (UNLIKELY(trace_arg->event & RUBY_INTERNAL_EVENT_OBJSPACE_MASK)) { + VM_ASSERT(hooks == rb_vm_global_hooks(ec)); + + if (ec->trace_arg && (ec->trace_arg->event & RUBY_INTERNAL_EVENT_OBJSPACE_MASK)) { /* skip hooks because this thread doing INTERNAL_EVENT */ } else { @@ -404,7 +540,7 @@ rb_exec_event_hooks(rb_trace_arg_t *trace_arg, rb_hook_list_t *hooks, int pop_p) ec->trace_arg = trace_arg; /* only global hooks */ - exec_hooks_unprotected(ec, rb_ec_ractor_hooks(ec), trace_arg); + exec_hooks_unprotected(ec, hooks, trace_arg); ec->trace_arg = prev_trace_arg; } } @@ -413,7 +549,7 @@ rb_exec_event_hooks(rb_trace_arg_t *trace_arg, rb_hook_list_t *hooks, int pop_p) trace_arg->self != rb_mRubyVMFrozenCore /* skip special methods. TODO: remove it. */) { const VALUE errinfo = ec->errinfo; const VALUE old_recursive = ec->local_storage_recursive_hash; - int state = 0; + enum ruby_tag_type state = 0; /* setup */ ec->local_storage_recursive_hash = ec->local_storage_recursive_hash_for_trace; @@ -433,6 +569,7 @@ rb_exec_event_hooks(rb_trace_arg_t *trace_arg, rb_hook_list_t *hooks, int pop_p) if (state) { if (pop_p) { if (VM_FRAME_FINISHED_P(ec->cfp)) { + rb_vm_tag_jmpbuf_deinit(&ec->tag->buf); ec->tag = ec->tag->prev; } rb_vm_pop_frame(ec); @@ -492,66 +629,65 @@ static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALU /* (2-1) set_trace_func (old API) */ /* - * call-seq: - * set_trace_func(proc) -> proc - * set_trace_func(nil) -> nil + * call-seq: + * set_trace_func(proc) -> proc + * set_trace_func(nil) -> nil * - * Establishes _proc_ as the handler for tracing, or disables - * tracing if the parameter is +nil+. + * Establishes _proc_ as the handler for tracing, or disables + * tracing if the parameter is +nil+. * - * *Note:* this method is obsolete, please use TracePoint instead. + * *Note:* this method is obsolete, please use TracePoint instead. * - * _proc_ takes up to six parameters: + * _proc_ takes up to six parameters: * - * * an event name - * * a filename - * * a line number - * * an object id - * * a binding - * * the name of a class + * * an event name string + * * a filename string + * * a line number + * * a method name symbol, or nil + * * a binding, or nil + * * the class, module, or nil * - * _proc_ is invoked whenever an event occurs. + * _proc_ is invoked whenever an event occurs. * - * Events are: + * Events are: * - * +c-call+:: call a C-language routine - * +c-return+:: return from a C-language routine - * +call+:: call a Ruby method - * +class+:: start a class or module definition - * +end+:: finish a class or module definition - * +line+:: execute code on a new line - * +raise+:: raise an exception - * +return+:: return from a Ruby method + * <code>"c-call"</code>:: call a C-language routine + * <code>"c-return"</code>:: return from a C-language routine + * <code>"call"</code>:: call a Ruby method + * <code>"class"</code>:: start a class or module definition + * <code>"end"</code>:: finish a class or module definition + * <code>"line"</code>:: execute code on a new line + * <code>"raise"</code>:: raise an exception + * <code>"return"</code>:: return from a Ruby method * - * Tracing is disabled within the context of _proc_. + * Tracing is disabled within the context of _proc_. * - * class Test - * def test - * a = 1 - * b = 2 - * end - * end + * class Test + * def test + * a = 1 + * b = 2 + * end + * end * - * set_trace_func proc { |event, file, line, id, binding, classname| - * printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname - * } - * t = Test.new - * t.test + * set_trace_func proc { |event, file, line, id, binding, class_or_module| + * printf "%8s %s:%-2d %16p %14p\n", event, file, line, id, class_or_module + * } + * t = Test.new + * t.test * - * line prog.rb:11 false - * c-call prog.rb:11 new Class - * c-call prog.rb:11 initialize Object - * c-return prog.rb:11 initialize Object - * c-return prog.rb:11 new Class - * line prog.rb:12 false - * call prog.rb:2 test Test - * line prog.rb:3 test Test - * line prog.rb:4 test Test - * return prog.rb:4 test Test + * Produces: * - * Note that for +c-call+ and +c-return+ events, the binding returned is the - * binding of the nearest Ruby method calling the C method, since C methods - * themselves do not have bindings. + * c-return prog.rb:8 :set_trace_func Kernel + * line prog.rb:11 nil nil + * c-call prog.rb:11 :new Class + * c-call prog.rb:11 :initialize BasicObject + * c-return prog.rb:11 :initialize BasicObject + * c-return prog.rb:11 :new Class + * line prog.rb:12 nil nil + * call prog.rb:2 :test Test + * line prog.rb:3 :test Test + * line prog.rb:4 :test Test + * return prog.rb:5 :test Test */ static VALUE @@ -663,6 +799,7 @@ get_event_id(rb_event_flag_t event) C(thread_end, THREAD_END); C(fiber_switch, FIBER_SWITCH); C(script_compiled, SCRIPT_COMPILED); + C(rescue, RESCUE); #undef C default: return 0; @@ -679,8 +816,8 @@ get_path_and_lineno(const rb_execution_context_t *ec, const rb_control_frame_t * *pathp = rb_iseq_path(iseq); if (event & (RUBY_EVENT_CLASS | - RUBY_EVENT_CALL | - RUBY_EVENT_B_CALL)) { + RUBY_EVENT_CALL | + RUBY_EVENT_B_CALL)) { *linep = FIX2INT(rb_iseq_first_lineno(iseq)); } else { @@ -712,8 +849,8 @@ call_trace_func(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klas if (RB_TYPE_P(klass, T_ICLASS)) { klass = RBASIC(klass)->klass; } - else if (FL_TEST(klass, FL_SINGLETON)) { - klass = rb_ivar_get(klass, id__attached__); + else if (RCLASS_SINGLETON_P(klass)) { + klass = RCLASS_ATTACHED_OBJECT(klass); } } @@ -761,16 +898,14 @@ tp_mark(void *ptr) if (tp->target_th) rb_gc_mark(tp->target_th->self); } -static size_t -tp_memsize(const void *ptr) -{ - return sizeof(rb_tp_t); -} - static const rb_data_type_t tp_data_type = { "tracepoint", - {tp_mark, RUBY_TYPED_DEFAULT_FREE, tp_memsize,}, - 0, 0, RUBY_TYPED_FREE_IMMEDIATELY + { + tp_mark, + RUBY_TYPED_DEFAULT_FREE, + NULL, // Nothing allocated externally, so don't need a memsize function + }, + 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE }; static VALUE @@ -805,6 +940,7 @@ symbol2event_flag(VALUE v) C(thread_end, THREAD_END); C(fiber_switch, FIBER_SWITCH); C(script_compiled, SCRIPT_COMPILED); + C(rescue, RESCUE); /* joke */ C(a_call, A_CALL); @@ -916,6 +1052,9 @@ rb_tracearg_parameters(rb_trace_arg_t *trace_arg) const rb_method_entry_t *me; VALUE iclass = Qnil; me = rb_method_entry_without_refinements(trace_arg->klass, trace_arg->called_id, &iclass); + if (!me) { + me = rb_method_entry_without_refinements(trace_arg->klass, trace_arg->id, &iclass); + } return rb_unnamed_parameters(rb_method_entry_arity(me)); } break; @@ -925,6 +1064,7 @@ rb_tracearg_parameters(rb_trace_arg_t *trace_arg) case RUBY_EVENT_CLASS: case RUBY_EVENT_END: case RUBY_EVENT_SCRIPT_COMPILED: + case RUBY_EVENT_RESCUE: rb_raise(rb_eRuntimeError, "not supported by this event"); break; } @@ -995,7 +1135,7 @@ rb_tracearg_return_value(rb_trace_arg_t *trace_arg) VALUE rb_tracearg_raised_exception(rb_trace_arg_t *trace_arg) { - if (trace_arg->event & (RUBY_EVENT_RAISE)) { + if (trace_arg->event & (RUBY_EVENT_RAISE | RUBY_EVENT_RESCUE)) { /* ok */ } else { @@ -1159,7 +1299,7 @@ tp_call_trace(VALUE tpval, rb_trace_arg_t *trace_arg) (*tp->func)(tpval, tp->data); } else { - if (tp->ractor == NULL || tp->ractor == GET_RACTOR()) { + if (tp->ractor == GET_RACTOR()) { rb_proc_call_with_block((VALUE)tp->proc, 1, &tpval, Qnil); } } @@ -1175,6 +1315,10 @@ rb_tracepoint_enable(VALUE tpval) rb_raise(rb_eArgError, "can't nest-enable a targeting TracePoint"); } + if (tp->tracing) { + return Qundef; + } + if (tp->target_th) { rb_thread_add_event_hook2(tp->target_th->self, (rb_event_hook_func_t)tp_call_trace, tp->events, tpval, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG); @@ -1201,14 +1345,33 @@ iseq_of(VALUE target) const rb_method_definition_t *rb_method_def(VALUE method); /* proc.c */ +rb_hook_list_t * +rb_method_def_local_hooks(rb_method_definition_t *def, rb_ractor_t *cr, bool create) +{ + st_data_t val; + rb_hook_list_t *hook_list = NULL; + if (st_lookup(rb_ractor_targeted_hooks(cr), (st_data_t)def, &val)) { + hook_list = (rb_hook_list_t*)val; + RUBY_ASSERT(hook_list->type == hook_list_type_targeted_def); + } + else if (create) { + hook_list = ZALLOC(rb_hook_list_t); + hook_list->type = hook_list_type_targeted_def; + st_insert(cr->pub.targeted_hooks, (st_data_t)def, (st_data_t)hook_list); + } + return hook_list; +} + +// Enable "local" (targeted) tracepoint static VALUE rb_tracepoint_enable_for_target(VALUE tpval, VALUE target, VALUE target_line) { rb_tp_t *tp = tpptr(tpval); - const rb_iseq_t *iseq = iseq_of(target); + const rb_iseq_t *iseq = iseq_of(target); // takes Proc, Iseq, Method int n = 0; unsigned int line = 0; bool target_bmethod = false; + rb_ractor_t *cr = GET_RACTOR(); if (tp->tracing > 0) { rb_raise(rb_eArgError, "can't nest-enable a targeting TracePoint"); @@ -1224,59 +1387,82 @@ rb_tracepoint_enable_for_target(VALUE tpval, VALUE target, VALUE target_line) } VM_ASSERT(tp->local_target_set == Qfalse); - tp->local_target_set = rb_obj_hide(rb_ident_hash_new()); - - /* bmethod */ - if (rb_obj_is_method(target)) { - rb_method_definition_t *def = (rb_method_definition_t *)rb_method_def(target); - if (def->type == VM_METHOD_TYPE_BMETHOD && - (tp->events & (RUBY_EVENT_CALL | RUBY_EVENT_RETURN))) { - if (def->body.bmethod.hooks == NULL) { - def->body.bmethod.hooks = ZALLOC(rb_hook_list_t); - } - rb_hook_list_connect_tracepoint(target, def->body.bmethod.hooks, tpval, 0); - rb_hash_aset(tp->local_target_set, target, Qfalse); - target_bmethod = true; + RB_OBJ_WRITE(tpval, &tp->local_target_set, rb_obj_hide(rb_ident_hash_new())); + + RB_VM_LOCKING() { + // Rewriting iseq instructions across ractors is not safe unless they are stopped. + rb_vm_barrier(); - n++; + /* bmethod */ + if (rb_obj_is_method(target)) { + rb_method_definition_t *def = (rb_method_definition_t *)rb_method_def(target); + if (def->type == VM_METHOD_TYPE_BMETHOD && (tp->events & (RUBY_EVENT_CALL | RUBY_EVENT_RETURN))) { + rb_hook_list_t *hook_list = rb_method_def_local_hooks(def, cr, true); + rb_hook_list_connect_local_tracepoint(hook_list, tpval, 0); + rb_hash_aset(tp->local_target_set, target, Qfalse); // Qfalse means not an iseq + rb_method_definition_addref(def); // in case `tp` gets GC'd and didn't disable the hook, `def` needs to stay alive + def->body.bmethod.local_hooks_cnt++; + target_bmethod = true; + n++; + } } - } - /* iseq */ - n += rb_iseq_add_local_tracepoint_recursively(iseq, tp->events, tpval, line, target_bmethod); - rb_hash_aset(tp->local_target_set, (VALUE)iseq, Qtrue); + /* iseq */ + n += rb_iseq_add_local_tracepoint_recursively(iseq, tp->events, tpval, line, target_bmethod); + if (n > 0) { + rb_hash_aset(tp->local_target_set, (VALUE)iseq, Qtrue); + if ((tp->events & (RUBY_EVENT_CALL | RUBY_EVENT_RETURN)) && + iseq->body->builtin_attrs & BUILTIN_ATTR_SINGLE_NOARG_LEAF) { + rb_clear_bf_ccs(); + } + + rb_yjit_tracing_invalidate_all(); + rb_zjit_tracing_invalidate_all(); + rb_ractor_targeted_hooks_incr(tp->ractor); + if (tp->events & ISEQ_TRACE_EVENTS) { + ruby_vm_iseq_events_enabled++; + } + if ((tp->events & RUBY_EVENT_C_CALL) || (tp->events & RUBY_EVENT_C_RETURN)) { + ruby_vm_c_events_enabled++; + } + tp->tracing = 1; + } + } if (n == 0) { rb_raise(rb_eArgError, "can not enable any hooks"); } - rb_yjit_tracing_invalidate_all(); - rb_mjit_tracing_invalidate_all(tp->events); - - ruby_vm_event_local_num++; - - tp->tracing = 1; - return Qnil; } static int -disable_local_event_iseq_i(VALUE target, VALUE iseq_p, VALUE tpval) +disable_local_tracepoint_i(VALUE target, VALUE iseq_p, VALUE tpval) { + rb_tp_t *tp = tpptr(tpval); + rb_ractor_t *cr; + rb_method_definition_t *def; + rb_hook_list_t *hook_list; + ASSERT_vm_locking_with_barrier(); + if (iseq_p) { - rb_iseq_remove_local_tracepoint_recursively((rb_iseq_t *)target, tpval); + rb_iseq_remove_local_tracepoint_recursively((rb_iseq_t *)target, tpval, tp->ractor); } else { + cr = GET_RACTOR(); /* bmethod */ - rb_method_definition_t *def = (rb_method_definition_t *)rb_method_def(target); - rb_hook_list_t *hooks = def->body.bmethod.hooks; - VM_ASSERT(hooks != NULL); - rb_hook_list_remove_tracepoint(hooks, tpval); - - if (hooks->events == 0) { - rb_hook_list_free(def->body.bmethod.hooks); - def->body.bmethod.hooks = NULL; + def = (rb_method_definition_t *)rb_method_def(target); + hook_list = rb_method_def_local_hooks(def, cr, false); + RUBY_ASSERT(hook_list != NULL); + if (rb_hook_list_remove_local_tracepoint(hook_list, tpval)) { + RUBY_ASSERT(def->body.bmethod.local_hooks_cnt > 0); + def->body.bmethod.local_hooks_cnt--; + if (hook_list->events == 0) { + st_delete(rb_ractor_targeted_hooks(cr), (st_data_t*)&def, NULL); + rb_hook_list_free(hook_list); + } + rb_method_definition_release(def); } } return ST_CONTINUE; @@ -1289,10 +1475,23 @@ rb_tracepoint_disable(VALUE tpval) tp = tpptr(tpval); - if (tp->local_target_set) { - rb_hash_foreach(tp->local_target_set, disable_local_event_iseq_i, tpval); - tp->local_target_set = Qfalse; - ruby_vm_event_local_num--; + if (RTEST(tp->local_target_set)) { + RUBY_ASSERT(GET_RACTOR() == tp->ractor); + RB_VM_LOCKING() { + rb_vm_barrier(); + + rb_hash_foreach(tp->local_target_set, disable_local_tracepoint_i, tpval); + RB_OBJ_WRITE(tpval, &tp->local_target_set, Qfalse); + rb_ractor_targeted_hooks_decr(tp->ractor); + if (tp->events & ISEQ_TRACE_EVENTS) { + RUBY_ASSERT(ruby_vm_iseq_events_enabled > 0); + ruby_vm_iseq_events_enabled--; + } + if ((tp->events & RUBY_EVENT_C_CALL) || (tp->events & RUBY_EVENT_C_RETURN)) { + RUBY_ASSERT(ruby_vm_c_events_enabled > 0); + ruby_vm_c_events_enabled--; + } + } } else { if (tp->target_th) { @@ -1307,26 +1506,30 @@ rb_tracepoint_disable(VALUE tpval) return Qundef; } +// connect a targeted (ie: "local") tracepoint to the hook list for the method +// ex: tp.enable(target: method(:puts)) void -rb_hook_list_connect_tracepoint(VALUE target, rb_hook_list_t *list, VALUE tpval, unsigned int target_line) +rb_hook_list_connect_local_tracepoint(rb_hook_list_t *list, VALUE tpval, unsigned int target_line) { rb_tp_t *tp = tpptr(tpval); - rb_event_hook_t *hook = alloc_event_hook((rb_event_hook_func_t)tp_call_trace, tp->events, tpval, + rb_event_hook_t *hook = alloc_event_hook((rb_event_hook_func_t)tp_call_trace, tp->events & ISEQ_TRACE_EVENTS, tpval, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG); hook->filter.target_line = target_line; - hook_list_connect(target, list, hook, FALSE); + hook_list_connect(list, hook, FALSE); } -void -rb_hook_list_remove_tracepoint(rb_hook_list_t *list, VALUE tpval) +bool +rb_hook_list_remove_local_tracepoint(rb_hook_list_t *list, VALUE tpval) { rb_event_hook_t *hook = list->hooks; rb_event_flag_t events = 0; + bool removed = false; while (hook) { if (hook->data == tpval) { hook->hook_flags |= RUBY_EVENT_HOOK_FLAG_DELETED; list->need_clean = true; + removed = true; } else if ((hook->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED) == 0) { events |= hook->events; @@ -1335,6 +1538,7 @@ rb_hook_list_remove_tracepoint(rb_hook_list_t *list, VALUE tpval) } list->events = events; + return removed; } static VALUE @@ -1358,6 +1562,9 @@ tracepoint_enable_m(rb_execution_context_t *ec, VALUE tpval, VALUE target, VALUE rb_raise(rb_eArgError, "can not override target_thread filter"); } tp->target_th = rb_thread_ptr(target_thread); + + RUBY_ASSERT(tp->target_th->self == target_thread); + RB_OBJ_WRITTEN(tpval, Qundef, target_thread); } else { tp->target_th = NULL; @@ -1425,9 +1632,9 @@ tracepoint_new(VALUE klass, rb_thread_t *target_th, rb_event_flag_t events, void rb_tp_t *tp; TypedData_Get_Struct(tpval, rb_tp_t, &tp_data_type, tp); - tp->proc = proc; - tp->ractor = rb_ractor_shareable_p(proc) ? NULL : GET_RACTOR(); - tp->func = func; + RB_OBJ_WRITE(tpval, &tp->proc, proc); + tp->ractor = GET_RACTOR(); + tp->func = func; // for internal events tp->data = data; tp->events = events; tp->self = tpval; @@ -1442,9 +1649,6 @@ rb_tracepoint_new(VALUE target_thval, rb_event_flag_t events, void (*func)(VALUE if (RTEST(target_thval)) { target_th = rb_thread_ptr(target_thval); - /* TODO: Test it! - * Warning: This function is not tested. - */ } return tracepoint_new(rb_cTracePoint, target_th, events, func, data, Qundef); } @@ -1493,7 +1697,7 @@ tracepoint_inspect(rb_execution_context_t *ec, VALUE self) VALUE sym = rb_tracearg_method_id(trace_arg); if (NIL_P(sym)) break; - return rb_sprintf("#<TracePoint:%"PRIsVALUE" %"PRIsVALUE":%d in `%"PRIsVALUE"'>", + return rb_sprintf("#<TracePoint:%"PRIsVALUE" %"PRIsVALUE":%d in '%"PRIsVALUE"'>", rb_tracearg_event(trace_arg), rb_tracearg_path(trace_arg), FIX2INT(rb_tracearg_lineno(trace_arg)), @@ -1503,7 +1707,7 @@ tracepoint_inspect(rb_execution_context_t *ec, VALUE self) case RUBY_EVENT_C_CALL: case RUBY_EVENT_RETURN: case RUBY_EVENT_C_RETURN: - return rb_sprintf("#<TracePoint:%"PRIsVALUE" `%"PRIsVALUE"' %"PRIsVALUE":%d>", + return rb_sprintf("#<TracePoint:%"PRIsVALUE" '%"PRIsVALUE"' %"PRIsVALUE":%d>", rb_tracearg_event(trace_arg), rb_tracearg_method_id(trace_arg), rb_tracearg_path(trace_arg), @@ -1551,7 +1755,6 @@ tracepoint_stat_s(rb_execution_context_t *ec, VALUE self) VALUE stat = rb_hash_new(); tracepoint_stat_event_hooks(stat, vm->self, rb_ec_ractor_hooks(ec)->hooks); - /* TODO: thread local hooks */ return stat; } @@ -1592,17 +1795,22 @@ Init_vm_trace(void) rb_undef_alloc_func(rb_cTracePoint); } -typedef struct rb_postponed_job_struct { - rb_postponed_job_func_t func; - void *data; -} rb_postponed_job_t; - -#define MAX_POSTPONED_JOB 1000 -#define MAX_POSTPONED_JOB_SPECIAL_ADDITION 24 +/* + * Ruby actually has two separate mechanisms for enqueueing work from contexts + * where it is not safe to run Ruby code, to run later on when it is safe. One + * is async-signal-safe but more limited, and accessed through the + * `rb_postponed_job_preregister` and `rb_postponed_job_trigger` functions. The + * other is more flexible but cannot be used in signal handlers, and is accessed + * through the `rb_workqueue_register` function. + * + * The postponed job functions form part of Ruby's extension API, but the + * workqueue functions are for internal use only. + */ struct rb_workqueue_job { struct ccan_list_node jnode; /* <=> vm->workqueue */ - rb_postponed_job_t job; + rb_postponed_job_func_t func; + void *data; }; // Used for VM memsize reporting. Returns the size of a list of rb_workqueue_job @@ -1620,52 +1828,51 @@ rb_vm_memsize_workqueue(struct ccan_list_head *workqueue) return size; } -// Used for VM memsize reporting. Returns the total size of the postponed job -// buffer that was allocated at initialization. -size_t -rb_vm_memsize_postponed_job_buffer(void) -{ - return sizeof(rb_postponed_job_t) * MAX_POSTPONED_JOB; -} - -void -Init_vm_postponed_job(void) +/* + * thread-safe and called from non-Ruby thread + * returns FALSE on failure (ENOMEM), TRUE otherwise + */ +int +rb_workqueue_register(unsigned flags, rb_postponed_job_func_t func, void *data) { + struct rb_workqueue_job *wq_job = malloc(sizeof(*wq_job)); rb_vm_t *vm = GET_VM(); - vm->postponed_job_buffer = ALLOC_N(rb_postponed_job_t, MAX_POSTPONED_JOB); - vm->postponed_job_index = 0; - /* workqueue is initialized when VM locks are initialized */ -} - -enum postponed_job_register_result { - PJRR_SUCCESS = 0, - PJRR_FULL = 1, - PJRR_INTERRUPTED = 2 -}; -/* Async-signal-safe */ -static enum postponed_job_register_result -postponed_job_register(rb_execution_context_t *ec, rb_vm_t *vm, - unsigned int flags, rb_postponed_job_func_t func, void *data, rb_atomic_t max, rb_atomic_t expected_index) -{ - rb_postponed_job_t *pjob; + if (!wq_job) return FALSE; + wq_job->func = func; + wq_job->data = data; - if (expected_index >= max) return PJRR_FULL; /* failed */ + rb_nativethread_lock_lock(&vm->workqueue_lock); + ccan_list_add_tail(&vm->workqueue, &wq_job->jnode); + rb_nativethread_lock_unlock(&vm->workqueue_lock); - if (ATOMIC_CAS(vm->postponed_job_index, expected_index, expected_index+1) == expected_index) { - pjob = &vm->postponed_job_buffer[expected_index]; - } - else { - return PJRR_INTERRUPTED; - } + // TODO: current implementation affects only main ractor + RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(rb_vm_main_ractor_ec(vm)); - /* unused: pjob->flags = flags; */ - pjob->func = func; - pjob->data = data; + return TRUE; +} - RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(ec); +#define PJOB_TABLE_SIZE (sizeof(rb_atomic_t) * CHAR_BIT) +/* pre-registered jobs table, for async-safe jobs */ +typedef struct rb_postponed_job_queue { + struct { + rb_postponed_job_func_t func; + void *data; + } table[PJOB_TABLE_SIZE]; + /* Bits in this are set when the corresponding entry in prereg_table has non-zero + * triggered_count; i.e. somebody called rb_postponed_job_trigger */ + rb_atomic_t triggered_bitset; +} rb_postponed_job_queues_t; - return PJRR_SUCCESS; +void +rb_vm_postponed_job_queue_init(rb_vm_t *vm) +{ + /* use mimmalloc; postponed job registration is a dependency of objspace, so this gets + * called _VERY_ early inside Init_BareVM */ + rb_postponed_job_queues_t *pjq = ruby_mimmalloc(sizeof(rb_postponed_job_queues_t)); + pjq->triggered_bitset = 0; + memset(pjq->table, 0, sizeof(pjq->table)); + vm->postponed_job_queue = pjq; } static rb_execution_context_t * @@ -1676,83 +1883,114 @@ get_valid_ec(rb_vm_t *vm) return ec; } -/* - * return 0 if job buffer is full - * Async-signal-safe - */ -int -rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data) +void +rb_vm_postponed_job_atfork(void) { rb_vm_t *vm = GET_VM(); - rb_execution_context_t *ec = get_valid_ec(vm); - - begin: - switch (postponed_job_register(ec, vm, flags, func, data, MAX_POSTPONED_JOB, vm->postponed_job_index)) { - case PJRR_SUCCESS : return 1; - case PJRR_FULL : return 0; - case PJRR_INTERRUPTED: goto begin; - default: rb_bug("unreachable\n"); + rb_postponed_job_queues_t *pjq = vm->postponed_job_queue; + /* make sure we set the interrupt flag on _this_ thread if we carried any pjobs over + * from the other side of the fork */ + if (pjq->triggered_bitset) { + RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(get_valid_ec(vm)); } + } -/* - * return 0 if job buffer is full - * Async-signal-safe - */ -int -rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data) +/* Frees the memory managed by the postponed job infrastructure at shutdown */ +void +rb_vm_postponed_job_free(void) { rb_vm_t *vm = GET_VM(); - rb_execution_context_t *ec = get_valid_ec(vm); - rb_postponed_job_t *pjob; - rb_atomic_t i, index; - - begin: - index = vm->postponed_job_index; - for (i=0; i<index; i++) { - pjob = &vm->postponed_job_buffer[i]; - if (pjob->func == func) { - RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(ec); - return 2; + ruby_xfree(vm->postponed_job_queue); + vm->postponed_job_queue = NULL; +} + +// Used for VM memsize reporting. Returns the total size of the postponed job +// queue infrastructure. +size_t +rb_vm_memsize_postponed_job_queue(void) +{ + return sizeof(rb_postponed_job_queues_t); +} + + +rb_postponed_job_handle_t +rb_postponed_job_preregister(unsigned int flags, rb_postponed_job_func_t func, void *data) +{ + /* The doc comments say that this function should be called under the GVL, because + * that is actually required to get the guarantee that "if a given (func, data) pair + * was already pre-registered, this method will return the same handle instance". + * + * However, the actual implementation here is called without the GVL, from inside + * rb_postponed_job_register, to support that legacy interface. In the presence + * of concurrent calls to both _preregister and _register functions on the same + * func, however, the data may get mixed up between them. */ + + rb_postponed_job_queues_t *pjq = GET_VM()->postponed_job_queue; + for (unsigned int i = 0; i < PJOB_TABLE_SIZE; i++) { + /* Try and set this slot to equal `func` */ + rb_postponed_job_func_t existing_func = (rb_postponed_job_func_t)(uintptr_t)RUBY_ATOMIC_PTR_CAS(pjq->table[i].func, NULL, (void *)(uintptr_t)func); + if (existing_func == NULL || existing_func == func) { + /* Either this slot was NULL, and we set it to func, or, this slot was already equal to func. + * In either case, clobber the data with our data. Note that concurrent calls to + * rb_postponed_job_register with the same func & different data will result in either of the + * datas being written */ + RUBY_ATOMIC_PTR_EXCHANGE(pjq->table[i].data, data); + return (rb_postponed_job_handle_t)i; + } + else { + /* Try the next slot if this one already has a func in it */ + continue; } } - switch (postponed_job_register(ec, vm, flags, func, data, MAX_POSTPONED_JOB + MAX_POSTPONED_JOB_SPECIAL_ADDITION, index)) { - case PJRR_SUCCESS : return 1; - case PJRR_FULL : return 0; - case PJRR_INTERRUPTED: goto begin; - default: rb_bug("unreachable\n"); - } + + /* full */ + return POSTPONED_JOB_HANDLE_INVALID; } -/* - * thread-safe and called from non-Ruby thread - * returns FALSE on failure (ENOMEM), TRUE otherwise - */ -int -rb_workqueue_register(unsigned flags, rb_postponed_job_func_t func, void *data) +void +rb_postponed_job_trigger(rb_postponed_job_handle_t h) { - struct rb_workqueue_job *wq_job = malloc(sizeof(*wq_job)); rb_vm_t *vm = GET_VM(); + rb_postponed_job_queues_t *pjq = vm->postponed_job_queue; - if (!wq_job) return FALSE; - wq_job->job.func = func; - wq_job->job.data = data; + RUBY_ATOMIC_OR(pjq->triggered_bitset, (((rb_atomic_t)1UL) << h)); + RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(get_valid_ec(vm)); +} - rb_nativethread_lock_lock(&vm->workqueue_lock); - ccan_list_add_tail(&vm->workqueue, &wq_job->jnode); - rb_nativethread_lock_unlock(&vm->workqueue_lock); - // TODO: current implementation affects only main ractor - RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(rb_vm_main_ractor_ec(vm)); +static int +pjob_register_legacy_impl(unsigned int flags, rb_postponed_job_func_t func, void *data) +{ + /* We _know_ calling preregister from a signal handler like this is racy; what is + * and is not promised is very exhaustively documented in debug.h */ + rb_postponed_job_handle_t h = rb_postponed_job_preregister(0, func, data); + if (h == POSTPONED_JOB_HANDLE_INVALID) { + return 0; + } + rb_postponed_job_trigger(h); + return 1; +} - return TRUE; +int +rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data) +{ + return pjob_register_legacy_impl(flags, func, data); } +int +rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data) +{ + return pjob_register_legacy_impl(flags, func, data); +} + + void rb_postponed_job_flush(rb_vm_t *vm) { + rb_postponed_job_queues_t *pjq = GET_VM()->postponed_job_queue; rb_execution_context_t *ec = GET_EC(); - const rb_atomic_t block_mask = POSTPONED_JOB_INTERRUPT_MASK|TRAP_INTERRUPT_MASK; + const rb_atomic_t block_mask = POSTPONED_JOB_INTERRUPT_MASK | TRAP_INTERRUPT_MASK; volatile rb_atomic_t saved_mask = ec->interrupt_mask & block_mask; VALUE volatile saved_errno = ec->errinfo; struct ccan_list_head tmp; @@ -1763,26 +2001,31 @@ rb_postponed_job_flush(rb_vm_t *vm) ccan_list_append_list(&tmp, &vm->workqueue); rb_nativethread_lock_unlock(&vm->workqueue_lock); + rb_atomic_t triggered_bits = RUBY_ATOMIC_EXCHANGE(pjq->triggered_bitset, 0); + ec->errinfo = Qnil; /* mask POSTPONED_JOB dispatch */ ec->interrupt_mask |= block_mask; { EC_PUSH_TAG(ec); if (EC_EXEC_TAG() == TAG_NONE) { - rb_atomic_t index; - struct rb_workqueue_job *wq_job; - - while ((index = vm->postponed_job_index) > 0) { - if (ATOMIC_CAS(vm->postponed_job_index, index, index-1) == index) { - rb_postponed_job_t *pjob = &vm->postponed_job_buffer[index-1]; - (*pjob->func)(pjob->data); - } + /* execute postponed jobs */ + while (triggered_bits) { + unsigned int i = bit_length(triggered_bits) - 1; + triggered_bits ^= ((1UL) << i); /* toggle ith bit off */ + rb_postponed_job_func_t func = pjq->table[i].func; + void *data = pjq->table[i].data; + (func)(data); } + + /* execute workqueue jobs */ + struct rb_workqueue_job *wq_job; while ((wq_job = ccan_list_pop(&tmp, struct rb_workqueue_job, jnode))) { - rb_postponed_job_t pjob = wq_job->job; + rb_postponed_job_func_t func = wq_job->func; + void *data = wq_job->data; free(wq_job); - (pjob.func)(pjob.data); + (func)(data); } } EC_POP_TAG(); @@ -1791,7 +2034,8 @@ rb_postponed_job_flush(rb_vm_t *vm) ec->interrupt_mask &= ~(saved_mask ^ block_mask); ec->errinfo = saved_errno; - /* don't leak memory if a job threw an exception */ + /* If we threw an exception, there might be leftover workqueue items; carry them over + * to a subsequent execution of flush */ if (!ccan_list_empty(&tmp)) { rb_nativethread_lock_lock(&vm->workqueue_lock); ccan_list_prepend_list(&vm->workqueue, &tmp); @@ -1799,4 +2043,10 @@ rb_postponed_job_flush(rb_vm_t *vm) RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(GET_EC()); } + /* likewise with any remaining-to-be-executed bits of the preregistered postponed + * job table */ + if (triggered_bits) { + RUBY_ATOMIC_OR(pjq->triggered_bitset, triggered_bits); + RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(GET_EC()); + } } |
