1 package gov.nasa.jpf.jvm; 20 21 22 25 public class JPF_java_lang_Thread { 26 27 public static boolean isAlive (MJIEnv env, int objref) { 28 return getThreadInfo(env, objref).isAlive(); 29 } 30 31 public static void setDaemon0 (MJIEnv env, int objref, boolean isDaemon) { 32 ThreadInfo ti = getThreadInfo(env, objref); 33 ti.setDaemon(isDaemon); 34 } 35 36 public static boolean isInterrupted (MJIEnv env, int objref, 37 boolean clearStatus) { 38 return getThreadInfo(env, objref).isInterrupted(clearStatus); 39 } 40 41 public static void setName0 (MJIEnv env, int objref, int nameRef) { 42 if (nameRef == -1) { 44 env.throwException("java.lang.IllegalArgumentException"); 45 46 return; 47 } 48 49 ThreadInfo ti = getThreadInfo(env, objref); 58 ti.setName(env.getStringObject(nameRef)); 59 } 60 61 public static void setPriority0 (MJIEnv env, int objref, int prio) { 62 ThreadInfo ti = getThreadInfo(env, objref); 64 ti.setPriority(prio); 65 } 66 67 public static int countStackFrames (MJIEnv env, int objref) { 68 return getThreadInfo(env, objref).countStackFrames(); 69 } 70 71 public static int currentThread (MJIEnv env, int clsObjRef) { 72 ThreadInfo ti = env.getThreadInfo(); 73 74 return ti.getObjectReference(); 75 } 76 77 public static boolean holdsLock (MJIEnv env, int clsObjRef, int objref) { 78 ThreadInfo ti = env.getThreadInfo(); 79 ElementInfo ei = env.getElementInfo(objref); 80 81 return ei.isLockedBy(ti); 82 } 83 84 88 89 public static void init0 (MJIEnv env, int objref, int rGroup, int rRunnable, 91 int rName, long stackSize) { 92 ThreadInfo ti = getThreadInfo(env, objref); 93 ti.init(rGroup, rRunnable, rName, stackSize, true); 94 } 95 96 public static void interrupt (MJIEnv env, int objref) { 97 env.getElementInfo(objref).interrupt(); 98 } 99 100 public static void registerNatives (MJIEnv env, int clsObjRef) { 101 } 103 104 public static void resume0 (MJIEnv env, int objref) { 105 } 107 108 public static void sleep__J (MJIEnv env, int clsObjRef, long millis) { 109 } 111 112 public static void sleep__JI (MJIEnv env, int clsObjRef, long millis, 113 int nanos) { 114 } 116 117 121 146 public static void start (MJIEnv env, int objref) { 147 ThreadInfo newThread = getThreadInfo(env, objref); 148 149 if (newThread.getStatus() != ThreadInfo.NEW) { 154 env.throwException("java.lang.IllegalThreadStateException"); 155 return; 156 } 157 158 int target = newThread.getTarget(); 161 162 if (target == -1) { 163 target = objref; 165 } 166 167 newThread.setTarget(target); 169 170 ElementInfo ei = env.getElementInfo(target); 171 ClassInfo ci = ei.getClassInfo(); 172 MethodInfo run = ci.getMethod("run()", true); 173 174 newThread.pushFrame(new StackFrame(run, false, target)); 175 newThread.setStatus(run.isSynchronized 176 ? ThreadInfo.SYNC_RUNNING : ThreadInfo.RUNNING); 177 178 if (newThread.usePor()){ env.getDynamicArea().analyzeHeap(false); } 184 } 185 186 public static void stop0 (MJIEnv env, int objref, int threadDeathExcptRef) { 187 } 190 191 public static void suspend0 (MJIEnv env, int objref) { 192 } 194 195 public static void yield (MJIEnv env, int clsObjRef) { 196 } 199 200 210 211 private static ThreadInfo getThreadInfo (MJIEnv env, int objref) { 212 KernelState ks = env.getKernelState(); 213 214 return ks.tl.locate(objref); 215 } 216 } 217 | Popular Tags |