APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.nio

pack-priv Class BufferCleaner

extends Object
Class Inheritance
Imports
java.lang.ref.PhantomReference, .Reference, .ReferenceQueue, java.util.Objects, jdk.internal.misc.InnocuousThread, sun.nio.Cleaner

BufferCleaner supports PhantomReference-based management of native memory referred to by Direct-XXX-Buffers. Unreferenced DBBs may be garbage collected, deactivating the associated PRefs and making them available for cleanup here. There is a configured limit to the amount of memory that may be allocated by DBBs. When that limit is reached, the allocator may invoke the garbage collector directly to attempt to trigger cleaning here, hopefully permitting the allocation to complete. Only if that doesn't free sufficient memory does the allocation fail. See java.nio.Bits::reserveMemory() for details. One of the requirements for that approach is having a way to determine that deactivated cleaners have been cleaned. java.lang.ref.Cleaner doesn't provide such a mechanism, and adding such a mechanism to that class to satisfy this unique requirement was deemed undesirable. Instead, this class uses the underlying primitives (PhantomReferences, ReferenceQueues) to provide the functionality needed for DBB management.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final BufferCleaner.CleanerList
private static Thread
private static final ReferenceQueue<Object>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Cleaner

Returns:

associated cleaner.
register
(Object
object to track.
obj
,
Runnable
cleanup action for obj.
action
)

Construct a new Cleaner for obj, with the associated action.

private static void
public static boolean

Returns:

true if a cleaner was found and executed, false if there weren't any cleaners in the queue.
tryCleaning
()

Try to do some cleaning.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cleanerListback to summary
private static final BufferCleaner.CleanerList cleanerList
cleaningThreadback to summary
private static Thread cleaningThread
queueback to summary
private static final ReferenceQueue<Object> queue

Constructor Detail

BufferCleanerback to summary
private BufferCleaner()

Method Detail

registerback to summary
public static Cleaner register(Object obj, Runnable action)

Construct a new Cleaner for obj, with the associated action.

Parameters
obj:Object

object to track.

action:Runnable

cleanup action for obj.

Returns:Cleaner

associated cleaner.

startCleaningThreadIfNeededback to summary
private static void startCleaningThreadIfNeeded()
tryCleaningback to summary
public static boolean tryCleaning()

Try to do some cleaning. Takes a cleaner from the queue and executes it.

Returns:boolean

true if a cleaner was found and executed, false if there weren't any cleaners in the queue.

java.nio back to summary

pack-priv final Class BufferCleaner.CleanerList

extends Object
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private BufferCleaner.CleanerList.Node
cache

Cached node instance to provide better behavior near NODE_CAPACITY threshold: if list size flips around NODE_CAPACITY, it would reuse the cached node instead of wasting and re-allocating a new node all the time.

private BufferCleaner.CleanerList.Node
head

Head node.

pack-priv static final int
NODE_CAPACITY

Capacity for a single node in the list.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
insert(BufferCleaner.PhantomCleaner phc)

Insert this PhantomCleaner in the list.

public synchronized boolean

Returns:

true if Cleaner was removed or false if not because it had already been removed before
remove
(BufferCleaner.PhantomCleaner phc)

Remove this PhantomCleaner from the list.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private BufferCleaner.CleanerList.Node cache

Cached node instance to provide better behavior near NODE_CAPACITY threshold: if list size flips around NODE_CAPACITY, it would reuse the cached node instead of wasting and re-allocating a new node all the time.

headback to summary
private BufferCleaner.CleanerList.Node head

Head node. This is the only node where PhantomCleanabls are added to or removed from. This is the only node with variable size, all other nodes linked from the head are always at full capacity.

NODE_CAPACITYback to summary
pack-priv static final int NODE_CAPACITY

Capacity for a single node in the list. This balances memory overheads vs locality vs GC walking costs.

Constructor Detail

CleanerListback to summary
public CleanerList()

Method Detail

insertback to summary
public synchronized void insert(BufferCleaner.PhantomCleaner phc)

Insert this PhantomCleaner in the list.

removeback to summary
public synchronized boolean remove(BufferCleaner.PhantomCleaner phc)

Remove this PhantomCleaner from the list.

Returns:boolean

true if Cleaner was removed or false if not because it had already been removed before

java.nio back to summary

pack-priv Class BufferCleaner.CleanerList.Node

extends Object
Class Inheritance

Segment node.

Field Summary

Modifier and TypeField and Description
pack-priv final BufferCleaner.PhantomCleaner[]
pack-priv BufferCleaner.CleanerList.Node
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv
Node()

Field Detail

arrback to summary
pack-priv final BufferCleaner.PhantomCleaner[] arr
nextback to summary
pack-priv BufferCleaner.CleanerList.Node next
sizeback to summary
pack-priv int size

Constructor Detail

Nodeback to summary
pack-priv Node()
java.nio back to summary

private final Class BufferCleaner.CleaningRunnable

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CleaningRunnableback to summary
public CleaningRunnable()

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
java.nio back to summary

private final Class BufferCleaner.PhantomCleaner

extends PhantomReference<Object>
implements Cleaner
Class Inheritance
All Implemented Interfaces
sun.nio.Cleaner

Field Summary

Modifier and TypeField and Description
private final Runnable
pack-priv int
pack-priv BufferCleaner.CleanerList.Node

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
clean()

Implements sun.nio.Cleaner.clean.

Unregisters the cleaner and invokes the cleaning action.

Inherited from java.lang.ref.PhantomReference:
get

Field Detail

actionback to summary
private final Runnable action
indexback to summary
pack-priv int index
nodeback to summary
pack-priv BufferCleaner.CleanerList.Node node

Constructor Detail

PhantomCleanerback to summary
public PhantomCleaner(Object obj, Runnable action)

Method Detail

cleanback to summary
public void clean()

Implements sun.nio.Cleaner.clean.

Doc from sun.nio.Cleaner.clean.

Unregisters the cleaner and invokes the cleaning action. The cleaner's cleaning action is invoked at most once, regardless of the number of calls to clean.

Annotations
@Override