Build Your Own VM with JIT Compilation for Dummies
summary
A small virtual machine is implemented for an RPN calculator: a parser generates a compact bytecode, an interpreter runs it on first execution, and a JIT translator emits x86_64 machine code into mmaped RWX pages. The generated code follows the SysV AMD64 calling convention (RDI, RSI, RDX, RCX, R8, R9, preserved registers), writes prologue/body/epilogue bytes, stitches contiguous basic blocks with distinct entry points, and calls the produced function pointer to achieve faster repeated runs (demonstrated with a Fibonacci example).
AI-written summary · about
chapters (8)
- 0:00JIT introduction
- 5:10Simple VM creation
- 16:20Machine code generation
- 23:07JIT generator
- 31:14Basic Blocks concept
- 33:01JIT integration
- 36:14Live demo
- 40:29Conclusion
related talks
40mCreating efficient VM with JIT in Go
20mBYOJ: Build your own JIT with Ruby
36mAccelerate RISC-V Instruction Set Simulation by Tiered JIT Compilation
43mCreate your own Interpreter with a JIT in 1 hour
48mOne VM To Rule Them All
54mWhat Lies Beneath
14mRISC-V for Gaming: Emulating X86 on RISC-V
22mGigue: A JIT Code Binary Generator for Hardware Testing
