From e1be448840da9ac2db4eeeed5d07ae8a765bacce Mon Sep 17 00:00:00 2001 From: k0kubun Date: Sat, 23 Jun 2018 14:11:19 +0000 Subject: mjit.c: disable calling JIT-ed code when TracePoint is enabled. We're cancelling JIT-ed code execution AFTER each instruction, but there is no guard before the first insn of method. To prevent spoiling performance, I don't want to modify the JIT-ed code to fix this. So this commit replaces `mjit_enabled` check with `mjit_call_p` check. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- iseq.c | 2 ++ mjit.c | 5 +++++ mjit.h | 5 +++-- vm_trace.c | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/iseq.c b/iseq.c index f64177dc5b..7744e3f54f 100644 --- a/iseq.c +++ b/iseq.c @@ -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) { diff --git a/mjit.c b/mjit.c index b760691459..5c6cf47cc7 100644 --- a/mjit.c +++ b/mjit.c @@ -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(); diff --git a/mjit.h b/mjit.h index 2f9ea85134..9460d7595f 100644 --- a/mjit.h +++ b/mjit.h @@ -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); } -- cgit v1.2.3