diff options
-rw-r--r-- | iseq.c | 2 | ||||
-rw-r--r-- | mjit.c | 5 | ||||
-rw-r--r-- | mjit.h | 5 | ||||
-rw-r--r-- | vm_trace.c | 4 |
4 files changed, 14 insertions, 2 deletions
@@ -2899,6 +2899,8 @@ rb_iseq_trace_set_all(rb_event_flag_t turnon_events) rb_objspace_each_objects(trace_set_i, &turnon_events); } +/* This is exported since Ruby 2.5 but not internally used for now. If you're going to use this, please + update `ruby_vm_event_enabled_flags` and set `mjit_call_p = FALSE` as well to cancel MJIT code. */ void rb_iseq_trace_on_all(void) { @@ -171,6 +171,9 @@ struct rb_mjit_unit_list { /* TRUE if MJIT is enabled. */ int mjit_enabled = FALSE; +/* TRUE if JIT-ed code should be called. When `ruby_vm_event_enabled_flags & ISEQ_TRACE_EVENTS` + and `mjit_call_p == FALSE`, any JIT-ed code execution is cancelled as soon as possible. */ +int mjit_call_p = FALSE; /* Priority queue of iseqs waiting for JIT compilation. This variable is a pointer to head unit of the queue. */ @@ -1410,6 +1413,7 @@ mjit_init(struct mjit_options *opts) mjit_opts = *opts; mjit_enabled = TRUE; + mjit_call_p = TRUE; /* Normalize options */ if (mjit_opts.min_calls == 0) @@ -1549,6 +1553,7 @@ mjit_finish(void) xfree(pch_file); pch_file = NULL; xfree(header_file); header_file = NULL; + mjit_call_p = FALSE; free_list(&unit_queue); free_list(&active_units); finish_conts(); @@ -51,9 +51,10 @@ struct mjit_options { typedef VALUE (*mjit_func_t)(rb_execution_context_t *, rb_control_frame_t *); +extern int mjit_enabled; RUBY_SYMBOL_EXPORT_BEGIN extern struct mjit_options mjit_opts; -extern int mjit_enabled; +extern int mjit_call_p; extern void mjit_add_iseq_to_process(const rb_iseq_t *iseq); extern mjit_func_t mjit_get_iseq_func(struct rb_iseq_constant_body *body); @@ -94,7 +95,7 @@ mjit_exec(rb_execution_context_t *ec) long unsigned total_calls; mjit_func_t func; - if (!mjit_enabled) + if (!mjit_call_p) return Qundef; iseq = ec->cfp->iseq; diff --git a/vm_trace.c b/vm_trace.c index 10ee1ca18e..fabb15be2f 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -25,6 +25,7 @@ #include "ruby/debug.h" #include "vm_core.h" +#include "mjit.h" #include "iseq.h" #include "eval_intern.h" @@ -68,6 +69,9 @@ update_global_event_hook(rb_event_flag_t vm_events) rb_event_flag_t enabled_iseq_events = ruby_vm_event_enabled_flags & ISEQ_TRACE_EVENTS; if (new_iseq_events & ~enabled_iseq_events) { + /* Stop calling all JIT-ed code. Compiling trace insns is not supported for now. */ + mjit_call_p = FALSE; + /* write all ISeqs iff new events are added */ rb_iseq_trace_set_all(new_iseq_events | enabled_iseq_events); } |