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
00008 import gov.nasa.arc.ase.jpf.jvm.runtime.*;
00009
00010
00011 public class JavaLangThreadReflection extends Reflection {
00012
00013
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
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
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
00037
00038
00039
00040 return exit();
00041 }
00042
00043
00044 if(name.equals("java.lang.Thread.stop()V")) {
00045
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
00054 throw new NativeMethodException("java.lang.Thread.countStackFrames()I");
00055 }
00056
00057 if(name.equals("java.lang.Thread.interrupt0()V")) {
00058
00059 throw new NativeMethodException("java.lang.Thread.interrupt0()V");
00060 }
00061
00062 if(name.equals("java.lang.Thread.isAlive()Z")) {
00063
00064 throw new NativeMethodException("java.lang.Thread.isAlive()Z");
00065 }
00066
00067 if(name.equals("java.lang.Thread.isInterrupted(Z)Z")) {
00068
00069 throw new NativeMethodException("java.lang.Thread.isInterrupted(Z)Z");
00070 }
00071
00072 if(name.equals("java.lang.Thread.resume0()V")) {
00073
00074 throw new NativeMethodException("java.lang.Thread.resume0()V");
00075 }
00076
00077 if(name.equals("java.lang.Thread.setPriority0(I)V")) {
00078
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
00099 t.setLocalVariableRef(0);
00100
00101
00102
00103 DEPEND_executeStart(th, t);
00104
00105
00106 return exit();
00107 }
00108
00109 if(name.equals("java.lang.Thread.stop0(Ljava/lang/Object;)V")) {
00110
00111 throw new NativeMethodException("java.lang.Thread.stop0(Ljava/lang/Object;)V");
00112 }
00113
00114 if(name.equals("java.lang.Thread.suspend0()V")) {
00115
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
00126 throw new NativeMethodException("java.lang.Thread.currentThread()Ljava/lang/Thread;");
00127 }
00128
00129 if(name.equals("java.lang.Thread.registerNatives()V")) {
00130
00131 throw new NativeMethodException("java.lang.Thread.registerNatives()V");
00132 }
00133
00134 if(name.equals("java.lang.Thread.sleep(J)V")) {
00135
00136 throw new NativeMethodException("java.lang.Thread.sleep(J)V");
00137 }
00138
00139 if(name.equals("java.lang.Thread.yield()V")) {
00140
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
00151 throw new NativeMethodException("java.lang.Thread.countStackFrames()I");
00152 }
00153
00154 if(name.equals("java.lang.Thread.interrupt0()V")) {
00155
00156 throw new NativeMethodException("java.lang.Thread.interrupt0()V");
00157 }
00158
00159 if(name.equals("java.lang.Thread.isAlive()Z")) {
00160
00161 throw new NativeMethodException("java.lang.Thread.isAlive()Z");
00162 }
00163
00164 if(name.equals("java.lang.Thread.isInterrupted(Z)Z")) {
00165
00166 throw new NativeMethodException("java.lang.Thread.isInterrupted(Z)Z");
00167 }
00168
00169 if(name.equals("java.lang.Thread.resume0()V")) {
00170
00171 throw new NativeMethodException("java.lang.Thread.resume0()V");
00172 }
00173
00174 if(name.equals("java.lang.Thread.setPriority0(I)V")) {
00175
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
00181 throw new NativeMethodException("java.lang.Thread.stop0(Ljava/lang/Object;)V");
00182 }
00183
00184 if(name.equals("java.lang.Thread.suspend0()V")) {
00185
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
00195 if(name.equals("java.lang.Thread.<init>"))
00196 return true;
00197
00198 if(name.equals("java.lang.Thread.countStackFrames()I")) {
00199
00200 throw new NativeMethodException("java.lang.Thread.countStackFrames()I");
00201 }
00202
00203 if(name.equals("java.lang.Thread.interrupt0()V")) {
00204
00205 throw new NativeMethodException("java.lang.Thread.interrupt0()V");
00206 }
00207
00208 if(name.equals("java.lang.Thread.isAlive()Z")) {
00209
00210 throw new NativeMethodException("java.lang.Thread.isAlive()Z");
00211 }
00212
00213 if(name.equals("java.lang.Thread.isInterrupted(Z)Z")) {
00214
00215 throw new NativeMethodException("java.lang.Thread.isInterrupted(Z)Z");
00216 }
00217
00218 if(name.equals("java.lang.Thread.resume0()V")) {
00219
00220 throw new NativeMethodException("java.lang.Thread.resume0()V");
00221 }
00222
00223 if(name.equals("java.lang.Thread.setPriority0(I)V")) {
00224
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
00244 throw new NativeMethodException("java.lang.Thread.stop0(Ljava/lang/Object;)V");
00245 }
00246
00247 if(name.equals("java.lang.Thread.suspend0()V")) {
00248
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
00259 throw new NativeMethodException("java.lang.Thread.currentThread()Ljava/lang/Thread;");
00260 }
00261
00262 if(name.equals("java.lang.Thread.registerNatives()V")) {
00263
00264 throw new NativeMethodException("java.lang.Thread.registerNatives()V");
00265 }
00266
00267 if(name.equals("java.lang.Thread.sleep(J)V")) {
00268
00269 throw new NativeMethodException("java.lang.Thread.sleep(J)V");
00270 }
00271
00272 if(name.equals("java.lang.Thread.yield()V")) {
00273
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
00284 throw new NativeMethodException("java.lang.Thread.currentThread()Ljava/lang/Thread;");
00285 }
00286
00287 if(name.equals("java.lang.Thread.registerNatives()V")) {
00288
00289 throw new NativeMethodException("java.lang.Thread.registerNatives()V");
00290 }
00291
00292 if(name.equals("java.lang.Thread.sleep(J)V")) {
00293
00294 throw new NativeMethodException("java.lang.Thread.sleep(J)V");
00295 }
00296
00297 if(name.equals("java.lang.Thread.yield()V")) {
00298
00299 throw new NativeMethodException("java.lang.Thread.yield()V");
00300 }
00301
00302 return super.isStaticMethodExecutable(mi);
00303 }
00304 }