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

769 Коммитов

Автор SHA1 Сообщение Дата
Koichi Sasada fdf0f8d814 btest-ruby OPTS=-v should disable quiet
`make btest-ruby` is run with -q (quiet) option and -v should
remove -q option.
2022-02-17 18:58:37 +09:00
Koichi Sasada 8e0899919b extend timeout for mjit
1 seconeds is not enough on an specific (busy) machine w/ mjit.
http://ci.rvm.jp/results/trunk-mjit@phosphorus-docker/3830178
2022-02-14 14:52:12 +09:00
Koichi Sasada 603ab70961 support concurrent btest execution
* `-j` option for concurrent test with threads
  * `-jN` uses N threads
  * `-j` uses nproc/2 threads
* Introduce `BT` struct to manage configurations
* Introduce `Assertion` to manage all assertions
* Remove all toplevel instance variables
* Show elapsed seconds at last

```
$ time make btest
...
real    0m37.319s
user    0m26.221s
sys     0m16.534s

$ time make btest TESTOPTS=-j
...
real    0m11.812s
user    0m36.667s
sys     0m21.872s
```
2022-02-06 03:05:47 +09:00
Koichi Sasada e953d68657 refactoring btest output
don't duplicate the message, but prepare `out` var to choose
stdout/err.
2022-01-26 09:56:27 +09:00
Koichi Sasada 5e3a320218 respect `--quiet` option for btest
Do not print anymore except errors.
2022-01-21 17:38:11 +09:00
Yuta Saito dd99ee1f7d [wasm] bootstraptest, basictest: disable backquote literal tests
WASI doesn't support spawning a new process for now.
2022-01-19 11:19:06 +09:00
John Hawthorn 930ebdd7ca YJIT: Support kwargs for cfunc
This adds support for passing keyword arguments to cfuncs. This is done
by calling a helper method to create the hash from the top N values on
the stack (determined by the callinfo) and then moving that value onto
the stack.
2022-01-10 10:53:31 -08:00
John Hawthorn 18b97eee5a YJIT: Add support for ruby array cfuncs (argc=-2)
This adds support for cfuncs which take variable arguments using a Ruby
array. This is specified with the method entry's argc == -2.
2022-01-08 11:40:55 -08:00
Alan Wu 54c91042ed YJIT: Discard local var type info on routine call
Routines that are called from YJIT's output code can call methods, and
calling methods mean they can capture and change the environment of the
calling frame.

Discard type info whenever we perform routine calls. This is more
conservative than strictly necessary as some routines need to perform GC
allocation but can never call methods and so should never be able to
change local variables. However, manually analyzing C functions for
whether they have code paths that call methods is error prone and can go
out of date as changes land in the codebase.

Closes: shopify/yjit#300
2022-01-07 19:29:03 -05:00
John Hawthorn 5414de4b6e YJIT: Fix SP index with optarg and unordered kwarg
Previously when we were calling a method with an optional argument and
multiple keywords arguments which weren't in the order the receiver
expected we would use the wrong SP index to rearrange them.

Fixes Bug #18453
2021-12-31 17:30:47 -08:00
Koichi Sasada 6050e3e2a6 @@cv is not accessible from non-main ractors
Class variables (@@cv) is not accessible from non-main ractors.
But without this patch cached @@cv can be read.

