javax.realtime
Class MemoryArea

java.lang.Object
  |
  +--javax.realtime.MemoryArea
Direct Known Subclasses:
HeapMemory, ImmortalMemory, ImmortalPhysicalMemory, NullMemoryArea, ScopedMemory

public abstract class MemoryArea
extends java.lang.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.


Field Summary
(package private)  boolean constant
          Indicates whether this memoryArea refers to a constant or not.
(package private)  boolean heap
          Indicates whether this is a HeapMemory.
protected  int id
          Every MemoryArea has a unique ID.
protected  java.lang.Runnable logic
          The run() method of this object is called whenever enter() is called.
protected  long memoryConsumed
          The size of the consumed memory
(package private) static java.lang.Class[] nullClassArr
           
protected  boolean nullMem
          Indicates whether this is a NullMemoryArea.
(package private) static java.lang.Object[] nullObjArr
           
private static int num
          This is used to create the unique ID.
(package private)  boolean scoped
          Indicates whether this is a ScopedMemory.
(package private)  javax.realtime.MemoryArea shadow
          The shadow of this.
protected  long size
          The size of this MemoryArea.
 
Constructor Summary
protected MemoryArea(long sizeInBytes)
          Create an instance of MemoryArea.
protected MemoryArea(long minimum, long maximum)
           
protected MemoryArea(long sizeInBytes, java.lang.Runnable logic)
          Create an instance of MemoryArea.
protected MemoryArea(javax.realtime.SizeEstimator size)
          Create an instance of MemoryArea.
protected MemoryArea(javax.realtime.SizeEstimator size, java.lang.Runnable logic)
          Create an instance of MemoryArea.
 
Method Summary
 void bless(java.lang.Object obj)
           
 void checkAccess(java.lang.Object obj)
          Check to see if this object can be accessed from this MemoryArea
 void checkNewInstance(javax.realtime.MemoryArea mem)
          Check access restrictions for a newInstance
 void enter()
          Associate this memory area to the current real-time thread for the duration of the execution of the run() method of the java.lang.Runnable passed at construction time.
 void enter(java.lang.Runnable logic)
          Associate this memory area to the current real-time thread for the duration of the execution of the run() method of the java.lang.Runnable passed at construction time.
protected  void enterMemBlock(javax.realtime.RealtimeThread rt, javax.realtime.MemAreaStack mas)
           
 void executeInArea(java.lang.Runnable logic)
          Execute the run() method from the logic parameter using this memory area as the current allocation context.
protected  void exitMemBlock(javax.realtime.RealtimeThread rt, javax.realtime.MemAreaStack mas)
           
static javax.realtime.MemoryArea getMemoryArea(java.lang.Object object)
          Gets the MemoryArea in which the given object is located.
 javax.realtime.MemoryArea getOuterScope()
          Get the outerScope of this MemoryArea, for non-ScopedMemory's, this defaults to null.
protected abstract  void initNative(long sizeInBytes)
           
 long memoryConsumed()
          An exact count, in bytes, of the all 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 newArray(java.lang.Class type, int[] dimensions)
          Create a new array, allocated out of this MemoryArea.
protected  java.lang.Object newArray(javax.realtime.RealtimeThread rt, java.lang.Class type, int number)
           
protected  java.lang.Object newArray(javax.realtime.RealtimeThread rt, java.lang.Class type, int[] dimensions)
           
 java.lang.Object newInstance(java.lang.Class type)
          Allocate an object in this memory area.
 java.lang.Object newInstance(java.lang.Class type, java.lang.Class[] parameterTypes, java.lang.Object[] parameters)
          Allocate an object in this memory area.
 java.lang.Object newInstance(java.lang.reflect.Constructor c, java.lang.Object[] args)
          Allocate an object in this memory area.
protected  java.lang.Object newInstance(javax.realtime.RealtimeThread rt, java.lang.reflect.Constructor constructor, java.lang.Object[] parameters)
           
protected  void postSetup()
           
protected  void preSetup()
           
protected  void registerFinal()
           
protected  javax.realtime.MemoryArea shadow()
           
 long size()
          Query the size of the memory area.
