edu.ksu.cis.projects.bogor.module.state
Class DefaultState

java.lang.Object
  extended by edu.ksu.cis.projects.bogor.module.state.DefaultState
All Implemented Interfaces:
IState, Disposable, Serializable

public class DefaultState
extends Object
implements IState

The default implementation of IState.

Version:
CVS $Revision: 1.19 $ $Date: 2005/04/18 23:12:00 $
Author:
Robby , Matt Hoosier
See Also:
Serialized Form

Field Summary
protected  IValueArray globalValues
          Holds the global values.
protected  IStateFactory sf
          Holds the state factory of this state.
protected  SymbolTable st
          Holds the symbol table for the BIR model.
protected  IntObjectTable<IntList> threadLocationStackMap
          Holds the mapping of thread id (int) to its location stack (TIntArrayList).
protected  IntIntTable threadLockCountMap
          Holds the mapping of thread id (int) to its lock count (int) when waiting.
protected  IntObjectTable<DefaultThreadStore> threadStoreMap
          Holds the mapping of thread id (int) to thread store (DefaultThreadStore).
protected  IntObjectTable<IntList> threadTransformationIndexStackMap
          Holds the mapping of thread id (int) to its transformation index stack (TIntArrayList).
 
Constructor Summary
protected DefaultState()
          Private constructor for cloning purposes.
protected DefaultState(SymbolTable st, IStateFactory sf, IValueArray globalValues)
          Default constructor.
 
Method Summary
protected  boolean checkCurrentInvokeTransformation(int threadId, int transformationIndex)
           
 IState clone(Map<Object,Object> cloneMap)
          Deep clone this state.
 void dispose()
          Remove references.
 void enterFunction(int threadId, IValueArray localValues, int beginLocationDesc, int transformationIndex)
          Enters a function for a particular thread.
 IValueArray exitFunction(int threadId)
          Exits a function for particular thread.
 IValueArray exitThread(int threadId)
          Kills a thread.
 int getGlobalCount()
          Gets the number of globals.
 IValue getGlobalValue(int globalIndex)
          Gets a global's value.
 IValueArray getGlobalValues()
          Gets all global values.
 int getLocalCount(int threadId)
          Gets the number of locals for a particular thread.
 IValue getLocalValue(int threadId, int localIndex)
          Gets a local's value.
 IValueArray getLocalValues(int threadId)
          Gets local values for a particular thread.
 IValueArray[] getLocalValuesStack(int threadId)
          Gets local values stack for a particular thread.
 int getLocation(int threadId)
          Gets a thread's location.
 int[] getLocationStack(int threadId)
          Gets the location stack for a particular thread.
 int getLockCount(int threadId)
          Gets the lock count for a particular thread when waiting.
 int getStackHeight(int threadId)
          Gets the stack height for a particular thread.
 int[] getThreadIds()
          Gets all the thread ids in this state.
 int getTransformationIndex(int threadId)
          Gets a thread's transformation index.
 int[] getTransformationIndexStack(int threadId)
          Gets the transformation index stack for a particular thread.
 boolean isThreadAlive(int threadId)
          Determines whether a thread is still alive.
 void newThread(int threadId, IValueArray localValues, int beginLocationDesc)
          Creates a new thread.
 int removeLockCount(int threadId)
          Removes the lock count for a particular thread when waiting.
 void setGlobalValue(int globalIndex, IValue value)
          Sets a global's value.
 void setLocalValue(int threadId, int localIndex, IValue value)
          Sets a local's value.
 void setLocation(int threadId, int locationDesc, int transformationIndex)
          Sets a thread's location.
 void storeLockCount(int threadId, int lockCount)
          Stores the lock count for a particular thread when waiting.
 void validate(IBogorConfiguration bc)
          Validates this state wrt.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

st

protected transient SymbolTable st
Holds the symbol table for the BIR model. Non-null.


sf

protected transient IStateFactory sf
Holds the state factory of this state. Non-null.


threadLockCountMap

protected IntIntTable threadLockCountMap
Holds the mapping of thread id (int) to its lock count (int) when waiting. Non-null.


threadLocationStackMap

protected IntObjectTable<IntList> threadLocationStackMap
Holds the mapping of thread id (int) to its location stack (TIntArrayList). Non-null.


threadTransformationIndexStackMap

protected IntObjectTable<IntList> threadTransformationIndexStackMap
Holds the mapping of thread id (int) to its transformation index stack (TIntArrayList). Non-null.


threadStoreMap

protected IntObjectTable<DefaultThreadStore> threadStoreMap
Holds the mapping of thread id (int) to thread store (DefaultThreadStore). Non-null.


globalValues

protected IValueArray globalValues
Holds the global values. Non-null.

Constructor Detail

DefaultState

protected DefaultState(SymbolTable st,
                       IStateFactory sf,
                       IValueArray globalValues)
Default constructor.

