mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add an option to lazily boot MJIT for experiments
You may use `RUBYOPT=--mjit=pause irb` to play with RubyVM::MJIT::C, control the boot timing of MJIT, or customize the implementation while paused. It's an undocumented feature for such experiments.
This commit is contained in:
parent
f6925fab85
commit
5b3bd91fcb
2 changed files with 21 additions and 6 deletions
23
mjit.c
23
mjit.c
|
@ -1779,6 +1779,10 @@ mjit_setup_options(const char *s, struct mjit_options *mjit_opt)
|
||||||
else if (opt_match_arg(s, l, "min-calls")) {
|
else if (opt_match_arg(s, l, "min-calls")) {
|
||||||
mjit_opt->min_calls = atoi(s + 1);
|
mjit_opt->min_calls = atoi(s + 1);
|
||||||
}
|
}
|
||||||
|
// --mjit=pause is an undocumented feature for experiments
|
||||||
|
else if (opt_match_noarg(s, l, "pause")) {
|
||||||
|
mjit_opt->pause = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
rb_raise(rb_eRuntimeError,
|
rb_raise(rb_eRuntimeError,
|
||||||
"invalid MJIT option `%s' (--help will show valid MJIT options)", s);
|
"invalid MJIT option `%s' (--help will show valid MJIT options)", s);
|
||||||
|
@ -1870,11 +1874,15 @@ mjit_init(const struct mjit_options *opts)
|
||||||
// rb_fiber_init_mjit_cont again with mjit_enabled=true to set the root_fiber's mjit_cont.
|
// rb_fiber_init_mjit_cont again with mjit_enabled=true to set the root_fiber's mjit_cont.
|
||||||
rb_fiber_init_mjit_cont(GET_EC()->fiber_ptr);
|
rb_fiber_init_mjit_cont(GET_EC()->fiber_ptr);
|
||||||
|
|
||||||
// TODO: Consider running C compiler asynchronously
|
// If --mjit=pause is given, lazily start MJIT when RubyVM::MJIT.resume is called.
|
||||||
make_pch();
|
// You can use it to control MJIT warmup, or to customize the JIT implementation.
|
||||||
|
if (!mjit_opts.pause) {
|
||||||
|
// TODO: Consider running C compiler asynchronously
|
||||||
|
make_pch();
|
||||||
|
|
||||||
// Enable MJIT compilation
|
// Enable MJIT compilation
|
||||||
start_worker();
|
start_worker();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1920,6 +1928,11 @@ mjit_resume(void)
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lazily prepare PCH when --mjit=pause is given
|
||||||
|
if (pch_status == PCH_NOT_READY) {
|
||||||
|
make_pch();
|
||||||
|
}
|
||||||
|
|
||||||
if (!start_worker()) {
|
if (!start_worker()) {
|
||||||
rb_raise(rb_eRuntimeError, "Failed to resume MJIT worker");
|
rb_raise(rb_eRuntimeError, "Failed to resume MJIT worker");
|
||||||
}
|
}
|
||||||
|
@ -1993,7 +2006,7 @@ mjit_finish(bool close_handle_p)
|
||||||
mjit_dump_total_calls();
|
mjit_dump_total_calls();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!mjit_opts.save_temps && getpid() == pch_owner_pid)
|
if (!mjit_opts.save_temps && getpid() == pch_owner_pid && pch_status != PCH_NOT_READY)
|
||||||
remove_file(pch_file);
|
remove_file(pch_file);
|
||||||
|
|
||||||
xfree(header_file); header_file = NULL;
|
xfree(header_file); header_file = NULL;
|
||||||
|
|
4
mjit.h
4
mjit.h
|
@ -49,7 +49,7 @@ struct mjit_options {
|
||||||
bool debug;
|
bool debug;
|
||||||
// Add arbitrary cflags.
|
// Add arbitrary cflags.
|
||||||
char* debug_flags;
|
char* debug_flags;
|
||||||
// If not 0, all ISeqs are synchronously compiled. For testing.
|
// If true, all ISeqs are synchronously compiled. For testing.
|
||||||
bool wait;
|
bool wait;
|
||||||
// Number of calls to trigger JIT compilation. For testing.
|
// Number of calls to trigger JIT compilation. For testing.
|
||||||
unsigned int min_calls;
|
unsigned int min_calls;
|
||||||
|
@ -59,6 +59,8 @@ struct mjit_options {
|
||||||
// Maximal permitted number of iseq JIT codes in a MJIT memory
|
// Maximal permitted number of iseq JIT codes in a MJIT memory
|
||||||
// cache.
|
// cache.
|
||||||
int max_cache_size;
|
int max_cache_size;
|
||||||
|
// [experimental] If true, do not start MJIT until MJIT.resume is called.
|
||||||
|
bool pause;
|
||||||
};
|
};
|
||||||
|
|
||||||
// State of optimization switches
|
// State of optimization switches
|
||||||
|
|
Loading…
Add table
Reference in a new issue