What does a just-in-time (JIT) compiler do?

后端 未结 18 1747
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 12:42

What does a JIT compiler specifically do as opposed to a non-JIT compiler? Can someone give a succinct and easy to understand description?

18条回答
  •  花落未央
    2020-11-22 12:59

    A just in time compiler (JIT) is a piece of software which takes receives an non executable input and returns the appropriate machine code to be executed. For example:

    Intermediate representation    JIT    Native machine code for the current CPU architecture
    
         Java bytecode            --->        machine code
         Javascript (run with V8) --->        machine code
    

    The consequence of this is that for a certain CPU architecture the appropriate JIT compiler must be installed.

    Difference compiler, interpreter, and JIT

    Although there can be exceptions in general when we want to transform source code into machine code we can use:

    1. Compiler: Takes source code and returns a executable
    2. Interpreter: Executes the program instruction by instruction. It takes an executable segment of the source code and turns that segment into machine instructions. This process is repeated until all source code is transformed into machine instructions and executed.
    3. JIT: Many different implementations of a JIT are possible, however a JIT is usually a combination of a compliler and an interpreter. The JIT first turn intermediary data (e.g. Java bytecode) which it receives into machine language via interpretation. A JIT can often sense when a certain part of the code is executed often and the will compile this part for faster execution.

提交回复
热议问题