fr.umlv.corosol.component.impl
Class DefaultJHeap

java.lang.Object
  extended by fr.umlv.corosol.component.impl.DefaultJHeap
All Implemented Interfaces:
JHeap, JObject, JVMComponent, JMemory

public class DefaultJHeap
extends java.lang.Object
implements JHeap

The DefaultJHeap class is the default implementation of the JHeap interface. This is the Corosol memory heap where the application object are allocated. In this heap :

Reference value are allocated with a number of bytes determinated by the method sizeofReference of the JReferenceManager interface.

Author:
Christophe Deleray
See Also:
JReferenceManager

Constructor Summary
DefaultJHeap()
          Creates a new DefaultJHeap object.
DefaultJHeap(int size)
          Creates a new DefaultJHeap with the specified number of bytes.
 
Method Summary
 void configure(JVirtualMachine jvm)
          Configures the heap via the specified JVM.
 java.lang.Class getComponentClass()
          Returns the class object describing this component.
 JReferenceManager getReferenceManager()
          Returns the reference manager that collaborates with this heap.
 boolean readBoolean(int index)
          Reads a boolean value starting at the specified position in this heap.
 byte readByte(int index)
          Reads one byte at the specified position in this memory.
 char readChar(int index)
          Reads a char value starting at the specified position in this heap.
 double readDouble(int index)
          Reads a double value starting at the specified position in this heap.
 float readFloat(int index)
          Reads a float value starting at the specified position in this heap.
 int readInt(int index)
          Reads an int value starting at the specified position in this heap.
 long readLong(int index)
          Reads a long value starting at the specified position in this heap.
 JHeapObject readReference(int index)
          Reads a reference value starting at the specified position in this heap and returns the object it referents to.
 short readShort(int index)
          Reads a short value starting at the specified position in this heap.
 void replace(JVMComponent component)
          Replaces the data of this heap by the data of the specified component.
 int size()
          Returns the number of bytes composing this heap.
 int sizeof(JClass type)
          Returns the number of bytes necessary to represent the specified type.
 java.lang.String toString()
          Returns a string representation of the heap.
 void writeBoolean(int index, boolean value)
          Writes the specified boolean value at the specified position in this memory.
 void writeByte(int index, byte value)
          Writes the specified byte value at the specified position in this memory.
 void writeChar(int index, char value)
          Writes the specified char value at the specified position in this memory.
 void writeDouble(int index, double value)
          Writes the specified double at the specified position in this heap.
 void writeFloat(int index, float value)
          Writes the specified float at the specified position in this heap.
 void writeInt(int index, int value)
          Writes the specified int value at the specified position in this heap.
 void writeLong(int index, long value)
          Writes the specified long at the specified position in this heap.
 void writeReference(int index, JHeapObject object)
          Writes the reference of the specified object at the specified position in this heap.
 void writeShort(int index, short value)
          Writes the specified short value at the specified position in this memory.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultJHeap

public DefaultJHeap()
Creates a new DefaultJHeap object.


DefaultJHeap

public DefaultJHeap(int size)
Creates a new DefaultJHeap with the specified number of bytes.

Parameters:
size - the number of bytes of the memory heap
Method Detail

getComponentClass

public java.lang.Class getComponentClass()
Returns the class object describing this component.

Specified by:
getComponentClass in interface JVMComponent

configure

public void configure(JVirtualMachine jvm)
Configures the heap via the specified JVM.

Specified by:
configure in interface JVMComponent
Parameters:
jvm - the Java Virtual Machine

replace

public void replace(JVMComponent component)
Replaces the data of this heap by the data of the specified component. The type of component must be the type of this JHeap component.

Specified by:
replace in interface JVMComponent
Parameters:
component - a component to be used to initialize this heap

readByte

public byte readByte(int index)
Reads one byte at the specified position in this memory.

Specified by:
readByte in interface JMemory
Parameters:
index - index at which the byte is to be read
Returns:
a byte value

readBoolean

public boolean readBoolean(int index)
Reads a boolean value starting at the specified position in this heap.

Specified by:
readBoolean in interface JMemory
Parameters:
index - index at which the boolean value is to be read
Returns:
a boolean value

readShort

public short readShort(int index)
Reads a short value starting at the specified position in this heap.

