≡ Menu

Troubleshooting GC: What is GC and how it works – Part 2


Generational heap:

The heap space is primarily divided into two segments as follows:

1. Nursery or Young generation (or Eden)

2. Old or Tenured generation

(There are other segments, and they vary by the JVM vendor. But for the most part understanding the above two segments is enough to troubleshoot GC issues)

As your application runs, the new objects are created in young generation. When the young generation is about to fill up, GC runs what is known as a ‘minor‘ collection and reclaims memory from unused objects in young generation. While at it, the minor collection also moves ‘long lived’ objects to ‘old’ generation. A ‘major‘ collection (a.k.a Full GC), which is invoked when there is serious unmet demand for memory, sweeps through the entire heap to reclaim memory.

Generally speaking, larger nursery may provide a bigger throughput as studies show that most of the Java objects are short lived. So, these objects are created and cleared up right in nursery, avoiding the overhead of moving the objects to old generation and keeping them there.

Verbose GC logs clearly show the performance of minor and major collections.

Permgen space:

JVM uses permgen space (permanent generation) to store class objects. If you load numerous large third party library, for example, you will need a larger permgen space. Permgen space is part of Heap. However, this has changed since Java 8 where PermGen is actually part of native memory and NOT part of heap. Also note that permgen space implementation is specific to JVM vendor.

Native Memory:

While Heap is the space in which your application objects are created, note that JVM itself is a process that is run by the host operating system. So, the JVM process is subject to the OS and hardware constraints just like any other process running in the host OS. The memory used to run the JVM process itself is the native memory and this limited only by the host operating system. For example, when your application deals with i/o, memory used by the i/o handles are allocated using native memory.

Generational heap

Note: There are also two survivor regions that act as an intermediate between Young and Old generations. You rarely have to tune this so I have omitted them in the diagram above.

Coming up: Troubleshooting GC: Various GC algorithms

Previous: Troubleshooting GC:What is GC and how it works – Part 1


{ 0 comments… add one }

Leave a Comment