|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectautohit.vm.VM
The abstract base class for virtual machines. A derived class will implement the abstract execute() method to actually run the VM. Also, it would normally use the pause() and resume() methods to control timing (rather than overloading and re-implementing them).
VM bring up sequence is as follows: instantiation with default constructor, call init(), call construct() of subclass, give VM to a Process, process will call attach(), process will call start() to run first instruction, start will call prepare() in the base class, start will call execute() for the first time.
The derived class MAY overload the method prepare() if it has anything it wants to do before the FIRST instruction (and only the first) is executed. For instance, it could add environment variables.
The pause() and resume() methods are not designed to be called by external threads. If you plan to wrap the derived vm in a threaded class, you may want to overload or just not use those methods outside of the vm. Also, these methods only manage state and timing; it is up the he execute() method in the derived class to actually stop execution.
This is not threadsafe, since one one thread should ever own an instance.
NO VM is valid until the init() method is called!!! Every VM needs a loader.
USE THESE SERVICES! Do not make your own ip, for instance! Methods of this class depend upon it.
EPG - Rewrite - 8May03
Field Summary | |
protected java.lang.StringBuffer |
buf
VM Buffer |
VMCore |
core
|
int |
errors
Running error total. |
int |
faults
Running faults total. |
protected int |
ip
Current instruction address/pointer. |
protected java.lang.Object |
left
Left value -- accumulator |
VMLoader |
loader
Controlling environment. |
AutohitLogInjectorWrapper |
myLog
The root logging mechinism. |
VMProcess |
process
|
protected java.lang.Object |
right
Right value |
protected Injector |
rinjector
Injector for response channel. |
java.lang.String |
rootProgram
Name of the root program |
java.lang.String |
sname
Session name. |
protected int |
state
VM state. |
static int |
STATE_ACTIVE_THRESHOLD
|
static int |
STATE_BUILDING
|
static int |
STATE_DONE
|
static int |
STATE_INVALID
State values for the VM. |
static int |
STATE_NEW
|
static int |
STATE_NO_VM
|
static int |
STATE_PAUSED
|
static int |
STATE_RUNNING
|
static int |
TIME_GRAN
Granulatiry for each tick of the VM's clock. |
Constructor Summary | |
VM()
Default Constructor. |
Method Summary | |
void |
attach(VMProcess vmp)
Attach VM to it's owning process. |
abstract void |
construct()
Complete construction. |
abstract void |
destruct()
Destroy. |
void |
die()
Mark the VM for death. |
abstract void |
execute()
Absract method for VM execution. |
protected void |
finalize()
finalizer It will kill the logs last. |
int |
getState()
Get VM state. |
void |
init(Injector responseChannel,
java.lang.String target)
Complete initialization. |
void |
pause()
Pause execution in the VM. |
void |
prepare()
Prepare for execution of the first instruction. |
void |
resume()
Resume execution in the VM. |
void |
setParentCore(VMCore pc)
This will set a parent core. |
void |
start()
Start the VM. |
int |
ticks()
Number of ticks the VM has been running. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int TIME_GRAN
public static final int STATE_INVALID
public static final int STATE_NO_VM
public static final int STATE_BUILDING
public static final int STATE_DONE
public static final int STATE_ACTIVE_THRESHOLD
public static final int STATE_NEW
public static final int STATE_RUNNING
public static final int STATE_PAUSED
protected int state
protected int ip
protected java.lang.Object right
protected java.lang.Object left
protected java.lang.StringBuffer buf
public VMLoader loader
public VMProcess process
public VMCore core
public java.lang.String rootProgram
public java.lang.String sname
public int errors
public int faults
public AutohitLogInjectorWrapper myLog
AutohitLogInjectorWrapper
protected Injector rinjector
Injector
Constructor Detail |
public VM()
Method Detail |
public void setParentCore(VMCore pc)
public void attach(VMProcess vmp) throws java.lang.Exception
org.omg.CORBA.Any
- exceptions it encounters.
TODO fix the id KLUDGE
java.lang.Exception
public void start() throws VMException
Calling this method consecutively will effectively reset the state and timing info. It is probibly a REAL BAD IDEA to call this from the execute method.
It throws any exceptions that are thrown out of execute().
VMException
public int getState()
You may call this from another thread, but it isn't very reliable.
public void pause()
It will only pause if the VM is running.
public void die()
public void resume()
It will only resume if the VM is paused.
public int ticks()
Note that it returns an int rather than a long like system time usually is. This means that the VM timing. This technically could cause some overflow problems, but I doubt a VM would ever run that long.
public abstract void execute() throws VMException
The implimentation of this method should only execute ONE INSTRUCTION. Successive calls would then execute the entire program. If you do not impliment it this way, you are likely to ghost the vm's.
NOTE! An implementing method MUST throw a VMException(VMException.DONE) when it reaches the end of execution.
If the derived-class VM encounters an instruction that it does now support, it should throw a VMException.INVALID_INSTRUCTION.
VMException
VMException
public abstract void construct() throws VMException
VMException
public abstract void destruct() throws VMException
VMException
public final void init(Injector responseChannel, java.lang.String target) throws VMException
responseChannel
- the response channeltarget
- target program in universe namespace
VMException
public void prepare() throws java.lang.Exception
org.omg.CORBA.Any
- exceptions it encounters.
java.lang.Exception
protected void finalize() throws java.lang.Throwable
java.lang.Throwable
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |