Java Virtual Machine
Architecture
Understanding the engine that powers Java applications
What is the JVM?
The Runtime Engine
The JVM is an abstract computing machine that enables
computers to run Java programs and applications written in
other languages compiled to Java bytecode.
Key characteristic: Platform independence through the
"write once, run anywhere" philosophy
JVM Architecture Overview
Class Loader Memory Areas
Loads .class files into Runtime data storage regions
memory
Execution Engine
Executes bytecode instructions
Class Loader Subsystem
Loading
Reads .class files and generates binary data in Method Area
Linking
Verification, preparation, and resolution of symbolic references
Initialization
Executes static initializers and static blocks
JVM Memory Architecture
Method Area
1
Stores class structure, runtime constant pool, field and method data
Heap
2
Runtime data area where objects are allocated
Stack
3
Stores frames containing local variables and partial results
PC Register
4
Contains address of current executing instruction
Native Method Stack
5
Contains native method information
Heap vs Stack Memory
Heap Memory Stack Memory
• Stores objects and instance • Stores method calls and
variables local variables
• Shared among all threads • Thread-specific, not shared
• Garbage collected • Auto-deallocated when
automatically method ends
• Slower access speed • Faster access speed
• Larger memory space • Limited size per thread
Execution Engine Components
Interpreter JIT Compiler Garbage Collector
Reads and executes bytecode Compiles frequently executed Automatically reclaims memory
instructions one by one bytecode to native machine code from unused objects
Trade-off: Easy to implement Benefit: Significantly improves Result: Prevents memory leaks
but slower execution performance
Garbage Collection Process
Sweep
Removes unreferenced objects
from heap
Mark
Identifies which objects are still in
use
Compact
Reorganizes memory to reduce
fragmentation
JVM Performance Metrics
3x 70% 200+
Speed Increase Memory Savings Bytecode
Instructions
JIT compilation vs Through efficient
pure interpretation garbage collection Available in JVM
instruction set
Key Takeaways
1 Platform Independence 2 Automatic Memory Management
JVM provides abstraction layer enabling "write Garbage collection handles object lifecycle
once, run anywhere" without manual intervention
3 Performance Optimization 4 Robust Architecture
JIT compiler balances interpretation speed with Class loaders, memory areas, and execution
execution efficiency engine work together seamlessly