与非JIT编译器相比,JIT编译器具体做什么?有人能给出简洁易懂的描述吗?


当前回答

在Java编译器生成字节代码(与体系结构无关)之后,执行将由JVM(在Java中)处理。字节代码将由加载器加载到JVM中,然后解释每个字节指令。

当我们需要多次调用一个方法时,我们需要多次解释相同的代码,这可能会花费更多的时间。所以我们有了JIT(即时)编译器。当字节被加载到JVM(它的运行时)中时,整个代码将被编译而不是解释,从而节省时间。

JIT编译器只在运行时工作,所以我们没有任何二进制输出。

其他回答

即时编译器(JIT)是一种软件,它接收一个不可执行的输入,并返回要执行的适当机器代码。例如:

Intermediate representation    JIT    Native machine code for the current CPU architecture

     Java bytecode            --->        machine code
     Javascript (run with V8) --->        machine code

其结果是,对于特定的CPU体系结构,必须安装适当的JIT编译器。

区别编译器、解释器和JIT

虽然在一般情况下,当我们想要将源代码转换为机器码时可能会有例外,但我们可以使用:

Compiler: Takes source code and returns a executable 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. JIT: Many different implementations of a JIT are possible, however a JIT is usually a combination of a compiler 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 measures when a certain part of the code is executed often and the will compile this part for faster execution.

Just In Time编译器也称为JIT编译器 Java的性能改进。默认启用。它是 编译在执行时完成。 Java通过将JIT编译器包含在 JVM。

Jit代表即时编译器 Jit是一个将Java字节代码转换为可以直接发送到处理器的指令的程序。

在特定的系统平台上使用java即时编译器(实际上是第二个编译器)将字节码遵从为特定的系统代码,一旦代码被jit编译器重新编译,它通常会在计算机中运行得更快。

即时编译器随虚拟机一起提供,可选使用。它将字节码编译为立即执行的特定于平台的可执行代码。

JIT代表Just-in-Time,这意味着代码在需要时才编译,而不是在运行时之前。

这是有益的,因为编译器可以生成针对特定机器优化的代码。静态编译器,就像普通的C编译器一样,将所有代码编译为开发人员机器上的可执行代码。因此,编译器将基于一些假设执行优化。它可以编译得更慢,做更多的优化,因为它不会降低用户执行程序的速度。

JIT指的是一些JVM实现中的执行引擎,它更快,但需要更多内存,是一种即时编译器。在此方案中,方法的字节码在第一次调用方法时被编译为本机机器码。然后缓存该方法的本机机器码,以便下次调用相同的方法时可以重用它。