JVM

= Java Virtual Machine =

There are a lot implementations of the Java Virtual Machine although the original one is the Oracle Java Virtual Machine (former Sun Microsystems). We can find some vendors who developed their own stack machine JVM like Oracle HotSpot, IBM, SAP, etc.

It's the responsible of reading the Java Bytecode using the ClassLoader and executing it by using the Java API. Its main features are:


 * Stack-based virtual machine: Instead of using the register-based like Intel x86 Architecture or ARM Architecture, JVM is a stack-based machine where each thread has a JVM stack which stores frames and a frame is created everytime a method is invoked, consisting of an operand stack, a reference to the runtime constant pool of the current class method and an array of local variables containing the parameters of the method and the values of the local variables in this order. We can find different cases:
 * a constructor or an instance method: the reference is stored at 0 index and every parameter is stored from index 1.
 * static method: from 0 index evey parameter is stored.


 * Symbolic reference: All types (class and interface) except for primitive data types are referred to through symbolic reference, instead of through explicit memory address-based reference.


 * Automated exception handling: provides a root-cause debugging information for any exception occurred at runtime.


 * Garbage collector: It's the responsible of managing which instances must stay alive or must be destroyed. This way a programmer delegates this task to the Virtual Machine which is periodically destroying objects based on their age and their usage.


 * Guarantees platform independence: accomplished by defining:
 * The primitive data type: The JVM clearly defines the primitive data type to maintain its compatibility between versions and to guarantee platform independence.
 * The network byte order: It uses Big Endian with a fixed byte order to mantain network transfer compatibility between Intel x86 Architecture, which uses the Little Endian, and the Big Endian used by the RISC Series Architecture.

Divides the memory into 4 sections:


 * Heap: objects.
 * Stack: methods, local variables and reference variables.
 * Code: contains bytecode.
 * Static: static methods and data.

To sum up, from a Java source file (.java file) we generate a Java Bytecode file (.class file) using the Java Compiler. This class file will be loaded by the Class loader which will work with the Execution Engine and the Runtime Data Areas.

You can take a look at the [Oracle Java Virtual Machine specification]