Backport #9415 to ruby_3_3 (#9424)

YJIT: Let RubyVM::YJIT.enable respect --yjit-stats
This commit is contained in:
Takashi Kokubun 2024-02-03 21:37:33 -08:00 committed by GitHub
parent ba16b34098
commit a065b68bd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 5 deletions

View file

@ -67,7 +67,19 @@ class TestYJIT < Test::Unit::TestCase
RUBY
end
def test_yjit_enable_stats
def test_yjit_enable_stats_false
assert_separately(["--yjit-disable", "--yjit-stats"], <<~RUBY, ignore_stderr: true)
assert_false RubyVM::YJIT.enabled?
assert_nil RubyVM::YJIT.runtime_stats
RubyVM::YJIT.enable
assert_true RubyVM::YJIT.enabled?
assert_true RubyVM::YJIT.runtime_stats[:all_stats]
RUBY
end
def test_yjit_enable_stats_true
args = []
args << "--disable=yjit" if RubyVM::YJIT.enabled?
assert_separately(args, <<~RUBY, ignore_stderr: true)

View file

@ -28,7 +28,11 @@ module RubyVM::YJIT
Primitive.rb_yjit_reset_stats_bang
end
# Enable \YJIT compilation.
# Enable \YJIT compilation. `stats` option decides whether to enable \YJIT stats or not.
#
# * `false`: Disable stats.
# * `true`: Enable stats. Print stats at exit.
# * `:quiet`: Enable stats. Do not print stats at exit.
def self.enable(stats: false)
return false if enabled?
at_exit { print_and_dump_stats } if stats

View file

@ -171,9 +171,11 @@ pub extern "C" fn rb_yjit_code_gc(_ec: EcPtr, _ruby_self: VALUE) -> VALUE {
pub extern "C" fn rb_yjit_enable(_ec: EcPtr, _ruby_self: VALUE, gen_stats: VALUE, print_stats: VALUE) -> VALUE {
with_vm_lock(src_loc!(), || {
// Initialize and enable YJIT
unsafe {
OPTIONS.gen_stats = gen_stats.test();
OPTIONS.print_stats = print_stats.test();
if gen_stats.test() {
unsafe {
OPTIONS.gen_stats = gen_stats.test();
OPTIONS.print_stats = print_stats.test();
}
}
yjit_init();