Just a few facts and terms (which I tend to forget or mix up):


  • The Sun-JVM process memory consists of the “Permanent Space” and the “Heap".

  • The Permanent Space (aka Permanent Generation) holds the bytecode of all loaded classes.
    MBean (Client-VM): java.lang:type=MemoryPool,name=Perm Gen
    MBean (Server-VM): java.lang:type=MemoryPool,name=PS Perm Gen

  • The “generational” Heap is divided into “Old Generation” and “Young Generation".
    MBean: java.lang:type=Memory (HeapMemoryUsage)

  • The Old Generation (aka Tentured Space) contains long-lived objects and is cleaned only during a major garbage collection.
    MBean (Client-VM): java.lang:type=MemoryPool,name=Tenured Gen
    MBean (Server-VM): java.lang:type=MemoryPool,name=PS Old Gen

  • The New Generation (aka New Space) is subdivided into “Eden” and two Survivor Spaces named “From Space” and “To Space".

  • Eden is for new and short-lived objects. Initial size is usually 32MB or 64MB, may be overwritten with -XX:NewSize and -XX:MaxNewSize.

  • From Space and To Space contain objects that have survived a minor garbage collection. Initial size is usually 1MB or 2MB each, may be overwritten with -XX:SurvivorRatio.

Garbage Collection

  • A Minor Collection (aka Copy Collection) cleans up Eden and moves the remaining objects up to the survivor spaces (and later into the tentured space)

  • A Major Collection (aka Stop-the-World Collection, aka Mark-and-Sweep, aka Mark-Sweep-Compact) is executed when a minor collection cannot reclaim enough memory (which should not occur more often than twice an hour) . It cleans up the whole heap (the young generation is empty afterwards).

The available collectors are:

  • Serial Collector (default on Client-VM)
    minor MBean: java.lang:type=GarbageCollector,name=Copy
    major MBean: java.lang:type=GarbageCollector,name=MarkSweepCompact

  • Parallel Collector (aka Throughput Collector, default on Server-VM)
    minor MBean: java.lang:type=GarbageCollector,name=PS Scavenge
    major MBean: java.lang:type=GarbageCollector,name=PS MarkSweep

  • Parallel Compacting Collector

  • Concurrent Mark-Sweep Collector (aka Low-Latency Collector)

(Note: all data refer to Java 6)

Recommended memory sizes (Steven Haines, Java 5):

  • Hint: allocate the heap at once (i.e. -Xms1024m -Xmx1024m for a 1GB heap)
  • Young generation: a little less than half the heapsize (i.e. -XX:NewSize=448m -XX:MaxNewSize=448m for a 1GB heap)
  • Each survivor space: 1/8 of the young generation (i.e. -XX:SurvivorRatio=6)
  • Permanent space: start with 128MB, max 256MB (i.e. -XX:PermSize=128m -XX:MaxPermSize=128m) - this value is not part of the heap!

See also: