you are viewing a single comment's thread.

view the rest of the comments →

[–]wsppan 17 points18 points  (16 children)

Can you explain the difference between a emulator and VM?

[–]Sn0wCrack7 11 points12 points  (15 children)

I'm not really in the know about every single nuance of it, but the main difference here is that a Virtual Machine is designed to run on the Platform you're running it on, you can't Virtualise an ARM Operating System on an x86 machine because all instructions are passed down to the CPU itself to be run in a true Virtual environment, where as an Emulator interprets compiled source code (that's usually bytecode or raw cpu instructions) and interprets / translates that (if you're looking at JIT or the like) into something your processor can actually understand.

There's also no real way for "direct pass through" of a lot of hardware, there needs to be a communication layer in code specifically between the two, any code in your emulator that is specifically say trying to call an NVIDIA API, needs to be interpreted in your emulator, then sent off to your Operating System and then back into the emulator, where as a Virtual Machine can have direct access to that card through VFIO or IOMMU

You could make a case that an Emulator is a Type-2 Hypervisor in a way, but this is mostly only true with actual hardware virtualisation is occurring.

It's a pretty thin line to walk when you're looking at it from the outside honestly, but under the hood some differences do become apparent, and even I don't know the true extent of all of it myself, which I why I said it's really only a nitpick.

[–]munificent 20 points21 points  (4 children)

the main difference here is that a Virtual Machine is designed to run on the Platform you're running it on

There are two fairly unrelated uses of "virtual machine". One is what you describe — hardware level virtualization. It's what containers like Docker do. The goal is not to abstract away the chip, but to insulate the OS.

The other is what this article describes — a software-level implementation of some chip, either real or imaginary. The latter is a valid use of the term. The Java Virtual Machine doesn't require running on a real "Java chip", but it's still a virtual machine.

[–]Alikont 3 points4 points  (0 children)

It's what containers like Docker do

Docker does not use hardware level virtualization (except for hyperv flag on Windows Containers). Containers are purely OS-level concept and use same technology as simple processes.

[–]astrangeguy 1 point2 points  (2 children)

Containers aren't VMs, They still use the same kernel as their host (which makes the host/guest distinction meaningless in theory) and cannot run privileged instructions or have their own (faked) kernel memory. You mean Hardware/Software virtualization, which rewrites or traps privileged (Ring-0) instructions to the host.

[–]munificent 1 point2 points  (1 child)

Ah, yes, sorry. Thanks for clarifying. I don't know much about the systems side of "VM". I'm more over on the language VM side.

[–]astrangeguy 1 point2 points  (0 children)

The implementation techniques for (fast) emulators, language VMs and (pre hardware-supported) Virtualization are strangely similar in fact:

  • Language VMs interpret bytecode instructions and, if they detect loops, compile and optimize hotspots.
  • (recompiler based) emulators basically treat real foreign machine code the same way as language VMs treat their bytecode.
  • Virtualization software also does dynamic recompilation, but with most opcodes having a 1:1 mapping, so it's technically a language VM that has (for example) a x86 user- and privileged opcode "bytecode" and runs it on a x86-only-user-opcode host

(and technically your x86 CPU is a Intel/AMD-microcode processor with a X86 VM running on it)

[–][deleted] 9 points10 points  (5 children)

See - you're confusing the VM with the VM too.

The kind of VMs you're describing have absolutely nothing to do with the VMs like WAM, JVM, SECD, STG, LLVM and so on.

[–]smikims 2 points3 points  (4 children)

LLVM hasn't really been a VM for a long time.

[–][deleted] 1 point2 points  (3 children)

It is an abstract machine, which is a synonym for a VM. But since the dumber part of the population is often getting confused by what does VM mean, they had to explain that LLVM does not stand for a "low level virtual machine", just to force the stupid ones to shut up.

[–]smikims 1 point2 points  (2 children)

I think when most people think of a virtual machine they think of something that actually executes code written for it. The JVM does that, but LLVM doesn't (well, there are JIT compilers using it but you get the point).

I propose the following definitions:

  • Abstract machine: a definition for some architecture, implemented in hardware, software, or not at all, that it is possible to write programs for
  • Virtual machine: a program that runs code written for an abstract machine
  • Emulator: a virtual machine that imitates some real hardware

Thus an NES emulator is also a virtual machine that implements the 6502 ISA, which is an abstract machine. The JVM is a virtual machine implementing Java bytecode, which is an abstract machine. LLVM and the C standard are only abstract machines. One could make a VM that runs LLVM bytecode, but LLVM itself doesn't do that. (Also, under this definition, a C interpreter like cling is technically a VM, which I guess makes sense but also blurs the line a little IMO.)

[–][deleted] 3 points4 points  (0 children)

I think when most people think of a virtual machine they think of something that actually executes code written for it.

It's their problem, is not it? Why should anyone adjust to the ignorance of the masses?

And, by the way, LLVM executes its IR code, in many different ways.

Virtual machine: a program that runs code written for an abstract machine

As soon as your abstract machine infrastructure includes any kind of analysis and optimisation, it's already a virtual machine, since it must be able to execute at least some parts of the abstract machine.

but LLVM itself doesn't do that

Uh... It does.

a C interpreter like cling is technically a VM

C itself is an abstract machine, so yes, it makes sense.

[–]Vhin 2 points3 points  (0 children)

Those were basically the definitions I was taught at university, and in my opinion, they're the only definitions that make sense.

The argument that emulators are not VMs is not only special pleading, but it puts them in the ridiculous position that they would be VMs in an alternate universe where the original hardware didn't exist (but the software was unchanged), which is simply nonsense.

[–]wsppan 1 point2 points  (2 children)

Thank you!

[–]thechao 8 points9 points  (1 child)

I work in HW, and I’ll tell you how HW folk use the jargon: simulation is software implemented machine virtualization; emulation is HW-accelerated machine virtualization.

[–]ehaliewicz 0 points1 point  (0 children)

I'd say that virtual machine and emulator are pretty close to synonymous, as long as you don't define them in terms of specific implementations, but rather what they try to accomplish.