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

YJIT: move --yjit-stats at_exit call into Ruby

This change fixes `-v --yjit-stats`. Previously in this situation,
YJIT._print_stats wasn't defined as yjit.rb is not evaluated when there
is only "-v" and no Ruby code to run.
This commit is contained in:
Alan Wu 2021-10-26 15:15:46 -04:00
parent 6875d6d1fa
commit fdbae38546
Notes: git 2021-10-28 02:00:39 +09:00
3 changed files with 17 additions and 14 deletions

View file

@ -37,6 +37,11 @@ class TestYJIT < Test::Unit::TestCase
assert_in_out_err('--yjit-greedy-versioning=1', '', [], /warning: argument to --yjit-greedy-versioning is ignored/) assert_in_out_err('--yjit-greedy-versioning=1', '', [], /warning: argument to --yjit-greedy-versioning is ignored/)
end end
def test_yjit_stats_and_v_no_error
_stdout, stderr, _status = EnvUtil.invoke_ruby(%w(-v --yjit-stats), '', true, true)
refute_includes(stderr, "NoMethodError")
end
def test_enable_from_env_var def test_enable_from_env_var
yjit_child_env = {'RUBY_YJIT_ENABLE' => '1'} yjit_child_env = {'RUBY_YJIT_ENABLE' => '1'}
assert_in_out_err([yjit_child_env, '--version'], '') do |stdout, stderr| assert_in_out_err([yjit_child_env, '--version'], '') do |stdout, stderr|

View file

@ -142,13 +142,18 @@ module YJIT
end end
def self.stats_enabled? def self.stats_enabled?
Primitive.cexpr! 'rb_yjit_opts.gen_stats ? Qtrue : Qfalse' Primitive.yjit_stats_enabled_p
end end
def self.enabled? def self.enabled?
Primitive.cexpr! 'rb_yjit_enabled_p() ? Qtrue : Qfalse' Primitive.cexpr! 'rb_yjit_enabled_p() ? Qtrue : Qfalse'
end end
# Avoid calling a method here to not interfere with compilation tests
if Primitive.yjit_stats_enabled_p
at_exit { _print_stats }
end
class << self class << self
private private

View file

@ -684,14 +684,6 @@ yjit_disasm(VALUE self, VALUE code, VALUE from)
} }
#endif #endif
static VALUE
at_exit_print_stats(RB_BLOCK_CALL_FUNC_ARGLIST(yieldarg, data))
{
// Defined in yjit.rb
rb_funcall(mYjit, rb_intern("_print_stats"), 0);
return Qnil;
}
// Primitive called in yjit.rb. Export all machine code comments as a Ruby array. // Primitive called in yjit.rb. Export all machine code comments as a Ruby array.
static VALUE static VALUE
comments_for(rb_execution_context_t *ec, VALUE self, VALUE start_address, VALUE end_address) comments_for(rb_execution_context_t *ec, VALUE self, VALUE start_address, VALUE end_address)
@ -723,6 +715,12 @@ comments_for(rb_execution_context_t *ec, VALUE self, VALUE start_address, VALUE
return comment_array; return comment_array;
} }
static VALUE
yjit_stats_enabled_p(rb_execution_context_t *ec, VALUE self)
{
return RBOOL(YJIT_STATS && rb_yjit_opts.gen_stats);
}
// Primitive called in yjit.rb. Export all YJIT statistics as a Ruby hash. // Primitive called in yjit.rb. Export all YJIT statistics as a Ruby hash.
static VALUE static VALUE
get_yjit_stats(rb_execution_context_t *ec, VALUE self) get_yjit_stats(rb_execution_context_t *ec, VALUE self)
@ -1144,11 +1142,6 @@ rb_yjit_init(struct rb_yjit_options *options)
#endif #endif
#endif #endif
if (YJIT_STATS && rb_yjit_opts.gen_stats) {
// Setup at_exit callback for printing out counters
rb_block_call(rb_mKernel, rb_intern("at_exit"), 0, NULL, at_exit_print_stats, Qfalse);
}
// Make dependency tables // Make dependency tables
method_lookup_dependency = st_init_numtable(); method_lookup_dependency = st_init_numtable();
cme_validity_dependency = st_init_numtable(); cme_validity_dependency = st_init_numtable();