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";
}
}
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