Search code examples
javascriptcompilationv8interpreterignition

Is V8's ignition a compiler or line by line interpreter?


I have tried looking into some of the V8 blogs to understand this, but it seems they use compiler and interpreter interchangeably. I want to know if ignition converts/compiles to bytecode and then it converts/interprets it and execute the resulting machine code, line by line. Or does it stop its work at generating bytecode. Then, what component interprets line by line? Also I think turbofan only compiles hot functions to optimise the execution.

How does Ignition and turbofan work together? Is it like ignition creates bytecode and also interprets and runs line by line a few times, and information about execution, like data types are profiled. Next, using this information, wherever possible turbofan optimizes code by generating machine code for hot functions. So ignition interprets line by line the non hot functions and the hot functions' machine code is just executed. Where unexpected data type change is encountered the optimized code fails and engine reverts back to line by line interpretation again by ignition. Is this how it all works?


Solution

  • I want to know if ignition converts/compiles to bytecode

    Yes exactly, Ignition converts JavaScript into bytecode. You might call that process compiling, but that term is heavily overloaded with different meanings.

    and then it converts/interprets it

    Yes exactly, it‘s basically a big loop with a switch on all the different instructions stored in the bytecode. That might be called bytecode interpreter (or virtual machine - yet another overloaded term).

    and execute the resulting machine code, line by line.

    No, there is no machine code yet (this is what Maglev and Turbofan will thengenerate), also the bytecode already abstracted away „lines“ of the original sourcecode, so it‘s not really „line by line“.

    Then, what component interprets line by line?

    As far as I know, V8 currently has no AST based interpreter.