(package private) static void startMem(javax.realtime.MemoryArea mem)
          Explicitly unsafe way to get by without polluting the previous scope with a Runnable
(package private) static void stopMem()
           
protected  void throwIllegalAssignmentError(java.lang.Object obj, javax.realtime.MemoryArea ma)
           
 java.lang.String toString()
          Output a helpful string describing this MemoryArea.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

size

protected long size
The size of this MemoryArea.


memoryConsumed

protected long memoryConsumed
The size of the consumed memory


scoped

boolean scoped
Indicates whether this is a ScopedMemory.


heap

boolean heap
Indicates whether this is a HeapMemory.


nullMem

protected boolean nullMem
Indicates whether this is a NullMemoryArea.


id

protected int id
Every MemoryArea has a unique ID.


logic

protected java.lang.Runnable logic
The run() method of this object is called whenever enter() is called.


num

private static int num
This is used to create the unique ID.


constant

boolean constant
Indicates whether this memoryArea refers to a constant or not. This is set by the compiler.


shadow

javax.realtime.MemoryArea shadow
The shadow of this.


nullClassArr

static java.lang.Class[] nullClassArr

nullObjArr

static java.lang.Object[] nullObjArr
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)
Create an instance of MemoryArea.

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

MemoryArea

protected MemoryArea(javax.realtime.SizeEstimator size)
Create an instance of MemoryArea.

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

MemoryArea

protected MemoryArea(javax.realtime.SizeEstimator size,
                     java.lang.Runnable logic)
Create an instance of MemoryArea.

Parameters:
size - A SizeEstimator object which indicates the amount of memory required by this MemoryArea.
logic - The run() method of this object will be called whenever enter() is called.

MemoryArea

protected MemoryArea(long minimum,
                     long maximum)
Method Detail

initNative

protected abstract void initNative(long sizeInBytes)

preSetup

protected void preSetup()

postSetup

protected void postSetup()

enter

public void enter()
Associate this memory area to the current real-time thread for the duration of the execution of the run() method of the java.lang.Runnable passed at construction time. During this bound period of execution, all objects are allocated from the memory area until another one takes effect, or the enter() method is exited. A runtime exception is thrown if this method is called from thread other than a RealtimeThread or NoHeapRealtimeThrea.

Throws:
java.lang.IllegalArgumentException - Thrown if no Runnable was passed in the constructor.

enter

public void enter(java.lang.Runnable logic)
Associate this memory area to the current real-time thread for the duration of the execution of the run() method of the java.lang.Runnable passed at construction time. During this bound period of execution, all objects are allocated from the memory area until another one takes effect, or the enter() method is exited. A runtime exception is thrown if this method is called from thread other than a RealtimeThread or NoHeapRealtimeThrea.

Parameters:
logic - The Runnable object whose run() method should be invoked.

executeInArea

public void executeInArea(java.lang.Runnable logic)
                   throws InaccessibleAreaException
Execute the run() method from the logic parameter using this memory area as the current allocation context. If the memory area is a scoped memory type, this method behaves as if it had moved the allocation context up the scope stack to the occurrence of the memory area. If the memory area is heap or immortal memory, this method behaves as if the run() method were running in that memory type with an empty scope stack.

Parameters:
logic - The runnable object whose run() method should be executed.
Throws:
java.lang.IllegalStateException - A non-realtime thread attempted to enter the memory area.
InaccessibleAreaException - The memory area is not in the thread's scope stack.

getMemoryArea

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

Returns:
The current instance of MemoryArea of the object.

memoryConsumed

public long memoryConsumed()
An exact count, in bytes, of the all of the memory currently used by the system for the allocated objects.

Returns:
The amount of memory consumed.

memoryRemaining

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

Returns:
The amount of remaining memory in bytes.

newArray

protected java.lang.Object newArray(javax.realtime.RealtimeThread rt,
                                    java.lang.Class type,
                                    int number)

newArray

protected java.lang.Object newArray(javax.realtime.RealtimeThread rt,
                                    java.lang.Class type,
                                    int[] dimensions)

newArray

