java virtual machine is an abstract computing machine that serves as runtime environment for executing java bytecode
- translates java bytecode into machine code for execution
- manages memory, security and execution of java application
- provides a consistent environment across different hardware and operating systems.
Architecture
- Class Loader Subsystem -
- Loading - loads, links and initializes
.classfiles into memory. - Linking- ensure bytecode is safe for execution -> allocate memory for static variables and assign default values -> resolve symbolic links to direct references.
- Initialization - executes static initializers and assigns values to static fields.
- Loading - loads, links and initializes
- Runtime Data Areas -
- Method area - stores class level data, class structures, method bytecode, constant pool, static vars. shared accross all threads.
- Heap - stores all objects and their instance vars.
- Stack - per-threaded memory for method calls, storing stack frames.
- PC (program counter) - per-threaded register that stores the address of the current instruction being executed.
- Native method stack - per-thread memory for native methods.
- Execution Engine -
- executes bytecode by translating it into machine code.
- components -
- interpreter - executes bytecode line by line
- just in time compiler (JIT) - compiles frequently executed code for faster execution.
- garbage collector - automatically reclaim memory from unused object in the heap.
- Native method interface - enables java code to interact with native application in c or c++
- Security Manager - enforces security policies, restricted untrusted code from accessing sensitive resources.