Virtual Machines

07 Jun 2019

What is a Virtual Machine?

A virtual machine is a simulated computer running within a real computer. The virtual computer runs an operating system that can be different than the host OS and all the requests to access real hardware are routed to the appropriate host hardware, so the virtual operating system and applications don’t know they are virtual.

Virtual X Concept

A process is already given the illusion that it has its own memory (via virtual memory) and own CPU (via time slicing). The virtual machine extends this idea to give a process the illusion that it also has its own hardware. Moreover, exted the concept from a process to an entire OS being given the illusion that it has its own memory, CPU, and I/O devices.

Benefits of Virtual Machines

  • VMs can run multipls OS simultaneously on the same host.
  • Fault isolation: if an OS fails, it doesn’t crash another VM or the host system. This is also useful for debugging a new OS.
  • It’s easier to deploy applications using VMs. An app can be deployed within a VM instance that is customized for the app, rather than being directly deployed and causing concern about compatibility with the target OS.
    • Useful for cloud server deployments.

How do VMs work?

Goal: We want to create a virtual machine that executes at close to native speeds on a CPU, so emulation and interpreting insturction by instruction are not good options - too much software overhead.

Solution: Have the guest OS execute normally, directly on the CPU, except not in kernel mode. Therfore, ay special privileged instructions invoked by the guest OS will be trapped to the hypervisor, which is in kernel mode. The hypervisor then emulates only these privileged instructions and when done, passes control back to the guest OS (this is alos known as a “VM entry”). This way, most ordinary (non-privileged) instructions operate at full speed, and only privileged instructions incur the overhead of a trap (also known as a “VM exit) to the hypervisor/VMM. This approach to VMs is called trap-and-emulate.

Cloud Computing

It is very easy to provision and deploy VM instances on the cloud.

  • e.g. Amazon’s Elastic Compute Cloud (EC2) uses Xen virtualization.

There are different types of VMs or instances that can be deployed.

  • Standard, High-Memory, High-CPU

Users cancreate and reboot their own VMs.

Java Virtual Machines

Process VMs, e.g. Java VMs differe from System VMs in that the goal is NOT to try to run multiple OS on the same host, but to provide porable code execution of a single application across different hosts.

Java applications are compiled into Java byte code that can be run on any Java VM.

  • Java VM acts as an interpreter of byte code, translating each byte code instruction into a local action the the host OS.

Just in time compilation can be used to speed up the execution of Java code.

  • Java byte code is compiled at run time into native machine code that is executed directly on the hardware, rather than being interpreted instruction by instruction.

Note: Java VMs virtualize an abstract machine, not actual hardware, unlike system VMs. i.e. the target machine that Java byte code is being compiled for is a software specification.

Top