Skip to content

Commit e515fa7

Browse files
committed
ZJIT: Improve documentation and make it easy to generate the types graph
1 parent 456ba32 commit e515fa7

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

doc/jit/zjit.md

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,35 @@ To build ZJIT on macOS:
1616
make -j miniruby
1717
```
1818

19+
To build ZJIT on Linux:
20+
21+
```bash
22+
./autogen.sh
23+
24+
./configure \
25+
--enable-zjit=dev \
26+
--prefix="$HOME"/.rubies/ruby-zjit \
27+
--disable-install-doc
28+
29+
make -j miniruby
30+
```
31+
32+
Note that `--enable-zjit=dev` does a lot of IR validation, which will help to catch errors early but mean compilation and warmup are significantly slower.
33+
34+
The valid values for `--enable-zjit` are, from fastest to slowest:
35+
* `--enable-zjit`: enable ZJIT in release mode for maximum performance
36+
* `--enable-zjit=stats`: enable ZJIT in extended-stats mode
37+
* `--enable-zjit=dev_nodebug`: enable ZJIT in development mode but without slow runtime checks
38+
* `--enable-zjit=dev`: enable ZJIT in debug mode for development, also enables `RUBY_DEBUG`
39+
40+
### Regenerate bindings
41+
42+
When modifying `zjit/bindgen/src/main.rs` you need to regenerate bindings in `zjit/src/cruby_bindings.inc.rs` with:
43+
44+
```bash
45+
make zjit-bindgen
46+
```
47+
1948
## Documentation
2049

2150
You can generate and open the source level documentation in your browser using:
@@ -24,6 +53,16 @@ You can generate and open the source level documentation in your browser using:
2453
cargo doc --document-private-items -p zjit --open
2554
```
2655

56+
### Graph of the Type System
57+
58+
You can generate a graph of the ZJIT type hierarchy using:
59+
60+
```bash
61+
ruby zjit/src/hir_type/gen_hir_type.rb > zjit/src/hir_type/hir_type.inc.rs
62+
dot -O -Tpdf zjit_types.dot
63+
open zjit_types.dot.pdf
64+
```
65+
2766
## Testing
2867

2968
Note that tests link against CRuby, so directly calling `cargo test`, or `cargo nextest` should not build. All tests are instead accessed through `make`.
@@ -139,14 +178,8 @@ end
139178

140179
### Performance Ratio
141180

142-
The `ratio_in_zjit` stat shows the percentage of Ruby instructions executed in JIT code vs interpreter. This metric only appears when ZJIT is built with `--enable-zjit=stats` (which enables `rb_vm_insn_count` tracking) and represents a key performance indicator for ZJIT effectiveness.
143-
144-
To build with stats support:
145-
146-
```bash
147-
./configure --enable-zjit=stats
148-
make -j
149-
```
181+
The `ratio_in_zjit` stat shows the percentage of Ruby instructions executed in JIT code vs interpreter.
182+
This metric only appears when ZJIT is built with `--enable-zjit=stats` [or more](#build-instructions) (which enables `rb_vm_insn_count` tracking) and represents a key performance indicator for ZJIT effectiveness.
150183

151184
### Tracing side exits
152185

zjit/src/hir_type/gen_hir_type.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ def subtype name
2525
end
2626

2727
# Helper to generate graphviz.
28-
def to_graphviz_rec type
28+
def to_graphviz_rec type, f
2929
type.subtypes.each {|subtype|
30-
puts type.name + "->" + subtype.name + ";"
30+
f.puts type.name + "->" + subtype.name + ";"
3131
}
3232
type.subtypes.each {|subtype|
33-
to_graphviz_rec subtype
33+
to_graphviz_rec subtype, f
3434
}
3535
end
3636

3737
# Generate graphviz.
38-
def to_graphviz type
39-
puts "digraph G {"
40-
to_graphviz_rec type
41-
puts "}"
38+
def to_graphviz type, f
39+
f.puts "digraph G {"
40+
to_graphviz_rec type, f
41+
f.puts "}"
4242
end
4343

4444
# ===== Start generating the type DAG =====
@@ -218,3 +218,7 @@ def add_union name, type_names
218218
}
219219
puts " ];"
220220
puts "}"
221+
222+
File.open("zjit_types.dot", "w") do |f|
223+
to_graphviz(any, f)
224+
end

0 commit comments

Comments
 (0)