与非JIT编译器相比,JIT编译器具体做什么?有人能给出简洁易懂的描述吗?
当前回答
代码被编译成某种IL(中间语言)。当你运行你的程序时,计算机不理解这段代码。它只理解本机代码。因此JIT编译器会动态地将IL编译为本地代码。它在方法级别上执行此操作。
其他回答
一开始,编译器负责将高级语言(定义为比汇编程序更高级别)转换成目标代码(机器指令),然后(通过链接器)将其链接成可执行文件。
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,这意味着代码在需要时才编译,而不是在运行时之前。
这是有益的,因为编译器可以生成针对特定机器优化的代码。静态编译器,就像普通的C编译器一样,将所有代码编译为开发人员机器上的可执行代码。因此,编译器将基于一些假设执行优化。它可以编译得更慢,做更多的优化,因为它不会降低用户执行程序的速度。
非jit编译器获取源代码,并在编译时将其转换为特定于机器的字节代码。JIT编译器获取编译时生成的与机器无关的字节代码,并在运行时将其转换为特定于机器的字节代码。Java使用的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.
即时(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
推荐文章
- 用自己的语言编写编译器
- 带有返回类型的Java方法在没有返回语句的情况下编译
- 使用g++编译多个.cpp和.h文件
- 在Visual Studio中设置“首选32位”的目的是什么?它实际上是如何工作的?
- Go是如何编译得这么快的?
- 编译警告:对于架构i386,没有处理文件的规则
- LL和LR解析之间的区别是什么?
- 为什么Java在连续整数上的切换与添加的情况下运行得更快?
- Clang vs GCC——哪个生成更快的二进制文件?
- __PRETTY_FUNCTION__, __FUNCTION__, __func__之间的区别是什么?
- 为什么编译Python代码?
- 显示构建日期
- 编译语言与解释语言
- 为什么要用C语言链接数学库?
- 如何防止较少试图编译CSS calc()属性?