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.bytecode.Instruction;
00006 //#ifdef RACE
00007 
00008 //#endif RACE
00009 
00010 public class JavaLangThreadReflection extends Reflection {
00011   public Instruction executeMethod(MethodInfo mi) {
00012     String name = mi.getFullName();
00013 
00014     // this is not native but we overload it
00015     if(name.equals("<init>()V")) {
00016       ks.tl.locate(objref).setTarget(-1);
00017 
00018       return exit();
00019     }
00020 
00021     // this is not native but we overload it
00022     if(name.equals("<init>(Ljava/lang/Runnable;)V")) {
00023       int target = getIntArgument(1);
00024 
00025       ks.tl.locate(objref).setTarget(target);
00026 //#ifdef REFERENCE_COUNT
00027 
00028 //#endif REFERENCE_COUNT
00029 
00030       return exit();
00031     }
00032 
00033     // this is not native but we overload it
00034     if(name.equals("stop()V")) {
00035       //** warning: should maybe check if the thread can be stopped **//
00036       ks.tl.locate(objref).setStatus(ThreadInfo.STOPPED);
00037 
00038       return exit();
00039     }
00040 
00041     if(name.equals("countStackFrames()I")) {
00042       return exit(ks.tl.locate(objref).countStackFrames());
00043     }
00044 
00045     if(name.equals("interrupt0()V")) {
00046       da.get(objref).interrupt();
00047 
00048       return exit();
00049     }
00050 
00051     if(name.equals("isAlive()Z")) {
00052       return exit(ks.tl.locate(objref).isAlive());
00053     }
00054 
00055     if(name.equals("isInterrupted(Z)Z")) {
00056       // throws a runtime exception for now
00057       throw new NativeMethodException("isInterrupted(Z)Z");
00058     }
00059 
00060     if(name.equals("resume0()V")) {
00061       // throws a runtime exception for now
00062       throw new NativeMethodException("resume0()V");
00063     }
00064 
00065     if(name.equals("setPriority0(I)V")) {
00066       // throws a runtime exception for now
00067       throw new NativeMethodException("setPriority0(I)V");
00068     }
00069 
00070     if(name.equals("start()V")) {
00071       ThreadInfo newThread = ks.tl.locate(objref);
00072       int target = newThread.getTarget();
00073 
00074       if (target == -1) target = objref;
00075 
00076       da.get(target).lock(newThread);
00077 
00078       ClassInfo ci = da.get(target).getClassInfo();
00079 
00080       MethodInfo run = ci.getDynamicMethod("run()V");
00081 
00082       newThread.setStatus(iThreadInfo.RUNNING);
00083       newThread.newFrame(run);
00084       newThread.setLocalVariable(0, target, true);
00085 
00086 //#ifdef RACE
00087 
00088 
00089 //#endif RACE
00090 
00091       return exit();
00092     }
00093 
00094     if(name.equals("stop0(Ljava/lang/Object;)V")) {
00095       // throws a runtime exception for now
00096       throw new NativeMethodException("stop0(Ljava/lang/Object;)V");
00097     }
00098 
00099     if(name.equals("suspend0()V")) {
00100       // throws a runtime exception for now
00101       throw new NativeMethodException("suspend0()V");
00102     }
00103 
00104     return super.executeMethod(mi);
00105   }  
00106   public Instruction executeStaticMethod(MethodInfo mi) {
00107     String name = mi.getFullName();
00108 
00109     if(name.equals("currentThread()Ljava/lang/Thread;")) {
00110       return exitReference(th.getObjectReference());
00111     }
00112 
00113     if(name.equals("registerNatives()V")) {
00114       return exit();
00115     }
00116 
00117     if(name.equals("sleep(J)V")) {
00118       return exit();
00119     }
00120 
00121     if(name.equals("yield()V")) {
00122       return exit();
00123     }
00124 
00125     return super.executeStaticMethod(mi);
00126   }  
00127   public boolean isMethodDeterministic(MethodInfo mi) {
00128     String name = mi.getFullName();
00129 
00130     //if(name.equals("isAlive()Z")) {
00131       // throws a runtime exception for now
00132     // throw new NativeMethodException("isAlive()Z");
00133     //}
00134 
00135     if(name.equals("isInterrupted(Z)Z")) {
00136       // throws a runtime exception for now
00137       throw new NativeMethodException("isInterrupted(Z)Z");
00138     }
00139 
00140     if(name.equals("resume0()V")) {
00141       // throws a runtime exception for now
00142       throw new NativeMethodException("resume0()V");
00143     }
00144 
00145     if(name.equals("setPriority0(I)V")) {
00146       // throws a runtime exception for now
00147       throw new NativeMethodException("setPriority0(I)V");
00148     }
00149 
00150     if(name.equals("stop0(Ljava/lang/Object;)V")) {
00151       // throws a runtime exception for now
00152       throw new NativeMethodException("stop0(Ljava/lang/Object;)V");
00153     }
00154 
00155     if(name.equals("suspend0()V")) {
00156       // throws a runtime exception for now
00157       throw new NativeMethodException("suspend0()V");
00158     }
00159 
00160     return super.isMethodDeterministic(mi);
00161   }  
00162   public boolean isMethodExecutable(MethodInfo mi) {
00163     String name = mi.getFullName();
00164 
00165     // this is not native but we overload it
00166     if(name.equals("<init>"))
00167       return true;
00168 
00169     //    if(name.equals("isAlive()Z")) {
00170     // throws a runtime exception for now
00171     // throw new NativeMethodException("isAlive()Z");
00172     //}
00173 
00174     if(name.equals("isInterrupted(Z)Z")) {
00175       // throws a runtime exception for now
00176       throw new NativeMethodException("isInterrupted(Z)Z");
00177     }
00178 
00179     if(name.equals("resume0()V")) {
00180       // throws a runtime exception for now
00181       throw new NativeMethodException("resume0()V");
00182     }
00183 
00184     if(name.equals("setPriority0(I)V")) {
00185       // throws a runtime exception for now
00186       throw new NativeMethodException("setPriority0(I)V");
00187     }
00188 
00189     if(name.equals("start()V")) {
00190       ThreadInfo newThread = ks.tl.locate(objref);
00191       int target = newThread.getTarget();
00192 
00193       if (target == -1) target = objref;
00194 
00195       return da.get(target).canLock(newThread);
00196     }
00197 
00198     if(name.equals("stop0(Ljava/lang/Object;)V")) {
00199       // throws a runtime exception for now
00200       throw new NativeMethodException("stop0(Ljava/lang/Object;)V");
00201     }
00202 
00203     if(name.equals("suspend0()V")) {
00204       // throws a runtime exception for now
00205       throw new NativeMethodException("suspend0()V");
00206     }
00207 
00208     return super.isMethodExecutable(mi);
00209   }  
00210   public boolean isStaticMethodDeterministic(MethodInfo mi) {
00211     String name = mi.getFullName();
00212 
00213     return super.isStaticMethodDeterministic(mi);
00214   }  
00215   public boolean isStaticMethodExecutable(MethodInfo mi) {
00216     String name = mi.getFullName();
00217 
00218     return super.isStaticMethodExecutable(mi);
00219   }  
00220 }

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