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

779 Коммитов

Автор SHA1 Сообщение Дата
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