An incremental approach to JIT construction

(dl.acm.org)

40 points | by andsoitis 2 days ago

3 comments

  • gopalv 4 hours ago
    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 top when you see a sequence of ops which you can line up together and JIT once.

    [1] - https://mirror.linux.org.au/pub/linux.conf.au/2003/papers/Rh...

    [2] - https://docs.rs/gnu-libjit/latest/gnu_libjit/struct.Function...

  • so-cal-schemer 1 hour ago
    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...

    • HexDecOctBin 1 hour ago
      Sorry, can you provide the link to the course? I was not able to find it.
  • noelwelsh 9 hours ago
    Really cool. I haven't read it but I'm familiar with some of the authors so I expect this to be good.