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

271 Коммитов

Автор SHA1 Сообщение Дата
Kevin Newton c5acbd0208 Bail out if passing keyword arguments to only positional and/or optional methods 2021-10-20 18:19:43 -04:00
Kevin Newton 06a826b8c8 Set up the callee stack pointer properly taking into account the bits object 2021-10-20 18:19:43 -04:00
Kevin Newton 5759d840c3 Correct for positional required arguments 2021-10-20 18:19:43 -04:00
Kevin Newton 266e12ac22 Push the unspecified_bits_value onto the stack 2021-10-20 18:19:42 -04:00
Kevin Newton 9aed5809e1 Reuse stack swapping logic 2021-10-20 18:19:42 -04:00
Kevin Newton 2c0891be20 Get kwargs reordering working 2021-10-20 18:19:42 -04:00
Kevin Newton 885bb972bf Get kwargs working for all passed in the correct order 2021-10-20 18:19:42 -04:00
Alan Wu f6da559d5b Put YJIT into a single compilation unit
For upstreaming, we want functions we export either prefixed with "rb_"
or made static. Historically we haven't been following this rule, so we
were "leaking" a lot of symbols as `make leak-globals` would tell us.

This change unifies everything YJIT into a single compilation unit,
yjit.o, and makes everything unprefixed static to pass `make leak-globals`.
This manual "unified build" setup is similar to that of vm.o.

Having everything in one compilation unit allows static functions to
be visible across YJIT files and removes the need for declarations in
headers in some cases. Unnecessary declarations were removed.

Other changes of note:
  - switched to MJIT_SYMBOL_EXPORT_BEGIN which indicates stuff as being
    off limits for native extensions
  - the first include of each YJIT file is change to be "internal.h"
  - undefined MAP_STACK before explicitly redefining it since it
    collide's with a definition in system headers. Consider renaming?
2021-10-20 18:19:42 -04:00
Alan Wu 7eea96c780 Fix gen_getclassvariable
We need to reconstruct interpreter state before calling into the
routines to be able to raise exceptions. I'm getting a crash in
debug build with:
    make test-all 'TESTS=test/ruby/variable.rb' RUN_OPTS='--yjit-call-threshold=1 --yjit-max-versions=1'
2021-10-20 18:19:42 -04:00
Maxime Chevalier-Boisvert 70c5bbf84b Fix counter names for getblockparamproxy. Print in --yjit-stats. 2021-10-20 18:19:42 -04:00
eileencodes c8e157bb5c Implement getclassvariable in yjit
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-10-20 18:19:42 -04:00
eileencodes f911e264a1 Add counted side exit to getblockparamproxy
This is so we know the specific reason we're exiting this instruction.

Co-authored-by: Aaron Patterson tenderlove@ruby-lang.org
2021-10-20 18:19:42 -04:00
Noah Gibbs be06112d48 Fix changes from rebase 2021-10-20 18:19:42 -04:00
Alan Wu f36a5a98c0 style: line break before "else" 2021-10-20 18:19:41 -04:00
Alan Wu ec4998bd69 style: switch statements indent
Case labels get half an indent and the opening brace is on the same line
as "switch".
2021-10-20 18:19:41 -04:00
Alan Wu a10cf74e5c style: align pointer "*" to the right 2021-10-20 18:19:41 -04:00
John Hawthorn 5b68d14c2f Add optimized Thread.current 2021-10-20 18:19:41 -04:00
Alan Wu 5c15850ea6 Use jit_guard_known_klass() for hashes in opt_aref
The old heap object check is not as efficient as the one in
jit_guard_known_klass(). Also, the old code saves cfp->sp after popping
the operands off the stack, which might cause the operands to be not
marked by the GC in some circumstances.
2021-10-20 18:19:41 -04:00
Alan Wu 9dce2d5132 Also do String#str 2021-10-20 18:19:41 -04:00
Alan Wu 1a5109cb5f Comment edits and moving functions around in the file 2021-10-20 18:19:41 -04:00
Alan Wu a09adac2d7 Add specialization for String#to_s on plain strings
When calling "to_s" on an instance of String, the method simply returns
self. In this situation most of the work comes from setting up the
method call. It turns out that both railsbench and liquid-render do this
a lot.

