1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
k0kubun 2018-06-23 14:11:19 +00:00
parent a62a776d57
commit e1be448840
4 changed files with 14 additions and 2 deletions

2
iseq.c
View file

@ -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)
{

5
mjit.c
View file

@ -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();

5
mjit.h
View file

@ -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;

View file

@ -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);
}