We received some questions around the G1 garbage collector
and the use of Permanent Generation with it. There seems to be some confusion
that the Hotspot JVM does not use permanent generation when G1 is used as the garbage
collector. Here’s some clarification:
Permanent Generation still exists in JDK 7 and its updates,
and is used by all the garbage collectors. In JDK7, the effort to remove the
permanent generation was started and some parts of the data residing in the
permanent generation were moved to either the Java Heap or to the native heap.
Permanent generation was not completely removed and it still exists in JDK 7
and its updates. Here's the list of things that were moved out of the permanent
generation in JDK7:
Symbols were moved to the native heap
Interned strings were moved to the Java Heap
Class statics were moved to the Java Heap
With G1 collector, PermGen is collected only at a Full GC
which is a stop-the-world (STW) GC. If
G1 is running optimally then it does not do Full GCs. G1 invokes the Full GCs
only when the PermGen is full or when the application does allocations faster
than G1 can concurrently collect garbage.
With CMS garbage collector, we can use option
-XX:+CMSClassUnloadingEnabled to collect PermGen space in the CMS concurrent
cycle. There is no equivalent option for G1. G1 only collects PermGen during the Full stop-the-world GCs.
We can use options PermSize and MaxPermSize to tune the
PermGen space size according to the application needs.
Permanent generation has been completely removed in JDK 8.
This work has been done under the bug
https://bugs.openjdk.java.net/browse/JDK-6964458. Options PermSize and
MaxPermSize have also been removed in JDK 8.
Email to openjdk alias regarding the PermGen elimination
In JDK 8, classes metadata is now stored in the native heap
and this space is called Metaspace. There are some new flags added for
Metaspace in JDK 8:
By default class
metadata allocation is only limited by the amount of available native memory. We
can use the new option MaxMetaspaceSize to limit the amount of native memory
used for the class metadata. It is analogous to MaxPermSize. A garbage collection is induced to collect the dead classloaders
and classes when the class metadata usage reaches MetaspaceSize (12Mbytes on
the 32bit client VM and 16Mbytes on the 32bit server VM with larger sizes on
the 64bit VMs). Set MetaspaceSize to a higher value to delay the induced
garbage collections. After an induced garbage collection, the class metadata usage
needed to induce the next garbage collection may be increased.