When generating code for opt_send_without_block, we already generate a
known class guard, so we can detect when the receiver is a String
instance. Since gen_send_cfunc() is also used for gen_invokesuper(), and
gen_invokesuper() doesn't generate a known class guard, a new nullable
parameter for specialized codegen function is added.

Closes GH-245
2021-10-20 18:19:41 -04:00
Maxime Chevalier-Boisvert 79015926eb Try to get getblockparamproxy to support level > 0 2021-10-20 18:19:41 -04:00
Alan Wu 8edb29e5a0 Reconstruct interpreter state before calling rb_ivar_get()
It could raise ractor exceptions. The included test didn't run properly
before this change.
2021-10-20 18:19:41 -04:00
Alan Wu d0a213b30d Remove a memory load in gen_send_iseq
Instead of loading from meory for REG_SP, do a register rename instead.
It's cheaper.
2021-10-20 18:19:41 -04:00
Alan Wu 0a108601ef Add counters for version invalidation reasons
I noticed that there were two st_table iterators that do exactly the
same thing so I merged them into one.
2021-10-20 18:19:41 -04:00
Noah Gibbs e48fc07d11 Fix counter names 2021-10-20 18:19:41 -04:00
Noah Gibbs 7704a6990a Fix typo in comment 2021-10-20 18:19:41 -04:00
Noah Gibbs a0790e6335 Break up callsite_not_simple into multiple cases. 2021-10-20 18:19:41 -04:00
Maxime Chevalier-Boisvert 0c1aa17556 Remove a few more uses of the global cb/ocb 2021-10-20 18:19:41 -04:00
Alan Wu 78b5e95e41 Add a slowpath for opt_getinlinecache
Before this change, when we encounter a constant cache that is specific
to a lexical scope, we unconditionally exit. This change falls back to
the interpreter's cache in this situation.

This should help constant expressions in `class << self`, which is popular
at Shopify due to the style guide.

This change relies on the cache being warm while compiling to detect the
need for checking the lexical scope for simplicity.
2021-10-20 18:19:41 -04:00
Maxime Chevalier-Boisvert f1eb48cb23 Step 2 to remove the global cb/ocb objects. 2021-10-20 18:19:41 -04:00
Maxime Chevalier-Boisvert c55d4cafc2 Pass the global cb through codegen functions 2021-10-20 18:19:41 -04:00
Alan Wu c46bda6f19 Fix excessive invalidation for opt_getinlinecache
YJIT expects the VM to invalidate opt_getinlinecache when updating the
constant cache, and the invalidation used to happen even when YJIT can't
use the cached value.

Once the first invalidation happens, the block for opt_getinlinecache
becomes a stub. When the stub is hit, YJIT fails to compile the
instruction as the cache is not usable. The stub becomes a block that
exits for opt_getinlinecache which can be invalidated again. Some
workloads that bust the interpreter's constant cache can create an
invalidation loop with this behavior.

Check if the cache is usable become doing invalidation to fix this
problem.

