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;
00009 private TrailInfo trail_info;
00010
00011
00012
00013 private int[] backtrack_data;
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
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 public SystemState() {
00052 scheduler = new Scheduler();
00053 trail_info = null;
00054
00055
00056
00057 backtrack_data = null;
00058
00059
00060
00061
00062
00063
00064
00065
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 public Object clone(){
00075 try{
00076
00077
00078 SystemState ss = (SystemState)super.clone();
00079
00080
00081 ss.scheduler = (Scheduler)scheduler.clone();
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 return ss;
00106 } catch(CloneNotSupportedException e){
00107 throw new InternalError(e.toString());
00108 }
00109 }
00110 public int[] getBacktrackData() {
00111 return backtrack_data;
00112 }
00113 public Scheduler getScheduler() {
00114 return scheduler;
00115 }
00116 public iTrailInfo getTrailInfo() {
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
00128 public boolean nextSuccessor(iKernelState ks) {
00129 ThreadInfo th;
00130
00131 if (VirtualMachine.options.verify)
00132 if (!VirtualMachine.options.po_reduction)
00133
00134
00135 th = (ThreadInfo)scheduler.locateRunningThread(this, ks);
00136 else
00137
00138 th = (ThreadInfo)scheduler.locateSafeThread(this, ks);
00139 else
00140
00141 th = (ThreadInfo)scheduler.locateRandomRunningThread(ks);
00142
00143
00144
00145
00146
00147
00148 if (th == null) return false;
00149
00150
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
00168 public void setBacktrackData(int[] o) {
00169 backtrack_data = o;
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 public void setScheduler(Scheduler sch) {
00192 scheduler = sch;
00193 }
00194 public void setTrailInfo(int thread, int line, String classname) {
00195
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 }