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

69097 Коммитов

Автор SHA1 Сообщение Дата
Aaron Patterson e8617d0e7e Make sure we can still compile with the JIT disabled
If `--disable-jit-support` is passed to configure, then `jit_func` is
removed from the iseq body and we can't compile YJIT.  This commit
detects when the JIT function pointer is gone and disables YJIT in that
case.
2021-10-20 18:19:38 -04:00
Aaron Patterson 41f405c486 Remove the scraper
Now that we're using the jit function entry point, we don't need the
scraper.  Thank you for your service, scraper. ❤️
2021-10-20 18:19:38 -04:00
Aaron Patterson 84a1e04e58 Change register definitions to match the entry point calling convention
The JIT entry point passes the CFP as RSI and the EC as RDI.  Lets match
that so we don't have to shuffle registers around.
2021-10-20 18:19:38 -04:00
Aaron Patterson 2a59bd7312 Disable YJIT in MJIT tests 2021-10-20 18:19:38 -04:00
Aaron Patterson 5336f6dada make compiler happy 2021-10-20 18:19:38 -04:00
Aaron Patterson 8fd3e0e9ff Fix BOP invalidation
Instead of mutating the iseqs, just clear the JIT function.
2021-10-20 18:19:38 -04:00
Aaron Patterson 05b5a7f011 Add a guard that we start executing on the first PC
Methods with optional parameters don't always start executing at the
first PC, but we compile all methods assuming that they do.  This commit
adds a guard to ensure that we're actually starting at the first PC for
methods with optional params
2021-10-20 18:19:37 -04:00
Aaron Patterson 0fdcdd267f fix alignment 2021-10-20 18:19:37 -04:00
Aaron Patterson d0174d99c6 Always use `ret` to return to the interpreter
Always using `ret` to return to the interpreter means that we never have
to check the VM_FRAME_FLAG_FINISH flag.

In the case that we return `Qundef`, the interpreter will execute the
cfp.  We can take advantage of this by setting the PC to the instruction
we can't handle, and let the interpreter pick up the ball from there.

If we return a value other than Qundef, the interpreter will take that
value as the "return value" from the JIT and push that to the SP of the
caller

The leave instruction puts the return value on the top of the calling
frame's stack.  YJIT does the same thing for leave instructions.
However, when we're returning back to the interpreter, the leave
instruction _should not_ put the return value on the top of the stack,
but put it in RAX and use RET.  This commit pops the last value from the
stack pointer and puts it in RAX so that the interpreter is happy with
SP.
2021-10-20 18:19:37 -04:00
Noah Gibbs b70383fbea YJIT stats should always include the inlined and outlined sizes, regardless of RUBY_DEBUG and --yjit-stats/YJIT_STATS settings 2021-10-20 18:19:37 -04:00
John Hawthorn adfecd8f4d Allow asserts on results, rather than stdout 2021-10-20 18:19:37 -04:00
John Hawthorn 9c9e23e277 Add assert_no_exits alias 2021-10-20 18:19:37 -04:00
John Hawthorn 4040ca8293 more testing 2021-10-20 18:19:37 -04:00
John Hawthorn 073e3b2eab Add test for recursion 2021-10-20 18:19:37 -04:00
John Hawthorn 7ed1e3ff0b Add test of yjit compilation 2021-10-20 18:19:37 -04:00
John Hawthorn 4dc821e643 Add YJIT.enabled? 2021-10-20 18:19:37 -04:00
Kevin Newton 9a436da064 Ensure we guard the value before we return
Otherwise you can end up not implicitly calling `to_ary`, which if it has side-effects will result in different behavior.
2021-10-20 18:19:37 -04:00
Maxime Chevalier-Boisvert 1943b27fe9 Update yjit.rb 2021-10-20 18:19:37 -04:00
Maxime Chevalier-Boisvert 84920fe8ee Update yjit.rb
Co-authored-by: Rafael França <rafael.franca@shopify.com>
2021-10-20 18:19:37 -04:00
Aaron Patterson a9c96222a9 Dup strings so we can mutate them
I guess the strings are frozen, so we need to dup before mutating
2021-10-20 18:19:37 -04:00
Maxime Chevalier-Boisvert 27681f2694 It's RUN_OPTS, not RUNOPTS!!! via @tenderlove 2021-10-20 18:19:37 -04:00
Kevin Newton 341d5bdcb2 Code review for expandarray and tests 2021-10-20 18:19:37 -04:00
Kevin Newton 97025db90e Convert jumps to cmov 2021-10-20 18:19:37 -04:00
Kevin Deisz bfde30c326 Implement expandarray 2021-10-20 18:19:37 -04:00
Kevin Newton be648e0940 Implement splatarray 2021-10-20 18:19:37 -04:00
John Hawthorn cb5571eece Flatten mappings when clearing locals
We clear locals when we know their values might change (ex. when
performing a method call). However previously values on the stack which
were originally pushed from a local would still point back to that
local.

With this commit, when clearing locals, we'll now iterate over the
mappings of the stack and copy the known type from the local to the
stack mapping, removing the association to the local.

