I have a very basic question about JVM: is it a compiler or an interpreter?
我有一个关于JVM的非常基本的问题:它是编译器还是解释器?
If it is an interpreter, then what about JIT compiler that exist inside the JVM?
If neither, then what exactly is the JVM? (I dont want the basic definition of jVM of converting byte code to machine specific code etc.)
如果它是一个解释器,那么JVM中存在的JIT编译器呢?如果两者都不是,那么JVM到底是什么?(我不希望jVM的基本定义是将字节码转换为特定于机器的代码等)
7 个解决方案
#1
123
First, let's have a clear idea of the following terms
首先,让我们对下列术语有一个清晰的概念
Javac
is Java Compiler -- Compiles your Java code into Bytecode
Javac是Java编译器——将Java代码编译成字节码
JVM
is Java Virtual Machine -- Runs/ Interprets/ translates Bytecode into Native Machine Code
JVM是Java虚拟机——运行/解释/将字节码转换为本机机器代码
JIT
is Just In Time Compiler -- Compiles the given bytecode instruction sequence to machine code at runtime before executing it natively. It's main purpose is to do heavy optimizations in performance.
JIT只是及时编译器——在运行时将给定的字节码指令序列编译为机器代码,然后再进行本机执行。它的主要目的是在性能上进行大量优化。
So now, Let's find answers to your questions..
现在,让我们来找出你的问题的答案。
1)JVM: is it a compiler or an interpreter?
-- Ans: Interpreter
1)JVM:是编译器还是解释器?——答:翻译
2)what about JIT compiler that exist inside the JVM?
-- Ans: If you read this reply completly, you probably know it now
2)JVM中是否存在JIT编译器?——答:如果你看得很清楚的话,你现在可能已经知道了
3)what exactly is the JVM?
-- Ans:
JVM到底是什么?——答:
- JVM is a virtual platform that resides on your RAM
- JVM是驻留在RAM中的虚拟平台。
- Its component, Class loader loads the
.class
file into the RAM - 它的组件,类加载器将.class文件加载到RAM中
- The Byte code Verifier component in JVM checks if there are any access restriction violations in your code. (This is one of the principle reasons why java is secure)
- JVM中的字节码验证器组件检查代码中是否存在任何访问限制违反。(这是java安全的主要原因之一)
- Next, the Execution Engine component converts the Bytecode into executable machine code
- 接下来,执行引擎组件将字节码转换为可执行的机器代码
Hope this helped you..
希望这有助于你. .
#2
29
It is a little of both, but neither in the traditional sense.
两者都有一点,但在传统意义上都不是。
Modern JVMs take bytecode and compile it into native code when first needed. "JIT" in this context stands for "just in time." It acts as an interpreter from the outside, but really behind the scenes it is compiling into machine code.
现代jvm接受字节码并在需要时将其编译成本机代码。在这个上下文中,“JIT”代表“及时”。它从外部充当解释器,但实际上是在幕后编译成机器码。
The JVM should not be confused with the Java compiler, which compiles source code into bytecode. So it is not useful to consider it "a compiler" but rather to know that in the background it does do some compilation.
JVM不应该与Java编译器混淆,后者将源代码编译成字节码。因此,把它当作“编译器”是没有用的,而是要知道在后台它确实做了一些编译。
#3
4
It is both. It starts by interpreting bytecode and can (should it decide it is worth it) then compile that bytecode to native machine code.
这是两个。它首先解释字节码,然后将字节码编译为本机代码(如果它认为值得的话)。
#4
3
It's both. It can interpret bytecode, and compile it to native code.
这是两个。它可以解释字节码,并将其编译为本机代码。
#5
3
Like @delnan already stated in the comment section, it's neither.
就像@delnan在评论部分已经说过的那样,两者都不是。
JVM is an abstract machine running Java bytecode.
JVM是运行Java字节码的抽象机器。
JVM has several implementations:
JVM有几个实现:
- HotSpot (interpreter + JIT compiler)
- 热点(解释器+ JIT编译器)
- Dalvik (interpreter + JIT compiler)
- Dalvik(解释器+ JIT编译器)
- ART (AOT compiler + JIT compiler)
- 艺术(AOT编译器+ JIT编译器)
- GCJ (AOT compiler)
- GCJ(AOT编译器)
- JamVM (interpreter)
- JamVM(翻译)
...and many others.
…和许多其他人。
Most of the others answers when talking about JVM refer either to HotSpot or some mixture of the above approaches to implementing the JVM.
在讨论JVM时,其他大多数答案要么指向HotSpot,要么是上述实现JVM的方法的混合。
#6
1
As others have said it is both! If you want to refer it in good detail than you can see:This IBM Description
就像其他人说的那样,两者都是!如果您想详细地引用它,您可以看到:这个IBM描述
#7
-3
JVM have both compiler and interpreter. Because the compiler compiles the code and generates bytecode. After that the interpreter converts bytecode to machine understandable code.
JVM有编译器和解释器。因为编译器编译代码并生成字节码。然后解释器将字节码转换为机器可理解的代码。
Example: Write and compile a program and it runs on Windows. Take the .class file to another OS (Unix) and it will run because of interpreter that converts the bytecode to machine understandable code.
示例:编写和编译一个程序,并在Windows上运行。将.class文件转换为另一个OS (Unix),它将运行,因为解释器将字节码转换为机器可理解的代码。
#1
123
First, let's have a clear idea of the following terms
首先,让我们对下列术语有一个清晰的概念
Javac
is Java Compiler -- Compiles your Java code into Bytecode
Javac是Java编译器——将Java代码编译成字节码
JVM
is Java Virtual Machine -- Runs/ Interprets/ translates Bytecode into Native Machine Code
JVM是Java虚拟机——运行/解释/将字节码转换为本机机器代码
JIT
is Just In Time Compiler -- Compiles the given bytecode instruction sequence to machine code at runtime before executing it natively. It's main purpose is to do heavy optimizations in performance.
JIT只是及时编译器——在运行时将给定的字节码指令序列编译为机器代码,然后再进行本机执行。它的主要目的是在性能上进行大量优化。
So now, Let's find answers to your questions..
现在,让我们来找出你的问题的答案。
1)JVM: is it a compiler or an interpreter?
-- Ans: Interpreter
1)JVM:是编译器还是解释器?——答:翻译
2)what about JIT compiler that exist inside the JVM?
-- Ans: If you read this reply completly, you probably know it now
2)JVM中是否存在JIT编译器?——答:如果你看得很清楚的话,你现在可能已经知道了
3)what exactly is the JVM?
-- Ans:
JVM到底是什么?——答:
- JVM is a virtual platform that resides on your RAM
- JVM是驻留在RAM中的虚拟平台。
- Its component, Class loader loads the
.class
file into the RAM - 它的组件,类加载器将.class文件加载到RAM中
- The Byte code Verifier component in JVM checks if there are any access restriction violations in your code. (This is one of the principle reasons why java is secure)
- JVM中的字节码验证器组件检查代码中是否存在任何访问限制违反。(这是java安全的主要原因之一)
- Next, the Execution Engine component converts the Bytecode into executable machine code
- 接下来,执行引擎组件将字节码转换为可执行的机器代码
Hope this helped you..
希望这有助于你. .
#2
29
It is a little of both, but neither in the traditional sense.
两者都有一点,但在传统意义上都不是。
Modern JVMs take bytecode and compile it into native code when first needed. "JIT" in this context stands for "just in time." It acts as an interpreter from the outside, but really behind the scenes it is compiling into machine code.
现代jvm接受字节码并在需要时将其编译成本机代码。在这个上下文中,“JIT”代表“及时”。它从外部充当解释器,但实际上是在幕后编译成机器码。
The JVM should not be confused with the Java compiler, which compiles source code into bytecode. So it is not useful to consider it "a compiler" but rather to know that in the background it does do some compilation.
JVM不应该与Java编译器混淆,后者将源代码编译成字节码。因此,把它当作“编译器”是没有用的,而是要知道在后台它确实做了一些编译。
#3
4
It is both. It starts by interpreting bytecode and can (should it decide it is worth it) then compile that bytecode to native machine code.
这是两个。它首先解释字节码,然后将字节码编译为本机代码(如果它认为值得的话)。
#4
3
It's both. It can interpret bytecode, and compile it to native code.
这是两个。它可以解释字节码,并将其编译为本机代码。
#5
3
Like @delnan already stated in the comment section, it's neither.
就像@delnan在评论部分已经说过的那样,两者都不是。
JVM is an abstract machine running Java bytecode.
JVM是运行Java字节码的抽象机器。
JVM has several implementations:
JVM有几个实现:
- HotSpot (interpreter + JIT compiler)
- 热点(解释器+ JIT编译器)
- Dalvik (interpreter + JIT compiler)
- Dalvik(解释器+ JIT编译器)
- ART (AOT compiler + JIT compiler)
- 艺术(AOT编译器+ JIT编译器)
- GCJ (AOT compiler)
- GCJ(AOT编译器)
- JamVM (interpreter)
- JamVM(翻译)
...and many others.
…和许多其他人。
Most of the others answers when talking about JVM refer either to HotSpot or some mixture of the above approaches to implementing the JVM.
在讨论JVM时,其他大多数答案要么指向HotSpot,要么是上述实现JVM的方法的混合。
#6
1
As others have said it is both! If you want to refer it in good detail than you can see:This IBM Description
就像其他人说的那样,两者都是!如果您想详细地引用它,您可以看到:这个IBM描述
#7
-3
JVM have both compiler and interpreter. Because the compiler compiles the code and generates bytecode. After that the interpreter converts bytecode to machine understandable code.
JVM有编译器和解释器。因为编译器编译代码并生成字节码。然后解释器将字节码转换为机器可理解的代码。
Example: Write and compile a program and it runs on Windows. Take the .class file to another OS (Unix) and it will run because of interpreter that converts the bytecode to machine understandable code.
示例:编写和编译一个程序,并在Windows上运行。将.class文件转换为另一个OS (Unix),它将运行,因为解释器将字节码转换为机器可理解的代码。