public abstract class CollectionWatcher extends AllocationFreeList.Element<CollectionWatcher>
Each CollectionWatcher instance may be registered at most once with
GC.registerCollectionWatcher(CollectionWatcher)
. If there is state that could be reused
between CollectionWatchers (e.g., the list of loaded classes), allocate it outside of the
CollectionWatcher instance and share it between CollectionWatcher instances.
Modifier | Constructor and Description |
---|---|
protected |
CollectionWatcher()
Constructor for subclasses.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
afterCollection()
Called after a collection.
|
abstract void |
beforeCollection()
Called before a collection.
|
void |
report()
Called when the collection is over.
|
getHasBeenOnList, getNextElement, getNextObject, removeElement, testingBackDoorGetNextElement, testingBackDoorIsEnabled
public abstract void beforeCollection()
A collection has been requested, so space is not available when this method is called. This method runs inside the collection VMOperation, so taking locks is not allowed.
public abstract void afterCollection()
A collection has finished, but allocation is still disallowed. This method is run inside the collection VMOperation, so taking locks is not allowed.
public void report()
Allocation is allowed, but too much allocation may cause another collection. Collections may be caused by VMOperations, in which case this method will be called inside that enclosing VMOperation, so taking locks is not allowed. More than one thread may end up calling this method for the same collection.
The default implementation is to do nothing.