This should mean both that we'll retain any information we already know
about the local type, and that if a local is modified we won't
incorrectly infer it's new type from the existing value on the stack.
2021-10-20 18:19:37 -04:00
Maxime Chevalier-Boisvert d5f18f7845 Add (void) for no arg functions 2021-10-20 18:19:37 -04:00
Maxime Chevalier-Boisvert 350b686a2c First pass at code page GC object. 2021-10-20 18:19:37 -04:00
Aaron Patterson 2440fafba0 rb_struct_define_under needs a trailing NULL
The last parameter to rb_struct_define_under needs to be NULL otherwise
we can get a SEGV.
2021-10-20 18:19:37 -04:00
John Hawthorn dc8aca1883 Use push and pop in jit_rb_obj_not to avoid corrupting types 2021-10-20 18:19:37 -04:00
John Hawthorn 0c390e9965 Add assertions of types in jit_guard_known_klass 2021-10-20 18:19:37 -04:00
Maxime Chevalier-Boisvert 51c84f0033 Code page allocation code 2021-10-20 18:19:37 -04:00
Aaron Patterson 09679f486c Add an lldb script to print YJIT comments
This script is an lldb helper that just loops through all the comments
stored and prints out the comment along with the address corresponding
to the comment.

For example, I'm crashing in JIT code at address 0x0000000110000168.
Using the `lc` helper I can see that it's probably crashing inside the
exit back to the interpreter

```
(lldb) bt 5
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x22220021)
    frame #0: 0x0000000110000168
  * frame #1: 0x00000001002b5ff5 miniruby`invoke_block_from_c_bh [inlined] invoke_block(ec=0x0000000100e05350, iseq=0x0000000100c1ff10, self=0x0000000100c76cc0, captured=<unavailable>, cref=0x0000000000000000, type=<unavailable>, opt_pc=<unavailable>) at vm.c:1268:12
    frame #2: 0x00000001002b5f7d miniruby`invoke_block_from_c_bh [inlined] invoke_iseq_block_from_c(ec=<unavailable>, captured=<unavailable>, self=0x0000000100c76cc0, argc=2, argv=<unavailable>, kw_splat=0, passed_block_handler=0x0000000000000000, cref=0x0000000000000000, is_lambda=<unavailable>, me=0x0000000000000000) at vm.c:1340
    frame #3: 0x00000001002b5e14 miniruby`invoke_block_from_c_bh(ec=<unavailable>, block_handler=<unavailable>, argc=<unavailable>, argv=<unavailable>, kw_splat=0, passed_block_handler=0x0000000000000000, cref=0x0000000000000000, is_lambda=<unavailable>, force_blockarg=0) at vm.c:1358
    frame #4: 0x000000010029860b miniruby`rb_yield_values(n=<unavailable>) at vm_eval.c:0
(lldb) lc
0x11000006d "putobject_INT2FIX_1_"
0x110000083 "leave"
0x110000087 "check for interrupts"
0x110000087 "RUBY_VM_CHECK_INTS(ec)"
0x110000098 "check for finish frame"
0x1100000ed "getlocal_WC_0"
0x110000107 "getlocal_WC_1"
0x11000012a "opt_send_without_block"
0x110000139 "opt_send_without_block"
0x11000013c "exit to interpreter"
```
2021-10-20 18:19:37 -04:00
Kevin Deisz ba9aa1f8ef Implement opt_div 2021-10-20 18:19:37 -04:00
Kevin Deisz b0ae4fdcfb Implement opt_mult
Basically the same thing as opt_mod, but for multiplying.
2021-10-20 18:19:37 -04:00
Maxime Chevalier-Boisvert 4bea8af69f Update deps 2021-10-20 18:19:37 -04:00
Maxime Chevalier-Boisvert 6cb4edd73f Implement swap instruction 2021-10-20 18:19:37 -04:00
John Hawthorn 9e0a56fb24 Add FLONUM detection 2021-10-20 18:19:37 -04:00
John Hawthorn dfc5e5e35b Support guards against symbols and integers
This adds guards
2021-10-20 18:19:37 -04:00
John Hawthorn c3f264b62c Allow chaining on immediate guard
In jit_guard_known_klass whenever we encounter a new class should
recompile the current instruction.

However, previously once jit_guard_known_klass had guarded for a heap
object it would not recompile for  any immediate (special const) objects
arriving afterwards and would take a plain side-exit instead of a chain
guard.

This commit uses jit_chain_guard inside jit_guard_known_klass instead of
the plain side exit, so that we can recompile for any special constants
arriving afterwards.
2021-10-20 18:19:37 -04:00
Noah Gibbs 6998246233 Use snprintf rather than double strncpy. 2021-10-20 18:19:37 -04:00
Noah Gibbs e2fe7e4aff Percentages should be out of 100.0%, not 1.0%. 2021-10-20 18:19:37 -04:00
Noah Gibbs db02d73e5e Change strcpy of a static string to strncpy 2021-10-20 18:19:37 -04:00
Noah Gibbs 5e164a77d5 Better comments where we add exits-by-opcode to the stats hash, plus a presumably-unneeded strncpy just to be sure. 2021-10-20 18:19:36 -04:00
Noah Gibbs 89ae21a092 Add back ifdefs for RUBY_DEBUG, accidentally removed 2021-10-20 18:19:36 -04:00
Noah Gibbs d2e9932908 Convert YJIT stats reporting on exit from C to Ruby. 2021-10-20 18:19:36 -04:00
Noah Gibbs 33227b1094 Add exit counters and inline/outlined code size to stats hash 2021-10-20 18:19:36 -04:00
Aaron Patterson 0d63600e4f Partial revert of ceebc7fc98
I'm looking through the places where YJIT needs notifications.  It looks
like these changes to gc.c and vm_callinfo.h have become unnecessary
since 84ab77ba59.  This commit just makes the diff against upstream
smaller, but otherwise shouldn't change any behavior.
2021-10-20 18:19:36 -04:00
Noah Gibbs b385f31188 Remove seven YJIT counters that are no longer used. 2021-10-20 18:19:36 -04:00
Noah Gibbs 25792c17d4 Convert yjit static stat variables to counters 2021-10-20 18:19:36 -04:00