fix [Bug #18128]
2021-12-24 13:52:02 +09:00
John Hawthorn c2197bf821 YJIT: Fix check for required kwargs
Previously, YJIT would not check that all the required keywords were
specified in the case that there were optional arguments specified. In
this case YJIT would incorrectly call the method with invalid arguments.
2021-12-17 15:26:04 -08:00
John Hawthorn 83aa68447c YJIT: Allow iseq with both opt and kwargs
Previously we mirrored the fast paths the interpreter had for having
only one of kwargs or optional args. This commit aims to combine the
cases and reduce complexity.

Though this allows calling iseqs which have have both optional and
keyword arguments, it requires that all optional arguments are specified
when there are keyword arguments, since unspecified optional arguments
appear before the kwargs. Support for this can be added a in a future
PR.
2021-12-17 15:26:04 -08:00
Yuta Saito 332d1e52e6 btest: assign $stderr = STDOUT instead of IO#reopen to be more portable
`IO#reopen` internally uses dup syscall but some platforms don't support
the syscall. re-assigning `$stderr` is enough to capture the interpreter's
errors and warnings.
2021-12-16 16:16:40 +09:00
Alan Wu ac5d6faea8
YJIT: Fix unexpected truncation when outputing VALUE
Previously, YJIT incorrectly discarded the upper 32 bits of the object
pointer when writing out VALUEs to setup default keyword arguments.

In addition to incorrectly truncating, the output pointers were not
properly tracked for handling GC compaction moving the referenced
objects.

YJIT previously attempted to encode a mov instruction with a memory
destination and a 64 bit immediate when there is no such encoding
possible in the ISA. Add an assert to mitigate not being able to
catch this at build time.
2021-12-14 19:47:42 -05:00
Koichi Sasada 397a509b6d prohibit load by `autoload` on non-main Ractor
fix [Bug #18120]
2021-12-15 02:33:17 +09:00
Takashi Kokubun 1a63468831
Prepare for removing RubyVM::JIT (#5262) 2021-12-13 23:07:46 -08:00
Koichi Sasada cce331272b `Ractor.make_shareable` checks proc's sefl
`Ractor.make_shareable(proc_obj)` raises an `IsolationError`
if the self of `proc_obj` is not a shareable object.

[Bug #18243]
2021-12-09 16:20:04 +09:00
Alan Wu 82bb9cedd3 YJIT: Fix leak in compilation loop
Previously, when there are too many blocks in a batch, the last block in
the batch is not tracked in the array of batches and not freed.
2021-12-08 16:59:52 -05:00
Alan Wu 286c07f0dc YJIT: Remove guard_self_is_heap()
It's superseded by functionality added to jit_guard_known_klass().
In weird situations such as the ones in the included test,
guard_self_is_heap() triggered assertions.

Co-authored-by: Jemma Issroff <jemmaissroff@gmail.com>
2021-12-07 17:20:34 -05:00
Alan Wu b7ea66bc32 YJIT: Fix incomplete invalidation from opt_setinlinecache
As part of YJIT's strategy for promoting Ruby constant expressions into
constants in the output native code, the interpreter calls
rb_yjit_constant_ic_update() from opt_setinlinecache.

The block invalidation loop indirectly calls rb_darray_remove_unordered(),
which does a shuffle remove. Because of this, looping with an
incrementing counter like done previously can miss some elements in the
array. Repeatedly invalidate the first element instead.

The bug this commit resolves does not seem to cause crashes or divergent
behaviors.

Co-authored-by: Jemma Issroff <jemmaissroff@gmail.com>
2021-12-06 19:24:41 -05:00
Alan Wu 34b5e2566d YJIT: Enable out of memory tests
As of [1] and [2], YJIT has enough support for out of memory conditions
to pass these two basic tests.

OOM code paths are prone to bugs since they are rarely exercised in
common workloads. We might want to add CI runs that stress test these
code paths. Maybe outside of GitHub Actions for capacity reasons.

[1]: f41b4d44f9
[2]: b5b6ab4194
2021-12-04 11:35:37 -05:00
John Hawthorn 733500e9d0
Lazily create singletons on instance_{exec,eval} (#5146)
* Lazily create singletons on instance_{exec,eval}

Previously when instance_exec or instance_eval was called on an object,
that object would be given a singleton class so that method
definitions inside the block would be added to the object rather than
its class.

This commit aims to improve performance by delaying the creation of the
singleton class unless/until one is needed for method definition. Most
of the time instance_eval is used without any method definition.

This was implemented by adding a flag to the cref indicating that it
represents a singleton of the object rather than a class itself. In this
case CREF_CLASS returns the object's existing class, but in cases that
we are defining a method (either via definemethod or
VM_SPECIAL_OBJECT_CBASE which is used for undef and alias).

This also happens to fix what I believe is a bug. Previously
instance_eval behaved differently with regards to constant access for
true/false/nil than for all other objects. I don't think this was
intentional.

    String::Foo = "foo"
    "".instance_eval("Foo")   # => "foo"
    Integer::Foo = "foo"
    123.instance_eval("Foo")  # => "foo"
    TrueClass::Foo = "foo"
    true.instance_eval("Foo") # NameError: uninitialized constant Foo

This also slightly changes the error message when trying to define a method
through instance_eval on an object which can't have a singleton class.

Before:

    $ ruby -e '123.instance_eval { def foo; end }'
    -e:1:in `block in <main>': no class/module to add method (TypeError)

After:

    $ ./ruby -e '123.instance_eval { def foo; end }'
    -e:1:in `block in <main>': can't define singleton (TypeError)

IMO this error is a small improvement on the original and better matches
the (both old and new) message when definging a method using `def self.`

    $ ruby -e '123.instance_eval{ def self.foo; end }'
    -e:1:in `block in <main>': can't define singleton (TypeError)

Co-authored-by: Matthew Draper <matthew@trebex.net>

* Remove "under" argument from yield_under

* Move CREF_SINGLETON_SET into vm_cref_new

* Simplify vm_get_const_base

* Fix leaf VM_SPECIAL_OBJECT_CONST_BASE

Co-authored-by: Matthew Draper <matthew@trebex.net>
2021-12-02 15:53:39 -08:00
Alan Wu d0772632bf YJIT: Fail gracefully while OOM for new entry points
Previously, YJIT crashes with rb_bug() when asked to compile new methods
while out of executable memory.

To handle this situation gracefully, this change keeps track of all the
blocks compiled each invocation in case YJIT runs out of memory in the
middle of a compliation sequence. The list is used to free all blocks in
case compilation fails.

yjit_gen_block() is renamed to gen_single_block() to make it distinct from
gen_block_version(). Call to limit_block_version() and block_t
allocation is moved into the function to help tidy error checking in the
outer loop.

limit_block_version() now returns by value. I feel that an out parameter
with conditional mutation is unnecessarily hard to read in code that
does not need to go for last drop performance. There is a good chance
that the optimizer is able to output identical code anyways.
2021-12-01 12:25:28 -05:00
Alan Wu b5b6ab4194
YJIT: Add ability to exit to interpreter from stubs
Previously, YJIT assumed that it's always possible to generate a new
basic block when servicing a stub in branch_stub_hit(). When YJIT is out
of executable memory, for example, this assumption doesn't hold up.

Add handling to branch_stub_hit() for servicing stubs without consuming
more executable memory by adding a code path that exits to the
interpreter at the location the branch stub represents. The new code
path reconstructs interpreter state in branch_stub_hit() and then exits
with a new snippet called `code_for_exit_from_stub` that returns
`Qundef` from the YJIT native stack frame.

As this change adds another place where we regenerate code from
`branch_t`, extract the logic for it into a new function and call it
regenerate_branch(). While we are at it, make the branch shrinking code
path in branch_stub_hit() more explicit.

This new functionality is hard to test without full support for out of
memory conditions. To verify this change, I ran
`RUBY_YJIT_ENABLE=1 make check -j12` with the following patch to stress
test the new code path:

```diff
diff --git a/yjit_core.c b/yjit_core.c
index 4ab63d9806..5788b8c5ed 100644
--- a/yjit_core.c
+++ b/yjit_core.c
@@ -878,8 +878,12 @@ branch_stub_hit(branch_t *branch, const uint32_t target_idx, rb_execution_contex
                 cb_set_write_ptr(cb, branch->end_addr);
             }

+if (rand() < RAND_MAX/2) {
             // Compile the new block version
             p_block = gen_block_version(target, target_ctx, ec);
+}else{
+    p_block = NULL;
+}

             if (!p_block && branch_modified) {
                 // We couldn't generate a new block for the branch, but we modified the branch.
```

We can enable the new test along with other OOM tests once full support
lands.

Other small changes:
 * yjit_utils.c (print_str): Update to work with new native frame shape.
       Follow up for 8fa0ee4d40.
 * yjit_iface.c (rb_yjit_init): Run yjit_init_core() after
       yjit_init_codegen() so `cb` and `ocb` are available.
2021-11-26 18:00:42 -05:00
John Hawthorn de9a1e4a96
YJIT: Implement new struct accessors (#5161)
* YJIT: Implement optimized_method_struct_aref

* YJIT: Implement struct_aref without method call

Struct member reads can be compiled directly into a memory read (with
either one or two levels of indirection).

* YJIT: Implement optimized struct aset

* YJIT: Update tests for struct access

* YJIT: Add counters for remaining optimized methods

* Check for INT32_MAX overflow

It only takes a struct with 0x7fffffff/8+1 members. Also add some
cheap compile time checks.

* Add tests for non-embedded struct aref/aset

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2021-11-25 11:56:58 -08:00
Alan Wu 13d1ded253 YJIT: Make block invalidation more robust
This commit adds an entry_exit field to block_t for use in
invalidate_block_version(). By patching the start of the block while
invalidating it, invalidate_block_version() can function correctly
while there is no executable memory left for new branch stubs.

This change additionally fixes correctness for situations where we
cannot patch incoming jumps to the invalidated block. In situations
such as Shopify/yjit#226, the address to the start of the block
is saved and used later, possibly after the block is invalidated.

The assume_* family of function now generate block->entry_exit before
remembering blocks for invalidation.

RubyVM::YJIT.simulate_oom! is introduced for testing out of memory
conditions. The test for it is disabled for now because OOM triggers
other failure conditions not addressed by this commit.

Fixes Shopify/yjit#226
2021-11-22 18:23:28 -05:00
Adam Hess 73388aff5e
Add YJIT codegen for objtostring (#5149)
This is the minimal correct objtostring implementation in YJIT.
For correctness, it is important that to_string not get called on strings or subclasses of string.
There is a new test for this behavior.

A follow up should implement an optimized version for other types as performed in `vm_objtostring`.

Co-authored-by: John Hawthorn <jhawthorn@github.com>

Co-authored-by: John Hawthorn <jhawthorn@github.com>
2021-11-19 16:57:09 -05:00
Nikita Vasilevsky c1c13c58ee Add one more test example for swap instruction 2021-11-09 16:56:44 +09:00
Nobuyoshi Nakada 334b69e504 rb_id_serial_to_id: return unregistered ID as an internal ID
```ruby
def foo(*); ->{ super }; end
```

This code makes anonymous parameters which is not registered as an
ID.  The problem is that when Ractors try to scan `getlocal`
instructions, it puts the Symbol corresponding to the parameter
in to a hash.  Since it is not registered, we end up with a
strange exception.  This commit wraps the unregistered ID in an
internal ID so that we get the same exception for `...` as `*`.

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
Co-Authored-By: John Hawthorn <john@hawthorn.email>
2021-11-07 12:40:27 +09:00
John Hawthorn fbd6cc5856
YJIT: Support iseq sends with mixed kwargs (#5082)
* YJIT: Support iseq sends with mixed kwargs

Co-authored-by: Kevin Newton <kddnewton@gmail.com>

* Add additional comments to iseq sends

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2021-11-05 17:01:07 -04:00
John Hawthorn 2fa51c7068
YJIT: Support kwargs sends with all defaults (#5067)
* YJIT: Support kwargs sends with all defaults

Previously keyword argument methods were only compiled by YJIT when all
keywords were specified in the caller.

This adds support for calling methods with keyword arguments when no
keyword arguments are specified and all are filled with the defaults.

* Remove unused send_iseq_kwargs_none_passed
2021-11-01 10:54:59 -04:00
John Hawthorn a6104b392a
YJIT: Support newhash with values (#5029)
* YJIT: Implement newhash with values

* YJIT: Add test of duphash

* Fix compilation on macos/clang
2021-10-27 10:55:43 -04:00
Satoshi Moris Tagomori 489e5e3a82 the core problem is the Proc is not shareable 2021-10-27 16:13:43 +09:00
Ian C. Anderson e943511455
YJIT: Implement duphash (#5009)
`duphash` showed up in the top-20 most frequent exit ops for @jhawthorn's benchmark that renders github.com/about

The implementation was almost exactly the same as `duparray`

Co-authored-by: John Hawthorn <john@hawthorn.email>

Co-authored-by: John Hawthorn <john@hawthorn.email>
2021-10-25 10:40:33 -04:00
Koichi Sasada acb23454e5 allow to access ivars of classes/modules
if an ivar of a class/module refer to a shareable object, this ivar
can be read from non-main Ractors.
2021-10-23 01:32:55 +09:00
Alan Wu ba4bf8a1e6
Fix simple test on platforms where compaction is not supported
844588f915 made it so that trying to call
gc_verify_compaction_references on unsupported platform result in an
exception rather than a crash. Rescue the exception in a YJIT btest
that uses gc_verify_compaction_references.
2021-10-22 10:53:42 -04:00
Alan Wu bdfc23cba9
YJIT: don't compile attr_accessor methods when tracing (#4998)
2d98593bf5 made it so that
attr_accessor methods fire C method tracing events.
Previously, we weren't checking for whether we are tracing before
compiling, leading to missed events.

Since global invalidation invalidates all code, and that attr_accessor
methods can never enable tracing while running, events are only dropped
when YJIT tries to compile when tracing is already enabled.

Factor out the code for checking tracing and check it before generating
code for attr_accessor methods.

This change fixes TestSetTraceFunc#test_tracepoint_attr when it's
ran in isolation.
2021-10-21 15:07:32 -04:00
git 7637175a84 * append newline at EOF. [ci skip] 2021-10-21 08:12:53 +09:00
Alan Wu cffa116275 Do kwarg shuffle after checking for interrupts
Previously, we were shuffling keyword arguments before checking for
interrupts. In the case that we side exit in the interrupt check,
we left the interpreter with an already-shuffled argument list for
the call, resulting in a double shuffle, leaving the locals in the
wrong order for the callee.

Do keyword shuffling after all the possible side exits.

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2021-10-20 18:19:43 -04:00
Alan Wu b74d6563a6 Extract yjit_force_iv_index and make it work when object is frozen
In an effort to simplify the logic YJIT generates for accessing instance
variable, YJIT ensures that a given name-to-index mapping exists at
compile time. In the case that the mapping doesn't exist, it was created
by using rb_ivar_set() with Qundef on the sample object we see at
compile time. This hack isn't fine if the sample object happens to be
frozen, in which case YJIT would raise a FrozenError unexpectedly.

To deal with this, make a new function that only reserves the mapping
but doesn't touch the object. This is rb_obj_ensure_iv_index_mapping().
This new function superceeds the functionality of rb_iv_index_tbl_lookup()
so it was removed.

Reported by and includes a test case from John Hawthorn <john@hawthorn.email>

Fixes: GH-282
2021-10-20 18:19:43 -04:00
Kevin Newton 13261f00fb More simple bootstrap tests for kwargs 2021-10-20 18:19:43 -04:00
Kevin Newton 56b1b93a0c Feedback, tests, and rebase for kwargs 2021-10-20 18:19:43 -04:00
Kevin Newton 2c0891be20 Get kwargs reordering working 2021-10-20 18:19:42 -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
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
John Hawthorn 9951a9a8ec Implement invokebuiltin 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
John Hawthorn 5092d6129a Fix opt_eq for overridden equality 2021-10-20 18:19:40 -04:00
John Hawthorn 9ebcd576f3 String and fixnum equality 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
John Hawthorn 3a3f706698 Additional invokesuper tests 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
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
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
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
eileencodes b91078ea74 Add setglobal to yjit
Adds yjit support for setting global variables.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Co-authored-by: John Hawthorn <john@hawthorn.email>
2021-10-20 18:19:38 -04:00
eileencodes 50029fb127 Add getglobal to yjit
Adds getglobal to yjit and a test for it.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-10-20 18:19:38 -04:00
Aaron Patterson 71cef74432 Clear JIT code when tracepoints get enabled
Clear out any JIT code on iseqs when tracepoints get enabled.  We can't
handle tracepoints right now, so we'll just try to recompile later.
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
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
Kevin Newton 341d5bdcb2 Code review for expandarray and tests 2021-10-20 18:19:37 -04:00
Kevin Newton be648e0940 Implement splatarray 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
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
Alan Wu 3996e0ab07 Add tests, comments, and an assert for invokesuper 2021-10-20 18:19:36 -04:00
Alan Wu 0cd3b97e02 Handle non-material empty singleton class properly
As an optimization, multiple objects could share the same singleton
class. The optimization introduced in 6698e43393
wasn't handling this correctly so was generating guards that never pass
for the inputs we defer compilation to wait for. After generating
identical code multiple times and failing, the call site is falsely
recognized as megamorphic and it side exits. See disassembly for the
following before this commit:

    def foo(obj)
      obj.itself
    end

    o = Object.new.singleton_class
    foo(o)
    puts YJIT.disasm(method(:foo))

See also: comment in rb_singleton_class_clone_and_attach().
2021-10-20 18:19:36 -04:00
Alan Wu 89110590a3 Disable invokesuper codegen for now. Add test
The added test fails with SystemStackError with --yjit-call-threshold=1.
2021-10-20 18:19:36 -04:00
Alan Wu da20ff1644 Fix bug in generic case for gen_checktype
When checking for T_HASH, which is Qnil and when the type check succeeds
we were outputting to the stack a Qnil instead of a Qtrue.
2021-10-20 18:19:36 -04:00
John Hawthorn 7d252186fe Simplify known class check for singletons
Singleton classes should only ever be attached to one object. This means
that checking for the object should be the same as checking for the
class. This should be slightly faster by avoiding one memory acccess as
well as allowing us to skip checking if the receiver is a heap object.

This will be most common for calling class methods.
2021-10-20 18:19:36 -04:00
Alan Wu 936ee55562 Improve opt_not by expanding cfunc codegen
This commit improves opt_not by making it correct when TrueClass#!
and/or FalseClass#! is defined and genearting better code when the
receiver is a heap object.

guard_known_class() can now handle true, false, and nil, and we
introduce a codegen function reimplementing rb_obj_not(), used when we
know we are calling into rb_obj_not().

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Noah Gibbs <the.codefolio.guy@gmail.com>
2021-10-20 18:19:36 -04:00
John Hawthorn b93f59ced0 Implement invokebuiltin_delegate
invokebuiltin_delegate is a special version of invokebuiltin used for
sending a contiguous subset of the current method's locals.

In some cases YJIT would already handle this for trivial cases it could
be inlined, implementing this OP allows it to work when the method isn't
inlinable (not marked as 'inline', does more than just call, not called
from yjit, etc).
2021-10-20 18:19:36 -04:00
Aaron Patterson 9043ad3d74 Implement topn instruction
This commit implements the topn instruction

Co-Authored-By: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-Authored-By: Noah Gibbs <noah.gibbs@shopify.com>
2021-10-20 18:19:36 -04:00
John Hawthorn 67c2cdc59a Implement gen_getlocal
This extracts the generation code from getlocal_wc1, since this is the
same just with more loops inside vm_get_ep.
2021-10-20 18:19:35 -04:00
John Hawthorn ea33b0a9ba Add concatstrings to yjit codegen (#58)
* Add ETYPE_TRUE and ETYPE_FALSE

* Implement checktype

* Implement concatstrings

* Update deps
2021-10-20 18:19:35 -04:00
John Hawthorn eb6e5be038 Add newhash and newarray instructions to yjit codegen (#48)
* Implement gen_newarray

* Implement newhash for n=0

* Add yjit tests for newhash/newarray

* Fix integer size warning on clang

* Save PC and SP in newhash and newarray

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2021-10-20 18:19:35 -04:00
Alan Wu 7eef8f09c0 Implement getblockparamproxy
* Implement getblockparamproxy

* Parallel runner: wait for timeout thread to terminate after killing

Or else the leak cheaker could sees the thread as running and cause test
failures in test-tool.

* Add a comment, use jne

* Comment about where 0x3 comes from
2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert c9feb72b65 Implement opt_mod as call to interpreter function (#29) 2021-10-20 18:19:35 -04:00
Alan Wu 0d64f5e8a8 Check for easy-to-handle cases of block param (#24)
In some cases, methods taking block parameters don't require extra
paramter setup. They are fairly popular in railsbench.
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert e5f8b41786 Implement send with alias method (#23)
* Implement send with alias method

* Add alias_method tests
2021-10-20 18:19:34 -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
Alan Wu 684e84df7c Use rb_ivar_get() for general case of getivar (#17)
* Use rb_ivar_get() for general case of getivar

Pretty straight forward. Buys about 1% coverage on railsbench.

* Update yjit_codegen.c

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2021-10-20 18:19:34 -04:00
Alan Wu 36134f7d29 Implement calls to methods with simple optional params
* Implement calls to methods with simple optional params

* Remove unnecessary MJIT_STATIC

See comment for MJIT_STATIC. I added it not knowing whether it's
required because the function next to it has it. Don't use it and wait
for problems to come up instead.

* Better naming, some comments

* Count bailing on kw only iseqs

On railsbench:
```
opt_send_without_block exit reasons:
                  bmethod      59729 (27.7%)
         optimized_method      59137 (27.5%)
      iseq_complex_callee      41362 (19.2%)
             alias_method      33346 (15.5%)
      callsite_not_simple      19170 ( 8.9%)
       iseq_only_keywords       1300 ( 0.6%)
                 kw_splat       1299 ( 0.6%)
    cfunc_ruby_array_varg         18 ( 0.0%)
```
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert bce6dea72d Fix assertions in `invalidate_block_version()`, add small repro (#14)
* Fix block invalidation assertions

* Add Alan's small repro for double invalidation bug
2021-10-20 18:19:34 -04:00
Aaron Patterson 435d7c5088 Improve set instance variable
This commit improves the set ivar implementation.
2021-10-20 18:19:34 -04:00
Maxime Chevalier-Boisvert edaf12def6 Fix local type tracking in getlocal, setlocal. Add test. 2021-10-20 18:19:33 -04:00
Alan Wu b69951cf55 add a couple of getivar tests for symbols 2021-10-20 18:19:33 -04:00
Alan Wu 4ea2e753f6 YJIT: implement calls to ivar getter methods 2021-10-20 18:19:33 -04:00
Alan Wu a8f7eb2f35 Polymorphic opt_send_without_block 2021-10-20 18:19:32 -04:00
Alan Wu 0cd9120f17 YJIT: hash specialization for opt_aref
Make it lazy and add a hash specialization in addition to the array
specialization.
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 fe3bd57007 Remove trailing whitespaces 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
Maxime Chevalier-Boisvert 7f4000b1f4 Machinery to implement deferred compilation 2021-10-20 18:19:31 -04:00
Maxime Chevalier-Boisvert d6d58795a9 Rename test files 2021-10-20 18:19:31 -04:00
Maxime Chevalier-Boisvert f93f3d6aa1 Implement support for variadic C functions 2021-10-20 18:19:30 -04:00
Alan Wu b87962eb04 Stop using UJIT.install_entry in btest
CI runs on some platforms uJIT doesn't support. They don't have
UJIT.install_entry. Maybe we want something like `install_entry_if_possible`.
2021-10-20 18:19:30 -04:00