Compaction is performed during garbage collection while all Java
threads are paused. Compaction of a large area with many objects will
thus increase the garbage collection pause times.
Insufficient compaction will lead to fragmentation of the heap,
which leads to lower performance. If the fragmentation increases over
time, the JRockit JVM will eventually be forced to either do a full
compaction of the heap, causing a long garbage collection pause, or
throw an OutOfMemoryError.
If your application shows performance degradation over time in a
periodic manner, such that the performance degrades until it suddenly
pops back to excellent, just to start degrading again, you are most
likely experiencing fragmentation problems. The heap becomes more and
more fragmented for each old collection until finally object
allocation becomes impossible and the JVM is forced to do a full
compaction of the heap.
The full compaction eliminates the fragmentation, but only until
the next garbage collection. You can verify this by looking at
-Xverbose:memory outputs, monitoring the JVM through the Management
Console in JRockit Mission Control or by creating a JRA recording and
examining the garbage collection data. If you see that the amount of
used heap after each old collection keeps increasing over time until
it hits the roof, and then drops down again at the next old
collection, you are experiencing a fragmentation problem.
Difference between system.gc() and runtime.gc().
System.gc()internally calls Runtime.gc(). System.gc() is a class
method where as Runtime.gc() is an instance method.
Explain PermGen and Metaspace?
PermGen is an
abbreviation for Permanent Generation. Special heap space which is
separate from the main Java heap where JVM keeps track of metadata of
the classes which have been loaded. It is there upto version 7. Java
8 Metaspace has been added and unlimited default maximum size.
PermGen -XX:PermSize=N and -XX:MaxPermSize=N
What Is Permgen Or Permanent Generation?
memory pool containing all the reflective data of the java virtual
machine itself such as class and method objects. With Java VMs that
use class data sharing, this generation is divided into read-only and
read-write areas. The Permanent generation contains metadata required
by the JVM to describe the classes and methods used in the
application. The permanent generation is populated by the JVM at
runtime based on classes in use by the application and Java SE library
classes and methods may be stored here.