解释器vs编译器vs虚拟机 [英] Interpreters vs Compilers vs Virtual Machines

查看:237
本文介绍了解释器vs编译器vs虚拟机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于解释器,编译器和VM的问题

I have a question about Interpreters,Compilers and VM

现在我知道解释器和编译器之间的区别,但是 VIRTUAL MACHINES <强>从前2?

Now I know the Differences between Interpreters and Compilers but what is different about the VIRTUAL MACHINES from the previous 2? What are the Pros and Cons of a VM over Interpreters and Compilers?

非常感谢

推荐答案

虚拟机不完全替代编译器或解释器。我想你在想一个JIT编译器,这是实现了多少虚拟机。

A virtual machine isn't exactly an alternative to compilers or interpreters. I think you are thinking of a JIT compiler, which is how many VMs are implemented.

虚拟机本身就是这个名字说的 - 它是一个机器(处理器)实际上并不存在。例如,大多数处理器不具有处理存储器分配或类型的任何知识的任何内在方式。 Java VM虽然有一个 new 指令,分配一个类的实例。 VM的设计者决定这是一个足够重要的概念,在语言中应该有自己的操作码,这是VM中的基本操作单元。

A virtual machine itself is exactly what the name says - it's a machine (processor) that doesn't actually exist. For example, most processors don't have any intrinsic way of dealing with memory allocation, or any knowledge of types. The Java VM though, has a new instruction that allocates an instance of a certain class. The designers of the VM decided that this was an important enough concept in the language to deserve its own opcode, which is the fundamental unit of operation in the VM.

创建自己的指令集通常是为了弥合长编译/优化时间和慢解释器之间的差距。当你编译一个Java类时,例如,你不必做任何寄存器分配或内联或任何传统的编译器东西。 JIT将在以后做,但只适用于您运行足够次数的代码部分,并且分布在程序运行。 JVM的指令集足够接近Java,初始编译是快速的,并且与Java源代码不同,VM的读取简单快速。

The advantages of creating your own instruction set are generally to bridge the gap between long compile/optimization times and slow interpreters. When you compile a Java class, for example, you don't have to do any register allocation or inlining or any of that traditional compiler stuff. The JIT will do that later, but only for the parts of code that you run enough times, and spread out over the run of the program. The JVM's instruction set is close enough to Java that the initial compile is quick, and it is simple and quick to read for the VM, unlike Java source code.

至于解释器和JIT编译器,这些权衡通常是关于运行时性能和开发时间。 JIT需要很长时间才能开发,但是解释器在运行时会慢很多。在很多情况下,像脚本和中小型网站,程序运行时间不够,你真的看不到使用JIT的任何好处。

As for interpreters vs JIT compilers, the tradeoffs are generally around runtime performance vs development time. A JIT takes a lot longer to develop, but an interpreter is a lot slower while running. In a lot of cases though, like scripting and small to medium sized websites, the program doesn't run long enough for you to really see any benefits of using a JIT.

我还应该提到像VMware这样的软件。这也是一个虚拟机,但它使用的指令集也恰好在真实硬件上使用。它和语言虚拟机是相同的基本概念,它假装是一个没有物理存在的机器,但实际上它是不同的,非常复杂。

I should also mention software like VMware. This is also a virtual machine, but it uses an instruction set that also happens to be used on real hardware. It's the same basic concept as a language VM, in that it pretends to be a machine that isn't physically present, but in practice it's different and very complicated.

这篇关于解释器vs编译器vs虚拟机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