APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.ref

public final Class CleanerImpl

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable
Imports
java.lang.ref.Cleaner, .Cleaner.Cleanable, .ReferenceQueue, java.security.AccessController, .PrivilegedAction, java.util.concurrent.ThreadFactory, java.util.concurrent.atomic.AtomicInteger, java.util.function.Function, jdk.internal.misc.InnocuousThread

CleanerImpl manages a set of object references and corresponding cleaning actions. CleanerImpl provides the functionality of java.lang.ref.Cleaner.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
CleanerImpl.CleanableList

A specialized implementation that tracks phantom cleanables.

pack-priv static class
CleanerImpl.CleanerCleanable

A PhantomCleanable implementation for tracking the Cleaner itself.

pack-priv static class
CleanerImpl.InnocuousThreadFactory

A ThreadFactory for InnocuousThreads.

public static class
CleanerImpl.PhantomCleanableRef

Perform cleaning on an unreachable PhantomReference.

Field Summary

Modifier and TypeField and Description
pack-priv final CleanerImpl.CleanableList
activeList

Currently active PhantomCleanable-s.

private static Function<Cleaner, CleanerImpl>
cleanerImplAccess

An object to access the CleanerImpl from a Cleaner; set by Cleaner init.

pack-priv final ReferenceQueue<Object>

Constructor Summary

AccessConstructor and Description
public
CleanerImpl()

Constructor for CleanerImpl.

Method Summary

Modifier and TypeMethod and Description
pack-priv static CleanerImpl

Returns:

the corresponding CleanerImpl
getCleanerImpl
(Cleaner
the cleaner
cleaner
)

Called to get the CleanerImpl for a Cleaner.

public void
run()

Implements java.lang.Runnable.run.

Process queued Cleanables as long as the cleanable lists are not empty.

public static void
setCleanerImplAccess(Function<Cleaner, CleanerImpl>
a function to map from Cleaner to CleanerImpl
access
)

Called by Cleaner static initialization to provide the function to map from Cleaner to CleanerImpl.

public void
start(Cleaner
the cleaner
cleaner
,
ThreadFactory
the thread factory
threadFactory
)

Starts the Cleaner implementation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activeListback to summary
pack-priv final CleanerImpl.CleanableList activeList

Currently active PhantomCleanable-s.

cleanerImplAccessback to summary
private static Function<Cleaner, CleanerImpl> cleanerImplAccess

An object to access the CleanerImpl from a Cleaner; set by Cleaner init.

queueback to summary
pack-priv final ReferenceQueue<Object> queue

Constructor Detail

CleanerImplback to summary
public CleanerImpl()

Constructor for CleanerImpl.

Method Detail

getCleanerImplback to summary
pack-priv static CleanerImpl getCleanerImpl(Cleaner cleaner)

Called to get the CleanerImpl for a Cleaner.

Parameters
cleaner:Cleaner

the cleaner

Returns:CleanerImpl

the corresponding CleanerImpl

runback to summary
public void run()

Implements java.lang.Runnable.run.

Process queued Cleanables as long as the cleanable lists are not empty. A Cleanable is in one of the lists for each Object and for the Cleaner itself. Terminates when the Cleaner is no longer reachable and has been cleaned and there are no more Cleanable instances for which the object is reachable.

If the thread is a ManagedLocalsThread, the threadlocals are erased before each cleanup

Annotations
@Override
setCleanerImplAccessback to summary
public static void setCleanerImplAccess(Function<Cleaner, CleanerImpl> access)

Called by Cleaner static initialization to provide the function to map from Cleaner to CleanerImpl.

Parameters
access:Function<Cleaner, CleanerImpl>

a function to map from Cleaner to CleanerImpl

startback to summary
public void start(Cleaner cleaner, ThreadFactory threadFactory)

Starts the Cleaner implementation. Ensure this is the CleanerImpl for the Cleaner. When started waits for Cleanables to be queued.

Parameters
cleaner:Cleaner

the cleaner

threadFactory:ThreadFactory

the thread factory

jdk.internal.ref back to summary

pack-priv final Class CleanerImpl.CleanableList

extends Object
Class Inheritance

A specialized implementation that tracks phantom cleanables.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private CleanerImpl.CleanableList.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 CleanerImpl.CleanableList.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(PhantomCleanable<?> phc)

Insert this PhantomCleanable in the list.

public synchronized boolean

Returns:

true if the list is empty
isEmpty
()

Returns true if cleanable list is empty.

public synchronized boolean

Returns:

true if Cleanable was removed or false if not because it had already been removed before
remove
(PhantomCleanable<?> phc)

Remove this PhantomCleanable from the list.

pack-priv synchronized void
reset()

Testing support: reset list to initial state.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private CleanerImpl.CleanableList.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 CleanerImpl.CleanableList.Node head

Head node. This is the only node where PhantomCleanables 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

CleanableListback to summary
public CleanableList()

Method Detail

insertback to summary
public synchronized void insert(PhantomCleanable<?> phc)

Insert this PhantomCleanable in the list.

isEmptyback to summary
public synchronized boolean isEmpty()

Returns true if cleanable list is empty.

Returns:boolean

