summaryrefslogtreecommitdiff
path: root/yjit.rb
Commit message (Collapse)AuthorAgeFilesLines
* For YJIT stats, set avg_len_in_yjit to 0 if denominator would be 0 (#7793)Noah Gibbs2023-05-101-1/+1
|
* YJIT: Show definedivar exit reasons (#7755)Takashi Kokubun2023-04-241-0/+1
|
* YJIT: Fix raw sample stack lengths in exit traces (#7728)John Hawthorn2023-04-181-1/+1
| | | | | | | | | | yjit-trace-exits appends a synthetic sample for the instruction being exited, but we didn't increment the size of the stack. Fixing this count correctly lets us successfully generate a flamegraph from the exits. I also replaced the line number for instructions with 0, as I don't think the previous value had meaning. Co-authored-by: Adam Hess <HParker@github.com>
* YJIT: Add a counter to all side exits (#7720)Takashi Kokubun2023-04-141-1/+1
|
* YJIT: Fix edge and total counts in exit_locations (#7702)John Hawthorn2023-04-131-5/+5
| | | | | | | | | | The stackprof-format raw samples are suffixed with a count (ie. how many times did the previously recorded side-exit repeat). Previously we were correctly using this value to increment the :samples count, but not the :total_samples count or edges. This made the stackprof aggregate results incorrect (though any flamegraphs generated should have been correct, since those only rely on raw samples).
* YJIT: Count the number of actually written bytes (#7658)Takashi Kokubun2023-04-051-1/+1
|
* YJIT: add stats for ratio of versions per block (#7653)Maxime Chevalier-Boisvert2023-04-041-0/+4
|
* YJIT: Stack temp register allocation (#7651)Takashi Kokubun2023-04-041-0/+3
| | | Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
* YJIT: Add `--yjit-pause` and `RubyVM::YJIT.resume` (#7609)Maxime Chevalier-Boisvert2023-03-281-0/+5
| | | | | | | | | | | | | | | | | | | * YJIT: Add --yjit-pause and RubyVM::YJIT.resume This allows booting YJIT in a suspended state. We chose to add a new command line option as opposed to simply allowing YJIT.resume to work without any command line option because it allows for combining with YJIT tuning command line options. It also simpifies implementation. Paired with Kokubun and Maxime. * Update yjit.rb Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com> --------- Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
* YJIT: skip intermediate arrays in print_sorted_exit_counts (#7547)Mau Magnaguagno2023-03-171-9/+10
| | | | | Early total_exits condition. Replace Array#sort_by/first(how_many) with Array#max_by(how_many). Replace Array#map/max with Array#max_by, match print_counters style for longest_name_length.
* YJIT: add stats to keep track of when branch direction is known (#7544)Maxime Chevalier-Boisvert2023-03-161-0/+4
| | | This measures the impact of changes made by @jhawthorn last year.
* YJIT: reject large stacks so we can use i8/u8 stack_size and stack_offset ↵Maxime Chevalier-Boisvert2023-03-011-0/+2
| | | | | | | (#7412) * Reject large stacks so we can use i8/u8 stack_size and stack_offset * Add rejection test for iseq too long as well
* YJIT: add defer_empty_count statMaxime Chevalier-Boisvert2023-02-281-0/+1
| | | | Count how often we defer from a block that is empty
* YJIT: Use rb_ivar_get at the end of ivar chains (#7334)Takashi Kokubun2023-02-171-0/+1
| | | | | * YJIT: Use rb_ivar_get at the end of ivar chains * Rename the counter to get_ivar_max_depth
* YJIT: Show Context stats on exit (#7327)Takashi Kokubun2023-02-161-3/+5
|
* YJIT: Pad more spaces to accommodate delimiters (#7302)Takashi Kokubun2023-02-141-33/+33
|
* YJIT: add counters for polymorphic send and send with known class (#7288)Maxime Chevalier-Boisvert2023-02-101-11/+18
|
* YJIT: format numbers in stats printouts with comma separators (#7281)Maxime Chevalier-Boisvert2023-02-091-31/+43
|
* Add stats so we can keep track of x86 rel32 vs register calls (#7142)Maxime Chevalier-Boisvert2023-01-181-0/+5
| | | | | | | * Add stats so we can keep track of x86 rel32 vs register calls To know if we get that "prime real estate" as Alan put it. * Fix bug pointed by Alan
* YJIT: Do not refer to an undefined constant (#7112)Takashi Kokubun2023-01-121-6/+3
|
* Document the public interface of YJIT [ci skip]Takashi Kokubun2022-12-221-6/+7
|
* YJIT: skip map in print_sorted_exit_counts (#6954)Mau Magnaguagno2022-12-191-1/+1
| | | Array#sum accepts a block.
* Make it so YJIT is no longer marked as experimental (#6909)Maxime Chevalier-Boisvert2022-12-121-1/+1
| | | | | Tested on production workloads at Shopify for > 1 year and proven to be quite stable. Enabling YJIT at run-time is still guarded behind the --yjit command-line option for now.
* YJIT: Filter out 0-exit ops from Top-20 exit ops (#6892)Takashi Kokubun2022-12-091-2/+2
|
* YJIT: add new counters for deferred compilation and queued blocks (#6837)Maxime Chevalier-Boisvert2022-11-301-0/+2
|
* YJIT: Add object shape count to stats (#6754)Takashi Kokubun2022-11-171-1/+5
|
* YJIT: Add missing key for non-stats buildTakashi Kokubun2022-11-171-1/+2
|
* YJIT: Fix typo in stats references (#6753)Takashi Kokubun2022-11-171-2/+2
|
* YJIT: Add compiled_branch_count stats (#6746)Takashi Kokubun2022-11-161-1/+2
|
* YJIT: Include actual memory region size in stats (#6736)Takashi Kokubun2022-11-151-0/+1
|
* YJIT: Instrument global allocations on stats build (#6712)Takashi Kokubun2022-11-131-0/+1
| | | | | * YJIT: Instrument global allocations on stats build * Just use GLOVAL_ALLOCATOR.stats()
* Remove inconsistencyTakashi Kokubun2022-11-101-2/+2
| | | | | I meant they should be also fixed in https://github.com/ruby/ruby/pull/6694#discussion_r1019445575
* Enable --yjit-stats for release builds (#6694)Jimmy Miller2022-11-101-7/+13
| | | | | | | | | | | | * Enable --yjit-stats for release builds In order for people in the real world to report information about how their application runs with YJIT, we want to expose stats without requiring rebuilding ruby. We can do this without overhead, with the exception of count ratio in yjit, since this relies on the interpreter also counting instructions. This change exposes those stats, while not showing ratio in yjit if we are not in a stats build. * Update yjit.rb Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com> Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
* Fix exit locations dump (#6703)Eileen M. Uchitelle2022-11-091-3/+27
| | | | | | | | | | | | | While I was working on my RubyConf talk for tracing yjit exit locations I realized that there were exits from the dump code included in the stats data. For example I saw 224 interp leave exits for a simple script that should have had 1 or 2. I realized that the dump code needs to be called _after_ the stats are generated, otherwise the dump code will be counted in the stats exits. I've added a `_dump_locations` method to the `at_exit` for stats generation to ensure that it runs last. I've updated the documentation to add a note that if you call `dump_exit_locations` directly, your stats will include the dump code exits as well.
* YJIT: Make more stats accessible from Ruby code (#6685)Takashi Kokubun2022-11-081-20/+29
|
* YJIT: Show side_exit count in stats as well (#6666)Takashi Kokubun2022-11-031-0/+1
|
* YJIT: Support invokeblock (#6640)Takashi Kokubun2022-11-021-0/+1
| | | | | | | | | * YJIT: Support invokeblock * Update yjit/src/backend/arm64/mod.rs * Update yjit/src/codegen.rs Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
* YJIT: Add RubyVM::YJIT.code_gc (#6644)Takashi Kokubun2022-10-311-2/+7
| | | | | * YJIT: Add RubyVM::YJIT.code_gc * Rename compiled_page_count to live_page_count
* YJIT: GC and recompile all code pages (#6406)Takashi Kokubun2022-10-251-1/+5
| | | | | when it fails to allocate a new page. Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
* YJIT: Avoid creating payloads for non-JITed ISEQs (#6549)Takashi Kokubun2022-10-141-0/+1
| | | | | * YJIT: Count freed ISEQs * YJIT: Avoid creating payloads for non-JITed ISEQs
* Speed up --yjit-trace-exits code (#6106)Eileen M. Uchitelle2022-07-121-19/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In a small script the speed of this feature isn't really noticeable but on Rails it's very noticeable how slow this can be. This PR aims to speed up two parts of the functionality. 1) The Rust exit recording code Instead of adding all samples as we see them to the yjit_raw_samples and yjit_line_samples, we can increment the counter on the ones we've seen before. This will be faster on traces where we are hitting the same stack often. In a crude measurement of booting just the active record base test (`test/cases/base_test.rb`) we found that this improved the speed by 1 second. This also results in a smaller marshal dump file which sped up the test boot time by 4 seconds with trace exits on. 2) The Ruby parsing code Previously we were allocating new arrays using `shift` and `each_with_index`. This change avoids allocating new arrays by using an index. This change saves us the most amount of time, gaining 11 seconds. Before this change the test boot time took 62 seconds, after it took 47 seconds. This is still too long but it's a step closer to faster functionality. Next we're going to tackle allowing you to collect trace exits for a specific instruction. There is also some potential slowness in the GC code that I'd like to take a second look at. Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org> Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
* YJIT: add a counter for gc object refs in the machine code (#6089)Maxime Chevalier-Boisvert2022-07-061-0/+1
| | | | | | Add a counter for gc object refs in the machine code This is to gather data for the eventual implementation of a constant pool.
* YJIT: Handle 0 total_exits YJIT Status Display (#6079)Dave Schwantes2022-06-301-13/+17
| | | handle case in YJIT stats where 0 exits causes NaN in the display
* YJIT: Use binwrite to write exit locationsJohn Hawthorn2022-06-171-1/+1
|
* Add ability to trace exit locations in yjit (#5970)Eileen M. Uchitelle2022-06-091-0/+100
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When running with `--yjit-stats` turned on, yjit can inform the user what the most common exits are. While this is useful information it doesn't tell you the source location of the code that exited or what the code that exited looks like. This change intends to fix that. To use the feature, run yjit with the `--yjit-trace-exits` option, which will record the backtrace for every exit that occurs. This functionality requires the stats feature to be turned on. Calling `--yjit-trace-exits` will automatically set the `--yjit-stats` option. Users must call `RubyVM::YJIT.dump_exit_locations(filename)` which will Marshal dump the contents of `RubyVM::YJIT.exit_locations` into a file based on the passed filename. *Example usage:* Given the following script, we write to a file called `concat_array.dump` the results of `RubyVM::YJIT.exit_locations`. ```ruby def concat_array ["t", "r", *x = "u", "e"].join end 1000.times do concat_array end RubyVM::YJIT.dump_exit_locations("concat_array.dump") ``` When we run the file with this branch and the appropriate flags the stacktrace will be recorded. Note Stackprof needs to be installed or you need to point to the library directly. ``` ./ruby --yjit --yjit-call-threshold=1 --yjit-trace-exits -I/Users/eileencodes/open_source/stackprof/lib test.rb ``` We can then read the dump file with Stackprof: ``` ./ruby -I/Users/eileencodes/open_source/stackprof/lib/ /Users/eileencodes/open_source/stackprof/bin/stackprof --text concat_array.dump ``` Results will look similar to the following: ``` ================================== Mode: () Samples: 1817 (0.00% miss rate) GC: 0 (0.00%) ================================== TOTAL (pct) SAMPLES (pct) FRAME 1001 (55.1%) 1001 (55.1%) concatarray 335 (18.4%) 335 (18.4%) invokeblock 178 (9.8%) 178 (9.8%) send 140 (7.7%) 140 (7.7%) opt_getinlinecache ...etc... ``` Simply inspecting the `concatarray` method will give `SOURCE UNAVAILABLE` because the source is insns.def. ``` ./ruby -I/Users/eileencodes/open_source/stackprof/lib/ /Users/eileencodes/open_source/stackprof/bin/stackprof --text concat_array.dump --method concatarray ``` Result: ``` concatarray (nonexistent.def:1) samples: 1001 self (55.1%) / 1001 total (55.1%) callers: 1000 ( 99.9%) Object#concat_array 1 ( 0.1%) Gem.suffixes callees (0 total): code: SOURCE UNAVAILABLE ``` However if we go deeper to the callee we can see the exact source of the `concatarray` exit. ``` ./ruby -I/Users/eileencodes/open_source/stackprof/lib/ /Users/eileencodes/open_source/stackprof/bin/stackprof --text concat_array.dump --method Object#concat_array ``` ``` Object#concat_array (/Users/eileencodes/open_source/rust_ruby/test.rb:1) samples: 0 self (0.0%) / 1000 total (55.0%) callers: 1000 ( 100.0%) block in <main> callees (1000 total): 1000 ( 100.0%) concatarray code: | 1 | def concat_array 1000 (55.0%) | 2 | ["t", "r", *x = "u", "e"].join | 3 | end ``` The `--walk` option is recommended for this feature as it make it easier to traverse the tree of exits. *Goals of this feature:* This feature is meant to give more information when working on YJIT. The idea is that if we know what code is exiting we can decide what areas to prioritize when fixing exits. In some cases this means adding prioritizing avoiding certain exits in yjit. In more complex cases it might mean changing the Ruby code to be more performant when run with yjit. Ultimately the more information we have about what code is exiting AND why, the better we can make yjit. *Known limitations:* * Due to tracing exits, running this on large codebases like Rails can be quite slow. * On complex methods it can still be difficult to pinpoint the exact cause of an exit. * Stackprof is a requirement to to view the backtrace information from the dump file. Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org> Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
* Rust YJITAlan Wu2022-04-271-131/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In December 2021, we opened an [issue] to solicit feedback regarding the porting of the YJIT codebase from C99 to Rust. There were some reservations, but this project was given the go ahead by Ruby core developers and Matz. Since then, we have successfully completed the port of YJIT to Rust. The new Rust version of YJIT has reached parity with the C version, in that it passes all the CRuby tests, is able to run all of the YJIT benchmarks, and performs similarly to the C version (because it works the same way and largely generates the same machine code). We've even incorporated some design improvements, such as a more fine-grained constant invalidation mechanism which we expect will make a big difference in Ruby on Rails applications. Because we want to be careful, YJIT is guarded behind a configure option: ```shell ./configure --enable-yjit # Build YJIT in release mode ./configure --enable-yjit=dev # Build YJIT in dev/debug mode ``` By default, YJIT does not get compiled and cargo/rustc is not required. If YJIT is built in dev mode, then `cargo` is used to fetch development dependencies, but when building in release, `cargo` is not required, only `rustc`. At the moment YJIT requires Rust 1.60.0 or newer. The YJIT command-line options remain mostly unchanged, and more details about the build process are documented in `doc/yjit/yjit.md`. The CI tests have been updated and do not take any more resources than before. The development history of the Rust port is available at the following commit for interested parties: https://github.com/Shopify/ruby/commit/1fd9573d8b4b65219f1c2407f30a0a60e537f8be Our hope is that Rust YJIT will be compiled and included as a part of system packages and compiled binaries of the Ruby 3.2 release. We do not anticipate any major problems as Rust is well supported on every platform which YJIT supports, but to make sure that this process works smoothly, we would like to reach out to those who take care of building systems packages before the 3.2 release is shipped and resolve any issues that may come up. [issue]: https://bugs.ruby-lang.org/issues/18481 Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> Co-authored-by: Noah Gibbs <the.codefolio.guy@gmail.com> Co-authored-by: Kevin Newton <kddnewton@gmail.com>
* Prefer RBOOLNobuyoshi Nakada2022-01-011-1/+1
|
* YJIT: Edit module documentation for clarityAlan Wu2021-12-111-5/+8
| | | | | | | Add an empty line before the module doc string so RDoc can find it. While we are at it, edit for clarity. The file should already be using frozen string literals since c10d5085a247266c6399dc6fb68706d87cbdab05. [ci skip]
* YJIT: Fail gracefully while OOM for new entry pointsAlan Wu2021-12-011-0/+4
| | | | | | | | | | | | | | | | | | | | Previously, YJIT crashes with rb_bug() when asked to compile new methods while out of executable memory. To handle this situation gracefully, this change keeps track of all the blocks compiled each invocation in case YJIT runs out of memory in the middle of a compliation sequence. The list is used to free all blocks in case compilation fails. yjit_gen_block() is renamed to gen_single_block() to make it distinct from gen_block_version(). Call to limit_block_version() and block_t allocation is moved into the function to help tidy error checking in the outer loop. limit_block_version() now returns by value. I feel that an out parameter with conditional mutation is unnecessarily hard to read in code that does not need to go for last drop performance. There is a good chance that the optimizer is able to output identical code anyways.
* YJIT: Make block invalidation more robustAlan Wu2021-11-221-0/+4
| | | | | | | | | | | | | | | | | | | | | This commit adds an entry_exit field to block_t for use in invalidate_block_version(). By patching the start of the block while invalidating it, invalidate_block_version() can function correctly while there is no executable memory left for new branch stubs. This change additionally fixes correctness for situations where we cannot patch incoming jumps to the invalidated block. In situations such as Shopify/yjit#226, the address to the start of the block is saved and used later, possibly after the block is invalidated. The assume_* family of function now generate block->entry_exit before remembering blocks for invalidation. RubyVM::YJIT.simulate_oom! is introduced for testing out of memory conditions. The test for it is disabled for now because OOM triggers other failure conditions not addressed by this commit. Fixes Shopify/yjit#226