Saturday, November 24, 2012

JVM Tuning - Heap Structure

Now for an overview of the structure of the JVM heap.

The heap is organized into three areas - the young generation, the old  (or tenured) generation, and the permanent generation. "Permanent generation" is a bit of a misnomer. It holds metadata such as class definitions. Newly created objects go into the Eden space in the young generation. The young generation also has the survivor spaces, "from" and "to", which we will explain in a moment. When the young generation is too full to accommodate new objects, a minor or partial collection occurs.


The left side of the diagram shows what happens in a healthy partial GC:

  1. Dead objects are marked. (shaded black in diagram)
  2. Live Eden objects move to the To space.
  3. Young enough objects in the From space move to the To space.
  4. Old enough objects in the From space move to the old generation.
The right side shows the heap after the partial GC is complete. Now Eden is empty, and the From and To spaces have traded roles.

Later, we will discuss what happens if there isn't enough room in the To space or in the old generation to accommodate the live objects that belong to them.

No comments:

Post a Comment