Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/jpf-core
authorbdemsky <bdemsky@uci.edu>
Sat, 3 Aug 2019 07:06:20 +0000 (00:06 -0700)
committerbdemsky <bdemsky@uci.edu>
Sat, 3 Aug 2019 07:06:20 +0000 (00:06 -0700)
main.jpf
src/main/gov/nasa/jpf/listener/VariableConflictTracker.java

index 2034df42d7db3a108b04f15add3747f737d79e40..5b61c44e740ca7727c0f1262fbcfe6b7dd1f345d 100644 (file)
--- a/main.jpf
+++ b/main.jpf
@@ -28,4 +28,7 @@ apps=App1,App2
 # Timeout in minutes (default is 0 which means no timeout)
 timeout=0
 
+#search.class = gov.nasa.jpf.search.heuristic.RandomHeuristic
 #search.class = gov.nasa.jpf.search.heuristic.UserHeuristic
+#search.class = gov.nasa.jpf.search.heuristic.BFSHeuristic
+#search.class = gov.nasa.jpf.search.heuristic.DFSHeuristic
index cee0d24b62df5953a0cc4fd8f58d32a54594fdaa..561a4091ce9e71d7e337d36ba607c563d5410a6e 100644 (file)
@@ -43,9 +43,8 @@ public class VariableConflictTracker extends ListenerAdapter {
   private final HashSet<String> conflictSet = new HashSet<>();
   private final HashSet<String> appSet = new HashSet<>();
   private boolean trackLocationVar;
-  private int timeout;
-  private Timer timeoutTimer;
-  private TimeoutTask timeoutTask;
+  private long timeout;
+  private long startTime;
 
   private final String SET_LOCATION_METHOD = "setLocationMode";
   private final String LOCATION_VAR = "location.mode";
@@ -66,42 +65,21 @@ public class VariableConflictTracker extends ListenerAdapter {
       }
     }
     trackLocationVar = config.getBoolean("track_location_var_conflict", false);
-    // Timeout is in minutes
-    timeout = config.getInt("timeout", 0);
-    timeoutTimer = null;
-    timeoutTask = null;
-  }
-
-  // Create a task for timer to do a timeout
-  private class TimeoutTask extends TimerTask {
-
-    VM vm;
-    Timer timer;
-
-    public TimeoutTask(VM vm, Timer timer) {
-      this.vm = vm;
-      this.timer = timer;
-    }
-
-    @Override
-    public void run() {
-      StringBuilder sb = new StringBuilder();
-      sb.append("Execution timeout!\n");
-      ThreadInfo ti = this.vm.getCurrentThread();
-      Instruction nextIns = ti.createAndThrowException("java.lang.RuntimeException", sb.toString());
-      ti.setNextPC(nextIns);
-      this.cancel();
-      this.timer.cancel();
-    }
+    // Timeout input from config is in minutes, so we need to convert into millis
+    timeout = config.getInt("timeout", 0) * 60 * 1000;
+    startTime = System.currentTimeMillis();
   }
 
   @Override
   public void instructionExecuted(VM vm, ThreadInfo ti, Instruction nextInsn, Instruction executedInsn) {
     // Instantiate timeoutTimer
-    if (timeout > 0 && timeoutTimer == null && timeoutTask == null) {
-      timeoutTimer = new Timer();
-      timeoutTask = new TimeoutTask(vm, timeoutTimer);
-      timeoutTimer.schedule(timeoutTask, timeout * 60 * 1000);
+    if (timeout > 0) {
+      if (System.currentTimeMillis() - startTime > timeout) {
+        StringBuilder sb = new StringBuilder();
+        sb.append("Execution timeout: " + (timeout / (60 * 1000)) + " minutes have passed!");
+        Instruction nextIns = ti.createAndThrowException("java.lang.RuntimeException", sb.toString());
+        ti.setNextPC(nextIns);
+      }
     }
 
     // CASE #1: Detecting variable write-after-write conflict