summaryrefslogtreecommitdiff
path: root/yjit/src
AgeCommit message (Collapse)Author
2022-08-29Progress on codegen.rs portMaxime Chevalier-Boisvert
2022-08-29* Arm64 Beginnings (https://github.com/Shopify/ruby/pull/291)Maxime Chevalier-Boisvert
* Initial setup for aarch64 * ADDS and SUBS * ADD and SUB for immediates * Revert moved code * Documentation * Rename Arm64* to A64* * Comments on shift types * Share sig_imm_size and unsig_imm_size
2022-08-29Add test for lea and ret. Fix codegen for lea and ret.Maxime Chevalier-Boisvert
2022-08-29Change codegen.rs to use backend Assembler directlyMaxime Chevalier-Boisvert
2022-08-29Implement gc offset logicMaxime Chevalier-Boisvert
2022-08-29Load GC Value operands into registersMaxime Chevalier-Boisvert
2022-08-29Add CCall IR insn, implement gen_swap()Maxime Chevalier-Boisvert
2022-08-29Add gen_dupnMaxime Chevalier-Boisvert
2022-08-29Add test with register reuseMaxime Chevalier-Boisvert
2022-08-29Fix issue with load, gen_dupMaxime Chevalier-Boisvert
2022-08-29Implement target-specific insn splitting with Kevin. Add tests.Maxime Chevalier-Boisvert
2022-08-29Make assembler methods public, sketch gen_dup with new backendMaxime Chevalier-Boisvert
2022-08-29Fix bug with asm.comment()Maxime Chevalier-Boisvert
2022-08-29Bias register allocator to reuse first operandMaxime Chevalier-Boisvert
2022-08-29Add dbg!() for Assembler. Fix regalloc issue.Maxime Chevalier-Boisvert
2022-08-29Function to map from Opnd => X86OpndMaxime Chevalier-Boisvert
2022-08-29Start work on platform-specific codegenMaxime Chevalier-Boisvert
2022-08-29Split insns (https://github.com/Shopify/ruby/pull/290)Kevin Newton
* Split instructions if necessary * Add a reusable transform_insns function * Split out comments labels from transform_insns * Refactor alloc_regs to use transform_insns
2022-08-29IR register allocationKevin Newton
PR: https://github.com/Shopify/ruby/pull/289
2022-08-29Removed String opnd so that we can derive Copy for OpndMaxime Chevalier-Boisvert
2022-08-29Complete sketch for guard_object_is_heapMaxime Chevalier-Boisvert
2022-08-29Change push insn macrosMaxime Chevalier-Boisvert
2022-08-29Switch IR to use Option<Target>Maxime Chevalier-Boisvert
2022-08-29Add macro to define opsMaxime Chevalier-Boisvert
2022-08-29Progress on IR sketchMaxime Chevalier-Boisvert
2022-08-29WIP backend IR sketchMaxime Chevalier-Boisvert
2022-08-24add --yjit-dump-iseqs param (https://github.com/Shopify/ruby/pull/332)Noah Gibbs
Notes: Merged: https://github.com/ruby/ruby/pull/6278
2022-08-19Rename mjit_exec to jit_exec (#6262)Takashi Kokubun
* Rename mjit_exec to jit_exec * Rename mjit_exec_slowpath to mjit_check_iseq * Remove mjit_exec references from comments Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-08-09Regen YJIT bindingsJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/6158
2022-08-04YJIT: Allow str-concat arg to be any string subtype, not just rb_cString (#6205)Noah Gibbs
Allow str-concat arg to be any string subtype, not just rb_cString Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-08-04YJIT: Add known_* helpers for Type (#6208)John Hawthorn
* YJIT: Add known_* helpers for Type This adds a few helpers to Type which all return Options representing what is known, from a Ruby perspective, about the type. This includes: * known_class_of: If known, the class represented by this type * known_value_type: If known, the T_ value type * known_exact_value: If known, the exact VALUE represented by this type (currently this is only available for true/false/nil) * known_truthy: If known, whether or not this value evaluates as true (not false or nil) The goal of this is to abstract away the specifics of the mappings between types wherever possible from the codegen. For example previously by introducing Type::CString as a more specific version of Type::TString, uses of Type::TString in codegen needed to be updated to check either case. Now by using known_value_type, at least in theory we can introduce new types with minimal (if any) codegen changes. I think rust's Option type allows us to represent this uncertainty fairly well, and should help avoid mistakes, and the matching using this turned out pretty cleanly. * YJIT: Use known_value_type for checktype * YJIT: Use known_value_type for T_STRING check * YJIT: Use known_class_of in guard_known_klass * YJIT: Use known truthyness in jit_rb_obj_not * YJIT: Rename known_class_of => known_class Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-07-28YJIT: Teach getblockparamproxy to handle the no-block case without exiting ↵Matthew Draper
(#6191) Teach getblockparamproxy to handle the no-block case without exiting Co-authored-by: John Hawthorn <john@hawthorn.email> Co-authored-by: John Hawthorn <john@hawthorn.email> Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-07-20YJIT: Skip setlocal WB check for immediate values (#6122)John Hawthorn
Write barriers may be required when VM_ENV_FLAG_WB_REQUIRED is set, however write barriers only affect heap objects being written. If we know an immediate value is being written we can skip this check. Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-07-18Extract vm_ic_entry API to mimic vm_cc behaviorJemma Issroff
Notes: Merged: https://github.com/ruby/ruby/pull/5978
2022-07-15Implement Objects on VWAPeter Zhu
This commit implements Objects on Variable Width Allocation. This allows Objects with more ivars to be embedded (i.e. contents directly follow the object header) which improves performance through better cache locality. Notes: Merged: https://github.com/ruby/ruby/pull/6117
2022-07-12Speed up --yjit-trace-exits code (#6106)Eileen M. Uchitelle
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> Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-07-06Switch YJIT to using rb_str_buf_append rather than rb_str_append when ↵Noah Gibbs (and/or Benchmark CI)
encodings don't match, as discussed with byroot Notes: Merged: https://github.com/ruby/ruby/pull/6095
2022-07-06YJIT: add a counter for gc object refs in the machine code (#6089)Maxime Chevalier-Boisvert
Add a counter for gc object refs in the machine code This is to gather data for the eventual implementation of a constant pool. Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-06-30YJIT: Refactor gen_opt_mod (#6078)Dave Schwantes
Refactor gen_opt_mod in YJIT Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-06-27Separate Type::String into Type::CString and Type::TString.Noah Gibbs (and/or Benchmark CI)
Also slightly broaden the cases where << on two strings will generate specialised code rather than a plain method call. Notes: Merged: https://github.com/ruby/ruby/pull/6022
2022-06-26YJIT: Fix copy pasted comment [ci skip]Alan Wu
2022-06-21Skip protected ancestry guard for FCALLs in YJITJohn Hawthorn
Notes: Merged: https://github.com/ruby/ruby/pull/5643
2022-06-14YJIT: On-demand executable memory allocation; faster boot (#5944)Alan Wu
This commit makes YJIT allocate memory for generated code gradually as needed. Previously, YJIT allocates all the memory it needs on boot in one go, leading to higher than necessary resident set size (RSS) and time spent on boot initializing the memory with a large memset(). Users should no longer need to search for a magic number to pass to `--yjit-exec-mem` since physical memory consumption should now more accurately reflect the requirement of the workload. YJIT now reserves a range of addresses on boot. This region start out with no access permission at all so buggy attempts to jump to the region crashes like before this change. To get this hardening at finer granularity than the page size, we fill each page with trapping instructions when we first allocate physical memory for the page. Most of the time applications don't need 256 MiB of executable code, so allocating on-demand ends up doing less total work than before. Case in point, a simple `ruby --yjit-call-threshold=1 -eitself` takes about half as long after this change. In terms of memory consumption, here is a table to give a rough summary of the impact: | Peak RSS in MiB | -eitself example | railsbench once | | :-------------: | ---------------: | --------------: | | before | 265 | 377 | | after | 11 | 143 | | no YJIT | 10 | 101 | A new module is introduced to handle allocation bookkeeping. `CodePtr` is moved into the module since it has a close relationship with the new `VirtualMemory` struct. This new interface has a slightly smaller surface than before in that marking a region as writable is no longer a public operation. Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-06-10Add tests for a variety of string-subclass operations (#5999)Noah Gibbs
This way YJIT has to match CRuby for each of them. Remove unused string_p() Rust function Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-06-10Don't return a value from jit_guard_known_klass. We never return anything ↵Noah Gibbs
but true at this point and we don't usually check the returned value. (#6000) Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-06-09Add ability to trace exit locations in yjit (#5970)Eileen M. Uchitelle
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> Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-06-07Add special-case code for the String unary plus operator (#5982)Noah Gibbs
Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-06-06Use bindgen to import Ruby constants wherever possible. (#5943)Noah Gibbs
Constants that can't be imported via bindgen should have a comment saying why not. Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-06-01Revert incorrect string-guard optimisation. (#5969)Noah Gibbs
Also add jhawthorn's test to for this bug. Fix String#to_s invalidation test Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-05-26Use bindgen to import CRuby constants for YARV instruction bytecodesNoah Gibbs (and/or Benchmark CI)
Notes: Merged: https://github.com/ruby/ruby/pull/5948