Java Reference
In-Depth Information
Tuning the young generation by specifying a range for its minimum and maximum sizes ends
up being fairly difficult. When a heap size is fixed (by setting -Xms equal to -Xmx ), it is usu-
ally preferable to use -Xmn to specify a fixed size for the young generation as well. If an ap-
plication needs a dynamically sized heap and requires a larger (or smaller) young generation,
then focus on setting the NewRatio value.
QUICK SUMMARY
1. Within the overall heap size, the sizes of the generations are controlled by how
much space is allocated to the young generation.
2. The young generation will grow in tandem with the overall heap size, but it can
also fluctuate as a percentage of the total heap (based on the initial and maximum
size of the young generation).
Sizing Permgen and Metaspace
When the JVM loads classes, it must keep track of certain metadata about those classes.
From the perspective of an end user, this is all just bookkeeping information. This data is
held in a separate heap space. In Java 7, this is called the permgen (or permanent generation),
and in Java 8, this is called the metaspace .
Permgen and metaspace are not exactly the same thing. In Java 7, permgen contains some
miscellaneous objects that are unrelated to class data; these are moved into the regular heap
in Java 8. Java 8 also fundamentally changes the kind of metadata that is held in this special
region—though since end users don't know what that data is in the first place, that change
doesn't really affect us. As end users, all we need to know is that permgen/metaspace holds a
bunch of class-related data, and that there are certain circumstances where the size of that re-
gion needs to be tuned.
Note that permgen/metaspace does not hold the actual instance of the class (the Class ob-
jects), nor reflection objects (e.g., Method objects); those are held in the regular heap. In-
formation in permgen/metaspace is really only used by the compiler and JVM runtime, and
the data it holds is referred to as class metadata.
There isn't a good way to calculate in advance how much space a particular program needs
for its permgen/metaspace. The size will be proportional to the number of classes it uses, so
Search WWH ::




Custom Search