00001 package gov.nasa.arc.ase.jpf.jvm;
00002
00003 import gov.nasa.arc.ase.jpf.Engine;
00004 import gov.nasa.arc.ase.jpf.Path;
00005 import gov.nasa.arc.ase.util.Debug;
00006 import java.io.Serializable;
00007
00008 public class JVMPath implements Path {
00009 private JVMPathEntry[] error_moves;
00010 private int[] moves;
00011 private int ups;
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 JVMPath(int s) {
00027 moves = new int[s];
00028 error_moves = new JVMPathEntry[s];
00029 }
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 JVMPath(int s, int u) {
00048 moves = new int[s];
00049 ups = u;
00050 }
00051 public Path append(Path p) {
00052 JVMPath pp = (JVMPath)p;
00053 int[] m1 = moves;
00054 int[] m2 = pp.moves;
00055 int l1 = m1.length;
00056 int l2 = m2.length;
00057 int u1 = ups;
00058 int u2 = pp.ups;
00059 int l, u, d;
00060
00061 if(l1 > u2) {
00062 d = l1 - u2;
00063 u = u1;
00064 } else {
00065 d = 0;
00066 u = u1 + u2 - l1;
00067 }
00068 l = d + l2;
00069
00070
00071
00072
00073
00074
00075
00076
00077 JVMPath ppp = new JVMPath(l, u);
00078
00079
00080 if(d != 0)
00081 System.arraycopy(m1, 0, ppp.moves, 0, d);
00082 System.arraycopy(m2, 0, ppp.moves, d, l2);
00083
00084 return ppp;
00085 }
00086 public boolean equals(Object o) {
00087 JVMPath p = (JVMPath)o;
00088
00089 if(p.ups != ups) return false;
00090 if(p.moves.length != moves.length) return false;
00091
00092 for(int i = 0; i < moves.length; i++)
00093 if(p.moves[i] != moves[i]) return false;
00094
00095 return true;
00096 }
00097 public static Path fromStoringData(Object o) {
00098 int[] data = (int[])o;
00099
00100
00101
00102 int length = data.length-1;
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 JVMPath p = new JVMPath(length, data[0]);
00124
00125 System.arraycopy(data, 1, p.moves, 0, length);
00126
00127 return p;
00128 }
00129
00130
00131 int get(int index) {
00132 return moves[index];
00133 }
00134 JVMPathEntry getErrorMove(int index) {
00135 return error_moves[index];
00136 }
00137 public Object getStoringData() {
00138 int length = moves.length;
00139
00140
00141
00142
00143
00144
00145
00146 int l = length + 1;
00147
00148
00149
00150
00151
00152 int[] data = new int[l];
00153
00154 data[0] = ups;
00155 System.arraycopy(moves, 0, data, 1, length);
00156
00157
00158
00159
00160
00161
00162
00163 return data;
00164 }
00165 public Path relativeTo(Path p) {
00166 int[] m1 = moves;
00167 int[] m2 = ((JVMPath)p).moves;
00168 int l1 = m1.length;
00169 int l2 = m2.length;
00170 int l = Math.min(l1, l2);
00171
00172 int common = 0;
00173 for(int idx = 0; idx < l; idx++)
00174 if(m1[idx] == m2[idx])
00175 common++;
00176 else
00177 break;
00178
00179
00180
00181
00182
00183
00184
00185
00186 JVMPath ppp = new JVMPath(l1 - common, l2 - common);
00187
00188
00189 for(int idx = common; idx < l1; idx++)
00190 ppp.moves[idx - common] = moves[idx];
00191
00192 return ppp;
00193 }
00194 void set(int index, int value) {
00195 moves[index] = value;
00196 }
00197 void setErrorMove(int index,
00198 int line,
00199 String cname,
00200 int thread,
00201 int random) {
00202 error_moves[index] = new JVMPathEntry(line,
00203 cname,
00204 thread,
00205 random);
00206 }
00207 public void setUps(int value) {
00208 ups = value;
00209 }
00210 public int size() {
00211 return moves.length;
00212 }
00213 public String toString() {
00214 StringBuffer sb = new StringBuffer("( ");
00215
00216 sb.append(ups);
00217 sb.append(", [");
00218
00219 int l = moves.length;
00220 for(int i = 0; i < l; i++) {
00221 if(i != 0) sb.append(", ");
00222 sb.append(moves[i]);
00223 }
00224
00225 sb.append("] )");
00226
00227 return sb.toString();
00228 }
00229 public int upCount() {
00230 return ups;
00231 }
00232 }