APIdia Launch Partner
Top Description Methods
com.sun.prism.impl

public Interface ResourcePool<T>

Known Direct Subinterfaces
com.sun.prism.impl.TextureResourcePool
Known Direct Implementers
com.sun.prism.impl.BaseResourcePool
Type Parameters
<T>
the type of resource stored in this pool

An interface for tracking the usage of a particular resource from which managed resources are allocated. A given resource pool may share its underlying space with another resource pool, such as the case of allocating textures from the Java heap. In the case of a shared resource, the used() and max() methods will return absolute values indicating the amounts used or available for all resources that come from the shared pool, but the managed() method will only indicate the amount of the resource used for managed resources and the target() method will return the amount of the total shared resource that the allocation methods should attempt to stay under.
    long newsize = ...; // size of new resource allocation
    if (pool.used() + newsize >= pool.target()) {
        cleanup(pool);
        // possibly multiple passes of increasing aggressiveness
    }
    if (pool.used() + newsize >= pool.max()) {
        throw OOM();
    }
    allocate(newsize);
The amounts and sizes returned from the methods should all be in the same units, usually bytes.
See Also
ManagedResource

Method Summary

Modifier and TypeMethod and Description
public void
freeDisposalRequestedAndCheckResources(boolean
true if the caller wishes to forgive and unlock all outstanding locks on non-permanent resources
forgiveStaleLocks
)

Check that all resources are in the correct state for an idle condition and free any resources which were disposed from a non-resource thread.

public boolean

Returns:

true if Thread.currentThread() is a thread that created this ResourcePool
isManagerThread
()

True if Thread.currentThread() is a thread that created this ResourcePool

public long

Returns:

the amount being used to hold managed resources
managed
()

The amount of this resource currently being used to hold managed resources.

public long

Returns:

the maximum amount of the resource
max
()

The total space available in this pool for allocating any kind of resource, even unmanaged resources, and including those resources already allocated.

public long

Returns:

the initial target amount of the resource to be used
origTarget
()

The initial target of the maximum amount of space in this resource pool that should be used so as to be friendly to other parts of the system.

public boolean

Returns:

true if there is room for the indicated resource
prepareForAllocation
(long
the size of the resource that is about to be allocated
size
)

Prepare for an allocation of a resource from this pool of the indicated size by freeing up uninteresting resources until the allocation fits within the target() or max() sizes.

public void
recordAllocated(long
the amount of the resource to be indicated as managed.
size
)

Record the indicated amount of the resource as being allocated for a ManagedResource.

public void
recordFree(long
the amount of the resource to remove from the managed amount.
size
)

Record the indicated amount of the resource as no longer being held in a ManagedResource.

public void
resourceFreed(ManagedResource<T>
the resource that is freed, no longer being managed
resource
)

Record the ManagedResource object as no longer being managed by this pool.

public void
resourceManaged(ManagedResource<T>
the resource that is now being managed
resource
)

Record the ManagedResource object as being currently managed by this pool.

public void
setTarget(long
the new current target to be set
newTarget
)

Sets a new current target of the maximum amount of space in this resource pool that should be used so as to be friendly to other parts of the system.

public long

Returns:

the space within this resource pool that the object occupies.
size
(T
the resource to be measured
resource
)

The estimated size of the indicated resource.

public long

Returns:

the current target amount of the resource to be used
target
()

The current target of the maximum amount of space in this resource pool that should be used so as to be friendly to other parts of the system.

public long

Returns:

the amount being used
used
()

The amount of a resource currently being used to hold any kind of resource, whether managed or not.

Method Detail

freeDisposalRequestedAndCheckResourcesback to summary
public void freeDisposalRequestedAndCheckResources(boolean forgiveStaleLocks)

Check that all resources are in the correct state for an idle condition and free any resources which were disposed from a non-resource thread. This method must be called on a thread that is appropriate for disposing and managing resources for this resource pool. The boolean forgiveStaleLocks parameter is used to indicate that an exceptional condition occurred which caused the caller to abort a cycle of resource usage, potentially with outstanding resource locks. This method will unlock all non-permanent resources that have outstanding locks if forgiveStaleLocks is true, or it will print out a warning and a resource summary if that parameter is false.

Parameters
forgiveStaleLocks:boolean

true if the caller wishes to forgive and unlock all outstanding locks on non-permanent resources

isManagerThreadback to summary
public boolean isManagerThread()

True if Thread.currentThread() is a thread that created this ResourcePool

Returns:boolean

true if Thread.currentThread() is a thread that created this ResourcePool

managedback to summary
public long managed()

The amount of this resource currently being used to hold managed resources. This amount may be less than the amount returned by the used() method if the pool is shared amongst other resources.

Returns:long

the amount being used to hold managed resources

maxback to summary
public long max()

The total space available in this pool for allocating any kind of resource, even unmanaged resources, and including those resources already allocated.

Returns:long

the maximum amount of the resource

origTargetback to summary
public long origTarget()

The initial target of the maximum amount of space in this resource pool that should be used so as to be friendly to other parts of the system. This number must be less than or equal to the amount returned by the max() method.

Returns:long

the initial target amount of the resource to be used

prepareForAllocationback to summary
public boolean prepareForAllocation(long size)

Prepare for an allocation of a resource from this pool of the indicated size by freeing up uninteresting resources until the allocation fits within the target() or max() sizes.

Parameters
size:long

the size of the resource that is about to be allocated

Returns:boolean

true if there is room for the indicated resource

recordAllocatedback to summary
public void recordAllocated(long size)

Record the indicated amount of the resource as being allocated for a ManagedResource.

Parameters
size:long

the amount of the resource to be indicated as managed.

recordFreeback to summary
public void recordFree(long size)

Record the indicated amount of the resource as no longer being held in a ManagedResource.

Parameters
size:long

the amount of the resource to remove from the managed amount.

resourceFreedback to summary
public void resourceFreed(ManagedResource<T> resource)

Record the ManagedResource object as no longer being managed by this pool.

Parameters
resource:ManagedResource<T>

the resource that is freed, no longer being managed

resourceManagedback to summary
public void resourceManaged(ManagedResource<T> resource)

Record the ManagedResource object as being currently managed by this pool.

Parameters
resource:ManagedResource<T>

the resource that is now being managed

setTargetback to summary
public void setTarget(long newTarget)

Sets a new current target of the maximum amount of space in this resource pool that should be used so as to be friendly to other parts of the system. The specified newTarget number must be less than or equal to the amount returned by the max() method, larger than the amount returned by the origTarget() method.

Parameters
newTarget:long

the new current target to be set

sizeback to summary
public long size(T resource)

The estimated size of the indicated resource.

Parameters
resource:T

the resource to be measured

Returns:long

the space within this resource pool that the object occupies.

targetback to summary
public long target()

The current target of the maximum amount of space in this resource pool that should be used so as to be friendly to other parts of the system. This number must be less than or equal to the amount returned by the max() method, larger than the amount returned by the origTarget() method, and may change over time.

Returns:long

the current target amount of the resource to be used

See Also
setTarget(long)
usedback to summary
public long used()

The amount of a resource currently being used to hold any kind of resource, whether managed or not.

Returns:long

the amount being used