Computer Science (9618)
Topic 12 of 17Cambridge A Levels

Virtual Machines

A software-based emulation of a computer system that runs programs like a physical machine.

A Virtual Machine (VM) is an abstract concept in computer science, representing a software-based emulation of a physical computer. It functions as a self-contained computing environment, allowing users to run an entire operating system or a specific application on top of their existing hardware and operating system. The physical machine on which the VM runs is called the host, while the VM itself is referred to as the guest.


### The Hypervisor: The Engine of Virtualization


The core technology that enables virtualization is the hypervisor, also known as a Virtual Machine Monitor (VMM). The hypervisor is a layer of software that sits between the physical hardware and the virtual machines. Its primary role is to create, manage, and run VMs by abstracting the host machine's resources—such as CPU, memory, and storage—and allocating them to each guest machine. This ensures that multiple VMs can run on a single host in complete isolation, unaware of each other's existence.


There are two main types of hypervisors:

  • Type 1 (Bare-Metal): This hypervisor runs directly on the host's hardware, acting as a lightweight operating system itself. It is highly efficient and is the standard for enterprise-level data centres and cloud computing (e.g., VMware vSphere, Microsoft Hyper-V).
  • Type 2 (Hosted): This hypervisor runs as an application on top of a conventional host operating system (like Windows or macOS). It is easier to set up and is ideal for desktop use and software development (e.g., Oracle VirtualBox, VMware Workstation).

  • ### The Role and Types of Virtual Machines


    Virtual machines serve several critical roles in modern computing:


    * Server Consolidation: Running multiple server applications on a single physical machine to maximise hardware utilisation and reduce energy costs.

    * Isolation and Security: VMs provide a sandboxed environment. If a guest OS is compromised by malware or crashes, it does not affect the host or any other guest VMs. This is invaluable for testing untrusted software.

    * Platform for Software: VMs provide a consistent and predictable environment for developing, testing, and deploying applications, eliminating the "it works on my machine" problem.

    * Legacy Support: Running outdated applications on older operating systems that are incompatible with modern hardware.


    There are two fundamental categories of virtual machines:


  • System Virtual Machines: These provide a complete emulation of a physical machine, including a full set of virtualised hardware. They are capable of running a complete, unmodified guest operating system (e.g., running a Linux distribution inside a VM on a Windows host).

  • Process Virtual Machines: These are designed not to emulate an entire operating system, but to provide a platform-independent programming environment to execute a single process. They abstract away the details of the underlying hardware and operating system. The most prominent example is the Java Virtual Machine (JVM).

  • ### The Process of Interpretation in a Virtual Machine


    The concept of a process VM is central to understanding how languages like Java achieve their "write once, run anywhere" capability. This is accomplished through a process involving compilation and interpretation.


  • Compilation to Intermediate Code: When a developer writes source code in a high-level language like Java, it is not compiled directly into the native machine code of a specific processor (e.g., x86 or ARM). Instead, it is compiled into a high-level, platform-independent intermediate code called bytecode.

  • Execution by the VM Interpreter: This bytecode is then executed by the process VM (e.g., the JVM). The VM acts as an interpreter. It reads the bytecode one instruction at a time, translates it into the corresponding native machine code for the host machine's CPU, and then executes it. This translation happens at runtime. Because there is a specific VM implementation for each platform (Windows, macOS, Linux), the same bytecode file can be run on any of them without modification.

  • Just-In-Time (JIT) Compilation: Pure interpretation can be slow because each instruction must be translated every time it is executed. To overcome this, modern VMs use a technique called Just-In-Time (JIT) compilation. The JIT compiler is part of the VM and monitors the running code. It identifies sections of bytecode that are executed frequently (known as "hotspots") and compiles them into native machine code on the fly. This native code is then cached and used for subsequent calls, significantly boosting performance to near-native speeds.
  • Key Points to Remember

    • 1A Virtual Machine (VM) is a software emulation of a computer system, with the physical machine being the 'host' and the VM the 'guest'.
    • 2A 'hypervisor' or VMM is the software that creates and manages VMs by allocating host resources.
    • 3System VMs emulate a full hardware set, allowing entire guest operating systems to run in isolation.
    • 4Process VMs (e.g., Java Virtual Machine) provide a platform-independent environment to execute a single program.
    • 5Source code is compiled into an intermediate 'bytecode', not native machine code.
    • 6The VM acts as an 'interpreter', translating bytecode into the host's native machine code at runtime.
    • 7This interpretation process allows the same bytecode to run on any machine with the appropriate VM installed.
    • 8'Just-In-Time' (JIT) compilation is a performance optimisation technique that compiles frequently used bytecode to native code.

    Pakistan Example

    Software Development and NADRA's IT Infrastructure

    In Pakistan, the vibrant software industry heavily relies on virtual machines. Software houses in cities like Lahore, Karachi, and Islamabad use VMs (like VirtualBox or VMware) to create isolated environments for testing applications across different operating systems (Windows, Linux, macOS) on a single developer machine. This is crucial for building robust software for international clients. Furthermore, large-scale government entities like NADRA (National Database and Registration Authority) utilise enterprise-grade virtualization to consolidate their servers. By running multiple virtual servers on a smaller number of powerful physical machines, they enhance security, improve resource management, and ensure high availability for critical national identity services.

    Quick Revision Infographic

    Computer Science — Quick Revision

    Virtual Machines

    Key Concepts

    1A Virtual Machine (VM) is a software emulation of a computer system, with the physical machine being the 'host' and the VM the 'guest'.
    2A 'hypervisor' or VMM is the software that creates and manages VMs by allocating host resources.
    3System VMs emulate a full hardware set, allowing entire guest operating systems to run in isolation.
    4Process VMs (e.g., Java Virtual Machine) provide a platform-independent environment to execute a single program.
    5Source code is compiled into an intermediate 'bytecode', not native machine code.
    6The VM acts as an 'interpreter', translating bytecode into the host's native machine code at runtime.
    Pakistan Example

    Software Development and NADRA's IT Infrastructure

    In Pakistan, the vibrant software industry heavily relies on virtual machines. Software houses in cities like Lahore, Karachi, and Islamabad use VMs (like VirtualBox or VMware) to create isolated environments for testing applications across different operating systems (Windows, Linux, macOS) on a single developer machine. This is crucial for building robust software for international clients. Furthermore, large-scale government entities like NADRA (National Database and Registration Authority) utilise enterprise-grade virtualization to consolidate their servers. By running multiple virtual servers on a smaller number of powerful physical machines, they enhance security, improve resource management, and ensure high availability for critical national identity services.

    SeekhoAsaan.com — Free RevisionVirtual Machines Infographic

    Test Your Knowledge!

    5 questions to test your understanding.

    Start Quiz