1.

Java Memory Model

Answer»

The Java Memory Model helps to understand the way the Java Virtual Machine works with the computer memory. The internal Java memory model divides the memory into thread stacks that are used by individual threads and the heap that is used by the entire APPLICATION.

A diagram that demonstrates the internal Java memory model is given as follows:

Details about the thread stack and Heap in the internal Java memory model are given as follows:

Thread Stack

The Thread Stack memory in Java is used for thread execution. Specific values are stored in the thread stack that are available for a short time. Also, stack memory may contain data references to objects getting referred from the method that are in the heap memory.

The order in Thread Stack memory is Last In First Out (LIFO). A block is created in the stack memory for all the primitive values and references to other objects in a method when that method is invoked. After the end of the method, the memory block in the stack memory is free and can be used by another method.

Heap

The heap space in Java is used to allocate memory to the Objects and the JRE CLASSES by the Java runtime. All the objects in the application are created in the heap space. The objects in the heap space are globally accessible from any place in the application and so they have a lifetime for the whole application execution.

The memory model of the heap space is divided into parts KNOWN as generations. Details about these are given as follows:

  • Young Generation

All the new objects are allocated in the young generation and they age here. When this place fills up, then minor garbage collection occurs.

  • Old Generation

All the longer existing objects are stored in the old generation. When objects in the young generation reach a certain age THRESHOLD, they are moved to the old generation.

  • Permanent Generation

The Java metadata for runtime classes is stored in the permanent generation.



Discussion

No Comment Found