Specified by:
readShort in interface JMemory
Parameters:
index - index at which the short value is to be read
Returns:
a short value

readChar

public char readChar(int index)
Reads a char value starting at the specified position in this heap.

Specified by:
readChar in interface JMemory
Parameters:
index - index at which the char value is to be read
Returns:
a char value

readInt

public int readInt(int index)
Reads an int value starting at the specified position in this heap.

Specified by:
readInt in interface JMemory
Parameters:
index - index at which the int value is to be read
Returns:
a int value

readFloat

public float readFloat(int index)
Reads a float value starting at the specified position in this heap.

Specified by:
readFloat in interface JMemory
Parameters:
index - index at which the float value is to be read
Returns:
a float value

readLong

public long readLong(int index)
Reads a long value starting at the specified position in this heap.

Specified by:
readLong in interface JMemory
Parameters:
index - index at which the long value is to be read
Returns:
a long value

readDouble

public double readDouble(int index)
Reads a double value starting at the specified position in this heap.

Specified by:
readDouble in interface JMemory
Parameters:
index - index at which the double value is to be read
Returns:
a double value

readReference

public JHeapObject readReference(int index)
Reads a reference value starting at the specified position in this heap and returns the object it referents to.

Specified by:
readReference in interface JMemory
Parameters:
index - index at which the reference value is to be read
Returns:
the object which the reference is read in this heap

writeByte

public void writeByte(int index,
                      byte value)
Writes the specified byte value at the specified position in this memory.

Specified by:
writeByte in interface JMemory
Parameters:
index - index at which the byte value is to be writed
value - the byte value to be writed in this memory

writeBoolean

public void writeBoolean(int index,
                         boolean value)
Writes the specified boolean value at the specified position in this memory.

Specified by:
writeBoolean in interface JMemory
Parameters:
index - index at which the boolean value is to be writed
value - the boolean value to be writed in this memory

writeChar

public void writeChar(int index,
                      char value)
Writes the specified char value at the specified position in this memory.

Specified by:
writeChar in interface JMemory
Parameters:
index - index at which the char value is to be writed
value - the char value to be writed in this memory

writeShort

public void writeShort(int index,
                       short value)
Writes the specified short value at the specified position in this memory.

Specified by:
writeShort in interface JMemory
Parameters:
index - index at which the short value is to be writed
value - the short value to be writed in this memory

writeInt

public void writeInt(int index,
                     int value)
Writes the specified int value at the specified position in this heap.

Specified by:
writeInt in interface JMemory
Parameters:
index - index at which the int value is to be writed
value - the int value to be writed in this memory

writeFloat

public void writeFloat(int index,
                       float value)
Writes the specified float at the specified position in this heap.

Specified by:
writeFloat in interface JMemory
Parameters:
index - index at which the float value is to be writed
value - the float value to be writed in this memory

writeLong

public void writeLong(int index,
                      long value)
Writes the specified long at the specified position in this heap.

Specified by:
writeLong in interface JMemory
Parameters:
index - index at which the long value is to be writed
value - the long value to be writed in this memory

writeDouble

public void writeDouble(int index,
                        double value)
Writes the specified double at the specified position in this heap.

Specified by:
writeDouble in interface JMemory
Parameters:
index - index at which the double value is to be writed
value - the double value to be writed in this memory

writeReference

public void writeReference(int index,
                           JHeapObject object)
Writes the reference of the specified object at the specified position in this heap.

Specified by:
writeReference in interface JMemory
Parameters:
index - index at which the reference value is to be writed
object - the object which reference is to be writed in this heap

size

public int size()
Returns the number of bytes composing this heap.

Specified by:
size in interface JMemory
Returns:
the number of bytes composing this heap

sizeof

public int sizeof(JClass type)
Returns the number of bytes necessary to represent the specified type.

Specified by:
sizeof in interface JMemory
Parameters:
type - a class representing a Java type
Returns:
the number of bytes necessary to represent the specified type

getReferenceManager

public JReferenceManager getReferenceManager()
Returns the reference manager that collaborates with this heap.

Specified by:
getReferenceManager in interface JHeap

toString

public java.lang.String toString()
Returns a string representation of the heap.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the heap