RJIT: Add --rjit-trace to allow TracePoint during JIT

This commit is contained in:
Takashi Kokubun 2023-12-21 20:57:34 -08:00
Родитель c18edc5b5d
Коммит 64c52cd1c2
3 изменённых файлов: 21 добавлений и 14 удалений

23
rjit.c
Просмотреть файл

@ -121,15 +121,21 @@ rb_rjit_setup_options(const char *s, struct rb_rjit_options *rjit_opt)
if (l == 0) {
return;
}
else if (opt_match_arg(s, l, "call-threshold")) {
rjit_opt->call_threshold = atoi(s + 1);
}
else if (opt_match_arg(s, l, "exec-mem-size")) {
rjit_opt->exec_mem_size = atoi(s + 1);
}
else if (opt_match_arg(s, l, "call-threshold")) {
rjit_opt->call_threshold = atoi(s + 1);
}
else if (opt_match_noarg(s, l, "stats")) {
rjit_opt->stats = true;
}
else if (opt_match_noarg(s, l, "disable")) {
rjit_opt->disable = true;
}
else if (opt_match_noarg(s, l, "trace")) {
rjit_opt->trace_exits = true;
}
else if (opt_match_noarg(s, l, "trace-exits")) {
rjit_opt->trace_exits = true;
}
@ -139,9 +145,6 @@ rb_rjit_setup_options(const char *s, struct rb_rjit_options *rjit_opt)
else if (opt_match_noarg(s, l, "verify-ctx")) {
rjit_opt->verify_ctx = true;
}
else if (opt_match_noarg(s, l, "disable")) {
rjit_opt->disable = true;
}
else {
rb_raise(rb_eRuntimeError,
"invalid RJIT option `%s' (--help will show valid RJIT options)", s);
@ -153,6 +156,8 @@ const struct ruby_opt_message rb_rjit_option_messages[] = {
M("--rjit-exec-mem-size=num", "", "Size of executable memory block in MiB (default: " STRINGIZE(DEFAULT_EXEC_MEM_SIZE) ")"),
M("--rjit-call-threshold=num", "", "Number of calls to trigger JIT (default: " STRINGIZE(DEFAULT_CALL_THRESHOLD) ")"),
M("--rjit-stats", "", "Enable collecting RJIT statistics"),
M("--rjit-disable", "", "Disable RJIT for lazily enabling it with RubyVM::RJIT.enable"),
M("--rjit-trace", "", "Allow TracePoint during JIT compilation"),
M("--rjit-trace-exits", "", "Trace side exit locations"),
#ifdef HAVE_LIBCAPSTONE
M("--rjit-dump-disasm", "", "Dump all JIT code"),
@ -167,12 +172,12 @@ extern VALUE rb_gc_enable(void);
extern VALUE rb_gc_disable(void);
extern uint64_t rb_vm_insns_count;
// Disable GC, TracePoint, and VM insns counter
// Disable GC, TracePoint, JIT, and VM insns counter
#define WITH_RJIT_ISOLATED(stmt) do { \
VALUE was_disabled = rb_gc_disable(); \
rb_hook_list_t *global_hooks = rb_ec_ractor_hooks(GET_EC()); \
rb_rjit_global_events = global_hooks->events; \
global_hooks->events = 0; \
if (!rb_rjit_opts.trace) global_hooks->events = 0; \
bool original_call_p = rb_rjit_call_p; \
rjit_stats_p = false; \
rb_rjit_call_p = false; \
@ -181,7 +186,7 @@ extern uint64_t rb_vm_insns_count;
rb_vm_insns_count = insns_count; \
rb_rjit_call_p = (rjit_cancel_p ? false : original_call_p); \
rjit_stats_p = rb_rjit_opts.stats; \
global_hooks->events = rb_rjit_global_events; \
if (!rb_rjit_opts.trace) global_hooks->events = rb_rjit_global_events; \
if (!was_disabled) rb_gc_enable(); \
} while (0);

10
rjit.h
Просмотреть файл

@ -22,20 +22,22 @@ struct rb_rjit_options {
// Converted from "rjit" feature flag to tell the enablement
// information to ruby_show_version().
bool on;
// Number of calls to trigger JIT compilation.
unsigned int call_threshold;
// Size of executable memory block in MiB
unsigned int exec_mem_size;
// Number of calls to trigger JIT compilation
unsigned int call_threshold;
// Collect RJIT statistics
bool stats;
// Do not start RJIT until RJIT.enable is called
bool disable;
// Allow TracePoint during JIT compilation
bool trace;
// Trace side exit locations
bool trace_exits;
// Enable disasm of all JIT code
bool dump_disasm;
// Verify context objects
bool verify_ctx;
// [experimental] Do not start RJIT until RJIT.resume is called.
bool disable;
};
RUBY_SYMBOL_EXPORT_BEGIN

2
ruby.c
Просмотреть файл

@ -389,7 +389,7 @@ usage(const char *name, int help, int highlight, int columns)
M("yjit", "", "in-process JIT compiler (default: disabled)"),
#endif
#if USE_RJIT
M("rjit", "", "pure-Ruby JIT compiler (default: disabled)"),
M("rjit", "", "pure-Ruby JIT compiler (experimental, default: disabled)"),
#endif
};
static const struct ruby_opt_message warn_categories[] = {