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

917 Коммитов

Автор SHA1 Сообщение Дата
Takashi Kokubun 8642a573e6 Rename BUILTIN_ATTR_SINGLE_NOARG_INLINE
to BUILTIN_ATTR_SINGLE_NOARG_LEAF

The attribute was created when the other attribute was called BUILTIN_ATTR_INLINE.
Now that the original attribute is renamed to BUILTIN_ATTR_LEAF, it's
only confusing that we call it "_INLINE".
2024-01-16 17:31:27 -08:00
Takashi Kokubun e37a37e696 Drop obsoleted BUILTIN_ATTR_NO_GC attribute
The thing that has used this in the past was very buggy, and we've never
revisied it. Let's remove it until we need it again.
2024-01-16 17:27:53 -08:00
Alan Wu 2bf9970101 YJIT: Finer breakdown for block_arg counters
For example, on `lobsters` the block_arg reason was at ~10%. With this
change it shows that 6% of that is `send_cfunc_block_arg`.
2024-01-16 16:54:34 -05:00
Maxime Chevalier-Boisvert 6a1bf4cf1b
YJIT: optimized codegen for String#length (#9543)
Minor optimization for programs doing string processing.
2024-01-15 17:35:29 -05:00
Takashi Kokubun 5e61cc26c9
YJIT: Optimize Integer#succ (#9519) 2024-01-15 10:32:48 -05:00
ywenc 16624ef463
YJIT: expandarray for non-arrays (#9495)
* YJIT: expandarray for non-arrays

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

* Skip the new test on RJIT

* Increment counter for to_ary exit

---------

Co-authored-by: John Hawthorn <john@hawthorn.email>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2024-01-12 15:41:58 +00:00
Alan Wu 015b0e2e1d YJIT: Fix unused warnings
```
warning: unused import: `condition::Condition`
  --> src/asm/arm64/arg/mod.rs:13:9
   |
13 | pub use condition::Condition;
   |         ^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused import: `rb_yjit_fix_mul_fix as rb_fix_mul_fix`
   --> src/cruby.rs:188:9
    |
188 | pub use rb_yjit_fix_mul_fix as rb_fix_mul_fix;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: unused import: `rb_insn_len as raw_insn_len`
   --> src/cruby.rs:142:9
    |
142 | pub use rb_insn_len as raw_insn_len;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unused_imports)]` on by default
```

Make asm public so it stops warning about unused public stuff in there.
2024-01-10 13:19:15 -05:00
Takashi Kokubun a0eecfb5ba
YJIT: Fallback Integer#<< if a shift amount varies (#9426)
* YJIT: Fallback Integer#<< if a shift amount varies

* YJIT: Do not fallback lshift in the first chain
2024-01-08 17:34:57 +00:00
Takashi Kokubun 7f9c174102
YJIT: Let RubyVM::YJIT.enable respect --yjit-stats (#9415) 2024-01-05 14:08:57 -05:00
Hiroshi SHIBATA 863ded45a1
Typofix under bootstraptest, spec and yjit directories 2023-12-25 13:50:23 +09:00
Takashi Kokubun bd91c5127f
YJIT: Add stats option to RubyVM::YJIT.enable (#9297) 2023-12-19 11:47:27 -08:00
Takashi Kokubun b266890dab
YJIT: Add --yjit-disable to help and reorder it (#9230) 2023-12-13 13:29:37 -08:00
Alan Wu d4bbee7475
YJIT: Fix off-by-one in Kernel#send type handling (#9212)
Previously, if the method ID argument happens to be on one below the top
of the stack, we didn't overwrite the type of the stack slot, which
leaves an incorrect type for the stack slot. The included script tripped
asserts both with and without --yjit-verify-ctx.
2023-12-12 22:10:14 +00:00
Alan Wu 9cb0ad863c YJIT: Fix missing arity check for splat calls to methods with optionals
Previously, for splat callsites that land in methods with optional
parameters, we didn't reject the case where the caller supplies too many
arguments. Accepting those calls previously caused YJIT to construct
corrupted control frames, which leads to crashes if the callee uses
certain stack walking methods such as Kernel#raise and String#gsub (for
setting up the frame-local `$~`).

Example crash in a debug build:

    Assertion Failed: ../vm_core.h:1375:VM_ENV_FLAGS:FIXNUM_P(flags)
2023-12-11 19:21:08 -05:00
Alan Wu 4755309474 YJIT: Rename helper function and correct counter name
Counter::guard_send_iseq_has_rest_and_splat_not_equal was using
jump-if-lesser-than, so wasn't checking for equality. Rename function
because moving is destructive in Rust, which is confusing for this function
which doesn't modify the array.
2023-12-11 19:21:08 -05:00
Jeremy Evans a950f23078 Ensure f(**kw, &block) calls kw.to_hash before block.to_proc
Previously, block.to_proc was called first, by vm_caller_setup_arg_block.
kw.to_hash was called later inside CALLER_SETUP_ARG or setup_parameters_complex.

This adds a splatkw instruction that is inserted before sends with
ARGS_BLOCKARG and KW_SPLAT and without KW_SPLAT_MUT. This is not needed in the
KW_SPLAT_MUT case, because then you know the value is a hash, and you don't
need to call to_hash on it.

The splatkw instruction checks whether the second to top block is a hash,
and if not, replaces it with the value of calling to_hash on it (using
rb_to_hash_type).  As it is always before a send with ARGS_BLOCKARG and
KW_SPLAT, second to top is the keyword splat, and top is the passed block.
2023-12-09 13:15:47 -08:00
Takashi Kokubun ac5fd58700
YJIT: Fix on-stack ISEQ comparison for auto_compact (#9164) 2023-12-07 22:53:05 +00:00
Alan Wu 9d9865d9bc YJIT: Add some object validity assertions
We've seen quite a few compaction bugs lately, and these assertions
should give clearer symptoms. We only call class_of() on
objects that the Ruby code can see.
2023-12-06 16:42:53 -05:00
Takashi Kokubun a439fc2f17
YJIT: Avoid register allocation conflict with a higher stack_idx (#9143)
YJIT: Avoid register allocation conflict

with a higher stack_idx
2023-12-06 15:19:43 -05:00
Alan Wu a063969ec1 YJIT: Assert code pages are not partially in-bounds
Helps understand page switching
2023-12-05 13:20:06 -05:00
Alan Wu 695e5c179e YJIT: Simplify code page switching logic, remove an assert
We have received a report of `assert!( !cb.has_dropped_bytes())` in
set_page() failing. The only explanation for this seems to be memory
allocation failing in write_byte(). The if condition implies that
`current_write_pos < dst_pos < mem_size`, which rules out failing to
encode the relative jump. The has_capacity() assert above not tripping
implies that we were in a place in the page where write_byte() did
attempt to write the byte and potentially made a syscall in the process.

Remove the assert, since memory allocation could fail. Also, return
failure if the destination is outside of the code region to detect that
out-of-memory situation quicker.
2023-12-05 13:20:06 -05:00
Alan Wu b5a62eb9ab
YJIT: Mark and update stubs in invalidated blocks (#9104)
Like in the example given in delayed_deallocation(), stubs can be hit
even if the block housing it is invalidated. Mark them so we don't
work with invalidate ISeqs when hitting these stubs.
2023-12-04 10:13:40 -05:00
Takashi Kokubun ba1cdadfc8
YJIT: Cancel on-stack jit_return on invalidation (#9086)
* YJIT: Cancel on-stack jit_return on invalidation

Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>

* Use RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P

---------

Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
2023-11-30 21:35:55 -05:00
Maxime Chevalier-Boisvert 73e6d8a0d0
YJIT: optimized codegen for `rb_ary_length()` (#9085)
YJIT: optimized codegen for rb_ary_length()
2023-11-30 17:14:53 -05:00
Takashi Kokubun d048bae96b
YJIT: Bump ec->cfp after setting cfp->jit_return (#9072) 2023-11-30 11:23:25 -05:00
Maxime Chevalier-Boisvert 8d1138c1cf
YJIT: edit `yjit.md` and bring it up to date (#9068)
Also make various minor edits to improve readability.
2023-11-29 18:09:55 -05:00
Maxime Chevalier-Boisvert ea3e17e430
YJIT: fix bug in top cfunc logging in `--yjit-stats` (#9056)
YJIT: correctly handle case where there are no cfunc calls

Fix bug in top cfunc logging in `--yjit-stats`
2023-11-28 22:27:11 +00:00
Maxime Chevalier-Boisvert 6310522a9a
YJIT: reduce default exec-mem-size to 64MiB (#9054) 2023-11-28 20:04:33 +00:00
Takashi Kokubun 476a231e7e
YJIT: Assert no patch overlap on pos_marker (#9048) 2023-11-28 10:41:14 -05:00
Maxime Chevalier-Boisvert 7f50c70574
YJIT: add top C function call counts to `--yjit-stats` (#9047)
* YJIT: gather call counts for individual cfuncs

Co-authored by Takashi Kokubun
2023-11-27 22:49:53 +00:00
Maxime Chevalier-Boisvert f05d586cc9
YJIT: record `num_send_cfunc` stat (#9022)
* YJIT: record num_send_cfunc stat

Also report num_send_known_cfunc as percentage of num_send_cfunc

* Rename num_send_known_cfunc => num_send_cfunc_inline

Name seems more descriptive of what we do with out custom codegen
2023-11-23 15:33:43 -05:00
Takashi Kokubun 440b59db10
YJIT: Apply patches ignoring page_end_reserve (#9015) 2023-11-23 10:53:12 -05:00
Takashi Kokubun 95369ac0a3
YJIT: Fix jmp_ptr_bytes on x86_64 (#9016) 2023-11-23 10:50:42 -05:00
Takashi Kokubun 926bfc3bc0
YJIT: Avoid a register spill on arm64 (#9014) 2023-11-22 15:13:32 -08:00
Takashi Kokubun 95d4a52b3a
YJIT: Skip dump-disasm if it fails to create a file (#8968) 2023-11-21 10:28:45 -05:00
Aaron Patterson 6fce8c7980 Don't try compacting ivars on Classes that are "too complex"
Too complex classes use a hash table to store ivs, and should always pin
their IVs.  We shouldn't touch those classes in compaction.
2023-11-20 16:09:48 -08:00
Takashi Kokubun fa547cd702
YJIT: Print a disasm path to stderr (#8967)
YJIT: Print a perf map path to stderr
2023-11-20 14:51:54 -08:00
Maxime Chevalier-Boisvert f9628fb4be
YJIT: make --yjit-max-versions=N option undocumented (#8962)
Not useful for the vast majority of end users to change
this option.
2023-11-20 21:26:18 +00:00
Maxime Chevalier-Boisvert c552a5f7b0
YJIT: shrink `Context` down to 15 bytes (#8911)
* WIP context refactoring

* Refactor to remove Context.temp_mapping
2023-11-13 17:14:24 -05:00
Alan Wu f5fa90fe0b YJIT: Fix `clippy::useless_vec` in a test 2023-11-10 16:55:56 -05:00
Alan Wu 8dfbfa15f6 YJIT: Take cargo --fix for unnecessary calls to into() 2023-11-10 16:55:56 -05:00
Alan Wu 408d5886cf YJIT: Auto fix for clippy::unnecessary_cast 2023-11-10 16:55:56 -05:00
Alan Wu 0a93ea4808 YJIT: Auto fix for clippy::clone_on_copy 2023-11-10 16:55:56 -05:00
Alan Wu b8eb4bd4ce YJIT: Panic with more info when global invalidation patching fails 2023-11-10 11:51:05 -05:00
Alan Wu 38fe710e08 YJIT: Invoke PosMarker callbacks only with solid positions
Previously, PosMarker callbacks ran even when the assembler failed to
assemble its contents due to insufficient space. This was problematic
because when Assembler::compile() failed, the callbacks were given
positions that have no valid code, contrary to general expectation.

For example, we use a PosMarker callback to record VM instruction
boundaries and patch in jumps to exits in case the guest program starts
tracing, however, previously, we could record a location near the end of
the code block, where there is no space to patch in jumps. I suspect
this is the cause of the recent occurrences of rare random failures on
GitHub Actions with the invariants.rs:529 "can rewrite existing code"
message. `--yjit-perf` also uses PosMarker and had a similar issue.

Buffer the list of callbacks to fire, and only fire them when all code
in the assembler are written out successfully. It's more intuitive this
way.
2023-11-10 11:51:05 -05:00
Edwin Garcia 1ee6968855 YJIT: Fix comment typos [ci skip] 2023-11-10 09:47:56 -05:00
Takashi Kokubun 50402db5a7
YJIT: Disable code GC (#8865)
Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
2023-11-08 10:21:04 -05:00
Jean Boussier d898e8d6f8 Refactor rb_shape_transition_shape_capa out
Right now the `rb_shape_get_next` shape caller need to
first check if there is capacity left, and if not call
`rb_shape_transition_shape_capa` before it can call `rb_shape_get_next`.

And on each of these it needs to checks if we got a TOO_COMPLEX
back.

All this logic is duplicated in the interpreter, YJIT and RJIT.

Instead we can have `rb_shape_get_next` do the capacity transition
when needed. The caller can compare the old and new shapes capacity
to know if resizing is needed. It also can check for TOO_COMPLEX
only once.
2023-11-08 11:02:55 +01:00
Alan Wu 7367336c4e YJIT: Fix assert in OOM scenario
We still need to do `jit.record_boundary_patch_point = false`
when gen_outlined_exit() returns `None` and we return with `?`.
Previously, we tripped the assert at codegen.rs:1042.

Found with `--yjit-exec-mem-size=3` on the lobsters benchmark.

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
2023-11-07 18:50:10 -05:00
Alan Wu a1c61f0ae5 YJIT: Use u32 for CodePtr to save 4 bytes each
We've long had a size restriction on the code memory region such that a
u32 could refer to everything. This commit capitalizes on this
restriction by shrinking the size of `CodePtr` to be 4 bytes from 8.

To derive a full raw pointer from a `CodePtr`, one needs a base pointer.
Both `CodeBlock` and `VirtualMemory` can be used for this purpose. The
base pointer is readily available everywhere, except for in the case of
the `jit_return` "branch". Generalize lea_label() to lea_jump_target()
in the IR to delay deriving the `jit_return` address until `compile()`,
when the base pointer is available.

On railsbench, this yields roughly a 1% reduction to `yjit_alloc_size`
(58,397,765 to 57,742,248).
2023-11-07 17:43:43 -05:00
Takashi Kokubun 9877f3ada8
YJIT: Inline basic Ruby methods (#8855)
* YJIT: Inline basic Ruby methods

* YJIT: Fix "InsnOut operand made it past register allocation"

checktype should not generate a useless instruction.
2023-11-07 10:54:33 -05:00
Jean byroot Boussier a294bb844c
YJIT: handle out of shape situation in gen_setinstancevariable (#8857)
If the VM ran out of shape, `rb_shape_transition_shape_capa` might
return `OBJ_TOO_COMPLEX_SHAPE`.

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2023-11-07 10:49:36 -05:00
Maxime Chevalier-Boisvert 6e38076b16
YJIT: implement two-step call threshold (#8839)
* YJIT: implement two-step call threshold

Automatically switch call threshold to a larger value for
larger, production-sized apps, while still allowing smaller apps
and command-line programs to start with a lower threshold.

* Update yjit/src/options.rs

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

* Make the new variables constants

* Check that a custom call threshold was not specified

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2023-11-03 21:07:13 +00:00
Alan Wu 38bdb9d0da YJIT: Delete some dead code and enable lints 2023-11-03 18:47:41 +00:00
Takashi Kokubun ad4f973ecd
YJIT: Always define method codegen table at boot (#8807) 2023-11-02 09:15:48 -07:00
Aaron Patterson dc81432482 updating bindgen 2023-10-24 10:52:06 -07:00
Takashi Kokubun 8a88172fd4
YJIT: Skip printing stats at exit if --yjit-disable (#8727) 2023-10-20 13:12:38 -07:00
Maxime Chevalier-Boisvert 3e65115cef
YJIT: remove unused `--yjit-greedy-versioning` command-line option (#8713) 2023-10-19 19:29:31 +00:00
Alan Wu cdc2a18541 YJIT: Return Option from asm.compile() for has_dropped_bytes()
So that we get a reminder to check CodeBlock::has_dropped_bytes().
Internally, asm.compile() already checks it, and this patch just
propagates it out to the caller with a `#[must_use]`.

Code GC logic moved out one level in entry_stub_hit(), so the body
can freely use `?`
2023-10-19 14:56:35 -04:00
Takashi Kokubun 6beb09c2c9
YJIT: Add RubyVM::YJIT.enable (#8705) 2023-10-19 10:54:35 -07:00
Alan Wu 9d9aa63e82 YJIT: Enable the dead_code lint and delete some dead code 2023-10-19 11:50:36 -04:00
Alan Wu d2b0c9da2e
YJIT: Add a live ISeq counter
It's an estimator for application size and could be used as a
compilation heuristic later.

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-10-18 23:46:35 +00:00
Katherine Oelsner a7032b80af Revert "shape.h: Make attr_index_t uint8_t"
This reverts commit e3afc212ec.
2023-10-18 15:01:13 -07:00
Takashi Kokubun f51b92fe23
YJIT: Add --yjit-perf (#8697)
Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
2023-10-18 21:07:03 +00:00
dependabot[bot] 58ee088bb3 Bump rustix from 0.38.2 to 0.38.19 in /yjit/bindgen
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 0.38.2 to 0.38.19.
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v0.38.2...v0.38.19)

---
updated-dependencies:
- dependency-name: rustix
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-18 12:34:10 -07:00
Alan Wu 36ee5d8ca8 YJIT: Fix clippy::redundant_locals
> note: `#[deny(clippy::redundant_locals)]` on by default

On Rust 1.73.0.
2023-10-17 18:36:23 -04:00
Alan Wu 2abd061e8b YJIT: Remove call to compile() on empty Assembler 2023-10-17 15:24:55 -04:00
Takashi Kokubun d458b4127f
YJIT: Add a few missing counters for send fallback (#8681) 2023-10-17 11:36:13 -04:00
Alan Wu 1f7234c015 YJIT: Lookup IDs on boot instead of binding to them
Previously, the version-controlled `cruby_bindings.inc.rs` file
contained the build-time artifact `id.h`, which nobu mentioned hinders
the goal of having fewer magic numbers in the repository.

Lookup the IDs YJIT needs on boot. It costs cycles, but it's fine since
YJIT only uses a handful of IDs at the moment. No perceptible
degradation to boot time found in my testing.
2023-10-17 11:30:35 -04:00
Takashi Kokubun 48c6cea330
YJIT: Count cold_iseq_entry by default (#8654) 2023-10-14 21:00:50 -07:00
Takashi Kokubun 5808999d30
YJIT: Fallback opt_getconstant_path for const_missing (#8623)
* YJIT: Fallback opt_getconstant_path for const_missing

* Fix a comment [ci skip]

* Remove a wrapper function
2023-10-13 08:52:23 -07:00
Alan Wu 0bf1749e9f
YJIT: Fix argument clobbering in some block_arg+rest_param calls (#8647)
Previously, for block argument callsites with some specific argument
count and callee local variable count combinations, YJIT ended up
writing over arguments that are supposed to be collected into a rest
parameter array unmodified.

Detect when clobbering would happen and avoid it. Also, place the block
handler after the stack overflow check, since it writes to new stack
space.

Reported-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-10-13 10:41:53 -04:00
Maxime Chevalier-Boisvert b2e1ddffa5
YJIT: port call threshold logic from Rust to C for performance (#8628)
* Port call threshold logic from Rust to C for performance

* Prefix global/field names with yjit_

* Fix linker error

* Fix preprocessor condition for rb_yjit_threshold_hit

* Fix third linker issue

* Exclude yjit_calls_at_interv from RJIT bindgen

---------

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-10-12 10:05:34 -04:00
Jean Boussier e3afc212ec shape.h: Make attr_index_t uint8_t
Given `SHAPE_MAX_NUM_IVS 80`, we transition to TOO_COMPLEX
way before we could overflow a 8bit counter.

This reduce the size of `rb_shape_t` from 32B to 24B.

If we decide to raise `SHAPE_MAX_NUM_IVS` we can always increase
that type again.
2023-10-11 08:33:09 +02:00
Takashi Kokubun 4d0a619f71
YJIT: Allow --yjit-trace-exits on release builds (#8619) 2023-10-10 14:54:19 -07:00
Jean Boussier 5cc44f48c5 Refactor rb_shape_transition_shape_capa to not accept capacity
This way the groth factor is encapsulated, which allows
rb_shape_transition_shape_capa to be smarter about ideal sizes.
2023-10-10 14:47:54 +02:00
Alan Wu 8cb906d706 YJIT: Simplify linker flavor check
By not allowlisting every OS that could have a GNU flavor linker,
it's also a bigger tent
2023-10-05 17:31:54 -04:00
Maxime Chevalier-Boisvert 13bde94a9f
YJIT: shink local types from 8 to 4 bytes (#8597)
* Shink local types from 8 to 4 bytes, context from 21 to 17 bytes

Use repr(packed)

* Add comment about Type being limited to 4 bits
2023-10-05 17:17:33 -04:00
Alan Wu 7d1abd5d31 YJIT: Run bindgen 2023-10-05 17:09:18 -04:00
Alan Wu 07a7c4bdaf YJIT: Remove duplicate cfp->iseq accessor 2023-10-05 16:40:27 -04:00
Alan Wu 41a6e4bdf9 YJIT: Avoid writing return value to memory in `leave`
Previously, at the end of `leave` we did
`*caller_cfp->sp = return_value`, like the interpreter.
With future changes that leaves the SP field uninitialized for C frames,
this will become problematic. For cases like returning from
`rb_funcall()`, the return value was written above the stack and
never read anyway (callers use the copy in the return register).

Leave the return value in a register at the end of `leave` and have the
code at `cfp->jit_return` decide what to do with it. This avoids the
unnecessary memory write mentioned above. For JIT-to-JIT returns, it goes
through `asm.stack_push()` and benefits from register allocation for
stack temporaries.

Mostly flat on benchmarks, with maybe some marginal speed improvements.

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-10-05 15:53:05 -04:00
Nobuyoshi Nakada cf1223348a
Remove unmatch parenthesis
```
yjit/yjit.mk:48: Extraneous text after `ifneq' directive
```
2023-10-06 03:39:33 +09:00
Thomas Hurst fd22d5debb
YJIT: Build on BSD platforms with GNU make (#8591) 2023-10-05 13:23:51 -04:00
Takashi Kokubun f834b1a40d YJIT: Add a comment for YJIT_OPTIONS [ci skip] 2023-10-04 10:28:32 -07:00
Takashi Kokubun 7db6f448ed Use a better variable name for w 2023-10-04 10:25:46 -07:00
Takashi Kokubun 577ff858bc Make the function names consistent 2023-10-04 10:25:46 -07:00
Takashi Kokubun 01c462ce6a YJIT: Move help descriptions to options.rs 2023-10-04 10:25:46 -07:00
Takashi Kokubun 465bc682a2
YJIT: Call mprotect after entry stub failure (#8582)
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2023-10-03 22:39:45 -07:00
Maxime Chevalier-Boisvert ea491802fa
YJIT: add heuristic to avoid compiling cold ISEQs (#8522)
* YJIT: Add counter to measure how often we compile "cold" ISEQs (#535)

Fix counter name in DEFAULT_COUNTERS

YJIT: add --yjit-cold-threshold, don't compile cold ISEQs

YJIT: increase default cold threshold to 200_000

Remove rb_yjit_call_threshold()

Remove conflict markers

Fix compilation errors

Threshold 1 should compile immediately

Debug deadlock issue with test_ractor

Fix call threshold issue with tests

* Revert exception threshold logic. Document option in yjid.md

* (void) for 0 parameter functions in C99

* Rename iseq_entry_cold => cold_iseq_entry

* Document --yjit-cold-threshold in ruby.c

* Update doc/yjit/yjit.md

Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>

* Shorten help string to appease test

* Address bug found by Kokubun. Reorder logic.

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>
2023-10-03 17:45:46 -04:00
Takashi Kokubun 1992aef722
YJIT: Stop spilling temps on jit_prepare_routine_call (#8581)
YJIT: Remove spill_temps from jit_prepare_routine_call
2023-10-03 12:54:24 -04:00
Takashi Kokubun 0b67e3fd3e
YJIT: Chain-guard opt_mult overflow (#8554)
* YJIT: Chain-guard opt_mult overflow

* YJIT: Support regenerating Jo after Mul
2023-09-29 21:55:48 -04:00
Takashi Kokubun 0d4c4b6573
YJIT: Use registers for passing C method arguments (#8538) 2023-09-29 10:08:15 -04:00
Takashi Kokubun a8578fff98
YJIT: Remove obsoleted jit_rb_int_mul (#8539) 2023-09-29 10:01:50 -04:00
Takashi Kokubun 9aeb6e72db
YJIT: Avoid creating a vector in get_temp_regs() (#8446)
* YJIT: Avoid creating a vector in get_temp_regs()

Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>

* Remove unused import

---------

Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2023-09-15 21:41:00 -04:00
Alan Wu 7cec7d14c3
YJIT: Fix object movement bug in iseq guard for invokeblock
Since the compile-time iseq used in the guard was not marked and updated
during compaction, a runtime value reusing the address could falsely pass
the guard.

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-09-15 19:03:48 -04:00
Alan Wu 0996cf5593 YJIT: Fix and enable the unused_imports warning 2023-09-15 16:15:15 -04:00
Takashi Kokubun 982d6503b9
YJIT: Skip Insn::Comment and format! if disasm is disabled (#8441)
* YJIT: Skip Insn::Comment and format!

if disasm is disabled

Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>

* YJIT: Get rid of asm.comment

---------

Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
2023-09-14 15:49:40 -07:00
Alan Wu 0ba6c603bc YJIT: Remove UTF-8 BOM [ci skip]
/yjit/src/backend/x86_64/mod.rs Is also UTF-8 and it doesn't have the
marker. The standard recommends against it, so remove it.
2023-09-14 18:40:45 -04:00
Alan Wu 1961c5bb76
YJIT: Plug native stack overflow
Previously, TestStack#test_machine_stack_size failed pretty consistently
on ARM64 macOS, with Rust code and part of the interpreter used for
per-instruction fallback (rb_vm_invokeblock() and friends) touching the
stack guard page and crashing with SEGV. I've also seen the same test
fail on x64 Linux, though with a different symptom.
2023-09-14 17:18:45 -04:00
Takashi Kokubun fcc1699162
YJIT: Initialize Vec with capacity for iterators (#8439) 2023-09-14 10:55:00 -07:00
Takashi Kokubun cdc69da9e5
YJIT: Initialize Assembler vectors with capacity (#8437) 2023-09-14 10:10:31 -04:00
Takashi Kokubun b49be2a70f
YJIT: Skip adding past_page_bytes for past pages (#8433)
YJIT: Skip adding past_pages_bytes for past pages
2023-09-13 16:44:23 -04:00
Takashi Kokubun ff329ce428
YJIT: Make yjit_alloc_size available by default (#8426) 2023-09-13 10:48:14 -04:00
Takashi Kokubun 721d21d301
YJIT: Make compile_time_ns a default counter (#8425) 2023-09-13 10:45:40 -04:00
Takashi Kokubun 0ae7f2d1ac
YJIT: Add compilation time counter (#8417)
* YJIT: Add compilation time counter

* YJIT: Use Instant instead
2023-09-12 13:52:40 -04:00
Alan Wu 39ee3e22bd Make Kernel#lambda raise when given non-literal block
Previously, Kernel#lambda returned a non-lambda proc when given a
non-literal block and issued a warning under the `:deprecated` category.
With this change, Kernel#lambda will always return a lambda proc, if it
returns without raising.

Due to interactions with block passing optimizations, we previously had
two separate code paths for detecting whether Kernel#lambda got a
literal block. This change allows us to remove one path, the hack done
with rb_control_frame_t::block_code introduced in 85a337f for supporting
situations where Kernel#lambda returned a non-lambda proc.

[Feature #19777]

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-09-12 11:25:07 -04:00
Ian Candy 78233e8352
Add `String#getbyte` YJIT implementation (#8397)
* Add getbyte JIT implementation

Adds an implementation for String#getbyte for YJIT, along with a
bootstrap test. This should be helpful for pure Ruby implementations
and to avoid unneeded allocations.

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

* Skip the getbyte test for RJIT for now

---------

Co-authored-by: John Hawthorn <jhawthorn@github.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-09-07 23:15:24 -04:00
Takashi Kokubun 89edce4321
YJIT: Decrease IVAR_MAX_DEPTH to 8 (#8398) 2023-09-07 23:15:08 -04:00
Takashi Kokubun fcdedf7f47
YJIT: Decrease SEND_MAX_DEPTH to 5 (#8390) 2023-09-07 14:22:34 -04:00
Aaron Patterson 0adca625ee
Remove function call for String#bytesize (#8389)
* Remove function call for String#bytesize

String size is stored in a consistent location, so we can eliminate the
function call.

* Update yjit/src/codegen.rs

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>

---------

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-09-07 09:54:05 -04:00
Alan Wu f1422e4cec YJIT: Different comment when only setting ec->cfp [ci skip] 2023-09-06 15:32:36 -04:00
Takashi Kokubun a334077b7b
YJIT: Make compiled_* stats available by default (#8379)
* YJIT: Make compiled_* stats available by default

* Update comment about default counters [ci skip]

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>

---------

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2023-09-06 09:29:33 -07:00
Alan Wu 6c4df555fd YJIT: Silence Clippy for bindgen generated code
New Clippy lint in 1.72.0 is breaking our build as GitHub has updated
their image. No point hearing about lints from generated code we don't
manually write.
2023-09-05 14:46:44 -04:00
John Hawthorn 43825fba6e YJIT: Handle getblockparamproxy with ifunc
getblockparamproxy for "ifunc" behaves identically to iseq, in just
pushing rb_block_param_proxy.
2023-08-31 10:46:24 -04:00
Maxime Chevalier-Boisvert e58fed128b
YJIT: shrink Context from 29 to 21 bytes by reducing space used by TempMapping (#8321)
* YJIT: merge tempmapping and temp types into a single-byte encoding

YJIT: refactor to shrink Context by 8 bytes

* Add tests, fix bug in TempMapping::map_to_local()

* Update yjit/src/core.rs

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>

* Update yjit/src/core.rs

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>

* Fewer transmutes where `as` would suffice. Also repr(u8)

* Update yjit/src/core.rs

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>

* Update yjit/src/core.rs

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>

* Update yjit/src/core.rs

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>

---------

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2023-08-30 11:14:51 -04:00
Alan Wu 23c83d172c YJIT: Remove Type::CArray and limit use of Type::CString
These types are essentially claims about what `RBASIC_CLASS(obj)`
returns. The field changes with singleton class creation, but we didn't
consider so previously and elided guards where we actually needed them.

Found running ruby/spec with --yjit-verify-ctx. The assertion interface
makes extensive use of singleton classes.
2023-08-28 17:14:33 -04:00
Alan Wu 5937a0da80 YJIT: Refactor to use Option<BlockHandler> in SpecVal
We pass block around as `Option<BlockHandler>` having SpecVal
match that simplifes code matching for the `None` case.
2023-08-24 17:35:10 -04:00
Alan Wu f61e620c4d YJIT: Move block handler SpecVal variants into BlockHandler
A refactor so that the variants correspond to
branches in vm_caller_setup_arg_block().
2023-08-24 17:35:10 -04:00
Alan Wu b4bc047f2f
YJIT: Implement VM_CALL_ARGS_BLOCKARG with Proc for ISeq calls
Rack uses this. Speculate that the `obj` in `the_call(&obj)`
will be a proc when the compile-time sample is a proc.

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2023-08-23 11:10:52 -04:00
Aaron Patterson 58c1ebb634
Fix guard-heap upgrades (#8264)
* Fix guard-heap upgrades

`getinstancevariable` was generating more heap guards than I thought.
It turns out that the upgrade code has a bug in it.

Given the following Ruby code:

```ruby
class Foo
  def initialize
    @a = 1
    @b = 1
  end

  def foo
    [@a, @b]
  end
end

foo = Foo.new
10.times { foo.foo }

puts RubyVM::YJIT.disasm Foo.instance_method(:foo)
```

Before this commit, the machine code was like this:

```
== BLOCK 1/4, ISEQ RANGE [0,3), 36 bytes ======================
  # Insn: 0000 getinstancevariable (stack_size: 0)
  0x5562fb831023: mov rax, qword ptr [r13 + 0x18]
  # guard object is heap
  0x5562fb831027: test al, 7
  0x5562fb83102a: jne 0x5562fb833080
  0x5562fb831030: test rax, rax
  0x5562fb831033: je 0x5562fb833080
  # guard shape
  0x5562fb831039: cmp dword ptr [rax + 4], 0x18
  0x5562fb83103d: jne 0x5562fb833062
  # reg_temps: 00000000 -> 00000001
  0x5562fb831043: mov rsi, qword ptr [rax + 0x10]

== BLOCK 2/4, ISEQ RANGE [3,6), 0 bytes =======================
== BLOCK 3/4, ISEQ RANGE [3,6), 36 bytes ======================
  # regenerate_branch
  # Insn: 0003 getinstancevariable (stack_size: 1)
  # regenerate_branch
  0x5562fb831047: mov rax, qword ptr [r13 + 0x18]
  # guard object is heap
  0x5562fb83104b: test al, 7
  0x5562fb83104e: jne 0x5562fb8330db
  0x5562fb831054: test rax, rax
  0x5562fb831057: je 0x5562fb8330db
  # guard shape
  0x5562fb83105d: cmp dword ptr [rax + 4], 0x18
  0x5562fb831061: jne 0x5562fb8330ba
  # reg_temps: 00000001 -> 00000011
  0x5562fb831067: mov rdi, qword ptr [rax + 0x18]
```

After this commit, the machine code has fewer guards for `self`:

```
== BLOCK 1/4, ISEQ RANGE [0,3), 36 bytes ======================
  # Insn: 0000 getinstancevariable (stack_size: 0)
  0x55cb5db5f023: mov rax, qword ptr [r13 + 0x18]
  # guard object is heap
  0x55cb5db5f027: test al, 7
  0x55cb5db5f02a: jne 0x55cb5db61080
  0x55cb5db5f030: test rax, rax
  0x55cb5db5f033: je 0x55cb5db61080
  # guard shape
  0x55cb5db5f039: cmp dword ptr [rax + 4], 0x18
  0x55cb5db5f03d: jne 0x55cb5db61062
  # reg_temps: 00000000 -> 00000001
  0x55cb5db5f043: mov rsi, qword ptr [rax + 0x10]

== BLOCK 2/4, ISEQ RANGE [3,6), 0 bytes =======================
== BLOCK 3/4, ISEQ RANGE [3,6), 18 bytes ======================
  # regenerate_branch
  # Insn: 0003 getinstancevariable (stack_size: 1)
  # regenerate_branch
  0x55cb5db5f047: mov rax, qword ptr [r13 + 0x18]
  # guard shape
  0x55cb5db5f04b: cmp dword ptr [rax + 4], 0x18
  0x55cb5db5f04f: jne 0x55cb5db610ba
  # reg_temps: 00000001 -> 00000011
  0x55cb5db5f055: mov rdi, qword ptr [rax + 0x18]
```

Co-Authored-By: Takashi Kokubun <takashikkbn@gmail.com>

* Fix array/string guards as well

---------

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-08-23 10:34:03 -04:00
Alan Wu ff55238913
YJIT: x64: Split mem-to-mem Insn::Store like Insn::Mov
The ARM backend allows for this so let's make x64 consistent.
2023-08-22 18:43:56 -04:00
Alan Wu 817ffa8ec4
YJIT: Remove unnecessary roundtrip conversion 2023-08-21 12:52:34 -04:00
ywenc 3dff315ed3
YJIT: Quiet mode when running with `--yjit-stats` (#8251)
Quiet mode for running with --yjit-stats
2023-08-18 18:27:59 -04:00
Alan Wu 4524aeba2f YJIT: Fix return type of Integer#/ with T_FIXNUM inputs
Issue found by running ruby/spec with `--yjit-verify-ctx`. Thanks!
2023-08-18 12:17:37 -04:00
Maxime Chevalier-Boisvert 314eed8a5e
YJIT: implement fast path for integer multiplication in opt_mult (#8204)
* YJIT: implement fast path for integer multiplication in opt_mult

* Update yjit/src/codegen.rs

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

* Implement mul with overflow checking on arm64

* Fix missing semicolon

* Add arm splitting for lshift, rshift, urshift

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2023-08-18 10:05:32 -04:00
Alan Wu 5d48825d55 YJIT: Fix String#<< return type
We previously falsely asserted that String#<< always returns a ::String
instance. Issue was discovered on CI with `--yjit-verify-ctx`.

https://github.com/ruby/ruby/actions/runs/5893760435/job/15986002531
2023-08-17 17:17:31 -04:00
Alan Wu 518d5ab5c8 Add note about rb_f_notimplement [ci skip]
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-08-17 17:14:46 -04:00
Alan Wu 9683eb06cf YJIT: Fix Kernel#respond_to? handling of rb_f_notimplement
We should return false for this type of special methods but wasn't
previously. Was reproducible with:

    make test-all TESTS=../test/-ext-/test_notimplement.rb RUN_OPTS='--yjit-call-threshold=1'
2023-08-17 17:14:46 -04:00
Maxime Chevalier-Boisvert 30a5b94517
YJIT: implement side chain fallback for setlocal to avoid exiting (#8227)
* YJIT: implement side chain fallback for setlocal to avoid exiting

* Update yjit/src/codegen.rs

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>

---------

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-08-17 10:11:17 -04:00
Alan Wu 9acc73d7c5
YJIT: Optional parameter rework and bugfix (#8220)
* YJIT: Fix splatting empty array with rest param

* YJIT: Rework optional parameter handling to fix corner case

The old code had a few unintuitive parts. The starting PC of the callee
was set in different places; `num_param`, which one would assume to be
static for a particular callee seemingly tallied to different amounts
depending on the what the caller passed; `opts_filled_with_splat` was
greater than zero even when the opts were not filled by items in the
splat array. Functionally, the bits that lets the callee know which
keyword parameters are unspecified were not passed properly when there
are optional parameters and a rest parameter, and then optional
parameters are all filled.

Make `num_param` non-mut and use parameter information in the callee
iseq as-is. Move local variable nil fill and placing of the rest array
out of `gen_push_frame()` as they are only ever relevant for iseq calls.
Always place the rest array at `lead_num + opt_num` to fix the
previously buggy situation.

* YJIT: Compile splat calls to iseqs with rest params

Test interactions with optional parameters.
2023-08-15 10:08:48 -04:00
Takashi Kokubun 75c9487a98
YJIT: Chain guard classes on instance_of (#8209) 2023-08-14 10:18:19 -04:00
Takashi Kokubun 02e5095108
YJIT: Implement GET_BLOCK_HANDLER() for invokesuper (#8206) 2023-08-11 13:07:16 -07:00
Maxime Chevalier-Boisvert b6c66604d8
YJIT: increase max chain depth for expandarray (#8205) 2023-08-11 14:08:45 -04:00
Maxime Chevalier-Boisvert a8cd18f08d
YJIT: implement codegen for rb_int_lshift (#8201)
* YJIT: implement codegen for rb_int_lshift

* Update yjit/src/asm/x86_64/mod.rs

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>

---------

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-08-11 11:01:16 -04:00
Takashi Kokubun 654b648223
YJIT: Implement checkmatch instruction (#8203) 2023-08-10 23:08:29 -04:00
Takashi Kokubun d7c0fec40b Update an outdated YJIT binding 2023-08-10 17:44:08 -07:00
Maxime Chevalier-Boisvert b5b34c1f84
YJIT: add mul() instruction to backend IR (#8195) 2023-08-10 14:47:03 -04:00
Takashi Kokubun 3ad306b4f0
YJIT: Fallback megamorphic super/yield to dynamic dispatch (#8197)
YJIT: Fallback megamorphic super/yield

to dynamic dispatch
2023-08-10 14:13:21 -04:00
Takashi Kokubun 92cf14b4c5
YJIT: Allow VM_CALL_ARGS_BLOCKARG on invokesuper (#8198) 2023-08-10 08:59:52 -07:00
Takashi Kokubun 1ccd0eae11
YJIT: Chain guard method IDs for respond_to? (#8196) 2023-08-09 14:46:42 -07:00
Takashi Kokubun 493acaf4d4
YJIT: Distinguish exit and fallback reasons for invokesuper/invokeblock (#8194)
YJIT: Distinguish exit and fallback reasons

for invokesuper/invokeblock
2023-08-09 15:34:30 -04:00
Takashi Kokubun d3efce69ea
YJIT: Count throw instructions for each tag (#8188)
* YJIT: Count throw instructions for each tag

* Show % of each throw type
2023-08-09 10:16:15 -07:00
Maxime Chevalier-Boisvert c9b30f9d76
YJIT: implement imul instruction encoding in x86 assembler (#8191) 2023-08-09 13:12:21 -04:00
Kevin Newton a41c617e41
Implement MUL instruction for aarch64 (#8193) 2023-08-09 12:21:53 -04:00
Takashi Kokubun 6acfc50bcc
YJIT: Count all opt_getconstant_path exit reasons (#8187) 2023-08-09 09:54:24 -04:00
Alan Wu 5eef3ce21f
YJIT: Correct name of a counter (#8186) 2023-08-09 09:47:42 -04:00
Takashi Kokubun cd8d20cd1f
YJIT: Compile exception handlers (#8171)
Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2023-08-08 16:06:22 -07:00
Maxime Chevalier-Boisvert 8d7861e3da
YJIT: expand bitwise shift support in x86 assembler (#8174) 2023-08-04 14:57:56 -04:00
Maxime Chevalier-Boisvert fc0b2a8df2
YJIT: guard for array_len >= num in expandarray (#8169)
Avoid generating long dispatch chains for all array lengths seen.
2023-08-04 10:09:43 -04:00
Maxime Chevalier-Boisvert 4f99240b2e
YJIT: add jb (unsigned less-than) instruction to backend (#8168) 2023-08-03 16:14:44 -04:00