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

JavaLangThreadReflection.java

00001 package gov.nasa.arc.ase.jpf.jvm.reflection;
00002 
00003 import gov.nasa.arc.ase.jpf.*;
00004 import gov.nasa.arc.ase.jpf.jvm.*;
00005 import gov.nasa.arc.ase.jpf.jvm.reflection.*;
00006 import de.fub.bytecode.generic.InstructionHandle;
00007 // ifdef RACE
00008 import gov.nasa.arc.ase.jpf.jvm.runtime.*;
00009 //#endif RACE
00010 
00011 public class JavaLangThreadReflection extends Reflection {
00012 //#endif RACE
00013 // ifdef RACE
00014   private void DEPEND_executeStart(ThreadInfo father,ThreadInfo son) {
00015     if (Depend.on()) {
00016       Depend.addFork(father,son);
00017     }
00018   }  
00019   public InstructionHandle executeMethod(MethodInfo mi, boolean atomic) {
00020     String name = mi.getFullName();
00021 
00022     // this is not native but we overload it
00023     if(name.equals("java.lang.Thread.<init>()V")) {
00024       ThreadInfo t = (ThreadInfo)ks.findThread(new ObjRef(objref));
00025       t.setTarget(-1);
00026 
00027       return exit();
00028     }
00029 
00030     // this is not native but we overload it
00031     if(name.equals("java.lang.Thread.<init>(Ljava/lang/Runnable;)V")) {
00032       int target = th.getLocalVariable(1);
00033 
00034       ThreadInfo t = (ThreadInfo)ks.findThread(new ObjRef(objref));
00035       t.setTarget(target);
00036 // ifdef REFERENCE_COUNT
00037 
00038 //#endif REFERENCE_COUNT
00039 
00040       return exit();
00041     }
00042 
00043     // this is not native but we overload it
00044     if(name.equals("java.lang.Thread.stop()V")) {
00045       //** warning: should maybe check if the thread can be stopped **//
00046       ThreadInfo t = (ThreadInfo)ks.findThread(new ObjRef(objref));
00047       t.setStatus(STATUS.STOPPED);
00048 
00049       return exit();
00050     }
00051 
00052     if(name.equals("java.lang.Thread.countStackFrames()I")) {
00053       // throws a runtime exception for now
00054       throw new NativeMethodException("java.lang.Thread.countStackFrames()I");
00055     }
00056 
00057     if(name.equals("java.lang.Thread.interrupt0()V")) {
00058       // throws a runtime exception for now
00059       throw new NativeMethodException("java.lang.Thread.interrupt0()V");
00060     }
00061 
00062     if(name.equals("java.lang.Thread.isAlive()Z")) {
00063       // throws a runtime exception for now
00064       throw new NativeMethodException("java.lang.Thread.isAlive()Z");
00065     }
00066 
00067     if(name.equals("java.lang.Thread.isInterrupted(Z)Z")) {
00068       // throws a runtime exception for now
00069       throw new NativeMethodException("java.lang.Thread.isInterrupted(Z)Z");
00070     }
00071 
00072     if(name.equals("java.lang.Thread.resume0()V")) {
00073       // throws a runtime exception for now
00074       throw new NativeMethodException("java.lang.Thread.resume0()V");
00075     }
00076 
00077     if(name.equals("java.lang.Thread.setPriority0(I)V")) {
00078       // throws a runtime exception for now
00079       throw new NativeMethodException("java.lang.Thread.setPriority0(I)V");
00080     }
00081 
00082     if(name.equals("java.lang.Thread.start()V")) {
00083       ThreadInfo t = (ThreadInfo)ks.findThread(new ObjRef(objref));
00084       int target = t.getTarget();
00085 
00086       if (target == -1) target = objref;
00087 
00088       ClassInfo ci = da.getClass(target);
00089       MethodInfo run = ci.getMethodInfo("run()V");
00090       if (run.getMethodGen().isSynchronized()) {
00091     if (!da.monitorLock(objref, th))
00092       return repeat();
00093       }
00094 
00095       t.setStatus(STATUS.RUNNING);
00096       t.newFrame(run);
00097       t.setLocalVariable(0, target);
00098 // ifdef MARK_N_SWEEP
00099       t.setLocalVariableRef(0);
00100 //#endif MARK_N_SWEEP
00101 
00102 // ifdef RACE
00103       DEPEND_executeStart(th, t);
00104 //#endif RACE
00105 
00106       return exit();
00107     }
00108 
00109     if(name.equals("java.lang.Thread.stop0(Ljava/lang/Object;)V")) {
00110       // throws a runtime exception for now
00111       throw new NativeMethodException("java.lang.Thread.stop0(Ljava/lang/Object;)V");
00112     }
00113 
00114     if(name.equals("java.lang.Thread.suspend0()V")) {
00115       // throws a runtime exception for now
00116       throw new NativeMethodException("java.lang.Thread.suspend0()V");
00117     }
00118 
00119     return super.executeMethod(mi, atomic);
00120   }  
00121   public InstructionHandle executeStaticMethod(MethodInfo mi, boolean atomic) {
00122     String name = mi.getFullName();
00123 
00124     if(name.equals("java.lang.Thread.currentThread()Ljava/lang/Thread;")) {
00125       // throws a runtime exception for now
00126       throw new NativeMethodException("java.lang.Thread.currentThread()Ljava/lang/Thread;");
00127     }
00128 
00129     if(name.equals("java.lang.Thread.registerNatives()V")) {
00130       // throws a runtime exception for now
00131       throw new NativeMethodException("java.lang.Thread.registerNatives()V");
00132     }
00133 
00134     if(name.equals("java.lang.Thread.sleep(J)V")) {
00135       // throws a runtime exception for now
00136       throw new NativeMethodException("java.lang.Thread.sleep(J)V");
00137     }
00138 
00139     if(name.equals("java.lang.Thread.yield()V")) {
00140       // throws a runtime exception for now
00141       throw new NativeMethodException("java.lang.Thread.yield()V");
00142     }
00143 
00144     return super.executeStaticMethod(mi, atomic);
00145   }  
00146   public boolean isMethodDeterministic(MethodInfo mi) {
00147     String name = mi.getFullName();
00148 
00149     if(name.equals("java.lang.Thread.countStackFrames()I")) {
00150       // throws a runtime exception for now
00151       throw new NativeMethodException("java.lang.Thread.countStackFrames()I");
00152     }
00153 
00154     if(name.equals("java.lang.Thread.interrupt0()V")) {
00155       // throws a runtime exception for now
00156       throw new NativeMethodException("java.lang.Thread.interrupt0()V");
00157     }
00158 
00159     if(name.equals("java.lang.Thread.isAlive()Z")) {
00160       // throws a runtime exception for now
00161       throw new NativeMethodException("java.lang.Thread.isAlive()Z");
00162     }
00163 
00164     if(name.equals("java.lang.Thread.isInterrupted(Z)Z")) {
00165       // throws a runtime exception for now
00166       throw new NativeMethodException("java.lang.Thread.isInterrupted(Z)Z");
00167     }
00168 
00169     if(name.equals("java.lang.Thread.resume0()V")) {
00170       // throws a runtime exception for now
00171       throw new NativeMethodException("java.lang.Thread.resume0()V");
00172     }
00173 
00174     if(name.equals("java.lang.Thread.setPriority0(I)V")) {
00175       // throws a runtime exception for now
00176       throw new NativeMethodException("java.lang.Thread.setPriority0(I)V");
00177     }
00178 
00179     if(name.equals("java.lang.Thread.stop0(Ljava/lang/Object;)V")) {
00180       // throws a runtime exception for now
00181       throw new NativeMethodException("java.lang.Thread.stop0(Ljava/lang/Object;)V");
00182     }
00183 
00184     if(name.equals("java.lang.Thread.suspend0()V")) {
00185       // throws a runtime exception for now
00186       throw new NativeMethodException("java.lang.Thread.suspend0()V");
00187     }
00188 
00189     return super.isMethodDeterministic(mi);
00190   }  
00191   public boolean isMethodExecutable(MethodInfo mi) {
00192     String name = mi.getFullName();
00193 
00194     // this is not native but we overload it
00195     if(name.equals("java.lang.Thread.<init>"))
00196       return true;
00197 
00198     if(name.equals("java.lang.Thread.countStackFrames()I")) {
00199       // throws a runtime exception for now
00200       throw new NativeMethodException("java.lang.Thread.countStackFrames()I");
00201     }
00202 
00203     if(name.equals("java.lang.Thread.interrupt0()V")) {
00204       // throws a runtime exception for now
00205       throw new NativeMethodException("java.lang.Thread.interrupt0()V");
00206     }
00207 
00208     if(name.equals("java.lang.Thread.isAlive()Z")) {
00209       // throws a runtime exception for now
00210       throw new NativeMethodException("java.lang.Thread.isAlive()Z");
00211     }
00212 
00213     if(name.equals("java.lang.Thread.isInterrupted(Z)Z")) {
00214       // throws a runtime exception for now
00215       throw new NativeMethodException("java.lang.Thread.isInterrupted(Z)Z");
00216     }
00217 
00218     if(name.equals("java.lang.Thread.resume0()V")) {
00219       // throws a runtime exception for now
00220       throw new NativeMethodException("java.lang.Thread.resume0()V");
00221     }
00222 
00223     if(name.equals("java.lang.Thread.setPriority0(I)V")) {
00224       // throws a runtime exception for now
00225       throw new NativeMethodException("java.lang.Thread.setPriority0(I)V");
00226     }
00227 
00228     if(name.equals("java.lang.Thread.start()V")) {
00229       ThreadInfo t = (ThreadInfo)ks.findThread(new ObjRef(objref));
00230       int target = t.getTarget();
00231 
00232       if (target == -1) target = objref;
00233 
00234       ClassInfo ci = da.getClass(target);
00235       MethodInfo run = ci.getMethodInfo("run()V");
00236       if (run.getMethodGen().isSynchronized())
00237     return da.monitorCheckLock(objref, th);
00238 
00239       return true;
00240     }
00241 
00242     if(name.equals("java.lang.Thread.stop0(Ljava/lang/Object;)V")) {
00243       // throws a runtime exception for now
00244       throw new NativeMethodException("java.lang.Thread.stop0(Ljava/lang/Object;)V");
00245     }
00246 
00247     if(name.equals("java.lang.Thread.suspend0()V")) {
00248       // throws a runtime exception for now
00249       throw new NativeMethodException("java.lang.Thread.suspend0()V");
00250     }
00251 
00252     return super.isMethodExecutable(mi);
00253   }  
00254   public boolean isStaticMethodDeterministic(MethodInfo mi) {
00255     String name = mi.getFullName();
00256 
00257     if(name.equals("java.lang.Thread.currentThread()Ljava/lang/Thread;")) {
00258       // throws a runtime exception for now
00259       throw new NativeMethodException("java.lang.Thread.currentThread()Ljava/lang/Thread;");
00260     }
00261 
00262     if(name.equals("java.lang.Thread.registerNatives()V")) {
00263       // throws a runtime exception for now
00264       throw new NativeMethodException("java.lang.Thread.registerNatives()V");
00265     }
00266 
00267     if(name.equals("java.lang.Thread.sleep(J)V")) {
00268       // throws a runtime exception for now
00269       throw new NativeMethodException("java.lang.Thread.sleep(J)V");
00270     }
00271 
00272     if(name.equals("java.lang.Thread.yield()V")) {
00273       // throws a runtime exception for now
00274       throw new NativeMethodException("java.lang.Thread.yield()V");
00275     }
00276 
00277     return super.isStaticMethodDeterministic(mi);
00278   }  
00279   public boolean isStaticMethodExecutable(MethodInfo mi) {
00280     String name = mi.getFullName();
00281 
00282     if(name.equals("java.lang.Thread.currentThread()Ljava/lang/Thread;")) {
00283       // throws a runtime exception for now
00284       throw new NativeMethodException("java.lang.Thread.currentThread()Ljava/lang/Thread;");
00285     }
00286 
00287     if(name.equals("java.lang.Thread.registerNatives()V")) {
00288       // throws a runtime exception for now
00289       throw new NativeMethodException("java.lang.Thread.registerNatives()V");
00290     }
00291 
00292     if(name.equals("java.lang.Thread.sleep(J)V")) {
00293       // throws a runtime exception for now
00294       throw new NativeMethodException("java.lang.Thread.sleep(J)V");
00295     }
00296 
00297     if(name.equals("java.lang.Thread.yield()V")) {
00298       // throws a runtime exception for now
00299       throw new NativeMethodException("java.lang.Thread.yield()V");
00300     }
00301 
00302     return super.isStaticMethodExecutable(mi);
00303   }  
00304 }

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