AsmJit is a C++ library for generating and running machine code at low latency, with emitters for x86, x64, and AArch64 and an optional register allocator.
Overview
AsmJit helps programs build native instructions in memory and execute them through a JIT runtime. It exposes layered emitters including Assembler, Builder, Compiler, and an experimental UJIT backend, plus architecture-specific APIs for x86 and AArch64 families. Instructions and operands can be composed at runtime with validation before emission.
The library ships with logging, error handling, sections for separating code and data, and a malloc-style JIT allocator that supports dual-mapped pages for W^X policies and MAPJIT on Apple platforms. The Compiler emitter includes a built-in register allocator intended to lower the effort needed for larger generated code snippets. Compile-time flags can disable modules to shrink binaries, and the project reports a compact footprint when all backends are enabled.
AsmJit has no external dependencies and avoids STL containers in its core, aiming for straightforward static linking or embedding. Related projects include AsmTK for assembler parsing atop AsmJit and online instruction grid tools fed by its instruction database. Consumers integrate through CMake targets or package managers, with documentation covering build presets and breaking-change guidance.
Typical use starts by initializing a CodeHolder against a JitRuntime environment, emitting through an architecture-specific assembler, then registering the buffer with the runtime for direct calls to generated functions.
Key features
- x86, x64, and AArch64 backends
- Assembler, Builder, Compiler emitters
- Optional built-in register allocator
- JIT runtime with executable memory management
- Runtime-constructed instructions and operands
- Logging and structured error handling
- Compile-time feature trimming
- No mandatory external dependencies
Use cases
- Just-in-time native code execution
- Dynamic expression or bytecode compilers
- Sandboxed codegen prototypes
- Low-level performance experiments
- Embedded language runtimes