Parameters:
sf - The state factory of this state. Must be non-null.
globalValues - The global values for this state. Must be non-null.

DefaultState

protected DefaultState()
Private constructor for cloning purposes.

Method Detail

getGlobalCount

public int getGlobalCount()
Description copied from interface: IState
Gets the number of globals.

Specified by:
getGlobalCount in interface IState
Returns:
The number of globals in this state.

setGlobalValue

public void setGlobalValue(int globalIndex,
                           IValue value)
Description copied from interface: IState
Sets a global's value.

Specified by:
setGlobalValue in interface IState
Parameters:
globalIndex - The index of the global. Must be at least zero and at most less than the number of globals.
value - The new value of the global. Must be non-null.
See Also:
SymbolTable.getGlobalIndexTable()

getGlobalValue

public IValue getGlobalValue(int globalIndex)
Description copied from interface: IState
Gets a global's value.

Specified by:
getGlobalValue in interface IState
Parameters:
globalIndex - The index of the global. Must be at least zero and at most less than the number of globals.
Returns:
The global's value.
See Also:
SymbolTable.getGlobalIndexTable()

getGlobalValues

public IValueArray getGlobalValues()
Description copied from interface: IState
Gets all global values.

Specified by:
getGlobalValues in interface IState
Returns:
All global values. Non-null.

getLocalCount

public int getLocalCount(int threadId)
Description copied from interface: IState
Gets the number of locals for a particular thread.

Specified by:
getLocalCount in interface IState
Parameters:
threadId - The thread id that is associated to the local. The thread id must be a valid thread id in this state.
Returns:
The number of locals for the given thread.

setLocalValue

public void setLocalValue(int threadId,
                          int localIndex,
                          IValue value)
Description copied from interface: IState
Sets a local's value.

Specified by:
setLocalValue in interface IState
Parameters:
threadId - The thread id that is associated to the local. The thread id must be a valid thread id in this state.
localIndex - The index of the local. Must be at least zero and at most less than the number of locals.
value - The new value of the local. Must be non-null.
See Also:
FSMSymbolTable.getLocalIndexTable()

getLocalValue

public IValue getLocalValue(int threadId,
                            int localIndex)
Description copied from interface: IState
Gets a local's value.

Specified by:
getLocalValue in interface IState
Parameters:
threadId - The thread id that is associated to the local. The thread id must be a valid thread id in this state.
localIndex - The index of the local. Must be at least zero and at most less than the number of locals.
Returns:
The local's value.
See Also:
FSMSymbolTable.getLocalIndexTable()

getLocalValues

public IValueArray getLocalValues(int threadId)
Description copied from interface: IState
Gets local values for a particular thread.

Specified by:
getLocalValues in interface IState
Parameters:
threadId - The thread id that is associated to the locals. The thread id must be a valid thread id in this state.
Returns:
The local values for the given thread. Non-null.

getLocalValuesStack

public IValueArray[] getLocalValuesStack(int threadId)
Description copied from interface: IState
Gets local values stack for a particular thread.

Specified by:
getLocalValuesStack in interface IState
Parameters:
threadId - The thread id that is associated to the locals. The thread id must be a valid thread id in this state.
Returns:
The local values stack for the given thread. Non-null. Each element is non-null. Top most (current) local values is at index zero.

setLocation

public void setLocation(int threadId,
                        int locationDesc,
                        int transformationIndex)
Description copied from interface: IState
Sets a thread's location.

Specified by:
setLocation in interface IState
Parameters:
threadId - The thread id that its location to be set. The thread id must be a valid thread id in this state.
locationDesc - The new location of the thread.
transformationIndex - The transformation index causing the move. It must be a transformation index of the old location desc.
See Also:
FSMSymbolTable.getLocationDescTable()

getLocation

public int getLocation(int threadId)
Description copied from interface: IState
Gets a thread's location.

Specified by:
getLocation in interface IState
Parameters:
threadId - The thread id that its location is queried. The thread id must be a valid thread id in this state.
Returns:
The thread's location.
See Also:
FSMSymbolTable.getLocationDescTable()

getLocationStack

public int[] getLocationStack(int threadId)
Description copied from interface: IState
Gets the location stack for a particular thread.

Specified by:
getLocationStack in interface IState
Parameters:
threadId - The thread id that is associated to the location stack. The thread id must be a valid thread id in this state.
Returns:
The location stack for the given thread. Non-null. Top most (current) location is at index zero.

getLockCount

public int getLockCount(int threadId)
Description copied from interface: IState
Gets the lock count for a particular thread when waiting.

Specified by:
getLockCount in interface IState
Parameters:
threadId - The thread id that is (must be) waiting.
Returns:
The number of locks operations. At least zero.

getStackHeight

public int getStackHeight(int threadId)
Description copied from interface: IState
Gets the stack height for a particular thread.

