与非JIT编译器相比,JIT编译器具体做什么?有人能给出简洁易懂的描述吗?
当前回答
我知道这是一个老线程,但是运行时优化是JIT编译的另一个重要部分,这里似乎没有讨论它。基本上,JIT编译器可以在程序运行时监视它,以确定改进执行的方法。然后,它可以在运行时动态地进行这些更改。谷歌JIT优化(javaworld有一篇关于它的很好的文章。)
其他回答
即时(JIT)编译(也称为动态翻译或运行时编译)是一种执行计算机代码的方式,它涉及在程序执行期间(在运行时)而不是在执行之前进行编译。
IT编译结合了两种传统的机器代码转换方法——预先编译(AOT)和解释,并结合了两者的一些优点和缺点。JIT编译结合了编译代码的速度和解释的灵活性。
让我们考虑在JVM中使用的JIT,
例如,HotSpot JVM JIT编译器生成动态优化。换句话说,它们在Java应用程序运行时做出优化决策,并生成针对底层系统架构的高性能本机机器指令。
When a method is chosen for compilation, the JVM feeds its bytecode to the Just-In-Time compiler (JIT). The JIT needs to understand the semantics and syntax of the bytecode before it can compile the method correctly. To help the JIT compiler analyze the method, its bytecode are first reformulated in an internal representation called trace trees, which resembles machine code more closely than bytecode. Analysis and optimizations are then performed on the trees of the method. At the end, the trees are translated into native code.
跟踪树是在编程代码的运行时编译中使用的数据结构。跟踪树用于一种“即时编译器”,它跟踪在热点期间执行的代码并编译它。提到这一点。
参考:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html https://en.wikipedia.org/wiki/Just-in-time_compilation
非jit编译器获取源代码,并在编译时将其转换为特定于机器的字节代码。JIT编译器获取编译时生成的与机器无关的字节代码,并在运行时将其转换为特定于机器的字节代码。Java使用的JIT编译器允许一个二进制文件无需修改就能在多种平台上运行。
JIT编译器在程序启动后运行,并实时(或称为just-in-time)将代码(通常是字节码或某种虚拟机指令)编译为通常更快的形式,通常是主机CPU的本机指令集。JIT可以访问动态运行时信息,而标准编译器不能,并且可以进行更好的优化,例如经常使用的内联函数。
这与传统的编译器相反,传统的编译器在程序第一次运行之前将所有代码编译为机器语言。
换句话说,在你第一次运行程序之前,传统的编译器会将整个程序构建为一个EXE文件。对于新样式的程序,程序集是用伪代码(p-code)生成的。只有在你在操作系统上执行程序之后(例如,通过双击它的图标),(JIT)编译器才会启动并生成基于英特尔处理器或其他能够理解的机器代码(m-code)。
JIT指的是一些JVM实现中的执行引擎,它更快,但需要更多内存,是一种即时编译器。在此方案中,方法的字节码在第一次调用方法时被编译为本机机器码。然后缓存该方法的本机机器码,以便下次调用相同的方法时可以重用它。
即时编译器(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.
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 阅读GHC核心
- 解析.py文件,读取AST,修改它,然后写回修改后的源代码
- 是否可以动态编译和执行c#代码片段?
- 为什么Java类的编译与空行不同?
- 如何使用cmake创建共享库?
- 在C和c++中静态变量存储在哪里?
- 无法加载文件或程序集…参数不正确
- 如果使用if-return-return或if-else-return?
- Java是编译型编程语言还是解释型编程语言?
- 为什么Swift的编译时间这么慢?
- 选项(RECOMPILE)总是更快;为什么?
- 如何在Angular 2.0中使用/创建动态模板来编译动态组件?
- 如何修复从源代码安装PHP时未发现xml2-config的错误?
- 用自己的语言编写编译器