Граф коммитов

85 Коммитов

Автор SHA1 Сообщение Дата
Noah Gibbs 25792c17d4 Convert yjit static stat variables to counters 2021-10-20 18:19:36 -04:00
Alan Wu 3996e0ab07 Add tests, comments, and an assert for invokesuper 2021-10-20 18:19:36 -04:00
Alan Wu 6883aeda77 Add a macro for tweaking default call threshold
For use in development for writing `test.rb` and running with `make
run`.
2021-10-20 18:19:36 -04:00
Maxime Chevalier-Boisvert 7030cae969 Try running with more YJIT options in CI to surface more bugs 2021-10-20 18:19:36 -04:00
Aaron Patterson 46d5e10279 Add graphviz output
This adds a method to blocks to get outgoing ids, then uses the outgoing
ids to generate a graphviz graph.  Two methods were added to the Block
object.  One method returns an id for the block, which is just the
address of the underlying block.  The other method returns a list of
outgoing block ids.  We can use Block#id in conjunction with
Block#outgoing_ids to construct a graph of blocks
2021-10-20 18:19:36 -04:00
Jean Boussier d416a15c86 Warn rather than raise when --yjit-stats is ignored 2021-10-20 18:19:36 -04:00
Noah Gibbs d1d3d2c0aa If --yjit-stats is given without RUBY_DEBUG, that should be an error. 2021-10-20 18:19:36 -04:00
Jean Boussier 3365e1d719 Allow to enable `--yjit-stats` via a env variable 2021-10-20 18:19:36 -04:00
Maxime Chevalier-Boisvert 860589c7fa Use builtin_inline_p to avoid pushing a frame for primitive C methods (#63)
* Use builtin_inline_p to skip a frame of C methods

* Fix bugs in primitive cfunc call code

* Remove if (push_frame) {}

* Remove if (push_frame) {}

* Push Aaron's fix to avoid hardcoding insn lengths

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert b415ceb92e Increase default YJIT call threshold to 10. Add exec mem size arg. (#52) 2021-10-20 18:19:35 -04:00
Alan Wu 0758115d11 Implement send with blocks
* Implement send with blocks

Not that much extra work compared to `opt_send_without_block`.
Moved the stack over flow check because it could've exited after changes
are made to cfp.

* rename oswb counters

* Might as well implement sending block to cfuncs

* Disable sending blocks to cfuncs for now

* Reconstruct interpreter sp before calling into cfuncs

In case the callee cfunc calls a method or delegates to a block.
This also has the side benefit of letting call sites that sometimes are
iseq calls and sometimes cfunc call share the same successor.

* only sync with interpreter sp when passing a block


Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Aaron Patterson <aaron.patterson@shopify.com>
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert 8249f6ef57 Print top-20 common exit reasons instead of just top-10 (#19) 2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert cf2b508375 Try to alloc executable memory within rel32 range on Linux machines (#12)
* Use INT32_MIN, INT32_MAX, etc. constants in yjit_asm.c

* Print warning on stderr when code past rel32 jump range

* Fix preprocessor snafu

* Move rel32 warning into --yjit-stats

* Try to allocate within rel32 offset on Linux machines

* Update yjit_asm.c

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>

* On Linux, use sysconf to get the page size

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert 96f4f918b0 Implement greedy versioning. Refactor versioning logic. (#10)
* Implement eager versioning. Refactor versioning logic.

* Add --version-limit and --greedy-versioning command-line args
2021-10-20 18:19:34 -04:00
Aaron Patterson ac88c61ed8 cYjitCodeComment is only defined if we're not in debugging mode
This commit fixes a build error.  If we build in release mode (IOW
*without* RUBY_DEBUG), then this constant isn't defined.  Release mode
builds are required by yjit-bench
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert 0cc73ca2a9 Malloc branch entries (#112)
* Malloc branch entries

* Add ASM comment for stack overflow check

* WIP

* Fix branch GC code. Add rb_darray_remove_unordered().

* Fix block end_pos after branch rewriting. Remove dst_patched bits.
2021-10-20 18:19:33 -04:00
Alan Wu b626dd7211 YJIT: Fancier opt_getinlinecache
Make sure `opt_getinlinecache` is in a block all on its own, and
invalidate it from the interpreter when `opt_setinlinecache`.
It will recompile with a filled cache the second time around.
This lets YJIT runs well when the IC for constant is cold.
2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert 032b2ecf4b Compute percentage of exits for top-10 exit ops 2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert 7108da16e9 Fix two stats bugs, refactor stats code, add total_insn_count print 2021-10-20 18:19:33 -04:00
Alan Wu 515fb988fe YJIT: add comments to disassembly
Introduce a new macro `ADD_COMMENT(cb, comment)` that records a comment
for the current write position in the code block.

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Aaron Patterson <aaron.patterson@shopify.com>
2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert 543bdde6c2 Update yjit_iface.c 2021-10-20 18:19:33 -04:00
Alan Wu 7f4b9e8e61 YJIT: make ratio_in_yjit more accurate
Don't count instructions that take exit to the interpreter.
2021-10-20 18:19:33 -04:00
Aaron Patterson 4faaa8e5dc Collect statistics about binding allocations / local variable set
This commit collects statistics about how many binding objects are
allocated as well as the number of local variables set on bindings.
Statistics are output along with other YJIT stats.  Here is an example
of the output:

```
***YJIT: Printing runtime counters from yjit.rb***
Number of Bindings Allocated: 195
Number of locals modified through binding: 0
opt_send_without_block exit reasons:
          ivar_get_method    7515891 (40.4%)
       se_cc_klass_differ    3081330 (16.6%)
       iseq_argc_mismatch    1564578 ( 8.4%)
     se_receiver_not_heap    1557663 ( 8.4%)
                 ic_empty    1407064 ( 7.6%)
         optimized_method     995823 ( 5.4%)
          iseq_not_simple     819413 ( 4.4%)
             alias_method     706972 ( 3.8%)
                  bmethod     685253 ( 3.7%)
      callsite_not_simple     225983 ( 1.2%)
                 kw_splat      25999 ( 0.1%)
          ivar_set_method        902 ( 0.0%)
       cfunc_toomany_args        394 ( 0.0%)
           refined_method         42 ( 0.0%)
    cfunc_ruby_array_varg         29 ( 0.0%)
              invalid_cme          4 ( 0.0%)
leave exit reasons:
    se_finish_frame    4067107 (100.0%)
       se_interrupt         24 ( 0.0%)
getinstancevariable exit reasons:
               undef     121177 (100.0%)
    idx_out_of_range          5 ( 0.0%)
opt_aref exit reasons:
    (all relevant counters are zero)
compiled_iseq_count:         3944
main_block_code_size:     1.1 MiB
side_block_code_size:     0.6 MiB
vm_insns_count:        1137268516
yjit_exec_insns_count:  414015644
ratio_in_yjit:              26.7%
avg_len_in_yjit:              7.5
total_exit_count:        55491789
most frequent exit op:
    opt_send_without_block:   18587628 (33.5%)
        opt_getinlinecache:   11075822 (20.0%)
                      send:    4949300 (8.9%)
                     leave:    4067131 (7.3%)
                   defined:    3975196 (7.2%)
       setinstancevariable:    3567315 (6.4%)
               invokesuper:    2982163 (5.4%)
        getblockparamproxy:    2168852 (3.9%)
                 opt_nil_p:    2104524 (3.8%)
                  opt_aref:    2013858 (3.6%)
```

Running RailsBench allocates 195 binding objects but doesn't set any
local variables.
2021-10-20 18:19:32 -04:00
Maxime Chevalier-Boisvert cb46a17ca1 Log code size in bytes instead of MiB 2021-10-20 18:19:32 -04:00
Alan Wu 983bcd5ac2 Fix improper use of st_foreach_with_replace
Replacing the key was only okay if the new key hashes to the same thing
as the old key. That doesn't hold for YJIT's table when the keys move.
2021-10-20 18:19:32 -04:00
Alan Wu d03b7f77d4 Fix GCC warnings
Mostly unused and uninitialized warnings here and there
2021-10-20 18:19:32 -04:00
Alan Wu fbb514f67e Introduce yjit_guard_known_klass() 2021-10-20 18:19:32 -04:00
Alan Wu a8f7eb2f35 Polymorphic opt_send_without_block 2021-10-20 18:19:32 -04:00
Alan Wu ec1cbbb07d Get rid of dependency on rb_call_cache 2021-10-20 18:19:32 -04:00
Alan Wu 5d834bcf9f YJIT: lazy polymorphic getinstancevariable
Lazily compile out a chain of checks for different known classes and
whether `self` embeds its ivars or not.

* Remove trailing whitespaces

* Get proper addresss in Capstone disassembly

* Lowercase address in Capstone disassembly

Capstone uses lowercase for jump targets in generated listings. Let's
match it.

* Use the same successor in getivar guard chains

Cuts down on duplication

* Address reviews

* Fix copypasta error

* Add a comment
2021-10-20 18:19:31 -04:00
Maxime Chevalier-Boisvert 439db7b81b Add metric for average # of insns spent in yjit before exiting 2021-10-20 18:19:31 -04:00
Alan Wu cee597bd01 Include ruby/ruby.h before vm_core.h
This is how vm.c does it, and if we don't follow it in yjit
compilation units, rb_vm_t would have a conflicting size.
2021-10-20 18:19:31 -04:00
Alan Wu cf011b6676 Check for null
Sometimes you bop before you init, you know?
2021-10-20 18:19:31 -04:00
Aaron Patterson c15a577eda Make Blocks depend on BOPS
When a BOP is redefined, the BOP redefinition callback will invalidate
any blocks that depend on BOPS.  This allows us to eliminate runtime
checks for BOP redefinition.
2021-10-20 18:19:31 -04:00
Jose Narvaez 4e2eb7695e Yet Another Ruby JIT!
Renaming uJIT to YJIT. AKA s/ujit/yjit/g.
2021-10-20 18:19:31 -04:00