Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions content/bvm/optimizing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ order: 65
# The JIT

bvm gets faster as a program runs. It starts every function in the interpreter, counts how often each one is called
and how often its loops turn, and compiles the hot ones to x86-64 machine code while the program keeps running. There
and how often its loops turn, and compiles the hot ones to machine code (x86-64 or arm64) while the program keeps running. There
is nothing to configure and no cache on disk, and it works for every language built on bvm, not just Burn.

![Functions start in the interpreter and are compiled to machine code when they get hot](../images/tiering.svg)
Expand Down Expand Up @@ -54,10 +54,14 @@ error names the same line and column. Threads started with `async` share the com
The results are always the same; only the speed changes. Burn's test suite runs every test program with
`BURN_JIT_THRESHOLD=1` and with `BURN_JIT=0` and compares their output with the native executables.

The JIT runs on x86-64 Linux and macOS. On arm64 (Apple silicon and Linux), bvm interprets for now.
The JIT runs on Linux and macOS, on x86-64 (`compiler/src/bvm/jit_x86.bn`) and arm64, Macs with Apple silicon
included (`jit_arm64.bn`). Both code generators share the tracking of the operand stack and jumps (`jitbase.bn`).
On arm64 the accumulator is `x9` and the frame base `x19`; on x86-64 they are `rax` and `rbx`.

## Numbers

Measured on x86-64 Linux:

| Program | Interpreted | With the JIT | Native executable |
| --- | --- | --- | --- |
| `fib(32)`, recursive calls | 1.4 s | 31 ms | 20 ms |
Expand Down
2 changes: 1 addition & 1 deletion content/bvm/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ What a language gets by targeting bvm:
run off the end of a function.
- **Fast execution.** Verified code runs on an interpreter with a precomputed frame size per function, so pushes
and pops aren't bounds-checked. At load time common instruction sequences are fused into
superinstructions, and functions and loops that run often are compiled to x86-64 machine code while the program
superinstructions, and functions and loops that run often are compiled to x86-64 or arm64 machine code while the program
runs (see [the JIT](./optimizing.mdx)).
- **Two interchangeable file formats**: readable assembly (`.bvm`) and compact bytecode (`.bvmc`). They convert
both ways without loss.
Expand Down
6 changes: 3 additions & 3 deletions content/images/tiering.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion content/internals/running.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jump", or "load a local and read one of its fields". The interpreter is a loop o
## Compiling hot code

bvm counts calls and loop turns per function. When a function gets hot (1000 calls or loop turns), the JIT compiles
it to x86-64 machine code that keeps the interpreter's frame, so compiled and interpreted functions call each other
it to machine code for the processor (x86-64 or arm64) that keeps the interpreter's frame, so compiled and interpreted functions call each other
freely, and a loop that is already running continues in the compiled code at its next turn (on-stack replacement).
Compiled code keeps values in registers and runs arithmetic, comparisons, fields, arrays and reference counting
inline. See [the JIT](../bvm/optimizing.mdx) for the details and its settings, `BURN_JIT` and `BURN_JIT_THRESHOLD`.
Expand Down
Loading