说中间代码在虚拟机中运行是否具有误导性
如果我对所读内容的理解正确的话,虚拟机本质上是中间代码的编译器。 但从未说过 Delphi(作为非托管代码的示例)在其编译器中运行。 将虚拟机描述为编译器会不会更容易混淆?
If I am correct in understanding what I've read a virtual machine is essentially a compiler for intermediate code.
But it is never said that Delphi (as an example of unmanaged code) runs in its compiler.
Would it be less confusing to just describe a virtual machine as a compiler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
传统编译器执行从源代码到目标代码的一次性转换。像 JVM 这样的虚拟机使用解释(字节码)和将字节码段编译为本机代码的即时编译器。将虚拟机整体描述为编译器是不准确的。
A traditional compiler does a one-time conversion from source code to object code. A virtual machine like the JVM uses a mixture of interpretation (of bytecode) and a just-in-time compiler that compiles segments of bytecode to native code. It's not accurate to describe a VM overall as a compiler.
有一个编译器将源代码转换为VM代码(字节码),还有一个用于VM代码的JIT编译器->机器代码。 VM是源代码->标准的VM的编译目标,不一定是具体的实现。它可以用真机实现,这样就不需要进行JIT编译。
虚拟机更接近模拟器(或者如果你的 JIT 真的很愚蠢,那就是解释器:))
There's a compiler that translates source code to VM code (bytecode), and a JIT compiler for VM code -> machine code. The VM is the standard that the source code -> VM compiler targets, not necessarily the specific implementation. It could be implemented with a real machine, in which case it wouldn't need to do JIT compilation.
A VM is closer to an emulator (or if your JIT is really stupid, an interpreter :))
我认为人们试图用这个术语来表达的是虚拟机有一个额外的抽象层。因此,相同的代码,但每个平台的虚拟机允许它在该特定平台上运行。
I think what people are trying to capture with the terminology is that there's an extra layer of abstraction with virtual machines. So, same code, but the VM for each platform allows it to run on that specific platform.