Friday, May 29, 2009

How the Shared Garbage Collector Works

he shared garbage collector (SGC) removes objects no longer needed from the shared pool (Shared Closures). Unlike the normal garbage collector (on local VMs), all VMs must contribute to the shared garbage collection. Only when all the VMs have contributed can global memory that is no longer needed be freed up.

Process Flow of Shared Garbage Collection

A shared garbage collection consists of a cycle which all Java VMs must contribute to. The SGC and the VMs assume various states during this cycle. You can see these states in the header area of the VM overview (see VM Overview: General Information).

Before the cycle starts the state of the SGC is Inactive and the state of the VMs in the SGC is Neutral (see VM Overview: Table of VMs).

An SGC cycle starts as soon as a VM performs a full garbage collection (full GC) in its local heap memory. The state of the SGC then changes to Active; VMs should contribute. The SGC state changes to Has contributed for those VMs that have already contributed and to to contribute for those VMs that have not yet contributed.

Once 80% of all VMs have contributed to the SGC, the remaining 20% are forced to contribute. The state of the SGC then changes to Active; VMs must contribute and the SGC state of the VMs to Must contribute.

If 90% of the global memory (shared pool) is used up, an SGC is also forced regardless of the contribution state of the VMs.

If all VMs have contributed to the SGC, the cycle is ended and the state of the SGC is Inactive again and the state of the VMs is Neutral.

Implementation of the Shared Garbage Collection

Each object in the shared pool has a black and white flag. The first VM that starts the SGC cycle with a (local) full GC, sets the flag to white for all objects. Then the VM sets a black flag for the objects referenced in its local heap. Each further VM contributing to the SGC likewise sets a black flag for its objects. New objects created during a cycle are also assigned a black flag. After the last VM has contributed to the SGC, the remaining objects are deleted with a white flag (since they are no longer being referenced by a VM), and the space they occupy in the shared memory is freed up.

No comments:

Blog Archive