javax.realtime
Class MemoryArea

java.lang.Object
  extended byjavax.realtime.MemoryArea
Direct Known Subclasses:
HeapMemory, ImmortalMemory, ImmortalPhysicalMemory, ScopedMemory

public abstract class MemoryArea
extends java.lang.Object

MemoryArea is the abstract base class of all classes dealing with the representation of allocatable memory areas, including the immortal memory area, physical memory and scoped memory areas. This is an abstract class, but no method in this class is abstract. An application should not subclass MemoryArea without complete knowledge of its implementation details.


Field Summary
protected  java.lang.Runnable logic
           
protected  SizeEstimator sizeEstimator
           
protected  long sizeInBytes
           
 
Constructor Summary
protected MemoryArea(long sizeInBytes)
          Create an instance of MemoryArea.
protected MemoryArea(long sizeInBytes, java.lang.Runnable logic)
          Constructor.
protected MemoryArea(SizeEstimator sizeEstimator)
          Create an instance of MemoryArea.
protected MemoryArea(SizeEstimator sizeEstimator, java.lang.Runnable logic)
          Create an instance of MemoryArea.
 
Method Summary
 void enter()
          Associate this memory area with the current schedulable object 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)
          Associate this memory area with the current schedulable object for the duration of the execution of the run() method of the given Runnable.
 void executeInArea(java.lang.Runnable logic)
          Execute the run() method from the logic parameter using this memory area as the current allocation context.
static MemoryArea getMemoryArea(java.lang.Object object)
          Gets the MemoryArea in which the given object is located.
 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 to the total amount of memory currently available for future allocated objects, measured in bytes.
 java.lang.Object newArray(java.lang.Class type, int number)
          Allocate an array of the given type in this memory area.
 java.lang.Object newInstance(java.lang.Class type)
           
 java.lang.Object newInstance(java.lang.reflect.Constructor c, java.lang.Object[] args)
          Allocate an object in this memory area.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sizeInBytes

protected long sizeInBytes

logic

protected java.lang.Runnable logic

sizeEstimator

protected SizeEstimator sizeEstimator
Constructor Detail

MemoryArea

protected MemoryArea(long sizeInBytes)
Create an instance of MemoryArea.

Parameters:
sizeInBytes - The size of MemoryArea to allocate, in bytes.

MemoryArea

protected MemoryArea(long sizeInBytes,
                     java.lang.Runnable logic)
Constructor.

Parameters:
sizeInBytes - The size of MemoryArea to allocate, in bytes.
logic - The run() method of this object will be called whenever enter() is called. If logic is null, this constructor is equivalent to MemoryArea(long size).

MemoryArea

protected MemoryArea(SizeEstimator sizeEstimator)
Create an instance of MemoryArea.

Parameters:
sizeEstimator - A SizeEstimator object which indicates the amount of memory required by this MemoryArea.

MemoryArea

protected MemoryArea(SizeEstimator sizeEstimator,
                     java.lang.Runnable logic)
Create an instance of MemoryArea.

Parameters:
sizeEstimator - A SizeEstimator object which indicates the amount of memory required by this MemoryArea.
logic - The Runnable object whose run() method should be invoked.
Method Detail

enter

public void enter()
           throws ScopedCycleException
Associate this memory area with the current schedulable object for the duration of the execution of the 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

Throws:
ScopedCycleException
ScopedCycleException

enter

public void enter(java.lang.Runnable logic)
           throws ScopedCycleException
Associate this memory area with the current schedulable object for the duration of the execution of the 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
Parameters:
logic - The Runnable object whose run() method should be invoked.
Throws:
ScopedCycleException
ScopedCycleException

executeInArea

public void executeInArea(java.lang.Runnable logic)
                   throws ScopedCycleException
Execute the 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.

Parameters:
logic - The runnable object whose run() method should be executed.
Throws:
ScopedCycleException
ScopedCycleException

getMemoryArea

public static MemoryArea getMemoryArea(java.lang.Object object)
Gets the MemoryArea in which the given object is located.

Parameters:
object -
Returns:
The instance of MemoryArea from which object was allocated.

Not currently implemented


memoryConsumed

public 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. For memory areas (such as heap) where the definition of "used" is imprecise, this returns the best value it can generate in constant time.

Returns:
the memory consumed

Not currently implemented


memoryRemaining

public long memoryRemaining()
An approximation to the total amount of memory currently available for future allocated objects, measured in bytes.

Returns:
the memory remaining

Not currently implemented


newArray

public java.lang.Object newArray(java.lang.Class type,
                                 int number)
                          throws java.lang.IllegalAccessException,
                                 java.lang.InstantiationException
Allocate an array of the given type in this memory area. This method may be concurrently used by multiple threads.

Parameters:
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.
Returns:
A new array of class type, of number elements.
Throws:
IllegalAccessException
InstantiationException

- Not currently implemented

java.lang.IllegalAccessException
java.lang.InstantiationException

newInstance

public java.lang.Object newInstance(java.lang.Class type)
                             throws java.lang.IllegalAccessException,
                                    java.lang.InstantiationException
Parameters:
type -
Returns:
object allocated
Throws:
IllegalAccessException
InstantiationException

- Not currently implemented

java.lang.IllegalAccessException
java.lang.InstantiationException

newInstance

public java.lang.Object newInstance(java.lang.reflect.Constructor c,
                                    java.lang.Object[] args)
                             throws java.lang.IllegalAccessException,
                                    java.lang.InstantiationException
Allocate an object in this memory area. This method may be concurrently used by multiple threads.

Parameters:
c - The constructor for the new instance.
args - An array of arguments to pass to the constructor.
Returns:
A new instance of the object constructed by c.
Throws:
IllegalAccessException
InstantiationException

- Not currently implemented

java.lang.IllegalAccessException
java.lang.InstantiationException