Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SystemState.java

00001 package gov.nasa.arc.ase.jpf.jvm;
00002 
00003 import gov.nasa.arc.ase.jpf.*;
00004 import gov.nasa.arc.ase.util.Debug;
00005 import java.util.Stack;
00006 
00007 public class SystemState implements iSystemState,Cloneable{
00008   private Scheduler   scheduler;    // The scheduler for the transitions
00009   private TrailInfo   trail_info;   // The information for the trail
00010 // ifdef NO_FASTBACKTRACK
00011 
00012 //#else NO_FASTBACKTRACK
00013   private int[]       backtrack_data;   // The compact version of the state
00014   public static int counter = 0;
00015 
00016   private int threadref = -1;
00017   private int depth = -1;
00018   private MethodInfo currentMethod = null;
00019   private int line = -1;
00020 
00021   private boolean intermediate = false;
00022   public int atomicLevel;
00023 
00024 // ifdef REFERENCE_COUNT
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 //#endif REFERENCE_COUNT
00041 //#endif NO_FASTBACKTRACK
00042   
00043 // ifdef REFERENCE_COUNT
00044 
00045 //#endif REFERENCE_COUNT
00046 
00047 // ifdef DISTRIBUTED
00048 
00049 //#endif DISTRIBUTED
00050 
00051   public SystemState() {
00052     scheduler = new Scheduler();
00053     trail_info = null;
00054 // ifdef NO_FASTBACKTRACK
00055 
00056 //#else NO_FASTBACKTRACK
00057     backtrack_data = null;
00058 //#endif NO_FASTBACKTRACK
00059 
00060 // ifdef DISTRIBUTED
00061 
00062 
00063 
00064 //#endif DISTRIBUTED
00065 
00066   }  
00067 // ifdef DEBUG
00068 
00069 
00070 
00071 
00072 //#endif DEBUG
00073 
00074   public Object clone(){
00075     try{
00076       // First basic cloning, copies all the fields values
00077       // including references
00078       SystemState ss = (SystemState)super.clone();
00079 
00080       // The scheduler has its own clone method
00081       ss.scheduler    = (Scheduler)scheduler.clone();
00082 
00083 // ifdef NO_COMPRESSION
00084 
00085 //#endif NO_COMPRESSION
00086 
00087       // The thead info are set again or never changed
00088       // so they can be scared
00089       // implicit: ss.thread_info = thread_info;
00090 
00091       // The backtrack data need to be shared for saving memory
00092       // Actually they should be coming from the hash table
00093       // implicit: ss.backtrack_data = backtrack_data
00094 
00095 // ifdef DISTRIBUTED
00096 
00097 
00098 
00099 
00100 
00101 
00102 //#endif DISTRIBUTED
00103 
00104       // Returns the newly created object
00105       return ss;
00106     } catch(CloneNotSupportedException e){
00107       throw new InternalError(e.toString());
00108     }
00109   }  
00110   public int[] getBacktrackData() { // gets the backtrack information
00111     return backtrack_data;
00112   }  
00113   public Scheduler getScheduler() { // returns the value of the scheduler
00114     return scheduler;
00115   }  
00116   public iTrailInfo getTrailInfo() { // return the trail information
00117     return trail_info;
00118   }  
00119   public boolean handleIntermediate(KernelState ks) {
00120     if(intermediate && threadref != getScheduler().getCurrentThread()) {
00121       Engine.vm.Backtrack();
00122       return true;
00123     }
00124 
00125     return false;
00126   }  
00127   //** May be moved to KernelState with SystemState a parameter **//
00128   public boolean nextSuccessor(iKernelState ks) { // generate the next successor
00129     ThreadInfo th; // Thread that is going to be executed
00130 
00131     if (VirtualMachine.options.verify) // verification vs simulation
00132       if (!VirtualMachine.options.po_reduction) 
00133     // With the partial order reduction the next thread
00134     // to be executed must also be a safe thread.
00135     th = (ThreadInfo)scheduler.locateRunningThread(this, ks);
00136       else 
00137     // Just picks the next thread that needs to be executed
00138     th = (ThreadInfo)scheduler.locateSafeThread(this, ks);
00139     else 
00140       // Random simulation just picks a thread at random
00141       th = (ThreadInfo)scheduler.locateRandomRunningThread(ks);
00142 
00143 // ifdef DEBUG
00144 
00145 //#endif DEBUG
00146 
00147     // there are no executable threads
00148     if (th == null) return false;
00149 
00150     // executes the next instruction for that thread
00151     intermediate = true;
00152     while(!th.executeStep(this, (KernelState)ks))
00153       ((VirtualMachine)Engine.vm).pushSystemState();
00154     intermediate = false;
00155 
00156     return true;
00157   }  
00158   public void restoreAtomicData(KernelState ks) {
00159     ((ThreadInfo)ks.getThreadInfo(threadref)).setAtomicData(depth, currentMethod, line);
00160   }  
00161   public void saveAtomicData(int t, int d, MethodInfo m, int l) {
00162     threadref = t;
00163     depth = d;
00164     currentMethod = m;
00165     line = l;
00166   }  
00167 // ifdef NO_FASTBACKTRACK
00168   public void setBacktrackData(int[] o) { // sets the backtrack information
00169     backtrack_data = o;
00170   }  
00171 //#endif NO_FASTBACKTRACK
00172 
00173 // ifdef DISTRIBUTED
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 //#endif DISTRIBUTED
00190 
00191   public void setScheduler(Scheduler sch) {
00192     scheduler = sch;
00193   }  
00194   public void setTrailInfo(int thread, int line, String classname) {
00195     // sets the value of the current instruction for the trail
00196     trail_info = new TrailInfo(thread, scheduler.getCurrentRandom(), line,
00197                    classname);
00198   }  
00199   public void setTrailInfo(TrailInfo ti) {
00200     trail_info = ti;
00201   }  
00202   public void updateExtra(iSystemState ss) {
00203     SystemState s = (SystemState)ss;
00204 
00205     threadref = s.threadref; s.threadref = -1;
00206     depth = s.depth; s.depth = -1;
00207     currentMethod = s.currentMethod; s.currentMethod = null;
00208     line = s.line; s.line = -1;
00209   }  
00210 }

Generated at Thu Feb 7 06:56:07 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001