Specified by:
getStackHeight in interface IState
Parameters:
threadId - The thread id that is associated to the stack. The thread id must be a valid thread id in this state.
Returns:
The stack height for the given thread. At least one.

isThreadAlive

public boolean isThreadAlive(int threadId)
Description copied from interface: IState
Determines whether a thread is still alive.

Specified by:
isThreadAlive in interface IState
Parameters:
threadId - The thread to be determined.
Returns:
True, if the given thread is still alive. False, otherwise.

getThreadIds

public int[] getThreadIds()
Description copied from interface: IState
Gets all the thread ids in this state.

Specified by:
getThreadIds in interface IState
Returns:
The sorted array containing all the thread ids in this state. Non-null.

getTransformationIndex

public int getTransformationIndex(int threadId)
Description copied from interface: IState
Gets a thread's transformation index.

Specified by:
getTransformationIndex in interface IState
Parameters:
threadId - The thread id that its transformation index is queried. The thread id must be a valid thread id in this state.
Returns:
The thread's transformation index.

getTransformationIndexStack

public int[] getTransformationIndexStack(int threadId)
Description copied from interface: IState
Gets the transformation index stack for a particular thread.

Specified by:
getTransformationIndexStack in interface IState
Parameters:
threadId - The thread id that is associated to the transformation index stack. The thread id must be a valid thread id in this state.
Returns:
The transformation index stack for the given thread. Non-null. Top most (current) transformation index is at index zero.

clone

public IState clone(Map<Object,Object> cloneMap)
Description copied from interface: IState
Deep clone this state.

Specified by:
clone in interface IState
Parameters:
cloneMap - Original values (IValue) to their clones ( IValue) mapping. The clone map to solve circular references in values.
Returns:
The clone of this state. Non-null.

dispose

public void dispose()
Description copied from interface: Disposable
Remove references. Once called, avoid using this object.

Specified by:
dispose in interface Disposable

enterFunction

public void enterFunction(int threadId,
                          IValueArray localValues,
                          int beginLocationDesc,
                          int transformationIndex)
Description copied from interface: IState
Enters a function for a particular thread. The current thread location is pushed to a stack and set the thread's current location to the function's initial location. The current thread local values are also pushed to a stack in a similar manner.

Specified by:
enterFunction in interface IState
Parameters:
threadId - The thread id of the thread that enters a function. The thread id must be a valid thread id in this state.
localValues - The local values of the function to be entered. Must be non-null.
beginLocationDesc - The function initial location.
See Also:
FSMSymbolTable.getLocationDescTable()

exitFunction

public IValueArray exitFunction(int threadId)
Description copied from interface: IState
Exits a function for particular thread. The current thread location is popped out from a stack and set the thread's location to the exit location. The current thread local values are also popped from a stack in a similar manner. The thread id no longer exists in this state.

Specified by:
exitFunction in interface IState
Parameters:
threadId - The thread id of the thread that enters a function. The thread id must be a valid thread id in this state.
Returns:
The local values of the exited function. Non-null.
See Also:
FSMSymbolTable.getLocationDescTable()

exitThread

public IValueArray exitThread(int threadId)
Description copied from interface: IState
Kills a thread. The thread with the given thread id will be assigned the dead status. All mappings of the thread id to its local values and its location are removed from the state.

Specified by:
exitThread in interface IState
Parameters:
threadId - The thread id to be killed. The thread id must be a valid thread id in this state.
Returns:
The local values of the exited thread. Non-null.

newThread

public void newThread(int threadId,
                      IValueArray localValues,
                      int beginLocationDesc)
Description copied from interface: IState
Creates a new thread. A new thread with the given thread id will be created in the state with status new. A mapping from thread id to the thread's local values and the thread's location are also located.

Specified by:
newThread in interface IState
Parameters:
threadId - The thread id for the new thread. The thread id must not already be in this state.
localValues - The local values of the new thread. Must be non-null.
beginLocationDesc - The initial location of the new thread.
See Also:
FSMSymbolTable.getLocationDescTable()

removeLockCount

public int removeLockCount(int threadId)
Description copied from interface: IState
Removes the lock count for a particular thread when waiting.

Specified by:
removeLockCount in interface IState
Parameters:
threadId - The thread id that is (must be) waiting.
Returns:
The number of locks operations. At least zero.

storeLockCount

public void storeLockCount(int threadId,
                           int lockCount)
Description copied from interface: IState
Stores the lock count for a particular thread when waiting.

Specified by:
storeLockCount in interface IState
Parameters:
threadId - The thread id that is waiting. The thread id must be a valid thread id in this state.
lockCount - The number of locks operations. At least zero.

validate

public void validate(IBogorConfiguration bc)
Description copied from interface: IState
Validates this state wrt. a configuration.

Specified by:
validate in interface IState
Parameters:
bc - The Bogor configuration to validate to.

checkCurrentInvokeTransformation

protected boolean checkCurrentInvokeTransformation(int threadId,
                                                   int transformationIndex)