public final class HeapMemory extends PerennialMemory
HeapMemory
class is a singleton object that allows
logic with a non-heap allocation context to allocate objects in the Java
heap.Modifier and Type | Method and Description |
---|---|
void |
enter()
Associates this memory area with the current
schedulable for the duration of the execution of the
run() method of the instance of Runnable given in
the constructor. |
void |
enter(java.lang.Runnable logic)
Associates this memory area with the current
schedulable for the duration of the execution of the
run() method of the given Runnable . |
void |
executeInArea(java.lang.Runnable logic)
Executes the run method from the
logic parameter using heap
as the current allocation context. |
static HeapMemory |
instance()
Returns a reference to the singleton instance of
HeapMemory
representing the Java heap. |
java.lang.Object |
newArray(java.lang.Class<?> type,
int number)
Allocates an array of the given type in this memory area.
|
<T> T |
newInstance(java.lang.Class<T> type)
Allocates an object in this memory area.
|
<T> T |
newInstance(java.lang.reflect.Constructor<T> c,
java.lang.Object[] args)
Allocates an object in this memory area.
|
enter, enter, enter, enter, enter, executeInArea, executeInArea, executeInArea, executeInArea, executeInArea, getMemoryArea, mayHoldReferenceTo, mayHoldReferenceTo, memoryConsumed, memoryRemaining, newArrayInArea, size
public void enter()
run()
method of the instance of Runnable
given in
the constructor.
During this period of execution, this memory area
becomes the default allocation context until another
default allocation context is selected (using enter
,
or executeInArea(java.lang.Runnable)
) or the enter
method exits.enter
in class MemoryArea
IllegalTaskStateException
- when the caller context in
not an instance of Schedulable
.StaticIllegalArgumentException
- when the caller is a schedulable and a null
value
for logic
was supplied when the memory area was
constructed.MemoryAccessError
- when caller is a schedulable which may
not use the heap.public void enter(java.lang.Runnable logic)
run()
method of the given Runnable
.
During this period of execution, this memory area
becomes the default allocation context until another
default allocation context is selected (using enter
,
or executeInArea(java.lang.Runnable)
) or the enter
method exits.enter
in class MemoryArea
logic
- The Runnable object whose run()
method
should be invoked.MemoryAccessError
- when caller is a schedulable which may
not use the heap.IllegalTaskStateException
- when the caller context is not an instance of Schedulable
.StaticIllegalArgumentException
- when the caller is a schedulable and logic
is
null
.public static HeapMemory instance()
HeapMemory
representing the Java heap.
The singleton instance of this class shall be allocated in the
ImmortalMemory
area.HeapMemory
object.public void executeInArea(java.lang.Runnable logic)
logic
parameter using heap
as the current allocation context.
For a schedulable, this saves the current scope
stack and replaces it with one consisting only of the
HeapMemory
instance;
restoring the original scope stack upon completion.executeInArea
in class MemoryArea
logic
- The runnable object whose run()
method should
be executed.StaticIllegalArgumentException
- when logic
is null
.MemoryAccessError
- when caller is a schedulable which may
not use the heap.public java.lang.Object newArray(java.lang.Class<?> type, int number)
newArray
in class MemoryArea
type
- The class of the elements of the new array. To create an array
of a primitive type use a type
such as
Integer.TYPE
(which
would call for an array of the primitive int type.)number
- The number of elements in the new array.MemoryAccessError
- when caller is a schedulable which may
not use the heap.StaticIllegalArgumentException
- when number
is less than zero,
type
is null
,
or type
is java.lang.Void.TYPE
.StaticOutOfMemoryError
- when space in the memory area is exhausted.public <T> T newInstance(java.lang.Class<T> type) throws java.lang.IllegalAccessException, java.lang.InstantiationException
newInstance
in class MemoryArea
T
- The type of the created objecttype
- The class of which to create a new instance.type
.MemoryAccessError
- when caller is a schedulable which may
not use the heap.java.lang.IllegalAccessException
- The class or initializer is inaccessible.StaticIllegalArgumentException
- when type
is null
.java.lang.ExceptionInInitializerError
- when an unexpected exception has
occurred in a static initializer.StaticOutOfMemoryError
- when space in the memory area is exhausted.java.lang.InstantiationException
- when the specified class object could not
be instantiated. Possible causes are it is an interface, it is
abstract, or it is an array.public <T> T newInstance(java.lang.reflect.Constructor<T> c, java.lang.Object[] args) throws java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.reflect.InvocationTargetException
newInstance
in class MemoryArea
T
- The type of the created objectc
- The constructor for the new instance.args
- An array of arguments to pass to the constructor.c
.MemoryAccessError
- when caller is a schedulable which may
not use the heap.java.lang.IllegalAccessException
- when the class or initializer is inaccessible under Java
access control.java.lang.InstantiationException
- when the specified class object could not be
instantiated. Possible causes are it is an interface, it is
abstract,
it is an array.StaticOutOfMemoryError
- when space in the memory area is exhausted.StaticIllegalArgumentException
- when c
is
null
, or the args
array does
not contain the number of arguments required by
c
. A null
value of
args
is treated like an array of length 0.java.lang.reflect.InvocationTargetException
- when the underlying constructor throws an exception.