Commit graph

28 commits

Author SHA1 Message Date
Max Bernstein
ef95e5ba3d
ZJIT: Profile type+shape distributions (#13901)
ZJIT uses the interpreter to take type profiles of what objects pass through
the code. It stores a compressed record of the history per opcode for the
opcodes we select.

Before this change, we re-used the HIR Type data-structure, a shallow type
lattice, to store historical type information. This was quick for bringup but
is quite lossy as profiles go: we get one bit per built-in type seen, and if we
see a non-built-in type in addition, we end up with BasicObject. Not very
helpful. Additionally, it does not give us any notion of cardinality: how many
of each type did we see?

This change brings with it a much more interesting slice of type history: a
histogram. A Distribution holds a record of the top-N (where N is fixed at Ruby
compile-time) `(Class, ShapeId)` pairs and their counts. It also holds an
*other* count in case we see more than N pairs.

Using this distribution, we can make more informed decisions about when we
should use type information. We can determine if we are strictly monomorphic,
very nearly monomorphic, or something else. Maybe the call-site is polymorphic,
so we should have a polymorphic inline cache. Exciting stuff.

I also plumb this new distribution into the HIR part of the compilation
pipeline.
2025-08-05 16:56:04 -04:00
Takashi Kokubun
b22eb0e468
ZJIT: Add --zjit-stats (#14034) 2025-07-29 10:00:15 -07:00
Takashi Kokubun
acc3172530
ZJIT: Profile each instruction at most num_profiles times (#13903)
* ZJIT: Profile each instruction at most num_profiles times

* Use saturating_add for num_profiles
2025-07-16 09:53:10 -07:00
Jeremy Evans
2ab38691a2 Add Set C-API
This should be a minimal C-API needed to deal with Set objects. It
supports creating the sets, checking whether an element is the set,
adding and removing elements, iterating over the elements, clearing
a set, and returning the size of the set.

Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>
2025-07-11 15:24:23 +09:00
John Hawthorn
581da51cb5 Fix whitespace on some RB_VM_LOCKING calls 2025-07-09 17:28:47 -07:00
Stan Lo
dc1b55a387
ZJIT: Add new ZJIT types for Set (#13743) 2025-06-30 09:58:32 -07:00
Jean Boussier
675f33508c Get rid of TOO_COMPLEX shape type
Instead it's now a `shape_id` flag.

This allows to check if an object is complex without having
to chase the `rb_shape_t` pointer.
2025-06-04 13:13:50 +02:00
git
aa00a2d07b * remove trailing spaces. [ci skip] 2025-05-26 02:44:58 +00:00
Nobuyoshi Nakada
aad9fa2853
Use RB_VM_LOCKING 2025-05-25 15:22:43 +09:00
Alan Wu
92b218fbc3 YJIT: ZJIT: Allow both JITs in the same build
This commit allows building YJIT and ZJIT simultaneously, a "combo
build". Previously, `./configure --enable-yjit --enable-zjit` failed. At
runtime, though, only one of the two can be enabled at a time.

Add a root Cargo workspace that contains both the yjit and zjit crate.
The common Rust build integration mechanisms are factored out into
defs/jit.mk.

Combo YJIT+ZJIT dev builds are supported; if either JIT uses
`--enable-*=dev`, both of them are built in dev mode.

The combo build requires Cargo, but building one JIT at a time with only
rustc in release build remains supported.
2025-05-15 00:39:03 +09:00
Alan Wu
33909a1c69 YJIT: ZJIT: Share identical glue functions
Working towards having YJIT and ZJIT in the same build, we need to
deduplicate some glue code that would otherwise cause name collision.
Add jit.c for this and build it for YJIT and ZJIT builds. Update bindgen
to look at jit.c; some shuffling of functions in the output, but the set
of functions shouldn't have changed.
2025-05-02 23:47:57 +09:00
Max Bernstein
6052b12de4
ZJIT: Replace GetConstantPath with Const if the IC is not empty (#13183)
* Add rb_zjit_constcache_shareable

* Add rb_zjit_multi_ractor_p

* Replace GetConstantPath with Const if the IC is not empty
2025-04-28 12:10:26 -07:00
Takashi Kokubun
58e3aa0224
ZJIT: Drop trace_zjit_* instructions (#13189) 2025-04-28 09:25:56 -07:00
Takashi Kokubun
8b72e07359 Disable ZJIT profiling at call-threshold (https://github.com/Shopify/zjit/pull/99)
* Disable ZJIT profiling at call-threshold

* Stop referencing ZJIT instructions in codegen
2025-04-18 21:53:01 +09:00
Takashi Kokubun
d488f74dee Resurrect icache invalidation for arm64 (https://github.com/Shopify/zjit/pull/68)
* Resurrect icache invalidation for arm64

* Get rid of cfg(not(test))
2025-04-18 21:53:00 +09:00
Takashi Kokubun
5a35c47c82 Stop sharing yjit/bindgen with ZJIT (https://github.com/Shopify/zjit/pull/64)
* cp -r yjit/bindgen zjit/

* Rename YJIT variables

* Stop mentioning YJIT in zjit.c
2025-04-18 21:53:00 +09:00
Max Bernstein
97f022b5e7 Print Ruby exception in test utils 2025-04-18 21:53:00 +09:00
Takashi Kokubun
33a052486b Assert everything is compiled in test_zjit (https://github.com/Shopify/zjit/pull/40)
* Assert everything is compiled in test_zjit

* Update a comment on rb_zjit_assert_compiles

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>

* Add a comment about assert_compiles

* Actually use pipe_fd

---------

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
2025-04-18 21:52:59 +09:00
Takashi Kokubun
0a543daf15 Add zjit_* instructions to profile the interpreter (https://github.com/Shopify/zjit/pull/16)
* Add zjit_* instructions to profile the interpreter

* Rename FixnumPlus to FixnumAdd

* Update a comment about Invalidate

* Rename Guard to GuardType

* Rename Invalidate to PatchPoint

* Drop unneeded debug!()

* Plan on profiling the types

* Use the output of GuardType as type refined outputs
2025-04-18 21:52:59 +09:00
Takashi Kokubun
562c35a560 Resurrect asm comment support 2025-04-18 21:52:58 +09:00
Takashi Kokubun
6a0748d2c5 Port align_ptr for x86 2025-04-18 21:52:56 +09:00
Alan Wu
14a4edaea6 bindgen works in --enable-zjit=dev mode. 2025-04-18 21:52:56 +09:00
Max Bernstein
bd22748c6b Add rb_insn_name to zjit 2025-04-18 21:52:56 +09:00
Takashi Kokubun
cf2e305d73 Initialize VirtualMem 2025-04-18 21:52:56 +09:00
Alan Wu
1d95139bf6 miniruby --zjit -e nil runs through iseq_to_ssa 2025-04-18 21:52:56 +09:00
Takashi Kokubun
0f9557e9a7 Copy VirtualMem and mmap 2025-04-18 21:52:56 +09:00
Takashi Kokubun
0bb709718b Hook ZJIT compilation 2025-04-18 21:52:56 +09:00
Takashi Kokubun
8ad08f1126 Fix template/Makefile.in 2025-04-18 21:52:55 +09:00