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

Engine.java

00001 package gov.nasa.arc.ase.jpf;
00002 
00003 import gov.nasa.arc.ase.jpf.jvm.VirtualMachine;
00004 import gov.nasa.arc.ase.util.Debug;
00005 import gov.nasa.arc.ase.util.Options;
00006 import gov.nasa.arc.ase.util.Statistics;
00007 import java.io.*;
00008 import java.net.*;
00009 import java.util.*;
00010 // ifdef DISTRIBUTED
00011 
00012 //#endif DISTRIBUTED
00013 // ifdef RACE
00014 import gov.nasa.arc.ase.jpf.jvm.JVMOptions;
00015 import gov.nasa.arc.ase.jpf.jvm.runtime.RaceWindow;
00016 import gov.nasa.arc.ase.jpf.jvm.runtime.LockOrder;
00017 import gov.nasa.arc.ase.jpf.jvm.runtime.Depend;
00018 //#endif RACE
00019 
00020 public class Engine {
00021   static String VERSION = "JPF 0.1 beta 12 - (C) 2000 RIACS/NASA Ames Research Center";
00022   static public iStore          store;
00023   static public rStatus         status;
00024   static public iVirtualMachine vm;
00025   static public iSearch         search;
00026   static public JPFOptions      options;
00027   static public String          className;
00028   static public Statistics  statistics;
00029   static public boolean         finished = false;
00030   static public boolean         cleanup = false;
00031 // ifdef DISTRIBUTED
00032 
00033 
00034 
00035 
00036 
00037 //#endif DISTRIBUTED
00038 // ifdef BUCHI
00039 
00040 //#endif BUCHI
00041 
00042   static private String[] classes;
00043 
00044 // ifdef DISTRIBUTED
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 //#endif DISTRIBUTED
00131   public static void init(String[] args) {
00132     Debug.println(Debug.ERROR, VERSION);
00133     try {
00134       Debug.println(Debug.ERROR, options.getMainClass().getField("VERSION").get(null));
00135     } catch(NoSuchFieldException e) {
00136     } catch(IllegalAccessException e) {
00137     }
00138     Debug.println(Debug.ERROR);
00139 
00140     classes = options.parse(args);
00141     if(options.version) {
00142       System.exit(0);
00143     }
00144 
00145     if(options.help) {
00146       options.usage();
00147       System.exit(0);
00148     }
00149 
00150     if(classes == null || classes.length != 1) {
00151       Debug.println(Debug.ERROR, "missing class name");
00152       System.exit(1);
00153     }
00154     className = classes[0];
00155 
00156     options.print();
00157 
00158     statistics = new Statistics();
00159     status = new rStatus();
00160 // ifdef DISTRIBUTED
00161 
00162 
00163 
00164 
00165 
00166 //#endif DISTRIBUTED
00167       store = new Store();
00168 // ifdef DISTRIBUTED
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 //#endif DISTRIBUTED
00177 
00178       if (options.verify)
00179     search = new MC();
00180       else
00181     search = new Simulation();
00182 // ifdef DISTRIBUTED
00183 
00184 //#endif DISTRIBUTED
00185   }  
00186   public static void start() {
00187 // ifdef DISTRIBUTED
00188 
00189 //#endif DISTRIBUTED
00190       status.start();
00191 
00192 // ifdef DISTRIBUTED
00193 
00194 //#endif DISTRIBUTED
00195       search.Deadlock();
00196 
00197 // ifdef RACE
00198       if (Depend.debug_on())Depend.print();
00199       if (LockOrder.on()) LockOrder.analyze((VirtualMachine)vm);
00200       if (((JVMOptions)options).post_verify) {
00201     RaceWindow.makeActive();
00202     RaceWindow.print();
00203     ((JVMOptions)Engine.options).race = false;
00204     ((JVMOptions)Engine.options).lock_order = false;
00205     ((JVMOptions)Engine.options).depend = false;
00206     ((JPFOptions)Engine.options).verify = true; 
00207     ((VirtualMachine)vm).reinit(className);
00208     Engine.status = new rStatus();
00209     search = new MC();
00210     search.Deadlock();
00211       }
00212 //#endif RACE
00213 // ifdef DISTRIBUTED
00214 
00215 //#endif DISTRIBUTED
00216 
00217 // ifdef DISTRIBUTED
00218 
00219 
00220 //#endif DISTRIBUTED
00221   }  
00222   static public void stop() {
00223 // ifdef DISTRIBUTED
00224 
00225 //#endif DISTRIBUTED
00226       if(search.getResult()) {
00227     if (Engine.options.bandera) {
00228       Engine.vm.ShowErrorTrail(search.getErrorPath());
00229     } else {
00230       /******************************************************************/
00231       // dump error to file - to be used in path simulation
00232       /******************************************************************/
00233       Engine.vm.getErrorTrail_to_file();
00234 
00235       search.getError().print();
00236       try {
00237         PrintStream out = new PrintStream(new FileOutputStream("error.trail"));
00238         search.getError().print(out);
00239         out.close();
00240       } catch(IOException e) {
00241       }
00242       if(Engine.options.assertions)
00243         Engine.status.print("Assertion broken!");
00244       else
00245         Engine.status.print("The program has a deadlock!");
00246 // ifdef DISTRIBUTED
00247 
00248 
00249 //#endif DISTRIBUTED
00250     }
00251       } else {
00252     if (Engine.options.assertions)
00253       Engine.status.print("The program has no assertion violations!");
00254     else 
00255       Engine.status.print("The program is deadlock free!");
00256       }
00257 // ifdef DISTRIBUTED
00258 
00259 //#endif DISTRIBUTED
00260 
00261     statistics.print();
00262 
00263 // ifdef DISTRIBUTED
00264 
00265 //#endif DISTRIBUTED
00266       if(!Engine.options.bandera)
00267     try {
00268       PrintStream out = new PrintStream(new FileOutputStream(className + ".log"));
00269       options.print(out);
00270       statistics.save(out);
00271       status.results.print(out, "The program is deadlock free");
00272       out.close();
00273     } catch(IOException e) {
00274     }
00275 // ifdef DISTRIBUTED
00276 
00277 //#endif DISTRIBUTED
00278     
00279 // ifdef DISTRIBUTED
00280 
00281 //#endif DISTRIBUTED
00282       status.stop();
00283   }  
00284   public static void threads() {
00285     ThreadGroup g = Thread.currentThread().getThreadGroup();
00286 
00287     while(g.getParent() != null)
00288       g = g.getParent();
00289 
00290     int count = 100;
00291     Thread[] t = new Thread[count];
00292 
00293     int l = g.enumerate(t, true);
00294     
00295     for(int i = 0; i < l; i++)
00296       Debug.println(Debug.WARNING, "#" + i + ": " + t[i]);
00297   }  
00298 }

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