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


当前回答

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

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

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

其他回答

20%的字节码在80%的时间内被使用。JIT编译器获得这些统计数据,并优化这20%的字节代码,通过添加内联方法、删除未使用的锁等,并创建特定于这台机器的字节码来更快地运行。我引用这篇文章,我发现它很方便。http://java.dzone.com/articles/just-time-compiler-jit-hotspot

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

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

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

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

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

JVM actually performs compilation steps during runtime for performance reasons. This means that Java doesn't have a clean compile-execution separation. It first does a so called static compilation from Java source code to bytecode. Then this bytecode is passed to the JVM for execution. But executing bytecode is slow so the JVM measures how often the bytecode is run and when it detects a "hotspot" of code that's run very frequently it performs dynamic compilation from bytecode to machinecode of the "hotspot" code (hotspot profiler). So effectively today Java programs are run by machinecode execution.

一开始,编译器负责将高级语言(定义为比汇编程序更高级别)转换成目标代码(机器指令),然后(通过链接器)将其链接成可执行文件。

At one point in the evolution of languages, compilers would compile a high-level language into pseudo-code, which would then be interpreted (by an interpreter) to run your program. This eliminated the object code and executables, and allowed these languages to be portable to multiple operating systems and hardware platforms. Pascal (which compiled to P-Code) was one of the first; Java and C# are more recent examples. Eventually the term P-Code was replaced with bytecode, since most of the pseudo-operations are a byte long.

即时(JIT)编译器是运行时解释器的一个特性,它不是在每次调用方法时都解释字节码,而是将字节码编译为运行机器的机器代码指令,然后调用此目标代码。理想情况下,运行目标代码的效率将克服每次运行时重新编译程序的低效率。