1 package gov.nasa.jpf.tools; 20 21 import gov.nasa.jpf.Config; 22 import gov.nasa.jpf.JPF; 23 import gov.nasa.jpf.Search; 24 import gov.nasa.jpf.ListenerAdapter; 25 import gov.nasa.jpf.VM; 26 import gov.nasa.jpf.jvm.ClassInfo; 27 import gov.nasa.jpf.jvm.JVM; 28 import gov.nasa.jpf.jvm.MethodInfo; 29 import gov.nasa.jpf.jvm.ThreadInfo; 30 import gov.nasa.jpf.jvm.bytecode.ArrayStoreInstruction; 31 import gov.nasa.jpf.jvm.bytecode.Instruction; 32 import gov.nasa.jpf.jvm.bytecode.InvokeInstruction; 33 import gov.nasa.jpf.util.DynamicObjectArray; 34 35 import java.util.HashMap ; 36 import java.util.logging.Logger ; 37 38 56 public class IdleFilter extends ListenerAdapter { 57 58 static Logger log = JPF.getLogger("gov.nasa.jpf.tools.IdleFilter"); 59 60 static class ThreadStat { 61 String tname; 62 63 int backJumps; 64 65 boolean isCleared = false; 66 67 int loopStartPc; 68 69 int loopEndPc; 70 71 int loopStackDepth; 72 73 ThreadStat(String tname) { 74 this.tname = tname; 75 } 76 } 77 78 DynamicObjectArray threadStats = new DynamicObjectArray(16); 79 80 ThreadStat ts; 81 82 int maxBackJumps; 83 84 boolean jumpPast; 85 86 89 public IdleFilter(Config config) { 90 maxBackJumps = config.getInt("idle.max_backjumps", 500); 91 jumpPast = config.getBoolean("idle.jump", false); 92 } 93 94 public void stateAdvanced(Search search) { 95 ts.backJumps = 0; 96 ts.isCleared = false; 97 ts.loopStackDepth = 0; 98 ts.loopStartPc = ts.loopEndPc = 0; 99 } 100 101 public void stateBacktracked(Search search) { 102 ts.backJumps = 0; 103 ts.isCleared = false; 104 ts.loopStackDepth = 0; 105 ts.loopStartPc = ts.loopEndPc = 0; 106 } 107 108 public void instructionExecuted(VM vm) { 110 JVM jvm = (JVM) vm; 111 Instruction insn = jvm.getLastInstruction(); 112 ThreadInfo ti = jvm.getLastThreadInfo(); 113 114 int tid = ti.getIndex(); 115 ts = (ThreadStat) threadStats.get(tid); 116 if (ts == null) { 117 ts = new ThreadStat(ti.getName()); 118 threadStats.set(tid, ts); 119 } 120 121 if (insn.isBackJump()) { 122 ts.backJumps++; 123 124 int loopStackDepth = ti.countStackFrames(); 125 int loopPc = jvm.getNextInstruction().getPosition(); 126 127 if ((loopStackDepth != ts.loopStackDepth) || (loopPc != ts.loopStartPc)) { 128 ts.isCleared = false; 130 ts.loopStackDepth = loopStackDepth; 131 ts.loopStartPc = loopPc; 132 ts.loopEndPc = insn.getPosition(); 133 ts.backJumps = 0; 134 } else { 135 if (!ts.isCleared) { 136 if (ts.backJumps > maxBackJumps) { 137 138 ti.yield(); MethodInfo mi = insn.getMethod(); 140 ClassInfo ci = mi.getClassInfo(); 141 int line = mi.getLineNumber(insn); 142 String file = ci.getSourceFileName(); 143 144 if (jumpPast) { 145 147 Instruction next = insn.getNext(); 148 ti.setPC(next); 149 150 log.warning("WARNING: IdleFilter jumped past loop in: " 151 + ti.getName() + "\n\tat " + ci.getName() + "." 152 + mi.getName() + "(" + file + ":" + line + ")"); 153 } else { 154 jvm.setIgnoreState(true); 156 157 log.warning("WARNING: IdleFilter pruned thread: " + ti.getName() 158 + "\n\tat " + ci.getName() + "." + mi.getName() + "(" + file 159 + ":" + line + ")"); 160 } 161 } 162 } 163 } 164 165 } else if (!ts.isCleared) { 166 if ((insn instanceof InvokeInstruction) 169 || (insn instanceof ArrayStoreInstruction)) { 170 int stackDepth = ti.countStackFrames(); 171 int pc = insn.getPosition(); 172 173 if (stackDepth == ts.loopStackDepth) { 174 if ((pc >= ts.loopStartPc) && (pc < ts.loopEndPc)) { 175 ts.isCleared = true; 176 } 177 } 178 } 179 } 180 } 181 182 } 183 | Popular Tags |