在 Java 中一直使用虚拟机"时,似乎很少阅读 Python虚拟机".
It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
两者都解释字节码;为什么叫一个虚拟机,另一个叫解释器?
Both interpret byte codes; why call one a virtual machine and the other an interpreter?
虚拟机是一种虚拟计算环境,具有一组特定的原子定义明确的指令,这些指令不受任何特定语言的支持,通常被认为是沙箱本身.VM 类似于特定 CPU 的指令集,并且倾向于在更基本的级别上工作,这些指令(或字节码)的非常基本的构建块独立于下一个.一条指令仅根据虚拟机的当前状态确定性地执行,而不依赖于该时间点指令流中其他地方的信息.
A virtual machine is a virtual computing environment with a specific set of atomic well defined instructions that are supported independent of any specific language and it is generally thought of as a sandbox unto itself. The VM is analogous to an instruction set of a specific CPU and tends to work at a more fundamental level with very basic building blocks of such instructions (or byte codes) that are independent of the next. An instruction executes deterministically based only on the current state of the virtual machine and does not depend on information elsewhere in the instruction stream at that point in time.
另一方面,解释器更复杂,因为它专门用于解析某些语法流,这些语法属于特定语言和特定语法,必须在周围标记的上下文中解码.您不能孤立地查看每个字节甚至每一行,并确切地知道下一步该做什么.不能像相对于 VM 的指令(字节码)那样孤立地使用语言中的标记.
An interpreter on the other hand is more sophisticated in that it is tailored to parse a stream of some syntax that is of a specific language and of a specific grammer that must be decoded in the context of the surrounding tokens. You can't look at each byte or even each line in isolation and know exactly what to do next. The tokens in the language can't be taken in isolation like they can relative to the instructions (byte codes) of a VM.
Java 编译器将 Java 语言转换为字节码流,这与 C 编译器将 C 语言程序转换为汇编代码没有什么不同.另一方面,解释器并不真正将程序转换为任何定义明确的中间形式,它只是将程序动作作为解释源代码的过程.
A Java compiler converts Java language into a byte-code stream no different than a C compiler converts C Language programs into assembly code. An interpreter on the other hand doesn't really convert the program into any well defined intermediate form, it just takes the program actions as a matter of the process of interpreting the source.
VM 和解释器之间区别的另一个测试是您是否认为它是独立于语言的.我们所知道的 Java VM 并不是真正的 Java 特定的.您可以使用其他语言制作编译器,生成可以在 JVM 上运行的字节码.另一方面,我认为我们不会真正考虑将 Python 以外的其他语言编译"成 Python 以供 Python 解释器进行解释.
Another test of the difference between a VM and an interpreter is whether you think of it as being language independent. What we know as the Java VM is not really Java specific. You could make a compiler from other languages that result in byte codes that can be run on the JVM. On the other hand, I don't think we would really think of "compiling" some other language other than Python into Python for interpretation by the Python interpreter.
由于解释过程的复杂性,这可能是一个相对缓慢的过程......特别是解析和识别语言标记等,并了解源的上下文以便能够在口译员.为了帮助加速此类解释语言,我们可以在这里定义更容易直接解释的预解析、预标记源代码的中间形式.这种二进制形式仍然在执行时被解释,它只是从一种人类可读性差得多的形式开始以提高性能.但是,执行该表单的逻辑不是虚拟机,因为这些代码仍然不能孤立地看待 - 周围令牌的上下文仍然很重要,它们只是现在处于一种不同的计算机效率更高的形式.
Because of the sophistication of the interpretation process, this can be a relatively slow process....specifically parsing and identifying the language tokens, etc. and understanding the context of the source to be able to undertake the execution process within the interpreter. To help accelerate such interpreted languages, this is where we can define intermediate forms of pre-parsed, pre-tokenized source code that is more readily directly interpreted. This sort of binary form is still interpreted at execution time, it is just starting from a much less human readable form to improve performance. However, the logic executing that form is not a virtual machine, because those codes still can't be taken in isolation - the context of the surrounding tokens still matter, they are just now in a different more computer efficient form.
这篇关于Java“虚拟机"vs. Python“解释器"用语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!