69165 Commits

Author SHA1 Message Date
Alan Wu
4b58d698b1 Count interpreter instructions when -DYJIT_STATS=1
The interpreter instruction count was enabled based on RUBY_DEBUG as
opposed to YJIT_STATS. In builds with YJIT_STATS=1 but RUBY_DEBUG=0,
the count was not available.

Move YJIT_STATS in yjit.h where declarations are expoed to code outside
of YJIT. Also reduce the changes made to the interpreter for calling
into YJIT's instruction counting function.
2021-10-20 18:19:40 -04:00
Maxime Chevalier-Boisvert
9bd6ce4745 Update README.md 2021-10-20 18:19:40 -04:00
Aaron Patterson
580e1bab18 disable yjit when testing mjit 2021-10-20 18:19:40 -04:00
Maxime Chevalier-Boisvert
a1d42c37f4 Update ruby.c 2021-10-20 18:19:40 -04:00
Aaron Patterson
234ab816ba Exit if YJIT and MJIT are both enabled
YJIT and MJIT can't be running in the same process otherwise they'll
clobber each other.  We should show an error and exit if they're both
enabled.
2021-10-20 18:19:40 -04:00
Maxime Chevalier-Boisvert
013a4a31d6 Prevent stats being enabled late at run-time 2021-10-20 18:19:40 -04:00
Aaron Patterson
640b162b51 Exit when the object is frozen
Exit when the object is frozen, also add tests
2021-10-20 18:19:39 -04:00
Aaron Patterson
376f5ec1a1 Add a write barrier to ivar set
We need to fire the write barrier during ivar set.  This function
extracts the write barrier function then calls it.

Co-Authored-By: John Hawthorn <john@hawthorn.email>
2021-10-20 18:19:39 -04:00
eileencodes
307a4369e1 Implement setivar method calls 2021-10-20 18:19:39 -04:00
John Hawthorn
ce02aefabb Allow calling variadic cfuncs with many args
We have a check to ensure we don't have to push args on the stack to
call a cfunc with many args. However we never need to use the stack for
variadic cfuncs, so we shouldn't care about the number of arguments.
2021-10-20 18:19:39 -04:00
John Hawthorn
922aed92b5 Add codegen for rb_true and rb_false
These are used by .nil? and therefore opt_nil_p
2021-10-20 18:19:39 -04:00
John Hawthorn
fd34c831f6 Allow special case of expandarray with nil 2021-10-20 18:19:39 -04:00
Alan Wu
d098c5560b Shave a few instructions off of leave
The code path for leave that returns to the interpreter
(gen_leave() -> yjit_gen_leave_exit()) used to have the logic:

```
    cfp->sp++;
    cfp->sp[-1] = return_val;
    cfp->sp--;
    return return_val;
```

The SP changes it made was unnecessary and this change removes it.

After this change, `leave` doesn't adjust the `cfp->sp` of the caller
and only writes `cfp->sp[0]`. To accomodate this in the JIT-to-JIT
return case, return stubs have an `sp_offset` of 1.

The change removes sp adjustment from the JIT-to-JIT return case, too,
making it more efficient. Also, since the C method case of `send`
has an `sp_offset` of 1 after the call, this change enables block
version sharing.
2021-10-20 18:19:39 -04:00
Alan Wu
ed85e8a33a Use reg1 in GEN_COUNTER_INC to avoid clobbering RAX 2021-10-20 18:19:39 -04:00
John Hawthorn
c210fade27 Implement newrange 2021-10-20 18:19:39 -04:00
John Hawthorn
3a3f706698 Additional invokesuper tests 2021-10-20 18:19:39 -04:00
John Hawthorn
3ecc6befcd Implement invokesuper using cfp->ep[ME] check
This fixes and re-enables invokesuper, replacing the existing guards
with a guard on the method entry for the EP.
2021-10-20 18:19:39 -04:00
John Hawthorn
fbde1d9bee Store block callee_cme in darray
This allows a block version to have dependencies on multiple CMEs.
2021-10-20 18:19:39 -04:00
Maxime Chevalier-Boisvert
9d5b3e1d0f Add a small test for the code GC 2021-10-20 18:19:39 -04:00
John Hawthorn
e527912fe0 Use jit_prepare_routine_call 2021-10-20 18:19:39 -04:00
John Hawthorn
69a2531249 Implement gen_putstring 2021-10-20 18:19:39 -04:00
Ufuk Kayserilioglu
2c93ef7ab3 Add YJIT logo
Adding YJIT logo with a link to https://yjit.org
2021-10-20 18:19:39 -04:00
Alan Wu
2bd99d7d7a typo, rename, comment 2021-10-20 18:19:39 -04:00
John Hawthorn
812597676b Avoid immediate side exits in checktype
Previously checktype only supported heap objects, however it's not
uncommon to receive an immediate, for example when string interpolating
a Symbol or Integer.
2021-10-20 18:19:39 -04:00
Alan Wu
54db64f7a5 filter out internal events. add comments. reorder 2021-10-20 18:19:39 -04:00
Alan Wu
4b815abb37 Lock, don't loock. 2021-10-20 18:19:39 -04:00
Aaron Patterson
0ca04e2dd4 Only clear the JIT function when we invalidate the entry block
We should only clear the JIT function when the entry point is
invalidated.  Right now we only support compiling functions with a PC
offset of zero (functions that take optional parameters can start at
non-zero PC), so this patch just checks that the index is 0 before
clearing the jit function
2021-10-20 18:19:39 -04:00
Jean Boussier
b5a0baf1c0 Allow to toggle YJIT stats collection from runtime
For use cases where you want to collect the metrics
for a specific piece of code (typically a web request)
you can have the stats turned off by default and then
turn them on at runtime before executing the code you care
about.
2021-10-20 18:19:39 -04:00
Alan Wu
924e3ca84f fix typo 2021-10-20 18:19:39 -04:00
Alan Wu
bd876c243a TracePoint support
This change fixes some cases where YJIT fails to fire tracing events.
Most of the situations YJIT did not handle correctly involves enabling
tracing while running inside generated code.

