JVM Architecture

JVM Architecture


Whenever a java application runs, a runtime instance is born. Thus the numbers of runtime instances on a machine are equal to the number of applications which are running. The JVM starts with the invocation of a main() method which needs to be public, static void and takes a String array as argument. Each instance of a JVM has one method area and a heap. These areas are shared by all threads running within the instance. The information regarding the type is loaded from the class files when the JVM loads a class file. This information is stored in the method area. All the objects which are instantiated placed on the heap. The information regarding the type is loaded from the class files when the JVM loads a class file. This information is stored in the method area. All the objects which are instantiated placed on the heap.

Figure: Method Area & Heap

inside jvm method area and heap


As each new thread is created, it is assigned its own pc register (program counter) and java stack. If the thread is executing a java method (not a native method), the counter in the pc register points to the next instruction to execute.

JVM Architecture

As we know objects are created inside heap memory and Garbage collection is a process which removes dead objects from Java Heap space and returns memory back to Heap in Java. For the sake of Garbage collection Heap is divided into three main regions named as New Generation, Old or Tenured Generation and Perm space. New Generation of Java Heap is part of Java Heap memory where newly created object are stored, During the course of application many objects created and died but those remain live they got moved to Old or Tenured Generation by Java Garbage collector thread. Perm space of Java Heap is where JVM stores Meta data about classes and methods, String pool and Class level details.
Benefits of the Java Heap:
Pre-allocate large blocks of memory.
Allocation of small amounts of memory is very fast.
No need to fish for a free memory segment in RAM.
No fragmentation.
Continuous memory blocks can make a big difference.