Option 1: Tune max heap size to optimize GC frequency | How fragmentation occurs


kCluster, pCluster, and fragmentation


Java objects located in the Java heap are usually mobile. That is, the garbage collector can move them around if it decides to re-sequence the heap. Some objects, however, cannot be moved either permanently or temporarily. Such immovable objects are known as pinned objects or dosed objects. Pinned and dosed objects are the immovable objects on the Java heap. GC does not move these objects during compaction. These are the major cause of heap fragmentation.

All objects that are referenced from JNI to call external programs are pinned. Use of JDBC-2 drivers is a case in point. All objects on the heap that are referenced from the thread stacks are dosed.

In the Java SDK Release 1.3.1, Service Refresh 7 and later, the garbage collector allocates what is called a kCluster as the first region at the bottom of the heap. A kCluster is an area of storage that is used exclusively for class blocks. It is large enough to hold 1280 entries and each class block is 256 bytes long.

The GC then allocates a pCluster as the second object on the heap. A pCluster is an area of storage that is used to allocate any pinned objects. It is 16 KB long.

When the kCluster is full, the GC allocates class blocks in the pCluster. When the pCluster is full, the GC allocates a new pCluster of 2 KB. Because this new pCluster can be allocated anywhere in the heap and must be pinned, it can lead to fragmentation problems.