A new operation to invalidate all generated code is added, which uses
patching to make generated code exit at the next VM instruction
boundary. A new routine called `jit_prepare_routine_call()` is
introduced to facilitate this and should be used when generating code
that could allocate, or could otherwise use `RB_VM_LOCK_ENTER()`.

The `c_return` event is fired in the middle of an instruction as opposed
to at an instruction boundary, so it requires special handling. C method
call return points are patched to go to a fucntion which does everything
the interpreter does, including firing the `c_return` event. The
generated code for C method calls normally does not fire the event.

Invalided code should not change after patching so the exits are not
clobbered. A new variable is introduced to track the region of code that
should not change.
2021-10-20 18:19:39 -04:00
Maxime Chevalier-Boisvert
0562459473 Redo the ivtable lookp once the ivar is set 2021-10-20 18:19:39 -04:00
Maxime Chevalier-Boisvert
b3e993a64b Make sure that there is always an index table entry for getivars 2021-10-20 18:19:39 -04:00
Maxime Chevalier-Boisvert
7f2828d1c8 Update README 2021-10-20 18:19:39 -04:00
Jean Boussier
0dc3bba6f2 Allow to compile with --yjit-stats support but not the full RUBY_DEBUG
RUBY_DEBUG have a very significant performance overhead. Enough that
YJIT with RUBY_DEBUG is noticeably slower than the interpreter without
RUBY_DEBUG.

This makes it hard to collect yjit-stats in production environments.

By allowing to collect JIT statistics without the RUBy_DEBUG overhead,
I hope to make such use cases smoother.
2021-10-20 18:19:39 -04:00
eileencodes
2ba090a1f9 Add toregexp to yjit
The FIXME is there so we remember to investigate why insns clears the
temporary array. Is this necessary? If it's not we can remove it from
both.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-10-20 18:19:39 -04:00
Maxime Chevalier-Boisvert
dd5082d7ca Use cmov to handle Qundef case in getivar instead of side-exit 2021-10-20 18:19:39 -04:00
Maxime Chevalier-Boisvert
c4b99d6a42 Add ASM comment 2021-10-20 18:19:39 -04:00
Mike Dalessio
918668b4a9 update README with correct repository URL 2021-10-20 18:19:39 -04:00
John Hawthorn
e18b0b6eba Implement putspecialobject 2021-10-20 18:19:39 -04:00
John Hawthorn
3edf29668e Add opt_regexpmatch2 2021-10-20 18:19:39 -04:00
John Hawthorn
595fdf8d66 Assign directly to C_ARG_REGS now when possible 2021-10-20 18:19:39 -04:00
John Hawthorn
8fa0ee4d40 Use callee-saved regs for REG_SP, REG_EP, REG_CFP 2021-10-20 18:19:39 -04:00
John Hawthorn
ed8aa3409a Detach mapping to local in ctx_set_local_type
Similar to the previous fix to ctx_clear_local_types, we must detach
mappings to a local if we are changing its value.
2021-10-20 18:19:38 -04:00
John Hawthorn
6d852e847e Fix stack size check for ctx_get_opnd_type
Previously all stack operands would become unknown once the stack grew
beyond a certain size. This worked, but unnecessarily hid available
information.
2021-10-20 18:19:38 -04:00
John Hawthorn
48dca3348a Move yjit_type_of_value into yjit_core.c 2021-10-20 18:19:38 -04:00
John Hawthorn
d78ea4abec Implement verify_ctx for debugging 2021-10-20 18:19:38 -04:00
John Hawthorn
a02002dc4f More detection of immediate constants 2021-10-20 18:19:38 -04:00
John Hawthorn
2e707ee66f Don't generate entry point when PC != 0
If we hit this at PC > 0 (ie. with an optional argument) the provided
types and context are likely incorrect and it is likely this block can't
be used.
2021-10-20 18:19:38 -04:00
eileencodes
d2e8b99b5b Implement tostring instruction for yjit
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-10-20 18:19:38 -04:00
Alan Wu
5b4305f71c Simpler fix for -DUSE_EMBED_CI=0
Nobu pointed out that saving the old ci to a local is enough to keep it
reachable.
2021-10-20 18:19:38 -04:00