public java.lang.Object newArray(java.lang.Class type,
                                 int number)
                          throws java.lang.IllegalAccessException,
                                 java.lang.InstantiationException,
                                 java.lang.OutOfMemoryError
Allocate an array of the given type in this memory area.

Parameters:
type - The class of the elements of the new array.
number - The number of elements in the new array.
Throws:
java.lang.IllegalAccessException - The class or initializer is inaccessible.
java.lang.InstantiationException - The array cannot be instantiated.
java.lang.OutOfMemoryError - Space in the memory area is exhaused.

newInstance

public java.lang.Object newInstance(java.lang.Class type)
                             throws java.lang.IllegalAccessException,
                                    java.lang.InstantiationException,
                                    java.lang.OutOfMemoryError
Allocate an object in this memory area.

Parameters:
type - The class of which to create a new instance.
Throws:
java.lang.IllegalAccessException - The class or initializer is inaccessible.
java.lang.InstantiationException - The specified class object could not be instantiated. Possible causes are: it is an interface; it is abstract; it is an array, or an exception was thrown by the constructor.
java.lang.OutOfMemoryError - Space in the memory area is exhaused.

newInstance

public java.lang.Object newInstance(java.lang.Class type,
                                    java.lang.Class[] parameterTypes,
                                    java.lang.Object[] parameters)
                             throws java.lang.IllegalAccessException,
                                    java.lang.InstantiationException,
                                    java.lang.OutOfMemoryError
Allocate an object in this memory area.

java.lang.IllegalAccessException
java.lang.InstantiationException
java.lang.OutOfMemoryError

newInstance

public java.lang.Object newInstance(java.lang.reflect.Constructor c,
                                    java.lang.Object[] args)
                             throws java.lang.IllegalAccessException,
                                    java.lang.InstantiationException,
                                    java.lang.OutOfMemoryError
Allocate an object in this memory area.

Throws:
java.lang.IllegalAccessException - The class or initializer is inaccessible.
java.lang.InstantiationException - The specified class object could not be instantianted. Possible causes are: it is an interface, it is abstract, it is an array, or an exception was thrown by the constructor.
java.lang.OutOfMemoryError - Space in the memory area is exhaused.

size

public long size()
Query the size of the memory area. The returned value is the current size. Current size may be larger than initial size for those areas that are allowed to grow.


newInstance

protected java.lang.Object newInstance(javax.realtime.RealtimeThread rt,
                                       java.lang.reflect.Constructor constructor,
                                       java.lang.Object[] parameters)
                                throws java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException

startMem

static void startMem(javax.realtime.MemoryArea mem)
Explicitly unsafe way to get by without polluting the previous scope with a Runnable


stopMem

static void stopMem()

enterMemBlock

protected void enterMemBlock(javax.realtime.RealtimeThread rt,
                             javax.realtime.MemAreaStack mas)

exitMemBlock

protected void exitMemBlock(javax.realtime.RealtimeThread rt,
                            javax.realtime.MemAreaStack mas)

throwIllegalAssignmentError

protected void throwIllegalAssignmentError(java.lang.Object obj,
                                           javax.realtime.MemoryArea ma)
                                    throws IllegalAssignmentError
IllegalAssignmentError

shadow

protected javax.realtime.MemoryArea shadow()

registerFinal

protected void registerFinal()

bless

public void bless(java.lang.Object obj)

newArray

public java.lang.Object newArray(java.lang.Class type,
                                 int[] dimensions)
                          throws java.lang.IllegalAccessException,
                                 java.lang.OutOfMemoryError
Create a new array, allocated out of this MemoryArea.

java.lang.IllegalAccessException
java.lang.OutOfMemoryError

checkAccess

public void checkAccess(java.lang.Object obj)
Check to see if this object can be accessed from this MemoryArea


checkNewInstance

public void checkNewInstance(javax.realtime.MemoryArea mem)
Check access restrictions for a newInstance


getOuterScope

public javax.realtime.MemoryArea getOuterScope()
Get the outerScope of this MemoryArea, for non-ScopedMemory's, this defaults to null.


toString

public java.lang.String toString()
Output a helpful string describing this MemoryArea.

Overrides:
toString in class java.lang.Object