public abstract class MemoryArea extends Object
Jamaica Real-Time Specification for Java class MemoryArea.
MemoryArea provides the abstract base class for all allocation environments.
In JamaicaVM, application code is not permitted to create instances of user-defined direct subclasses of MemoryArea.
Modifier and Type | Field and Description |
---|---|
protected static Object |
memoryAreaHeapLock
Lock to protect alloc() and free() from concurrent execution.
|
Modifier | Constructor and Description |
---|---|
protected |
MemoryArea(long sizeInBytes)
Constructor for a memory area of given size.
|
protected |
MemoryArea(long sizeInBytes,
Runnable logic)
Constructor for a memory area that of given size in bytes and
sets a logic.
|
protected |
MemoryArea(SizeEstimator size)
Constructor for a memory area that gets its size from a
SizeEstimator.
|
protected |
MemoryArea(SizeEstimator size,
Runnable logic)
Constructor for a memory area that of given size from a
SizeEstimator and sets a logic.
|
Modifier and Type | Method and Description |
---|---|
protected void |
clearMemory() |
protected void |
createStackedMemory()
Create a new child StackedMemory for this memory area.
|
void |
enter()
enter enters this memory area and executes the logic that was
passed to this memory area's constructor.
|
void |
enter(Runnable logic)
enter enters this memory area and executes the given logic.
|
void |
executeInArea(Runnable logic)
executeInArea executes a code sequence given as logic in this
memory area.
|
protected void |
freeStacked()
frees a StackedMemory child previously created with
createStackedMemory() |
static MemoryArea |
getMemoryArea(Object object)
getMemoryArea returns the memory area a given object was
allocated in.
|
long |
memoryConsumed()
memoryConsumed returns the number of bytes of memory of this
memory area that have been consumed.
|
protected boolean |
memoryNeedsToBeCleared() |
protected boolean |
memoryNeedsToBeFreed() |
long |
memoryRemaining()
memoryRemaining returns the number of available bytes left in
this memory area.
|
Object |
newArray(Class<?> type,
int number)
Allocate a new array with number elements in this memory
area.
|
Object |
newInstance(Class<?> type)
allocate a new instance of class type in this memory area.
|
Object |
newInstance(Constructor<?> c,
Object[] args)
newInstance allocates a new instance using the given constructor
and passing arguments to this constructor.
|
long |
size()
size returns the size of this memory area in bytes.
|
protected static Object memoryAreaHeapLock
protected MemoryArea(long sizeInBytes)
IllegalArgumentException
- if sizeInBytes < 0 or this is
called by a user-defined subclass that does not know about the
memory area implementation details.OutOfMemoryError
- if there is not sufficient memory
available for the new MemoryArea.sizeInBytes
- size of the area in bytes.protected MemoryArea(SizeEstimator size)
IllegalArgumentException
- if size is null or this is
called by a user-defined subclass that does not know about the
memory area implementation details.OutOfMemoryError
- if there is not sufficient memory
available for the new MemoryArea.size
- the requested size.protected MemoryArea(long sizeInBytes, Runnable logic)
IllegalArgumentException
- if sizeInBytes < 0 or this is
called by a user-defined subclass that does not know about the
memory area implementation details.OutOfMemoryError
- if there is not sufficient memory
available for the new MemoryArea.sizeInBytes
- size of the area in bytes.logic
- the logic to be associated with this memory
area. May be null not to set a default logic.protected MemoryArea(SizeEstimator size, Runnable logic)
IllegalArgumentException
- if size is null or this is
called by a user-defined subclass that does not know about the
memory area implementation details.OutOfMemoryError
- if there is not sufficient memory
available for the new MemoryArea.size
- size of the area.logic
- the logic to be associated with this memory area.protected void createStackedMemory()
protected void freeStacked()
createStackedMemory()
protected boolean memoryNeedsToBeFreed()
protected boolean memoryNeedsToBeCleared()
protected void clearMemory()
public void enter()
IllegalArgumentException
- if no logic was provided to the
constructor or the logic that was provided was null.public void enter(Runnable logic)
IllegalArgumentException
- if logic is null.logic
- the code to be executed in this memory area.public static MemoryArea getMemoryArea(Object object)
object
- the object, must not be null.public long memoryConsumed()
public long memoryRemaining()
public Object newArray(Class<?> type, int number) throws IllegalArgumentException, OutOfMemoryError, InaccessibleAreaException
IllegalArgumentException
- iff number is negative, type is
null or type is Void.TYPE.OutOfMemoryError
- iff the space in this memory area
is exhaustedInaccessibleAreaException
- iff this memory area is not
accessible, i.e. not on the current memory area stack.type
- the array typenumber
- the number of elements of the array.public Object newInstance(Class<?> type) throws IllegalAccessException, InstantiationException
IllegalAccessException
- thrown if class or constructor is
inaccessible.IllegalArgumentException
- iff type is null.InstantiationException
- if object could not be
instantiated (due to type being abstract or an interface or the
constructor caused an exception)OutOfMemoryError
- iff the space in this memory area is exhaustedExceptionInInitializerError
- iff initialization of class
type caused an exception.InaccessibleAreaException
- iff this memory area is not
accessible, i.e. not on the memory area stack.type
- the type of the new object that is to be allocated.public Object newInstance(Constructor<?> c, Object[] args) throws IllegalAccessException, InstantiationException, InvocationTargetException
IllegalAccessException
- thrown if type is inaccessibleIllegalArgumentException
- iff c is null or args does not
contain the number of arguments required by c (args may be null
if the arguments list is empty).InstantiationException
- if object could not be
instantiated (due to type being abstract or an interface or the
constructor caused an exception)OutOfMemoryError
- iff the space in this memory area is exhaustedExceptionInInitializerError
- iff initialization of class
type caused an exception.InaccessibleAreaException
- iff this memory area is not
accessible, i.e. not on the memory area stack.InvocationTargetException
c
- the constructor of the new instanceargs
- the arguments to be passed to the constructorpublic long size()
public void executeInArea(Runnable logic) throws InaccessibleAreaException
InaccessibleAreaException
logic
- the logic whose run method is to be executed in this
memory area.aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2016 aicas GmbH. All Rights Reserved.