From 98bcd549b5826ed0d60687aac2be40dc54aa9533 Mon Sep 17 00:00:00 2001 From: Steven Webb Date: Tue, 27 Jan 2026 13:29:33 +0800 Subject: [PATCH 1/2] [DOC] Example usage for --zjit-dump-hir Learning about the HIR format is difficult if you can't get zjit to generate it for code snippets. It's not obvious to newcomers that HIR won't be generated unless the `zjit-call-threshold` is reached (default 30). --- doc/jit/zjit.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/jit/zjit.md b/doc/jit/zjit.md index a284fce8115869..fd9934975ec591 100644 --- a/doc/jit/zjit.md +++ b/doc/jit/zjit.md @@ -306,6 +306,14 @@ A file called `zjit_exits_{pid}.dump` will be created in the same directory as ` stackprof path/to/zjit_exits_{pid}.dump ``` +### Viewing HIR as text + +The compiled zjit HIR can be viewed as text using the `--zjit-dump-hir` option. However, HIR will only be generated if the `zjit-call-threshold` is reached (default 30). By setting the threshold to 1 you can easily view the HIR for code snippets such as `1 + 1`: + +```bash +./miniruby --zjit --zjit-dump-hir --zjit-call-threshold=1 -e "1 + 1" +``` + ### Viewing HIR in Iongraph Using `--zjit-dump-hir-iongraph` will dump all compiled functions into a directory named `/tmp/zjit-iongraph-{PROCESS_PID}`. Each file will be named `func_{ZJIT_FUNC_NAME}.json`. In order to use them in the Iongraph viewer, you'll need to use `jq` to collate them to a single file. An example invocation of `jq` is shown below for reference. From ca5385e8c1131311eb02ce7788c4ee8bae814426 Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Sat, 31 Jan 2026 08:58:56 -0500 Subject: [PATCH 2/2] Update doc/jit/zjit.md --- doc/jit/zjit.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/jit/zjit.md b/doc/jit/zjit.md index fd9934975ec591..ab215a0172fb65 100644 --- a/doc/jit/zjit.md +++ b/doc/jit/zjit.md @@ -308,12 +308,19 @@ stackprof path/to/zjit_exits_{pid}.dump ### Viewing HIR as text -The compiled zjit HIR can be viewed as text using the `--zjit-dump-hir` option. However, HIR will only be generated if the `zjit-call-threshold` is reached (default 30). By setting the threshold to 1 you can easily view the HIR for code snippets such as `1 + 1`: +The compiled ZJIT HIR can be viewed as text using the `--zjit-dump-hir` option. However, HIR will only be generated if the call threshold is reached (default 30). By setting the threshold to 1 you can easily view the HIR for code snippets such as `1 + 1`: ```bash ./miniruby --zjit --zjit-dump-hir --zjit-call-threshold=1 -e "1 + 1" ``` +Note that this disables profiling. To inject interpreter profiles into ZJIT, consider running your sample code 30 times: + +```bash +./miniruby --zjit --zjit-dump-hir -e "30.times { 1 + 1 }" +``` +``` + ### Viewing HIR in Iongraph Using `--zjit-dump-hir-iongraph` will dump all compiled functions into a directory named `/tmp/zjit-iongraph-{PROCESS_PID}`. Each file will be named `func_{ZJIT_FUNC_NAME}.json`. In order to use them in the Iongraph viewer, you'll need to use `jq` to collate them to a single file. An example invocation of `jq` is shown below for reference.