In the test harness, evaluate the test script in a lambda instead of a
proc so `return` doesn't return out of the harness.
2021-10-20 18:19:41 -04:00
Alan Wu 6ef1609fab Correct margin for stack overflow test
In vm_push_frame(), the stack overflow test is done against a
decremented cfp. YJIT wasn't accounting for that in its stack overflow
tests.
2021-10-20 18:19:41 -04:00
John Hawthorn 7482744e04 Add jit_obj_info_dump 2021-10-20 18:19:41 -04:00
John Hawthorn 561882e96e Add comment explaining argc + 2 2021-10-20 18:19:41 -04:00
John Hawthorn 9951a9a8ec Implement invokebuiltin 2021-10-20 18:19:41 -04:00
John Hawthorn 82f60df5aa Implement generic setlocal 2021-10-20 18:19:41 -04:00
John Hawthorn 90de2dc703 Extract gen_get_ep 2021-10-20 18:19:41 -04:00
John Hawthorn 2ff26b9ec2 Fix opt_aset comptime_key check 2021-10-20 18:19:41 -04:00
Alan Wu 1f09eb66e6 Expand tabs 2021-10-20 18:19:41 -04:00
Maxime Chevalier-Boisvert 0ad9d1fa48 Update yjit_codegen.c 2021-10-20 18:19:41 -04:00
John Hawthorn 5e37f280d1 Remove vm_opt_aset 2021-10-20 18:19:41 -04:00
John Hawthorn ba9d01b3cf Specialize based on types of opt_aset 2021-10-20 18:19:41 -04:00
Alan Wu a71590e681 Don't store cfp->pc when doing iseq calls
We set it before calling routines and when we are exiting.
2021-10-20 18:19:41 -04:00
Alan Wu 1f6641681b No need to do ec->cfp = reg_cfp on exits
It's already up to date. We set it when we do iseq calls and it's set
properly on entry. If it's not set properly exceptions wouldn't work.
2021-10-20 18:19:40 -04:00
Alan Wu bc7652998e Fix warnings about redefining YJIT_STATS
Follow up for ecb5b383a0. Now that
YJIT_STATS is defined in yjit.h, it shoudl be the only place that
defines it.
2021-10-20 18:19:40 -04:00
John Hawthorn 7d99e85601 Check for comptime fixnum in gen_fixnum_cmp 2021-10-20 18:19:40 -04:00
John Hawthorn f1b7568f5a Check for comptime fixnums in opt_and and opt_or 2021-10-20 18:19:40 -04:00
John Hawthorn cb9bc13fcb Check for comptime integers in opt_plus and opt_minus 2021-10-20 18:19:40 -04:00
John Hawthorn fd10634b1a Move forward declaration up 2021-10-20 18:19:40 -04:00
Maxime Chevalier-Boisvert bd8cfb351b Fix misplaced ivar_set_method exit counter 2021-10-20 18:19:40 -04:00
John Hawthorn 96fd8afbf4 Skip opt_case_dispatch 2021-10-20 18:19:40 -04:00
John Hawthorn fc13ff14a2 Add comments to getspecial 2021-10-20 18:19:40 -04:00
Aaron Patterson 25f8431d46 only compile for T_OBJECT types 2021-10-20 18:19:40 -04:00
Aaron Patterson 5bc0343261 Refactor attrset to use a function
This new function will do the write barrier / resize the object / check
frozen for us
2021-10-20 18:19:40 -04:00
John Hawthorn 5092d6129a Fix opt_eq for overridden equality 2021-10-20 18:19:40 -04:00
John Hawthorn 44214e8ad9 Implement getspecial 2021-10-20 18:19:40 -04:00
Alan Wu cbb0271dd6 Deduplicate side exits
Send instructions currently generate the exact same side exit twice.
Cache the exit the first time we generate it. Also add a comment
explaining what side exits do.

Closes GH-117.
2021-10-20 18:19:40 -04:00
Maxime Chevalier-Boisvert 11599e5e1e Add rb_darray_clear() for Kevin. Fix some warnings. 2021-10-20 18:19:40 -04:00
Aaron Patterson f380856923 Add fixes for feedback 2021-10-20 18:19:40 -04:00
John Hawthorn f30f299060 Use C_ARG_REGS earlier 2021-10-20 18:19:40 -04:00
John Hawthorn 9ebcd576f3 String and fixnum equality 2021-10-20 18:19:40 -04:00
John Hawthorn 6db5e80dd7 Use method dispatch for opt_eq 2021-10-20 18:19:40 -04:00
John Hawthorn 692f94ba0c Add jit_rb_obj_equal 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 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 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
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
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
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
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 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
eileencodes d2e8b99b5b Implement tostring instruction for yjit
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-10-20 18:19:38 -04:00
John Hawthorn 6c80150d40 Introduce ctx_{get,set}_opnd_mapping 2021-10-20 18:19:38 -04:00
John Hawthorn 4ea69e5c0b Rename to ctx_upgrade_opnd_type 2021-10-20 18:19:38 -04:00
John Hawthorn 53079ca585 Return if fixnums impossible 2021-10-20 18:19:38 -04:00
Alan Wu f4f940e5a6 Save PC and SP before accessing globals
These instructions are marked as not leaf in insns.def, which indicate
that they could raise exceptions and/or call Ruby methods.
2021-10-20 18:19:38 -04:00