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

JVMPath.java

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 // ifdef DISTRIBUTED
00013 // ifdef CHILDREN_LOOKAHEAD
00014 
00015 
00016 
00017 //#endif CHILDREN_LOOKAHEAD
00018 //#endif DISTRIBUTED
00019 // ifdef DISTRIBUTED
00020 // ifdef CHILDREN_LOOKAHEAD
00021 
00022 //#endif CHILDREN_LOOKAHEAD
00023 //#endif DISTRIBUTED
00024 
00025   // used for executing error-trails
00026   JVMPath(int s) {
00027     moves = new int[s];
00028     error_moves = new JVMPathEntry[s];
00029   }  
00030 // ifdef DISTRIBUTED
00031 // ifdef CHILDREN_LOOKAHEAD
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 //#else CHILDREN_LOOKAHEAD
00041 
00042 
00043 
00044 
00045 //#endif CHILDREN_LOOKAHEAD
00046 //#else DISTRIBUTED
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 // ifdef DISTRIBUTED
00071 // ifdef CHILDREN_LOOKAHEAD
00072 
00073 //#else CHILDREN_LOOKAHEAD
00074 
00075 //#endif CHILDREN_LOOKAHEAD
00076 //#else DISTRIBUTED
00077     JVMPath ppp = new JVMPath(l, u);
00078 //#endif DISTRIBUTED
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 // ifdef DISTRIBUTED
00100 
00101 //#endif DISTRIBUTED
00102     int length = data.length-1;
00103 // ifdef DISTRIBUTED
00104 // ifdef CHILDREN_LOOKAHEAD
00105 
00106 
00107 
00108 
00109 
00110 
00111 //#endif CHILDREN_LOOKAHEAD
00112 //#endif DISTRIBUTED
00113     
00114 // ifdef DISTRIBUTED
00115 // ifdef CHILDREN_LOOKAHEAD
00116 
00117 
00118 
00119 //#else CHILDREN_LOOKAHEAD
00120 
00121 //#endif CHILDREN_LOOKAHEAD
00122 //#else DISTRIBUTED
00123     JVMPath p = new JVMPath(length, data[0]);
00124 //#endif DISTRIBUTED
00125     System.arraycopy(data, 1, p.moves, 0, length);
00126 
00127     return p;
00128   }  
00129 //#endif DISTRIBUTED
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 // ifdef DISTRIBUTED
00140 // ifdef CHILDREN_LOOKAHEAD
00141 
00142 
00143 
00144 //#endif CHILDREN_LOOKAHEAD
00145 //#endif DISTRIBUTED
00146     int l = length + 1;
00147 // ifdef DISTRIBUTED
00148 // ifdef CHILDREN_LOOKAHEAD
00149 
00150 //#endif CHILDREN_LOOKAHEAD
00151 //#endif DISTRIBUTED
00152     int[] data = new int[l];
00153 
00154     data[0] = ups;
00155     System.arraycopy(moves, 0, data, 1, length);
00156 // ifdef DISTRIBUTED
00157 // ifdef CHILDREN_LOOKAHEAD
00158 
00159 
00160 //#endif CHILDREN_LOOKAHEAD
00161 //#endif DISTRIBUTED
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 // ifdef DISTRIBUTED
00180 // ifdef CHILDREN_LOOKAHEAD
00181 
00182 //#else CHILDREN_LOOKAHEAD
00183 
00184 //#endif CHILDREN_LOOKAHEAD
00185 //#else DISTRIBUTED
00186     JVMPath ppp = new JVMPath(l1 - common, l2 - common);
00187 //#endif DISTRIBUTED
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 }

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