true if the list is empty

removeback to summary
public synchronized boolean remove(PhantomCleanable<?> phc)

Remove this PhantomCleanable from the list.

Returns:boolean

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

resetback to summary
pack-priv synchronized void reset()

Testing support: reset list to initial state.

jdk.internal.ref back to summary

pack-priv Class CleanerImpl.CleanableList.Node

extends Object
Class Inheritance

Segment node.

Field Summary

Modifier and TypeField and Description
pack-priv final PhantomCleanable<?>[]
pack-priv CleanerImpl.CleanableList.Node
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv
Node()

Field Detail

arrback to summary
pack-priv final PhantomCleanable<?>[] arr
nextback to summary
pack-priv CleanerImpl.CleanableList.Node next
sizeback to summary
pack-priv int size

Constructor Detail

Nodeback to summary
pack-priv Node()
jdk.internal.ref back to summary

pack-priv final Class CleanerImpl.CleanerCleanable

extends PhantomCleanable<Cleaner>
Class Inheritance

A PhantomCleanable implementation for tracking the Cleaner itself.

Field Summary

Inherited from jdk.internal.ref.PhantomCleanable:
indexnode

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
performCleanup()

Implements abstract jdk.internal.ref.PhantomCleanable.performCleanup.

The performCleanup abstract method is overridden to implement the cleaning logic.

Inherited from jdk.internal.ref.PhantomCleanable:
cleanclearenqueueisEnqueued

Constructor Detail

CleanerCleanableback to summary
pack-priv CleanerCleanable(Cleaner cleaner)

Method Detail

performCleanupback to summary
protected void performCleanup()

Implements abstract jdk.internal.ref.PhantomCleanable.performCleanup.

Doc from jdk.internal.ref.PhantomCleanable.performCleanup.

The performCleanup abstract method is overridden to implement the cleaning logic. The performCleanup method should not be called except by the clean method which ensures at most once semantics.

Annotations
@Override
jdk.internal.ref back to summary

pack-priv final Class CleanerImpl.InnocuousThreadFactory

extends Object
implements ThreadFactory
Class Inheritance
All Implemented Interfaces
java.util.concurrent.ThreadFactory

A ThreadFactory for InnocuousThreads. The factory is a singleton.

Field Summary

Modifier and TypeField and Description
pack-priv final AtomicInteger
pack-priv static final ThreadFactory

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static ThreadFactory
public Thread
newThread(Runnable r)

Implements java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cleanerThreadNumberback to summary
pack-priv final AtomicInteger cleanerThreadNumber
factoryback to summary
pack-priv static final ThreadFactory factory

Constructor Detail

InnocuousThreadFactoryback to summary
pack-priv InnocuousThreadFactory()

Method Detail

factoryback to summary
pack-priv static ThreadFactory factory()
newThreadback to summary
public Thread newThread(Runnable r)

Implements java.util.concurrent.ThreadFactory.newThread.

Doc from java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

jdk.internal.ref back to summary

public final Class CleanerImpl.PhantomCleanableRef

extends PhantomCleanable<Object>
Class Inheritance

Perform cleaning on an unreachable PhantomReference.

Field Summary

Modifier and TypeField and Description
private final Runnable
Inherited from jdk.internal.ref.PhantomCleanable:
indexnode

Constructor Summary

AccessConstructor and Description
public
PhantomCleanableRef(Object
the object to monitor
obj
,
Cleaner
the cleaner
cleaner
,
Runnable
the action Runnable
action
)

Constructor for a phantom cleanable reference.

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Overrides jdk.internal.ref.PhantomCleanable.clear.

Direct clearing of the referent is not supported.

public Object
get()

Overrides java.lang.ref.PhantomReference.get.

Prevent access to referent even when it is still alive.

protected void
performCleanup()

Implements abstract jdk.internal.ref.PhantomCleanable.performCleanup.

The performCleanup abstract method is overridden to implement the cleaning logic.

Inherited from jdk.internal.ref.PhantomCleanable:
cleanenqueueisEnqueued

Field Detail

actionback to summary
private final Runnable action

Constructor Detail

PhantomCleanableRefback to summary
public PhantomCleanableRef(Object obj, Cleaner cleaner, Runnable action)

Constructor for a phantom cleanable reference.

Parameters
obj:Object

the object to monitor

cleaner:Cleaner

the cleaner

action:Runnable

the action Runnable

Method Detail

clearback to summary
public void clear()

Overrides jdk.internal.ref.PhantomCleanable.clear.

Direct clearing of the referent is not supported.

Annotations
@Override
Exceptions
UnsupportedOperationException:
always
getback to summary
public Object get()

Overrides java.lang.ref.PhantomReference.get.

Prevent access to referent even when it is still alive.

Annotations
@Override
Exceptions
UnsupportedOperationException:
always
performCleanupback to summary
protected void performCleanup()

Implements abstract jdk.internal.ref.PhantomCleanable.performCleanup.

Doc from jdk.internal.ref.PhantomCleanable.performCleanup.

The performCleanup abstract method is overridden to implement the cleaning logic. The performCleanup method should not be called except by the clean method which ensures at most once semantics.

Annotations
@Override