Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport #9415 to ruby_3_3 #9424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion test/ruby/test_yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,19 @@ def test_yjit_enable
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)
Expand Down
6 changes: 5 additions & 1 deletion yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def self.reset_stats!
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
Expand Down
8 changes: 5 additions & 3 deletions yjit/src/yjit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down