From IcedTea

Jump to: navigation, search


1 Memory Management

A good introduction is the Hotspot Memory Management Whitepaper

1.1 Generations

Hotspot has 3 generations in OpenJDK version 7 (or less): YoungGen, OldGen, and PermGen. Since OpenJDK 8, PermGen has been removed.

YounGen and OldGen may have different garbage collectors operating on them. PermGen uses the same garbage collector and is collected along with OldGen. PermGen has been removed with OpenJDK 8 and replaced by Metaspace on the native heap.

2 Garbage Collectors

There is a lot of inconsistency and old documentation around this area. This is an attempt to summarize it.

An overview is available at JVM Internals and Question of the Month - Garbage Collection Algorithms. See Java Hotspot Garbage Collection and Garbage Collection FAQ for more details.

A minor collection (or young generation collection) is a collection operation performed on just that generation. A major collection (or full collection) causes a collection to be performed on all generations. For a major collection, the specific YounGen collector is run on the YoungGen, and the OldGen collector is run on OldGen and PermGen).

2.1 Serial Collector (-XX:+UseSerialGC)

A serial stop-the-world-collector. Collects YoungGen (using a copying collector called Copy) and OldGen (using a mark-sweep-compact collector called MSC ).

2.2 Parallel Collector (-XX:+UseParallelGC)

A parallel stop-the-world collector. Collects YoungGen (a parallel version of SerialGC called PSScavenge). Has support for adapting heap sizes. If no OldGen collector is explicitly specified, uses PSMarkSweep.

2.3 Parallel Compacting Collector (-XX:+UseParallelOldGC)

Collects OldGen (using a collector named PSParallelCompact). Needs/Implies UseParallelGC.

2.4 Parallel Young Generation Collector (-XX:+UseParNewGC)

A parallel stop-the-world collector. Collects YoungGen (using a collector named PCopy). Similar to UseParallelGC, but does not support hotspot ergonomics. If no OldGen collector is specified, MSC is used.

2.5 Concurrent Mark Sweep Collector (+XX:UseConcMarkSweepGC)

Collects OldGen (in multiple phases - some stop-the-world, others concurrent - using a collector named CMS). Needs/Implies UseParNewGC. The -Xincgc option turns this on.

2.6 Garbage-First Garbage Collector (-XX:+UseG1GC)

Collects YoungGen (using a collector named G1 incremental collections) and OldGen (using a collector named G1 stop-the-world full collections). See the description for more information.

2.7 OpenJDK 8: Available Collectors

With OpenJDK 8 there are basically 4 major collectors available:

  • Serial Collector
  • Parallel Collector
  • Mostly Concurrent Collectors:
    • Concurrent Mark and Sweep Collector
    • Garbage First (G1) Collector

Here is more information about Mostly Concurrent Collectors and Available Collectors in OpenJDK 8

3 Heaps

Hotspot provides features to analyze heaps of a live VM or dump them into a file for later analysis. It would be really cool if we could support both in thermostat.

To analyze the heap of a live VM, hotspot's servicability agent (SA) comes in handy. With it, we can walk over the heap, and records things we come across. This is what "jmap -histo" uses. There is some documentation on SA on the hotspot servicability page and a paper on SA is available at the usenix website.

Heaps can be written out to the disk using jmap (jmap -dump:format=b,file=somefilename). The format is binary. The documentation is included in the JDK (at demo/jvmti/hprof/src/manual.html). It is also available online. Bob Foster wrote a blog entry with more comments on the format and parsing it.

Personal tools