public abstract class AllocatorContext extends Context
This class represents an allocator context; it defines the
the allocation policy of the objects produced by
ObjectFactory
.
The default
context used by new threads is
HeapContext
. ConcurrentContext
threads inherits
the allocator context from their parent thread (the one which
entered the concurrent context).
Specializations may allocate from thread-local stacks
(e.g.StackContext
), shared pools (e.g. PoolContext
),
specific memory areas (e.g. ImmortalContext
) or using any user
defined policy such as aging pools (where
objects sufficiently old are recycled), switchable spaces (objects from
recycled when buffers are swapped), etc.
Modifier and Type | Class and Description |
---|---|
static class |
AllocatorContext.Reference<T>
This class represents a
reference
allocated from the current AllocatorContext . |
Modifier and Type | Field and Description |
---|---|
static Configurable<java.lang.Class<? extends AllocatorContext>> |
DEFAULT
Holds the default allocator context shared by all newly created threads
(the default is a
HeapContext instance). |
Modifier | Constructor and Description |
---|---|
protected |
AllocatorContext()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
deactivate()
Deactivates the
allocators belonging to this context
for the current thread. |
protected abstract Allocator |
getAllocator(ObjectFactory factory)
Returns the allocator for the specified factory in this context.
|
static AllocatorContext |
getCurrentAllocatorContext()
Returns the current allocator context.
|
static AllocatorContext |
getDefault()
Returns the default instance (
DEFAULT implementation). |
static <T extends ValueType> |
outerCopy(T value)
Performs a copy of the specified value allocated outside of the
current allocator context.
|
static void |
outerCopy(ValueType[] values)
Performs a copy of the specified values outside of the
current stack context (convenience method).
|
static void |
outerExecute(java.lang.Runnable logic)
Executes the specified logic outside of the current allocator context.
|
enter, enter, enterAction, exit, exit, exitAction, getCurrentContext, getOuter, getOwner, setConcurrentContext, toString
public static final Configurable<java.lang.Class<? extends AllocatorContext>> DEFAULT
HeapContext
instance).
The default allocator context is configurable. For example the following
runs the javolution built-in tests with a PoolContext
as default
(javolution built-in tests loads
their configuration from systems properties)
> java -Djavolution.AllocatorContext.Default=javolution.context.PoolContext -jar javolution.jar time
public static AllocatorContext getCurrentAllocatorContext()
getDefault()
is returned.public static AllocatorContext getDefault()
DEFAULT
implementation).protected abstract Allocator getAllocator(ObjectFactory factory)
factory
- the factory for which the allocator is returned.protected abstract void deactivate()
allocators
belonging to this context
for the current thread. This method is typically called when an inner
allocator context is entered by the current thread, when exiting an
allocator context or when a concurrent executor has completed its task
within this allocator context. Deactivated allocators have no
user
(null
).public static <T extends ValueType> T outerCopy(T value)
value
- the value to be copied.public static void outerCopy(ValueType[] values)
AllocatorContext.outerExecute(new Runnable() {
public void run() {
for (int i = 0; i < values.length; i++) {
values[i] = {ValueType) values[i].copy();
}
}
});
values
- the array whose elements are exported.public static void outerExecute(java.lang.Runnable logic)
logic
- the logic to be executed outside of the current stack
context.Copyright © 2005 - 2007 Javolution.