Building a JIT compiler one small step at a time
An incremental approach to JIT construction
A paper from ACM presents an incremental method for constructing JIT compilers, breaking the work into smaller stages rather than building the whole system at once. Posted to Hacker News, it drew little discussion, so the details of the approach remain largely unexamined in the thread.
An incremental approach to JIT construction
- so-cal-schemer
I'm very interested in reading this and checking out the associated course site.
Also, I'm taking opportunities to link to relevant sections in SICP, so some suggested reading:
5.5 Compilation
https://sarabander.github.io/sicp/html/5_002e5.xhtml#g_t5_00...
- gopalv
This is a great example of going from AOT to JIT specializing function calls by types.
I assume this intended at a class which has already finished writing an AOT compiler and wants to build faster functions than you can derive at a compile time.
> On the first call to a function, the compiler calls compile_me, which reconstructs argument types from their tag bits and builds a temporary type environment. The function body is then optimized using those concrete argument types.
It's been two decades since I have worked on Rhys's brilliant libjit and the work that came before it[1], but the first-call recompilation can mix well with a byte code interpreter as well.
You still need to be able to JIT a whole function with the first-call recompiler here, but you can do even more incremental if you are pairing it with an interpreter which gets to pick up the slack of the JIT.
For example, with an interpreter, I could JIT about ~15% of a function and incrementally implement one opcode at a time without handling the complex ones on day one.
The switch loop with direct threading can jump into a JIT block or the next instruction's compiled location, in identical fashion. So you get to operate register to register for adjacent instructions being JIT'ed together, but write back to heap for the interpreter to take over for an unsupported one.
This is referred to as unrolling in the impl there, because what it really does is partially unroll the for(op in ops) loop and skip the jump to the […]
- noelwelsh
Really cool. I haven't read it but I'm familiar with some of the authors so I expect this to be good.