SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
CAIE 9618 · Paper 3 · Topic 3.4.2

VM for
Intermediary Code

Bytecode · JIT Compilation · Platform Independence · .NET CLR

CSZone Cambridge International AS & A Level Computer Science 9618
Intermediary Code

Between Source Code and Machine Code

Intermediary code (also called intermediate code or bytecode) sits between the high-level source language and platform-specific machine code. It is portable — not tied to any specific CPU architecture.
Source code
(.java / .py / .cs)
Compiler
(front-end)
Bytecode
(.class / .pyc / MSIL)
VM / Runtime
(JVM / CLR)
Machine Code
(CPU-specific)
WHY BYTECODE?
Platform independent — run on any machine that has the VM
"Write once, run anywhere" — one compiled bytecode for all platforms
TRADE-OFF
Slower than native compiled code — extra interpretation step
VM must be installed on target machine
JIT Compilation

Just-In-Time: Best of Both Worlds

JIT (Just-In-Time) compilation is a technique used by VMs to improve performance. Instead of purely interpreting bytecode line by line, the JIT compiler identifies frequently executed code and compiles it to native machine code at runtime.
HOW JIT WORKS
VM starts interpreting bytecode (slow initially)
JIT profiler identifies "hot spots" — frequently executed loops or functions
Hot spots compiled to native machine code and cached
On next execution of that code, native version runs directly
Result: near-native performance for hot code paths
JIT vs AOT vs INTERPRETER
Interpreter: translate+execute each line at runtime. Slow.
AOT (Ahead of Time): fully compiled before run. Fast but platform-specific.
JIT: interpret first, compile hot paths at runtime. Portable + fast.
REAL-WORLD EXAMPLES
JVM (Java): JIT compiles hot bytecode to x86/ARM.
.NET CLR (C#): MSIL bytecode JIT-compiled.
V8 (JavaScript): JIT for browser performance.
PyPy (Python): JIT for CPython bytecode.
Exam Practice

Cambridge-style questions

Question 1
Java source code is compiled to bytecode, which is then run by the Java Virtual Machine (JVM). Explain two benefits of this approach compared to compiling directly to machine code. [4]
1+1
Bytecode is platform-independent — the same compiled bytecode can run on any machine that has a JVM installed, regardless of its processor architecture (x86, ARM, etc.). This eliminates the need to recompile for each target platform.
1+1
JIT compilation within the JVM can achieve near-native performance: the JVM identifies frequently executed code paths ("hot spots") and compiles them to native machine code at runtime, while still maintaining platform portability for infrequently-run code.
Common Mistakes

Don't lose easy marks

1
Saying "bytecode IS machine code" — bytecode is NOT machine code for any real CPU. It's an intermediate virtual instruction set understood by the VM. Real machine code is specific to a CPU architecture (x86 binary, ARM binary).
2
Saying "JIT compiles all code" — JIT only compiles frequently-used ("hot") code paths. Rarely-executed code may remain interpreted. JIT compilation itself has an overhead — it would be wasteful to compile code that runs only once.
3
Writing "Write once, run anywhere means it runs on any device automatically" — the target device still needs the appropriate JVM installed. "Write once, run anywhere" means one bytecode file, but each platform needs its own JVM implementation.
Topic Summary — 3.4.2

What You Need to Know

INTERMEDIARY CODE (BYTECODE)
Source → Compiler → Bytecode → VM → Machine Code. Platform-independent — runs wherever VM is installed. Examples: Java .class files, C# MSIL.
JIT COMPILATION
VM starts interpreting. Profiler finds hot spots. JIT compiles hot spots to native machine code. Cached for future executions. Near-native performance + portability. Used by JVM, .NET CLR, V8, PyPy.
CSZone

Next Video

3.5.1
Security Threats
Malware · Social Engineering · SQL Injection · Firewalls
Head to CSZone.co.uk for the complete worksheet, quiz, and interactive tools