与非JIT编译器相比,JIT编译器具体做什么?有人能给出简洁易懂的描述吗?
当前回答
Jit代表即时编译器 Jit是一个将Java字节代码转换为可以直接发送到处理器的指令的程序。
在特定的系统平台上使用java即时编译器(实际上是第二个编译器)将字节码遵从为特定的系统代码,一旦代码被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.
在Java编译器生成字节代码(与体系结构无关)之后,执行将由JVM(在Java中)处理。字节代码将由加载器加载到JVM中,然后解释每个字节指令。
当我们需要多次调用一个方法时,我们需要多次解释相同的代码,这可能会花费更多的时间。所以我们有了JIT(即时)编译器。当字节被加载到JVM(它的运行时)中时,整个代码将被编译而不是解释,从而节省时间。
JIT编译器只在运行时工作,所以我们没有任何二进制输出。
一开始,编译器负责将高级语言(定义为比汇编程序更高级别)转换成目标代码(机器指令),然后(通过链接器)将其链接成可执行文件。
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)编译器是运行时解释器的一个特性,它不是在每次调用方法时都解释字节码,而是将字节码编译为运行机器的机器代码指令,然后调用此目标代码。理想情况下,运行目标代码的效率将克服每次运行时重新编译程序的低效率。
JIT编译器在程序启动后运行,并实时(或称为just-in-time)将代码(通常是字节码或某种虚拟机指令)编译为通常更快的形式,通常是主机CPU的本机指令集。JIT可以访问动态运行时信息,而标准编译器不能,并且可以进行更好的优化,例如经常使用的内联函数。
这与传统的编译器相反,传统的编译器在程序第一次运行之前将所有代码编译为机器语言。
换句话说,在你第一次运行程序之前,传统的编译器会将整个程序构建为一个EXE文件。对于新样式的程序,程序集是用伪代码(p-code)生成的。只有在你在操作系统上执行程序之后(例如,通过双击它的图标),(JIT)编译器才会启动并生成基于英特尔处理器或其他能够理解的机器代码(m-code)。
即时编译器(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.
推荐文章
- Go是如何编译得这么快的?
- 编译警告:对于架构i386,没有处理文件的规则
- LL和LR解析之间的区别是什么?
- 为什么Java在连续整数上的切换与添加的情况下运行得更快?
- Clang vs GCC——哪个生成更快的二进制文件?
- __PRETTY_FUNCTION__, __FUNCTION__, __func__之间的区别是什么?
- 为什么编译Python代码?
- 显示构建日期
- 编译语言与解释语言
- 为什么要用C语言链接数学库?
- 如何防止较少试图编译CSS calc()属性?
- 错误:java:无效的源代码发布:8 Intellij。这是什么意思?
- .NET 3.5 JIT在运行应用程序时无法工作
- Java JIT在运行JDK代码时会作弊吗?
- 如何检查Python脚本的语法而不执行它?