public abstract class MemoryArea extends Object
MemoryArea
is the abstract base class of all classes dealing with the
representations of allocatable memory areas, including the immortal memory
area, physical memory and scoped memory areas.
In JamaicaVM, application code is not permitted to create instances of user- defined direct subclasses of MemoryArea.
Modifier | Constructor and Description |
---|---|
protected |
MemoryArea(long sizeInBytes)
Equivalent to
MemoryArea(long, Runnable) with the argument
list (size, null) . |
protected |
MemoryArea(long sizeInBytes,
Runnable logic)
Creates an instance of
MemoryArea . |
protected |
MemoryArea(SizeEstimator size)
Equivalent to
MemoryArea(long, Runnable) with the argument
list (size.getEstimate(), null) . |
protected |
MemoryArea(SizeEstimator size,
Runnable logic)
Equivalent to
MemoryArea(long, Runnable) with the argument
list (size.getEstimate(), logic) . |
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. |
boolean |
enter(BooleanSupplier logic)
Same as
enter(Runnable) except that the executed method is
called getAsBoolean() and a boolean is returned. |
double |
enter(DoubleSupplier logic)
Same as
enter(Runnable) except that the executed method is
called getAsDouble() and a double is returned. |
int |
enter(IntSupplier logic)
Same as
enter(Runnable) except that the executed method is
called getAsInt() and an int is returned. |
long |
enter(LongSupplier logic)
Same as
enter(Runnable) except that the executed method is
called getAsLong() and a long is returned. |
void |
enter(Runnable logic)
Associates this memory area with the current schedulable for the duration
of the execution of the
run() method of the given Runnable . |
<T> T |
enter(Supplier<T> logic)
Same as
enter(Runnable) except that the executed method is
called get() and an object is returned. |
boolean |
executeInArea(BooleanSupplier logic)
Executes the
getAsBoolean() method from the logic
parameter using this memory area as the current allocation
context. |
double |
executeInArea(DoubleSupplier logic)
Executes the
getAsDouble() method from the logic parameter
using this memory area as the current allocation context. |
int |
executeInArea(IntSupplier logic)
Executes the
getAsInt() method from the logic parameter
using this memory area as the current allocation context. |
long |
executeInArea(LongSupplier logic)
Executes the
getAsLong() method from the logic parameter
using this memory area as the current allocation context. |
void |
executeInArea(Runnable logic)
Executes the
run() method from the logic parameter
using this memory area as the current allocation context. |
<T> T |
executeInArea(Supplier<T> logic)
Executes the
get() method from the logic parameter
using this memory area as the current allocation context. |
static MemoryArea |
getMemoryArea(Object object)
Gets the
MemoryArea in which the given object is located. |
boolean |
mayHoldReferenceTo()
Determines whether an object
A allocated in the memory area
represented by this can hold a reference to an object
B allocated in the current memory area. |
boolean |
mayHoldReferenceTo(Object value)
Determines whether an object allocated in the memory area
represented by
this can hold a reference to the object
value . |
long |
memoryConsumed()
For memory areas where memory is freed under program control this returns
an exact count, in bytes, of the memory currently used by the system for
the allocated objects.
|
long |
memoryRemaining()
An approximation of the total amount of memory currently
available for future allocated objects, measured in bytes.
|
Object |
newArray(Class<?> type,
int number)
Allocates an array of the given type in this memory area.
|
static Object |
newArrayInArea(Object object,
Class<?> type,
int size)
A helper method for creating an array of type
type in the
memory area containing object. |
<T> T |
newInstance(Class<T> type)
Allocates an object in this memory area.
|
<T> T |
newInstance(Constructor<T> c,
Object[] args)
Allocates a new instance using the given constructor
and passing arguments to this constructor.
|
long |
size()
Queries the size of the memory area.
|
protected MemoryArea(long sizeInBytes)
MemoryArea(long, Runnable)
with the argument
list (size, null)
.StaticIllegalArgumentException
- when size
is less
than zero.OutOfMemoryError
- when there is insufficient memory for
the MemoryArea
object or for
its allocation area in its backing
store.UnsupportedOperationException
- in JamaicaVM when a user-defined
subclass does not know about the
memory area implementation details.sizeInBytes
- The size of MemoryArea
to allocate, in bytes.protected MemoryArea(SizeEstimator size)
MemoryArea(long, Runnable)
with the argument
list (size.getEstimate(), null)
.StaticIllegalArgumentException
- when the size
parameter is null
,
or size.getEstimate()
is negative.OutOfMemoryError
- when there is insufficient memory for
the MemoryArea
object or for
its allocation area in its backing
store.UnsupportedOperationException
- in JamaicaVM when a user-defined
subclass does not know about the
memory area implementation details.size
- A SizeEstimator
object which indicates the amount of
memory required by this MemoryArea
.protected MemoryArea(long sizeInBytes, Runnable logic)
MemoryArea
.StaticIllegalArgumentException
- when the size
parameter is less than zero.OutOfMemoryError
- when there is insufficient memory for
the MemoryArea
object or for
its allocation area in its backing
store.IllegalAssignmentError
- when storing logic
in this
would violate the assignment
rules.UnsupportedOperationException
- in JamaicaVM when a user-defined
subclass does not know about the
memory area implementation details.sizeInBytes
- The size of MemoryArea
to allocate, in bytes.logic
- A runnable, whose run()
method will be called
whenever enter()
is called. When logic
is null
, this constructor is equivalent to
MemoryArea(long size)
.protected MemoryArea(SizeEstimator size, Runnable logic)
MemoryArea(long, Runnable)
with the argument
list (size.getEstimate(), logic)
.StaticIllegalArgumentException
- when size
is null
or size.getEstimate()
is
negative.OutOfMemoryError
- when there is insufficient memory for
the MemoryArea
object or for
its allocation are in its backing
store.IllegalAssignmentError
- when storing logic
in
this
would violate
the assignment rules.UnsupportedOperationException
- in JamaicaVM when a user-defined
subclass does not know about the
memory area implementation details.size
- A SizeEstimator
object which indicates the amount of
memory required by this MemoryArea
.logic
- A runnable, whose run()
method will be called
whenever enter()
is called. When logic
is
null
, this constructor is equivalent to
MemoryArea(SizeEstimator 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.IllegalTaskStateException
- when the caller context is 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.ThrowBoundaryError
- Thrown when the JVM needs to
propagate an exception allocated
in this
scope to (or
through) the memory area of the
caller. Storing a reference to
that exception would cause an
IllegalAssignmentError
, so
the JVM cannot be permitted to
deliver the exception. The ThrowBoundaryError
instance is
preallocated by the VM to avoid
cascading creation of ThrowBoundaryError
.MemoryAccessError
- when caller is a schedulable that
may not use the heap and this
memory area's logic value is
allocated in heap memory.public void enter(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.IllegalTaskStateException
- when the caller context is not an
instance of Schedulable
.StaticIllegalArgumentException
- when the caller is a schedulable
and logic
is
null
.ThrowBoundaryError
- Thrown when the JVM needs to
propagate an exception allocated
in this
scope to (or
through) the memory area of the
caller. Storing a reference to
that exception would cause an
IllegalAssignmentError
, so
the JVM cannot be permitted to
deliver the exception. The ThrowBoundaryError
instance is
preallocated by the VM to avoid
cascading creation of ThrowBoundaryError
.logic
- The Runnable object whose run()
method should be
invoked.public boolean enter(BooleanSupplier logic)
enter(Runnable)
except that the executed method is
called getAsBoolean()
and a boolean is returned.UnsupportedOperationException
- everytime, since this is not
supported yet.logic
- The object whose getAsboolean()
method is to
be executed.getAsBoolean()
method.public double enter(DoubleSupplier logic)
enter(Runnable)
except that the executed method is
called getAsDouble()
and a double is returned.logic
- The object whose getAsDouble()
method is to be
executed.getAsDouble()
method.public int enter(IntSupplier logic)
enter(Runnable)
except that the executed method is
called getAsInt()
and an int is returned.logic
- The object whose getAsInt()
method is to be
executed.getAsInt()
method.public long enter(LongSupplier logic)
enter(Runnable)
except that the executed method is
called getAsLong()
and a long is returned.logic
- The object whose getAsLong()
method is to be
executed.getAsLong()
method.public <T> T enter(Supplier<T> logic)
enter(Runnable)
except that the executed method is
called get()
and an object is returned. The
The get()
method must ensure that the returned object is
allocated outside the area, when the area is not a PerennialMemory.logic
- The object whose get()
method is to be
executed.get()
method.public static MemoryArea getMemoryArea(Object object)
MemoryArea
in which the given object is located.StaticIllegalArgumentException
- when the value of object
is null
.object
- the object, must not be null.MemoryArea
from which object
was
allocated.public long memoryConsumed()
In JamaicaVM, the memoryConsumed() for HeapMemory is amount of allocated (i.e., non-free) memory. It is an upper bound for the amount of reachable memory.
public long memoryRemaining()
In JamaicaVM, memoryRemaining for HeapMemory is the total heap memory minus memoryConsumed().
public Object newArray(Class<?> type, int number) throws StaticIllegalArgumentException, OutOfMemoryError
In JamaicaVM this method is save to be used concurrently by several
threads, it synchronizes on this
.
StaticIllegalArgumentException
- when number
is
less than zero, type
is
null
, or type
is
java.lang.Void.TYPE
.OutOfMemoryError
- when space in the memory area is
exhausted.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.public <T> T newInstance(Class<T> type) throws IllegalAccessException, InstantiationException
IllegalAccessException
- thrown if class or constructor is
inaccessible.StaticIllegalArgumentException
- 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.T
- The type of the created objecttype
- the type of the new object that is to be allocated.public <T> T newInstance(Constructor<T> c, Object[] args) throws IllegalAccessException, InstantiationException, InvocationTargetException, OutOfMemoryError, StaticIllegalArgumentException
IllegalAccessException
- thrown if type is inaccessibleStaticIllegalArgumentException
- 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
T
- The type of the created objectc
- the constructor of the new instanceargs
- the arguments to be passed to the constructorpublic long size()
public void executeInArea(Runnable logic)
run()
method from the logic
parameter
using this memory area as the current allocation context. The
effect of executeInArea
on the scope stack is specified in
the subclasses of MemoryArea
.StaticIllegalArgumentException
- when logic
is null
.logic
- The logic whose run()
method is to be executed.public boolean executeInArea(BooleanSupplier logic)
getAsBoolean()
method from the logic
parameter using this memory area as the current allocation
context. The effect of executeInArea
on the scope stack is
specified in the subclasses of MemoryArea
.StaticIllegalArgumentException
- when logic
is null
.logic
- The logic whose getAsBoolean()
method is to be
executed.getAsBoolean()
method.public double executeInArea(DoubleSupplier logic)
getAsDouble()
method from the logic
parameter
using this memory area as the current allocation context. The
effect of executeInArea
on the scope stack is specified in
the subclasses of MemoryArea
.StaticIllegalArgumentException
- when logic
is null
.logic
- The logic whose getAsDouble()
method is to be
executed.getAsDouble()
method.public int executeInArea(IntSupplier logic)
getAsInt()
method from the logic
parameter
using this memory area as the current allocation context. The
effect of executeInArea
on the scope stack is specified in
the subclasses of MemoryArea
.StaticIllegalArgumentException
- when logic
is null
.logic
- The logic whose getAsInt()
method is to be executed.getAsInt()
method.public long executeInArea(LongSupplier logic)
getAsLong()
method from the logic
parameter
using this memory area as the current allocation context. The
effect of executeInArea
on the scope stack is specified in
the subclasses of MemoryArea
.StaticIllegalArgumentException
- when logic
is null
.logic
- The logic whose getAsLong()
method is to be executed.getAsLong()
method.public <T> T executeInArea(Supplier<T> logic)
get()
method from the logic
parameter
using this memory area as the current allocation context. The
effect of executeInArea
on the scope stack is specified in
the subclasses of MemoryArea
.StaticIllegalArgumentException
- when logic
is null
.logic
- The logic whose get()
method is to be executed.get()
method.public boolean mayHoldReferenceTo()
A
allocated in the memory area
represented by this
can hold a reference to an object
B
allocated in the current memory area.true
only when the current memory area is also an
instance of PerennialMemory
.public boolean mayHoldReferenceTo(Object value)
this
can hold a reference to the object
value
.value
- The object to test.public static Object newArrayInArea(Object object, Class<?> type, int size) throws StaticIllegalArgumentException, OutOfMemoryError
type
in the
memory area containing object.OutOfMemoryError
StaticIllegalArgumentException
UnsupportedOperationException
- everytime, since this is not
supported yet.object
- is the reference for determining the area in which to
allocate the array.type
- is the type of the array element for the returned array.size
- is the size of the array to return.aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2022 aicas GmbH. All Rights Reserved.