What does a JIT compiler do?

后端 未结 9 1303
孤街浪徒
孤街浪徒 2020-12-13 00:28

I was just watching the Google IO videos and they talked about the JIT compiler that they included in the android. They showed a demo of performance improvements thanks to t

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 01:01

    The Just-In-Time (JIT) compiler is a component of the Java™ Runtime Environment that improves the performance of Java applications at run time.

    Refer to the IBM documentation here.

    The interpreter basically does this:

    1. Read the next bytecode to be executed
    2. Look at what the bytecode is and find the native machine instruction(s) that correspond to it
    3. Execute the native machine instruction(s)
    4. Go to step 1

    That is simple, it works well, and it will run your Java program. But it's also inefficient, because looking up the native instruction(s) for every single bytecode to be executed costs processing time. So the JVM contains a second mechanism, the Just-In-Time compiler, which basically does this:

    1. Read all the bytecodes for the method that needs to be executed
    2. Convert all those bytecodes to native machine instructions
    3. Execute the generated native machine instructions

    After it has converted the bytecodes for a method to native machine instructions, the JVM remembers that native code, so that the next time the method has to be run, it can simply run the native instructions - it doesn't need to convert the bytecodes every time the method is run. This makes the program run much faster.

    Also, the JIT performs lots of optimizations to generate native code that runs as fast as possible.

提交回复
热议问题