What are the differences between a Just-in-Time-Compiler and an Interpreter, and are there differences between the .NET and the Java JIT compiler?
实时编译器和解释器之间有什么区别,.NET和Java JIT编译器之间有什么区别吗?
8 个解决方案
#1
30
Just-in-time compilation is the conversion of non-native code, for example bytecode, into native code just before it is executed.
即时编译是在执行非本机代码之前将非本机代码(例如字节码)转换为本机代码。
From Wikipedia:
从*:
JIT builds upon two earlier ideas in run-time environments: bytecode compilation and dynamic compilation. It converts code at runtime prior to executing it natively, for example bytecode into native machine code.
JIT基于运行时环境中的两个早期思想:字节码编译和动态编译。它在运行时将代码转换为本机代码,例如字节码转换为本机代码。
An interpreter executes a program. It may or may not have a jitter.
解释器执行程序。它可能有也可能没有抖动。
Again, from Wikipedia:
再次,从*:
An interpreter may be a program that either
解释器也可以是一个程序
- executes the source code directly
- 直接执行源代码
- translates source code into some efficient intermediate representation (code) and immediately executes this
- 将源代码转换为一些有效的中间表示(代码)并立即执行
- explicitly executes stored precompiled code made by a compiler which is part of the interpreter system
- 显式执行编译器(解释器系统的一部分)所存储的预编译代码
Both the standard Java and .NET distributions have JIT compilation, but it is not required by the standards. The JIT compiler in .NET and C# are of course different because the intermediate bytecode is different. The principle is the same though.
标准的Java和. net发行版都有JIT编译,但是标准不需要JIT编译。. net和c#中的JIT编译器当然是不同的,因为中间字节码是不同的。原理是一样的。
#2
25
I've always found that a more abstract explanation sometimes helps. Let's say that you are trying to ask everyone in Mexico "Hello. How are you?" (your source language) Of course, you'll first need to translate it to Spanish (the native language of the country). That translation would be "Hola. Como estas?"
我总是发现一个更抽象的解释有时会有帮助。假设你想问墨西哥的每个人“你好”。你好吗?”当然,你首先需要把它翻译成西班牙语(这个国家的母语)。这个翻译就是“Hola”。你好吗?”
If you know Spanish, there would be no need for you to translate (native code / assembler). You just ask "Hola. Como estas?"
如果您懂西班牙语,就不需要翻译(本机代码/汇编程序)。你只是问“你好。你好吗?”
If you don't know Spanish, there are 3 ways to deal with it.
如果你不懂西班牙语,有三种方法可以解决它。
The first is to get a Spanish Dictionary (a compiler) and look up what the Spanish words are before you go. Perhaps you realize that "Hola. Que tal?" is one syllable shorter (compiler optimization) and use that instead. This is language compilation; you are converting the information to the native language beforehand.
第一步是找一本西班牙语词典(编译器),在你去之前查一下西班牙语单词是什么。也许你意识到“你好”。只有一个音节更短(编译器优化),而是使用它。这是语言编译;您正在提前将信息转换为母语。
The second is where you look up the words in the Spanish Dictionary while you are standing in front of the first person and then store the result (looking up the words just-in-time). The advantage here is that you could get a Mandarin Dictionary and then do the same experiment in China without having to keep ten sticky notes (binaries for different platforms) of translated phrases.
第二种方法是,你站在第一个人面前,在西班牙语字典中查找单词,然后将结果存储起来(及时查找单词)。这样做的好处是,你可以买一本汉语词典,然后在中国做同样的实验,而不必保留10个翻译短语的便签(不同平台的二进制)。
The third is where you look up the words while you are standing in front of each person. In essence, you interpret the words for each person separately (you act as an interpreter). The advantage here is that any changes are instantly reflected with the next person (you could change to asking "Hello. What color is your dog?" without having to fly home and restart - you don't need to recompile the phrases).
第三种是你站在每个人面前的时候查单词。本质上,你是分别为每个人翻译单词(你是翻译)。这里的优点是,任何更改都会立即反映到下一个人身上(您可以更改为询问“Hello”。你的狗是什么颜色的?
- Translating beforehand means you can ask people fastest (pre-compiliation); you don't need to even bring the dictionary with you.
- 提前翻译意味着你可以问别人最快的问题(预编译);你甚至不需要带字典。
- Translating when you see the first person in each country is almost as fast as translating beforehand but still allows you to travel to multiple countries without needing to go home to get a dictionary but means that you need to bring several dictionaries with you (a platform independent runtime).
- 当你在每个国家看到第一个人的时候,翻译几乎和翻译一样快,但是仍然允许你去多个国家,而不需要回家去买一本字典,但这意味着你需要带几本词典(一个独立的平台)。
- Translating on demand is much slower but allows you to change the words without traveling home (source distributed language).
- 按需翻译速度要慢得多,但允许您在不需要回家的情况下更改单词(源分布式语言)。
#3
9
An interpreter generates and executes machine code instructions on the fly for each instruction, regardless of whether it has previously been executed.
A JIT caches the instructions that have been previously interpreted to machine code, and reuses those native machine code instructions thus saving time & resources by not having to re-interpret statements that have already been interpreted.
无论之前是否执行过,解释器都会为每个指令生成和执行机器代码指令。JIT缓存以前被解释为机器码的指令,并重新使用那些本机代码指令,从而节省时间和资源,不必重新解释已经解释过的语句。
#4
6
The question of whether an execution engine is a compiler or an interpreter can be answered very simply by considering what happens if a routine is executed 1,000 times. If code within the execution engine will have to examine some particular representation of the code 1,000 times, the execution engine is an interpreter of that representation. If code within the execution the execution engine will only have to examine that particular representation of the code some smaller number of times (typically, though not necessarily, once), it is a compiler or translator of that representation. Note that it is very common for an execution engine to take input code and convert it to some other form which can be examined more readily. Such an execution engine would combine a compiler or translator of the former form with an interpreter of the latter form.
执行引擎是编译器还是解释器的问题可以很简单地通过考虑如果一个例程被执行1000次会发生什么来回答。如果执行引擎中的代码必须对代码的某些特定表示进行1000次检查,那么执行引擎就是该表示的解释器。如果执行引擎中的代码只需要检查代码的特定表示(通常,虽然不一定,只有一次),那么它就是该表示的编译器或转换器。注意,对于执行引擎来说,获取输入代码并将其转换为其他更容易检查的形式是非常常见的。这样的执行引擎将把以前表单的编译器或翻译与后一种形式的解释器结合起来。
Note that interpreters very seldom produce any form of machine code. Just about the only time an interpreter will produce machine code is when a statement is supposed to perform some operation that really cannot be done any other way. For example, if a BASIC interpreter running on the 8080 encounters the instruction "OUT 100,5", it would typically perform that operation by storing D3 64 C9 (OUT 64h / RET) into three consecutive bytes at some fixed address, loading A with 5, and CALLing that address. The interpreter may technically be generating machine code, but if one were to perform the same OUT instruction 500 times, the interpreter would have to re-generate the machine code every time.
注意,解释器很少生成任何形式的机器代码。解释器产生机器代码的唯一时间是当一个语句被假定执行某种操作时,而这种操作实际上不能用其他任何方式执行。例如,如果一个运行在8080上的基本解释器遇到指令“OUT 100,5”,它通常通过将D3 64 C9 (OUT 64h / RET)存储到一个固定地址的三个连续字节中,然后将a装载到5,然后调用这个地址来执行这个操作。从技术上讲,解释器可能正在生成机器代码,但是如果要执行相同的OUT指令500次,解释器将不得不每次重新生成机器代码。
#5
2
JIT compiler produces binary machine codes translating block source code. Interpreter translates line by line.
JIT编译器生成二进制机器代码翻译块源代码。译员逐行翻译。
#6
1
When the first time a class is referenced the JIT Execution Engine re-compiles the .class files (primary Binaries) generated by Java Compiler containing JVM Instruction Set to Binaries containing HOST system’s Instruction Set. JIT stores and reuses those recompiled binaries from Memory going forward, there by reducing interpretation time and benefits from Native code execution.
当第一次类引用JIT执行引擎重新编译生成的. class文件(主二进制文件)Java编译器包含JVM指令集的二进制文件包含主机系统的指令集。JIT商店和重用那些从内存重新编译的二进制文件,通过减少解释时间和受益于本地代码执行。
On the other hand a plain old java interpreter interprets one JVM instruction from class file at a time and calls a procedure against it.
另一方面,一个普通的旧java解释器一次解释一个来自类文件的JVM指令,并对它调用一个过程。
Find a detail comparison here http://bitshub.blogspot.com/2010/01/Flavors-of-JVM.html
在http://bitshub.blogspot.com/2010/01/flavors of jvm.html找到详细的比较
#7
1
tl;dr
博士tl;
Interpreter: takes only one instruction at a time for execution
一次只执行一条指令
Just-in-time: takes a block of code at once and compile it before execute. so has plenty room for optimization
准时制:一次获取一个代码块,并在执行之前编译它。因此,有足够的空间进行优化。
#8
0
When you compile a Microsoft.NET language, the complier generates code written in the Microsoft Intermediate Language (MSIL). MSIL is a set of instructions that can quickly be translated into native code.
当你编译一个微软。编译器生成用Microsoft中间语言(MSIL)编写的代码。MSIL是一组可以快速转换为本机代码的指令。
A Microsoft.NET application can be run only after the MSIL code is translated into native machine code. In .NET Framework, the intermediate language is complied "just in time" (JIT) into native code when the application or component is run instead of compiling the application at development time.
一个微软。NET应用程序只能在MSIL代码被翻译成本机代码之后才能运行。在。net框架中,当运行应用程序或组件而不是在开发时编译应用程序时,中间语言被“及时”(JIT)编译成本机代码。
更多信息
#1
30
Just-in-time compilation is the conversion of non-native code, for example bytecode, into native code just before it is executed.
即时编译是在执行非本机代码之前将非本机代码(例如字节码)转换为本机代码。
From Wikipedia:
从*:
JIT builds upon two earlier ideas in run-time environments: bytecode compilation and dynamic compilation. It converts code at runtime prior to executing it natively, for example bytecode into native machine code.
JIT基于运行时环境中的两个早期思想:字节码编译和动态编译。它在运行时将代码转换为本机代码,例如字节码转换为本机代码。
An interpreter executes a program. It may or may not have a jitter.
解释器执行程序。它可能有也可能没有抖动。
Again, from Wikipedia:
再次,从*:
An interpreter may be a program that either
解释器也可以是一个程序
- executes the source code directly
- 直接执行源代码
- translates source code into some efficient intermediate representation (code) and immediately executes this
- 将源代码转换为一些有效的中间表示(代码)并立即执行
- explicitly executes stored precompiled code made by a compiler which is part of the interpreter system
- 显式执行编译器(解释器系统的一部分)所存储的预编译代码
Both the standard Java and .NET distributions have JIT compilation, but it is not required by the standards. The JIT compiler in .NET and C# are of course different because the intermediate bytecode is different. The principle is the same though.
标准的Java和. net发行版都有JIT编译,但是标准不需要JIT编译。. net和c#中的JIT编译器当然是不同的,因为中间字节码是不同的。原理是一样的。
#2
25
I've always found that a more abstract explanation sometimes helps. Let's say that you are trying to ask everyone in Mexico "Hello. How are you?" (your source language) Of course, you'll first need to translate it to Spanish (the native language of the country). That translation would be "Hola. Como estas?"
我总是发现一个更抽象的解释有时会有帮助。假设你想问墨西哥的每个人“你好”。你好吗?”当然,你首先需要把它翻译成西班牙语(这个国家的母语)。这个翻译就是“Hola”。你好吗?”
If you know Spanish, there would be no need for you to translate (native code / assembler). You just ask "Hola. Como estas?"
如果您懂西班牙语,就不需要翻译(本机代码/汇编程序)。你只是问“你好。你好吗?”
If you don't know Spanish, there are 3 ways to deal with it.
如果你不懂西班牙语,有三种方法可以解决它。
The first is to get a Spanish Dictionary (a compiler) and look up what the Spanish words are before you go. Perhaps you realize that "Hola. Que tal?" is one syllable shorter (compiler optimization) and use that instead. This is language compilation; you are converting the information to the native language beforehand.
第一步是找一本西班牙语词典(编译器),在你去之前查一下西班牙语单词是什么。也许你意识到“你好”。只有一个音节更短(编译器优化),而是使用它。这是语言编译;您正在提前将信息转换为母语。
The second is where you look up the words in the Spanish Dictionary while you are standing in front of the first person and then store the result (looking up the words just-in-time). The advantage here is that you could get a Mandarin Dictionary and then do the same experiment in China without having to keep ten sticky notes (binaries for different platforms) of translated phrases.
第二种方法是,你站在第一个人面前,在西班牙语字典中查找单词,然后将结果存储起来(及时查找单词)。这样做的好处是,你可以买一本汉语词典,然后在中国做同样的实验,而不必保留10个翻译短语的便签(不同平台的二进制)。
The third is where you look up the words while you are standing in front of each person. In essence, you interpret the words for each person separately (you act as an interpreter). The advantage here is that any changes are instantly reflected with the next person (you could change to asking "Hello. What color is your dog?" without having to fly home and restart - you don't need to recompile the phrases).
第三种是你站在每个人面前的时候查单词。本质上,你是分别为每个人翻译单词(你是翻译)。这里的优点是,任何更改都会立即反映到下一个人身上(您可以更改为询问“Hello”。你的狗是什么颜色的?
- Translating beforehand means you can ask people fastest (pre-compiliation); you don't need to even bring the dictionary with you.
- 提前翻译意味着你可以问别人最快的问题(预编译);你甚至不需要带字典。
- Translating when you see the first person in each country is almost as fast as translating beforehand but still allows you to travel to multiple countries without needing to go home to get a dictionary but means that you need to bring several dictionaries with you (a platform independent runtime).
- 当你在每个国家看到第一个人的时候,翻译几乎和翻译一样快,但是仍然允许你去多个国家,而不需要回家去买一本字典,但这意味着你需要带几本词典(一个独立的平台)。
- Translating on demand is much slower but allows you to change the words without traveling home (source distributed language).
- 按需翻译速度要慢得多,但允许您在不需要回家的情况下更改单词(源分布式语言)。
#3
9
An interpreter generates and executes machine code instructions on the fly for each instruction, regardless of whether it has previously been executed.
A JIT caches the instructions that have been previously interpreted to machine code, and reuses those native machine code instructions thus saving time & resources by not having to re-interpret statements that have already been interpreted.
无论之前是否执行过,解释器都会为每个指令生成和执行机器代码指令。JIT缓存以前被解释为机器码的指令,并重新使用那些本机代码指令,从而节省时间和资源,不必重新解释已经解释过的语句。
#4
6
The question of whether an execution engine is a compiler or an interpreter can be answered very simply by considering what happens if a routine is executed 1,000 times. If code within the execution engine will have to examine some particular representation of the code 1,000 times, the execution engine is an interpreter of that representation. If code within the execution the execution engine will only have to examine that particular representation of the code some smaller number of times (typically, though not necessarily, once), it is a compiler or translator of that representation. Note that it is very common for an execution engine to take input code and convert it to some other form which can be examined more readily. Such an execution engine would combine a compiler or translator of the former form with an interpreter of the latter form.
执行引擎是编译器还是解释器的问题可以很简单地通过考虑如果一个例程被执行1000次会发生什么来回答。如果执行引擎中的代码必须对代码的某些特定表示进行1000次检查,那么执行引擎就是该表示的解释器。如果执行引擎中的代码只需要检查代码的特定表示(通常,虽然不一定,只有一次),那么它就是该表示的编译器或转换器。注意,对于执行引擎来说,获取输入代码并将其转换为其他更容易检查的形式是非常常见的。这样的执行引擎将把以前表单的编译器或翻译与后一种形式的解释器结合起来。
Note that interpreters very seldom produce any form of machine code. Just about the only time an interpreter will produce machine code is when a statement is supposed to perform some operation that really cannot be done any other way. For example, if a BASIC interpreter running on the 8080 encounters the instruction "OUT 100,5", it would typically perform that operation by storing D3 64 C9 (OUT 64h / RET) into three consecutive bytes at some fixed address, loading A with 5, and CALLing that address. The interpreter may technically be generating machine code, but if one were to perform the same OUT instruction 500 times, the interpreter would have to re-generate the machine code every time.
注意,解释器很少生成任何形式的机器代码。解释器产生机器代码的唯一时间是当一个语句被假定执行某种操作时,而这种操作实际上不能用其他任何方式执行。例如,如果一个运行在8080上的基本解释器遇到指令“OUT 100,5”,它通常通过将D3 64 C9 (OUT 64h / RET)存储到一个固定地址的三个连续字节中,然后将a装载到5,然后调用这个地址来执行这个操作。从技术上讲,解释器可能正在生成机器代码,但是如果要执行相同的OUT指令500次,解释器将不得不每次重新生成机器代码。
#5
2
JIT compiler produces binary machine codes translating block source code. Interpreter translates line by line.
JIT编译器生成二进制机器代码翻译块源代码。译员逐行翻译。
#6
1
When the first time a class is referenced the JIT Execution Engine re-compiles the .class files (primary Binaries) generated by Java Compiler containing JVM Instruction Set to Binaries containing HOST system’s Instruction Set. JIT stores and reuses those recompiled binaries from Memory going forward, there by reducing interpretation time and benefits from Native code execution.
当第一次类引用JIT执行引擎重新编译生成的. class文件(主二进制文件)Java编译器包含JVM指令集的二进制文件包含主机系统的指令集。JIT商店和重用那些从内存重新编译的二进制文件,通过减少解释时间和受益于本地代码执行。
On the other hand a plain old java interpreter interprets one JVM instruction from class file at a time and calls a procedure against it.
另一方面,一个普通的旧java解释器一次解释一个来自类文件的JVM指令,并对它调用一个过程。
Find a detail comparison here http://bitshub.blogspot.com/2010/01/Flavors-of-JVM.html
在http://bitshub.blogspot.com/2010/01/flavors of jvm.html找到详细的比较
#7
1
tl;dr
博士tl;
Interpreter: takes only one instruction at a time for execution
一次只执行一条指令
Just-in-time: takes a block of code at once and compile it before execute. so has plenty room for optimization
准时制:一次获取一个代码块,并在执行之前编译它。因此,有足够的空间进行优化。
#8
0
When you compile a Microsoft.NET language, the complier generates code written in the Microsoft Intermediate Language (MSIL). MSIL is a set of instructions that can quickly be translated into native code.
当你编译一个微软。编译器生成用Microsoft中间语言(MSIL)编写的代码。MSIL是一组可以快速转换为本机代码的指令。
A Microsoft.NET application can be run only after the MSIL code is translated into native machine code. In .NET Framework, the intermediate language is complied "just in time" (JIT) into native code when the application or component is run instead of compiling the application at development time.
一个微软。NET应用程序只能在MSIL代码被翻译成本机代码之后才能运行。在。net框架中,当运行应用程序或组件而不是在开发时编译应用程序时,中间语言被“及时”(JIT)编译成本机代码。
更多信息