Skip to content

Commit

Permalink
RJIT: Add --rjit-trace to allow TracePoint during JIT
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Dec 22, 2023
1 parent c18edc5 commit 64c52cd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
23 changes: 14 additions & 9 deletions rjit.c
Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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"),
Expand All @@ -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; \
Expand All @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions rjit.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ruby.c
Expand Up @@ -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[] = {
Expand Down

0 comments on commit 64c52cd

Please sign in to comment.