Fixing a bug: in the second round of boolean CG, we might encounter states in the...
[jpf-core.git] / src / main / gov / nasa / jpf / listener / DPORStateReducer.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package gov.nasa.jpf.listener;
19
20 import gov.nasa.jpf.Config;
21 import gov.nasa.jpf.JPF;
22 import gov.nasa.jpf.ListenerAdapter;
23 import gov.nasa.jpf.search.Search;
24 import gov.nasa.jpf.jvm.bytecode.*;
25 import gov.nasa.jpf.vm.*;
26 import gov.nasa.jpf.vm.bytecode.ReadInstruction;
27 import gov.nasa.jpf.vm.bytecode.WriteInstruction;
28 import gov.nasa.jpf.vm.choice.IntChoiceFromSet;
29 import gov.nasa.jpf.vm.choice.IntIntervalGenerator;
30
31 import java.io.FileWriter;
32 import java.io.PrintWriter;
33 import java.lang.reflect.Field;
34 import java.util.*;
35 import java.util.logging.Logger;
36 import java.io.IOException;
37
38 /**
39  * This a DPOR implementation for event-driven applications with loops that create cycles of state matching
40  * In this new DPOR algorithm/implementation, each run is terminated iff:
41  * - we find a state that matches a state in a previous run, or
42  * - we have a matched state in the current run that consists of cycles that contain all choices/events.
43  */
44 public class DPORStateReducer extends ListenerAdapter {
45
46   // Information printout fields for verbose mode
47   private boolean verboseMode;
48   private boolean stateReductionMode;
49   private final PrintWriter out;
50   private PrintWriter fileWriter;
51   private String detail;
52   private int depth;
53   private int id;
54   private Transition transition;
55
56   // DPOR-related fields
57   // Basic information
58   private Integer[] choices;
59   private Integer[] refChoices; // Second reference to a copy of choices (choices may be modified for fair scheduling)
60   private int choiceCounter;
61   private int maxEventChoice;
62   // Data structure to track the events seen by each state to track cycles (containing all events) for termination
63   private HashSet<Integer> currVisitedStates;   // States being visited in the current execution
64   private HashSet<Integer> justVisitedStates;   // States just visited in the previous choice/event
65   private HashSet<Integer> prevVisitedStates;   // States visited in the previous execution
66   private HashSet<ClassInfo> nonRelevantClasses;// Class info objects of non-relevant classes
67   private HashSet<FieldInfo> nonRelevantFields; // Field info objects of non-relevant fields
68   private HashSet<FieldInfo> relevantFields;    // Field info objects of relevant fields
69   private HashMap<Integer, HashSet<Integer>> stateToEventMap;
70   // Data structure to analyze field Read/Write accesses and conflicts
71   private HashMap<Integer, LinkedList<BacktrackExecution>> backtrackMap;  // Track created backtracking points
72   private PriorityQueue<Integer> backtrackStateQ;                 // Heap that returns the latest state
73   private Execution currentExecution;                             // Holds the information about the current execution
74   private HashSet<String> doneBacktrackSet;                       // Record state ID and trace already constructed
75   private HashMap<Integer, RestorableVMState> restorableStateMap; // Maps state IDs to the restorable state object
76   private RGraph rGraph;                                          // R-Graph for past executions
77
78   // Boolean states
79   private boolean isBooleanCGFlipped;
80   private boolean isEndOfExecution;
81
82   // Statistics
83   private int numOfConflicts;
84   private int numOfTransitions;
85         
86   public DPORStateReducer(Config config, JPF jpf) {
87     verboseMode = config.getBoolean("printout_state_transition", false);
88     stateReductionMode = config.getBoolean("activate_state_reduction", true);
89     if (verboseMode) {
90       out = new PrintWriter(System.out, true);
91     } else {
92       out = null;
93     }
94     String outputFile = config.getString("file_output");
95     if (!outputFile.isEmpty()) {
96       try {
97         fileWriter = new PrintWriter(new FileWriter(outputFile, true), true);
98       } catch (IOException e) {
99       }
100     }
101     isBooleanCGFlipped = false;
102                 numOfConflicts = 0;
103                 numOfTransitions = 0;
104                 nonRelevantClasses = new HashSet<>();
105                 nonRelevantFields = new HashSet<>();
106                 relevantFields = new HashSet<>();
107     restorableStateMap = new HashMap<>();
108     initializeStatesVariables();
109   }
110
111   @Override
112   public void stateRestored(Search search) {
113     if (verboseMode) {
114       id = search.getStateId();
115       depth = search.getDepth();
116       transition = search.getTransition();
117       detail = null;
118       out.println("\n==> DEBUG: The state is restored to state with id: " + id + " -- Transition: " + transition +
119               " and depth: " + depth + "\n");
120     }
121   }
122
123   @Override
124   public void searchStarted(Search search) {
125     if (verboseMode) {
126       out.println("\n==> DEBUG: ----------------------------------- search started" + "\n");
127     }
128   }
129
130   @Override
131   public void stateAdvanced(Search search) {
132     if (verboseMode) {
133       id = search.getStateId();
134       depth = search.getDepth();
135       transition = search.getTransition();
136       if (search.isNewState()) {
137         detail = "new";
138       } else {
139         detail = "visited";
140       }
141
142       if (search.isEndState()) {
143         out.println("\n==> DEBUG: This is the last state!\n");
144         detail += " end";
145       }
146       out.println("\n==> DEBUG: The state is forwarded to state with id: " + id + " with depth: " + depth +
147               " which is " + detail + " Transition: " + transition + "\n");
148     }
149     if (stateReductionMode) {
150       updateStateInfo(search);
151     }
152   }
153
154   @Override
155   public void stateBacktracked(Search search) {
156     if (verboseMode) {
157       id = search.getStateId();
158       depth = search.getDepth();
159       transition = search.getTransition();
160       detail = null;
161
162       out.println("\n==> DEBUG: The state is backtracked to state with id: " + id + " -- Transition: " + transition +
163               " and depth: " + depth + "\n");
164     }
165     if (stateReductionMode) {
166       updateStateInfo(search);
167     }
168   }
169
170   static Logger log = JPF.getLogger("report");
171
172   @Override
173   public void searchFinished(Search search) {
174     if (stateReductionMode) {
175       // Number of conflicts = first trace + subsequent backtrack points
176       numOfConflicts += 1 + doneBacktrackSet.size();
177     }
178     if (verboseMode) {
179       out.println("\n==> DEBUG: ----------------------------------- search finished");
180       out.println("\n==> DEBUG: State reduction mode  : " + stateReductionMode);
181       out.println("\n==> DEBUG: Number of conflicts   : " + numOfConflicts);
182       out.println("\n==> DEBUG: Number of transitions : " + numOfTransitions);
183       out.println("\n==> DEBUG: ----------------------------------- search finished" + "\n");
184
185       fileWriter.println("==> DEBUG: State reduction mode  : " + stateReductionMode);
186       fileWriter.println("==> DEBUG: Number of conflicts   : " + numOfConflicts);
187       fileWriter.println("==> DEBUG: Number of transitions : " + numOfTransitions);
188       fileWriter.println();
189       fileWriter.close();
190     }
191   }
192
193   @Override
194   public void choiceGeneratorRegistered(VM vm, ChoiceGenerator<?> nextCG, ThreadInfo currentThread, Instruction executedInstruction) {
195     if (stateReductionMode) {
196       // Initialize with necessary information from the CG
197       if (nextCG instanceof IntChoiceFromSet) {
198         IntChoiceFromSet icsCG = (IntChoiceFromSet) nextCG;
199         // Tell JPF that we are performing DPOR
200         icsCG.setDpor();
201         if (!isEndOfExecution) {
202           // Check if CG has been initialized, otherwise initialize it
203           Integer[] cgChoices = icsCG.getAllChoices();
204           // Record the events (from choices)
205           if (choices == null) {
206             choices = cgChoices;
207             // Make a copy of choices as reference
208             refChoices = copyChoices(choices);
209             // Record the max event choice (the last element of the choice array)
210             maxEventChoice = choices[choices.length - 1];
211           }
212           icsCG.setNewValues(choices);
213           icsCG.reset();
214           // Use a modulo since choiceCounter is going to keep increasing
215           int choiceIndex = choiceCounter % choices.length;
216           icsCG.advance(choices[choiceIndex]);
217         } else {
218           // Set done all CGs while transitioning to a new execution
219           icsCG.setDone();
220         }
221       }
222     }
223   }
224
225   @Override
226   public void choiceGeneratorAdvanced(VM vm, ChoiceGenerator<?> currentCG) {
227     if (stateReductionMode) {
228       // Check the boolean CG and if it is flipped, we are resetting the analysis
229       if (currentCG instanceof BooleanChoiceGenerator) {
230         if (!isBooleanCGFlipped) {
231           isBooleanCGFlipped = true;
232         } else {
233           // Number of conflicts = first trace + subsequent backtrack points
234           numOfConflicts = 1 + doneBacktrackSet.size();
235           // Allocate new objects for data structure when the boolean is flipped from "false" to "true"
236           initializeStatesVariables();
237         }
238       }
239       // Check every choice generated and ensure fair scheduling!
240       if (currentCG instanceof IntChoiceFromSet) {
241         IntChoiceFromSet icsCG = (IntChoiceFromSet) currentCG;
242         // If this is a new CG then we need to update data structures
243         resetStatesForNewExecution(icsCG, vm);
244         // If we don't see a fair scheduling of events/choices then we have to enforce it
245         ensureFairSchedulingAndSetupTransition(icsCG, vm);
246         // Update backtrack set of an executed event (transition): one transition before this one
247         updateBacktrackSet(currentExecution, choiceCounter - 1);
248         // Explore the next backtrack point:
249         // 1) if we have seen this state or this state contains cycles that involve all events, and
250         // 2) after the current CG is advanced at least once
251         if (terminateCurrentExecution() && choiceCounter > 0) {
252           exploreNextBacktrackPoints(vm, icsCG);
253         } else {
254           numOfTransitions++;
255         }
256         // Map state to event
257         mapStateToEvent(icsCG.getNextChoice());
258         justVisitedStates.clear();
259         choiceCounter++;
260       }
261     } else {
262       numOfTransitions++;
263     }
264   }
265
266   @Override
267   public void instructionExecuted(VM vm, ThreadInfo ti, Instruction nextInsn, Instruction executedInsn) {
268     if (stateReductionMode) {
269       if (!isEndOfExecution) {
270         // Has to be initialized and a integer CG
271         ChoiceGenerator<?> cg = vm.getChoiceGenerator();
272         if (cg instanceof IntChoiceFromSet || cg instanceof IntIntervalGenerator) {
273           int currentChoice = choiceCounter - 1;  // Accumulative choice w.r.t the current trace
274           if (currentChoice < 0) { // If choice is -1 then skip
275             return;
276           }
277           currentChoice = checkAndAdjustChoice(currentChoice, vm);
278           // Record accesses from executed instructions
279           if (executedInsn instanceof JVMFieldInstruction) {
280             // We don't care about libraries
281             if (!isFieldExcluded(executedInsn)) {
282               analyzeReadWriteAccesses(executedInsn, currentChoice);
283             }
284           } else if (executedInsn instanceof INVOKEINTERFACE) {
285             // Handle the read/write accesses that occur through iterators
286             analyzeReadWriteAccesses(executedInsn, ti, currentChoice);
287           }
288         }
289       }
290     }
291   }
292
293
294   // == HELPERS
295
296   // -- INNER CLASSES
297
298   // This class compactly stores backtrack execution:
299   // 1) backtrack choice list, and
300   // 2) first backtrack point (linking with predecessor execution)
301   private class BacktrackExecution {
302     private Integer[] choiceList;
303     private TransitionEvent firstTransition;
304
305     public BacktrackExecution(Integer[] choList, TransitionEvent fTransition) {
306       choiceList = choList;
307       firstTransition = fTransition;
308     }
309
310     public Integer[] getChoiceList() {
311       return choiceList;
312     }
313
314     public TransitionEvent getFirstTransition() {
315       return firstTransition;
316     }
317   }
318
319   // This class stores a representation of an execution
320   // TODO: We can modify this class to implement some optimization (e.g., clock-vector)
321   // TODO: We basically need to keep track of:
322   // TODO:    (1) last read/write access to each memory location
323   // TODO:    (2) last state with two or more incoming events/transitions
324   private class Execution {
325     private HashMap<IntChoiceFromSet, Integer> cgToChoiceMap;   // Map between CG to choice numbers for O(1) access
326     private ArrayList<TransitionEvent> executionTrace;          // The BacktrackPoint objects of this execution
327     private boolean isNew;                                      // Track if this is the first time it is accessed
328     private HashMap<Integer, ReadWriteSet> readWriteFieldsMap;  // Record fields that are accessed
329
330     public Execution() {
331       cgToChoiceMap = new HashMap<>();
332       executionTrace = new ArrayList<>();
333       isNew = true;
334       readWriteFieldsMap = new HashMap<>();
335     }
336
337     public void addTransition(TransitionEvent newBacktrackPoint) {
338       executionTrace.add(newBacktrackPoint);
339     }
340
341     public void clearCGToChoiceMap() {
342       cgToChoiceMap = null;
343     }
344
345     public int getChoiceFromCG(IntChoiceFromSet icsCG) {
346       return cgToChoiceMap.get(icsCG);
347     }
348
349     public ArrayList<TransitionEvent> getExecutionTrace() {
350       return executionTrace;
351     }
352
353     public TransitionEvent getFirstTransition() {
354       return executionTrace.get(0);
355     }
356
357     public TransitionEvent getLastTransition() {
358       return executionTrace.get(executionTrace.size() - 1);
359     }
360
361     public HashMap<Integer, ReadWriteSet> getReadWriteFieldsMap() {
362       return readWriteFieldsMap;
363     }
364
365     public boolean isNew() {
366       if (isNew) {
367         // Right after this is accessed, it is no longer new
368         isNew = false;
369         return true;
370       }
371       return false;
372     }
373
374     public void mapCGToChoice(IntChoiceFromSet icsCG, int choice) {
375       cgToChoiceMap.put(icsCG, choice);
376     }
377   }
378
379   // This class compactly stores a predecessor
380   // 1) a predecessor execution
381   // 2) the predecessor choice in that predecessor execution
382   private class Predecessor {
383     private int choice;           // Predecessor choice
384     private Execution execution;  // Predecessor execution
385
386     public Predecessor(int predChoice, Execution predExec) {
387       choice = predChoice;
388       execution = predExec;
389     }
390
391     public int getChoice() {
392       return choice;
393     }
394
395     public Execution getExecution() {
396       return execution;
397     }
398   }
399
400   // This class represents a R-Graph (in the paper it is a state transition graph R)
401   // This implementation stores reachable transitions from and connects with past executions
402   private class RGraph {
403     private int hiStateId;                                     // Maximum state Id
404     private HashMap<Integer, HashSet<TransitionEvent>> graph;  // Reachable transitions from past executions
405
406     public RGraph() {
407       hiStateId = 0;
408       graph = new HashMap<>();
409     }
410
411     public void addReachableTransition(int stateId, TransitionEvent transition) {
412       HashSet<TransitionEvent> transitionSet;
413       if (graph.containsKey(stateId)) {
414         transitionSet = graph.get(stateId);
415       } else {
416         transitionSet = new HashSet<>();
417         graph.put(stateId, transitionSet);
418       }
419       // Insert into the set if it does not contain it yet
420       if (!transitionSet.contains(transition)) {
421         transitionSet.add(transition);
422       }
423       // Update highest state ID
424       if (hiStateId < stateId) {
425         hiStateId = stateId;
426       }
427     }
428
429     public HashSet<TransitionEvent> getReachableTransitionsAtState(int stateId) {
430       if (!graph.containsKey(stateId)) {
431         // This is a loop from a transition to itself, so just return the current transition
432         HashSet<TransitionEvent> transitionSet = new HashSet<>();
433         transitionSet.add(currentExecution.getLastTransition());
434         return transitionSet;
435       }
436       return graph.get(stateId);
437     }
438
439     public HashSet<TransitionEvent> getReachableTransitions(int stateId) {
440       HashSet<TransitionEvent> reachableTransitions = new HashSet<>();
441       // All transitions from states higher than the given state ID (until the highest state ID) are reachable
442       for(int stId = stateId; stId <= hiStateId; stId++) {
443         // We might encounter state IDs from the first round of Boolean CG
444         // The second round of Boolean CG should consider these new states
445         if (graph.containsKey(stId)) {
446           reachableTransitions.addAll(graph.get(stId));
447         }
448       }
449       return reachableTransitions;
450     }
451   }
452
453   // This class compactly stores Read and Write field sets
454   // We store the field name and its object ID
455   // Sharing the same field means the same field name and object ID
456   private class ReadWriteSet {
457     private HashMap<String, Integer> readMap;
458     private HashMap<String, Integer> writeMap;
459
460     public ReadWriteSet() {
461       readMap = new HashMap<>();
462       writeMap = new HashMap<>();
463     }
464
465     public void addReadField(String field, int objectId) {
466       readMap.put(field, objectId);
467     }
468
469     public void addWriteField(String field, int objectId) {
470       writeMap.put(field, objectId);
471     }
472
473     public void removeReadField(String field) {
474       readMap.remove(field);
475     }
476
477     public void removeWriteField(String field) {
478       writeMap.remove(field);
479     }
480
481     public boolean isEmpty() {
482       return readMap.isEmpty() && writeMap.isEmpty();
483     }
484
485     public ReadWriteSet getCopy() {
486       ReadWriteSet copyRWSet = new ReadWriteSet();
487       // Copy the maps in the set into the new object copy
488       copyRWSet.setReadMap(new HashMap<>(this.getReadMap()));
489       copyRWSet.setWriteMap(new HashMap<>(this.getWriteMap()));
490       return copyRWSet;
491     }
492
493     public Set<String> getReadSet() {
494       return readMap.keySet();
495     }
496
497     public Set<String> getWriteSet() {
498       return writeMap.keySet();
499     }
500
501     public boolean readFieldExists(String field) {
502       return readMap.containsKey(field);
503     }
504
505     public boolean writeFieldExists(String field) {
506       return writeMap.containsKey(field);
507     }
508
509     public int readFieldObjectId(String field) {
510       return readMap.get(field);
511     }
512
513     public int writeFieldObjectId(String field) {
514       return writeMap.get(field);
515     }
516
517     private HashMap<String, Integer> getReadMap() {
518       return readMap;
519     }
520
521     private HashMap<String, Integer> getWriteMap() {
522       return writeMap;
523     }
524
525     private void setReadMap(HashMap<String, Integer> rMap) {
526       readMap = rMap;
527     }
528
529     private void setWriteMap(HashMap<String, Integer> wMap) {
530       writeMap = wMap;
531     }
532   }
533
534   // This class compactly stores transitions:
535   // 1) CG,
536   // 2) state ID,
537   // 3) choice,
538   // 4) predecessors (for backward DFS).
539   private class TransitionEvent {
540     private int choice;                        // Choice chosen at this transition
541     private int choiceCounter;                 // Choice counter at this transition
542     private Execution execution;               // The execution where this transition belongs
543     private HashSet<Predecessor> predecessors; // Maps incoming events/transitions (execution and choice)
544     private int stateId;                       // State at this transition
545     private IntChoiceFromSet transitionCG;     // CG at this transition
546
547     public TransitionEvent() {
548       choice = 0;
549       choiceCounter = 0;
550       execution = null;
551       predecessors = new HashSet<>();
552       stateId = 0;
553       transitionCG = null;
554     }
555
556     public int getChoice() {
557       return choice;
558     }
559
560     public int getChoiceCounter() {
561       return choiceCounter;
562     }
563
564     public Execution getExecution() {
565       return execution;
566     }
567
568     public HashSet<Predecessor> getPredecessors() {
569       return predecessors;
570     }
571
572     public int getStateId() {
573       return stateId;
574     }
575
576     public IntChoiceFromSet getTransitionCG() { return transitionCG; }
577
578     public void recordPredecessor(Execution execution, int choice) {
579       predecessors.add(new Predecessor(choice, execution));
580     }
581
582     public void setChoice(int cho) {
583       choice = cho;
584     }
585
586     public void setChoiceCounter(int choCounter) {
587       choiceCounter = choCounter;
588     }
589
590     public void setExecution(Execution exec) {
591       execution = exec;
592     }
593
594     public void setPredecessors(HashSet<Predecessor> preds) {
595       predecessors = new HashSet<>(preds);
596     }
597
598     public void setStateId(int stId) {
599       stateId = stId;
600     }
601
602     public void setTransitionCG(IntChoiceFromSet cg) {
603       transitionCG = cg;
604     }
605   }
606
607   // -- CONSTANTS
608   private final static String DO_CALL_METHOD = "doCall";
609   // We exclude fields that come from libraries (Java and Groovy), and also the infrastructure
610   private final static String[] EXCLUDED_FIELDS_CONTAINS_LIST = {"_closure"};
611   private final static String[] EXCLUDED_FIELDS_ENDS_WITH_LIST =
612           // Groovy library created fields
613           {"stMC", "callSiteArray", "metaClass", "staticClassInfo", "__constructor__",
614           // Infrastructure
615           "sendEvent", "Object", "reference", "location", "app", "state", "log", "functionList", "objectList",
616           "eventList", "valueList", "settings", "printToConsole", "app1", "app2"};
617   private final static String[] EXCLUDED_FIELDS_STARTS_WITH_LIST =
618           // Java and Groovy libraries
619           { "java", "org", "sun", "com", "gov", "groovy"};
620   private final static String[] EXCLUDED_FIELDS_READ_WRITE_INSTRUCTIONS_STARTS_WITH_LIST = {"Event"};
621   private final static String GET_PROPERTY_METHOD =
622           "invokeinterface org.codehaus.groovy.runtime.callsite.CallSite.callGetProperty";
623   private final static String GROOVY_CALLSITE_LIB = "org.codehaus.groovy.runtime.callsite";
624   private final static String JAVA_INTEGER = "int";
625   private final static String JAVA_STRING_LIB = "java.lang.String";
626
627   // -- FUNCTIONS
628   private Integer[] copyChoices(Integer[] choicesToCopy) {
629
630     Integer[] copyOfChoices = new Integer[choicesToCopy.length];
631     System.arraycopy(choicesToCopy, 0, copyOfChoices, 0, choicesToCopy.length);
632     return copyOfChoices;
633   }
634
635   private void ensureFairSchedulingAndSetupTransition(IntChoiceFromSet icsCG, VM vm) {
636     // Check the next choice and if the value is not the same as the expected then force the expected value
637     int choiceIndex = choiceCounter % refChoices.length;
638     int nextChoice = icsCG.getNextChoice();
639     if (refChoices[choiceIndex] != nextChoice) {
640       int expectedChoice = refChoices[choiceIndex];
641       int currCGIndex = icsCG.getNextChoiceIndex();
642       if ((currCGIndex >= 0) && (currCGIndex < refChoices.length)) {
643         icsCG.setChoice(currCGIndex, expectedChoice);
644       }
645     }
646     // Get state ID and associate it with this transition
647     int stateId = vm.getStateId();
648     TransitionEvent transition = setupTransition(icsCG, stateId, choiceIndex);
649     // Add new transition to the current execution and map it in R-Graph
650     for (Integer stId : justVisitedStates) {  // Map this transition to all the previously passed states
651       rGraph.addReachableTransition(stId, transition);
652     }
653     currentExecution.mapCGToChoice(icsCG, choiceCounter);
654     // Store restorable state object for this state (always store the latest)
655     RestorableVMState restorableState = vm.getRestorableState();
656     restorableStateMap.put(stateId, restorableState);
657   }
658
659   private TransitionEvent setupTransition(IntChoiceFromSet icsCG, int stateId, int choiceIndex) {
660     // Get a new transition
661     TransitionEvent transition;
662     if (currentExecution.isNew()) {
663       // We need to handle the first transition differently because this has a predecessor execution
664       transition = currentExecution.getFirstTransition();
665     } else {
666       transition = new TransitionEvent();
667       currentExecution.addTransition(transition);
668       transition.recordPredecessor(currentExecution, choiceCounter - 1);
669     }
670     transition.setExecution(currentExecution);
671     transition.setTransitionCG(icsCG);
672     transition.setStateId(stateId);
673     transition.setChoice(refChoices[choiceIndex]);
674     transition.setChoiceCounter(choiceCounter);
675
676     return transition;
677   }
678
679   // --- Functions related to cycle detection and reachability graph
680
681   // Detect cycles in the current execution/trace
682   // We terminate the execution iff:
683   // (1) the state has been visited in the current execution
684   // (2) the state has one or more cycles that involve all the events
685   // With simple approach we only need to check for a re-visited state.
686   // Basically, we have to check that we have executed all events between two occurrences of such state.
687   private boolean completeFullCycle(int stId) {
688     // False if the state ID hasn't been recorded
689     if (!stateToEventMap.containsKey(stId)) {
690       return false;
691     }
692     HashSet<Integer> visitedEvents = stateToEventMap.get(stId);
693     // Check if this set contains all the event choices
694     // If not then this is not the terminating condition
695     for(int i=0; i<=maxEventChoice; i++) {
696       if (!visitedEvents.contains(i)) {
697         return false;
698       }
699     }
700     return true;
701   }
702
703   private void initializeStatesVariables() {
704     // DPOR-related
705     choices = null;
706     refChoices = null;
707     choiceCounter = 0;
708     maxEventChoice = 0;
709     // Cycle tracking
710     currVisitedStates = new HashSet<>();
711     justVisitedStates = new HashSet<>();
712     prevVisitedStates = new HashSet<>();
713     stateToEventMap = new HashMap<>();
714     // Backtracking
715     backtrackMap = new HashMap<>();
716     backtrackStateQ = new PriorityQueue<>(Collections.reverseOrder());
717     currentExecution = new Execution();
718     currentExecution.addTransition(new TransitionEvent()); // Always start with 1 backtrack point
719     doneBacktrackSet = new HashSet<>();
720     rGraph = new RGraph();
721     // Booleans
722     isEndOfExecution = false;
723   }
724
725   private void mapStateToEvent(int nextChoiceValue) {
726     // Update all states with this event/choice
727     // This means that all past states now see this transition
728     Set<Integer> stateSet = stateToEventMap.keySet();
729     for(Integer stateId : stateSet) {
730       HashSet<Integer> eventSet = stateToEventMap.get(stateId);
731       eventSet.add(nextChoiceValue);
732     }
733   }
734
735   private boolean terminateCurrentExecution() {
736     // We need to check all the states that have just been visited
737     // Often a transition (choice/event) can result into forwarding/backtracking to a number of states
738     for(Integer stateId : justVisitedStates) {
739       if (prevVisitedStates.contains(stateId) || completeFullCycle(stateId)) {
740         return true;
741       }
742     }
743     return false;
744   }
745
746   private void updateStateInfo(Search search) {
747     // Update the state variables
748     int stateId = search.getStateId();
749     // Insert state ID into the map if it is new
750     if (!stateToEventMap.containsKey(stateId)) {
751       HashSet<Integer> eventSet = new HashSet<>();
752       stateToEventMap.put(stateId, eventSet);
753     }
754     analyzeReachabilityAndCreateBacktrackPoints(search.getVM(), stateId);
755     justVisitedStates.add(stateId);
756     if (!prevVisitedStates.contains(stateId)) {
757       // It is a currently visited states if the state has not been seen in previous executions
758       currVisitedStates.add(stateId);
759     }
760   }
761
762   // --- Functions related to Read/Write access analysis on shared fields
763
764   private void addNewBacktrackPoint(int stateId, Integer[] newChoiceList, TransitionEvent conflictTransition) {
765     // Insert backtrack point to the right state ID
766     LinkedList<BacktrackExecution> backtrackExecList;
767     if (backtrackMap.containsKey(stateId)) {
768       backtrackExecList = backtrackMap.get(stateId);
769     } else {
770       backtrackExecList = new LinkedList<>();
771       backtrackMap.put(stateId, backtrackExecList);
772     }
773     // Add the new backtrack execution object
774     TransitionEvent backtrackTransition = new TransitionEvent();
775     backtrackTransition.setPredecessors(conflictTransition.getPredecessors());
776     backtrackExecList.addFirst(new BacktrackExecution(newChoiceList, backtrackTransition));
777     // Add to priority queue
778     if (!backtrackStateQ.contains(stateId)) {
779       backtrackStateQ.add(stateId);
780     }
781   }
782
783   // Analyze Read/Write accesses that are directly invoked on fields
784   private void analyzeReadWriteAccesses(Instruction executedInsn, int currentChoice) {
785     // Get the field info
786     FieldInfo fieldInfo = ((JVMFieldInstruction) executedInsn).getFieldInfo();
787     // Analyze only after being initialized
788     String fieldClass = fieldInfo.getFullName();
789     // Do the analysis to get Read and Write accesses to fields
790     ReadWriteSet rwSet = getReadWriteSet(currentChoice);
791     int objectId = fieldInfo.getClassInfo().getClassObjectRef();
792     // Record the field in the map
793     if (executedInsn instanceof WriteInstruction) {
794       // We first check the non-relevant fields set
795       if (!nonRelevantFields.contains(fieldInfo)) {
796         // Exclude certain field writes because of infrastructure needs, e.g., Event class field writes
797         for (String str : EXCLUDED_FIELDS_READ_WRITE_INSTRUCTIONS_STARTS_WITH_LIST) {
798           if (fieldClass.startsWith(str)) {
799             nonRelevantFields.add(fieldInfo);
800             return;
801           }
802         }
803       } else {
804         // If we have this field in the non-relevant fields set then we return right away
805         return;
806       }
807       rwSet.addWriteField(fieldClass, objectId);
808     } else if (executedInsn instanceof ReadInstruction) {
809       rwSet.addReadField(fieldClass, objectId);
810     }
811   }
812
813   // Analyze Read accesses that are indirect (performed through iterators)
814   // These accesses are marked by certain bytecode instructions, e.g., INVOKEINTERFACE
815   private void analyzeReadWriteAccesses(Instruction instruction, ThreadInfo ti, int currentChoice) {
816     // Get method name
817     INVOKEINTERFACE insn = (INVOKEINTERFACE) instruction;
818     if (insn.toString().startsWith(GET_PROPERTY_METHOD) &&
819             insn.getMethodInfo().getName().equals(DO_CALL_METHOD)) {
820       // Extract info from the stack frame
821       StackFrame frame = ti.getTopFrame();
822       int[] frameSlots = frame.getSlots();
823       // Get the Groovy callsite library at index 0
824       ElementInfo eiCallsite = VM.getVM().getHeap().get(frameSlots[0]);
825       if (!eiCallsite.getClassInfo().getName().startsWith(GROOVY_CALLSITE_LIB)) {
826         return;
827       }
828       // Get the iterated object whose property is accessed
829       ElementInfo eiAccessObj = VM.getVM().getHeap().get(frameSlots[1]);
830       if (eiAccessObj == null) {
831         return;
832       }
833       // We exclude library classes (they start with java, org, etc.) and some more
834       ClassInfo classInfo = eiAccessObj.getClassInfo();
835       String objClassName = classInfo.getName();
836       // Check if this class info is part of the non-relevant classes set already
837       if (!nonRelevantClasses.contains(classInfo)) {
838         if (excludeThisForItStartsWith(EXCLUDED_FIELDS_READ_WRITE_INSTRUCTIONS_STARTS_WITH_LIST, objClassName) ||
839                 excludeThisForItStartsWith(EXCLUDED_FIELDS_STARTS_WITH_LIST, objClassName)) {
840           nonRelevantClasses.add(classInfo);
841           return;
842         }
843       } else {
844         // If it is part of the non-relevant classes set then return immediately
845         return;
846       }
847       // Extract fields from this object and put them into the read write
848       int numOfFields = eiAccessObj.getNumberOfFields();
849       for(int i=0; i<numOfFields; i++) {
850         FieldInfo fieldInfo = eiAccessObj.getFieldInfo(i);
851         if (fieldInfo.getType().equals(JAVA_STRING_LIB) || fieldInfo.getType().equals(JAVA_INTEGER)) {
852           String fieldClass = fieldInfo.getFullName();
853           ReadWriteSet rwSet = getReadWriteSet(currentChoice);
854           int objectId = fieldInfo.getClassInfo().getClassObjectRef();
855           // Record the field in the map
856           rwSet.addReadField(fieldClass, objectId);
857         }
858       }
859     }
860   }
861
862   private int checkAndAdjustChoice(int currentChoice, VM vm) {
863     // If current choice is not the same, then this is caused by the firing of IntIntervalGenerator
864     // for certain method calls in the infrastructure, e.g., eventSince()
865     ChoiceGenerator<?> currentCG = vm.getChoiceGenerator();
866     // This is the main event CG
867     if (currentCG instanceof IntIntervalGenerator) {
868       // This is the interval CG used in device handlers
869       ChoiceGenerator<?> parentCG = ((IntIntervalGenerator) currentCG).getPreviousChoiceGenerator();
870       // Iterate until we find the IntChoiceFromSet CG
871       while (!(parentCG instanceof IntChoiceFromSet)) {
872         parentCG = ((IntIntervalGenerator) parentCG).getPreviousChoiceGenerator();
873       }
874       // Find the choice related to the IntIntervalGenerator CG from the map
875       currentChoice = currentExecution.getChoiceFromCG((IntChoiceFromSet) parentCG);
876     }
877     return currentChoice;
878   }
879
880   private void createBacktrackingPoint(Execution execution, int currentChoice,
881                                        Execution conflictExecution, int conflictChoice) {
882     // Create a new list of choices for backtrack based on the current choice and conflicting event number
883     // E.g. if we have a conflict between 1 and 3, then we create the list {3, 1, 0, 2}
884     // for the original set {0, 1, 2, 3}
885     Integer[] newChoiceList = new Integer[refChoices.length];
886     ArrayList<TransitionEvent> currentTrace = execution.getExecutionTrace();
887     ArrayList<TransitionEvent> conflictTrace = conflictExecution.getExecutionTrace();
888     int currChoice = currentTrace.get(currentChoice).getChoice();
889     int stateId = conflictTrace.get(conflictChoice).getStateId();
890     // Check if this trace has been done from this state
891     if (isTraceAlreadyConstructed(currChoice, stateId)) {
892       return;
893     }
894     // Put the conflicting event numbers first and reverse the order
895     newChoiceList[0] = currChoice;
896     // Put the rest of the event numbers into the array starting from the minimum to the upper bound
897     for (int i = 0, j = 1; i < refChoices.length; i++) {
898       if (refChoices[i] != newChoiceList[0]) {
899         newChoiceList[j] = refChoices[i];
900         j++;
901       }
902     }
903     // Predecessor of the new backtrack point is the same as the conflict point's
904     addNewBacktrackPoint(stateId, newChoiceList, conflictTrace.get(conflictChoice));
905   }
906
907   private boolean excludeThisForItContains(String[] excludedStrings, String className) {
908     for (String excludedField : excludedStrings) {
909       if (className.contains(excludedField)) {
910         return true;
911       }
912     }
913     return false;
914   }
915
916   private boolean excludeThisForItEndsWith(String[] excludedStrings, String className) {
917     for (String excludedField : excludedStrings) {
918       if (className.endsWith(excludedField)) {
919         return true;
920       }
921     }
922     return false;
923   }
924
925   private boolean excludeThisForItStartsWith(String[] excludedStrings, String className) {
926     for (String excludedField : excludedStrings) {
927       if (className.startsWith(excludedField)) {
928         return true;
929       }
930     }
931     return false;
932   }
933
934   private void exploreNextBacktrackPoints(VM vm, IntChoiceFromSet icsCG) {
935                 // Check if we are reaching the end of our execution: no more backtracking points to explore
936                 // cgMap, backtrackMap, backtrackStateQ are updated simultaneously (checking backtrackStateQ is enough)
937                 if (!backtrackStateQ.isEmpty()) {
938                         // Set done all the other backtrack points
939                         for (TransitionEvent backtrackTransition : currentExecution.getExecutionTrace()) {
940         backtrackTransition.getTransitionCG().setDone();
941                         }
942                         // Reset the next backtrack point with the latest state
943                         int hiStateId = backtrackStateQ.peek();
944                         // Restore the state first if necessary
945                         if (vm.getStateId() != hiStateId) {
946                                 RestorableVMState restorableState = restorableStateMap.get(hiStateId);
947                                 vm.restoreState(restorableState);
948                         }
949                         // Set the backtrack CG
950                         IntChoiceFromSet backtrackCG = (IntChoiceFromSet) vm.getChoiceGenerator();
951                         setBacktrackCG(hiStateId, backtrackCG);
952                 } else {
953                         // Set done this last CG (we save a few rounds)
954                         icsCG.setDone();
955                 }
956                 // Save all the visited states when starting a new execution of trace
957                 prevVisitedStates.addAll(currVisitedStates);
958                 // This marks a transitional period to the new CG
959                 isEndOfExecution = true;
960   }
961
962   private boolean isConflictFound(Execution execution, int reachableChoice, Execution conflictExecution, int conflictChoice,
963                                   ReadWriteSet currRWSet) {
964     ArrayList<TransitionEvent> executionTrace = execution.getExecutionTrace();
965     ArrayList<TransitionEvent> conflictTrace = conflictExecution.getExecutionTrace();
966     HashMap<Integer, ReadWriteSet> confRWFieldsMap = conflictExecution.getReadWriteFieldsMap();
967     // Skip if this event does not have any Read/Write set or the two events are basically the same event (number)
968     if (!confRWFieldsMap.containsKey(conflictChoice) ||
969             executionTrace.get(reachableChoice).getChoice() == conflictTrace.get(conflictChoice).getChoice()) {
970       return false;
971     }
972     // R/W set of choice/event that may have a potential conflict
973     ReadWriteSet confRWSet = confRWFieldsMap.get(conflictChoice);
974     // Check for conflicts with Read and Write fields for Write instructions
975     Set<String> currWriteSet = currRWSet.getWriteSet();
976     for(String writeField : currWriteSet) {
977       int currObjId = currRWSet.writeFieldObjectId(writeField);
978       if ((confRWSet.readFieldExists(writeField) && confRWSet.readFieldObjectId(writeField) == currObjId) ||
979           (confRWSet.writeFieldExists(writeField) && confRWSet.writeFieldObjectId(writeField) == currObjId)) {
980         // Remove this from the write set as we are tracking per memory location
981         currRWSet.removeWriteField(writeField);
982         return true;
983       }
984     }
985     // Check for conflicts with Write fields for Read instructions
986     Set<String> currReadSet = currRWSet.getReadSet();
987     for(String readField : currReadSet) {
988       int currObjId = currRWSet.readFieldObjectId(readField);
989       if (confRWSet.writeFieldExists(readField) && confRWSet.writeFieldObjectId(readField) == currObjId) {
990         // Remove this from the read set as we are tracking per memory location
991         currRWSet.removeReadField(readField);
992         return true;
993       }
994     }
995     // Return false if no conflict is found
996     return false;
997   }
998
999   private ReadWriteSet getReadWriteSet(int currentChoice) {
1000     // Do the analysis to get Read and Write accesses to fields
1001     ReadWriteSet rwSet;
1002     // We already have an entry
1003     HashMap<Integer, ReadWriteSet> currReadWriteFieldsMap = currentExecution.getReadWriteFieldsMap();
1004     if (currReadWriteFieldsMap.containsKey(currentChoice)) {
1005       rwSet = currReadWriteFieldsMap.get(currentChoice);
1006     } else { // We need to create a new entry
1007       rwSet = new ReadWriteSet();
1008       currReadWriteFieldsMap.put(currentChoice, rwSet);
1009     }
1010     return rwSet;
1011   }
1012
1013   private boolean isFieldExcluded(Instruction executedInsn) {
1014     // Get the field info
1015     FieldInfo fieldInfo = ((JVMFieldInstruction) executedInsn).getFieldInfo();
1016     // Check if the non-relevant fields set already has it
1017     if (nonRelevantFields.contains(fieldInfo)) {
1018       return true;
1019     }
1020     // Check if the relevant fields set already has it
1021     if (relevantFields.contains(fieldInfo)) {
1022       return false;
1023     }
1024     // Analyze only after being initialized
1025     String field = fieldInfo.getFullName();
1026     // Check against "starts-with", "ends-with", and "contains" list
1027     if (excludeThisForItStartsWith(EXCLUDED_FIELDS_STARTS_WITH_LIST, field) ||
1028             excludeThisForItEndsWith(EXCLUDED_FIELDS_ENDS_WITH_LIST, field) ||
1029             excludeThisForItContains(EXCLUDED_FIELDS_CONTAINS_LIST, field)) {
1030       nonRelevantFields.add(fieldInfo);
1031       return true;
1032     }
1033     relevantFields.add(fieldInfo);
1034     return false;
1035   }
1036
1037   // Check if this trace is already constructed
1038   private boolean isTraceAlreadyConstructed(int firstChoice, int stateId) {
1039     // Concatenate state ID and only the first event in the string, e.g., "1:1 for the trace 10234 at state 1"
1040     // TODO: THIS IS AN OPTIMIZATION!
1041     // This is the optimized version because after we execute, e.g., the trace 1:10234, we don't need to try
1042     // another trace that starts with event 1 at state 1, e.g., the trace 1:13024
1043     // The second time this event 1 is explored, it will generate the same state as the first one
1044     StringBuilder sb = new StringBuilder();
1045     sb.append(stateId);
1046     sb.append(':');
1047     sb.append(firstChoice);
1048     // Check if the trace has been constructed as a backtrack point for this state
1049     if (doneBacktrackSet.contains(sb.toString())) {
1050       return true;
1051     }
1052     doneBacktrackSet.add(sb.toString());
1053     return false;
1054   }
1055
1056   // Reset data structure for each new execution
1057   private void resetStatesForNewExecution(IntChoiceFromSet icsCG, VM vm) {
1058     if (choices == null || choices != icsCG.getAllChoices()) {
1059       // Reset state variables
1060       choiceCounter = 0;
1061       choices = icsCG.getAllChoices();
1062       refChoices = copyChoices(choices);
1063       // Clear data structures
1064       currVisitedStates = new HashSet<>();
1065       stateToEventMap = new HashMap<>();
1066       isEndOfExecution = false;
1067     }
1068   }
1069
1070   // Set a backtrack point for a particular state
1071   private void setBacktrackCG(int stateId, IntChoiceFromSet backtrackCG) {
1072     // Set a backtrack CG based on a state ID
1073     LinkedList<BacktrackExecution> backtrackExecutions = backtrackMap.get(stateId);
1074     BacktrackExecution backtrackExecution = backtrackExecutions.removeLast();
1075     backtrackCG.setNewValues(backtrackExecution.getChoiceList());  // Get the last from the queue
1076     backtrackCG.setStateId(stateId);
1077     backtrackCG.reset();
1078     // Update current execution with this new execution
1079     Execution newExecution = new Execution();
1080     TransitionEvent firstTransition = backtrackExecution.getFirstTransition();
1081     newExecution.addTransition(firstTransition);
1082     // Try to free some memory since this map is only used for the current execution
1083     currentExecution.clearCGToChoiceMap();
1084     currentExecution = newExecution;
1085     // Remove from the queue if we don't have more backtrack points for that state
1086     if (backtrackExecutions.isEmpty()) {
1087       backtrackMap.remove(stateId);
1088       backtrackStateQ.remove(stateId);
1089     }
1090   }
1091
1092   // Update backtrack sets
1093   // 1) recursively, and
1094   // 2) track accesses per memory location (per shared variable/field)
1095   private void updateBacktrackSet(Execution execution, int currentChoice) {
1096     // Copy ReadWriteSet object
1097     HashMap<Integer, ReadWriteSet> currRWFieldsMap = execution.getReadWriteFieldsMap();
1098     ReadWriteSet currRWSet = currRWFieldsMap.get(currentChoice);
1099     if (currRWSet == null) {
1100       return;
1101     }
1102     currRWSet = currRWSet.getCopy();
1103     // Memorize visited TransitionEvent object while performing backward DFS to avoid getting caught up in a cycle
1104     HashSet<TransitionEvent> visited = new HashSet<>();
1105     // Update backtrack set recursively
1106     // TODO: The following is the call to the original version of the method
1107 //    updateBacktrackSetRecursive(execution, currentChoice, execution, currentChoice, currRWSet, visited);
1108     // TODO: The following is the call to the version of the method with pushing up happens-before transitions
1109     updateBacktrackSetRecursive(execution, currentChoice, execution, currentChoice, execution, currentChoice, currRWSet, visited);
1110   }
1111
1112 //  TODO: This is the original version of the recursive method
1113 //  private void updateBacktrackSetRecursive(Execution execution, int currentChoice,
1114 //                                           Execution conflictExecution, int conflictChoice,
1115 //                                           ReadWriteSet currRWSet, HashSet<TransitionEvent> visited) {
1116 //    // Halt when we have found the first read/write conflicts for all memory locations
1117 //    if (currRWSet.isEmpty()) {
1118 //      return;
1119 //    }
1120 //    TransitionEvent confTrans = conflictExecution.getExecutionTrace().get(conflictChoice);
1121 //    // Halt when we have visited this transition (in a cycle)
1122 //    if (visited.contains(confTrans)) {
1123 //      return;
1124 //    }
1125 //    visited.add(confTrans);
1126 //    // Explore all predecessors
1127 //    for (Predecessor predecessor : confTrans.getPredecessors()) {
1128 //      // Get the predecessor (previous conflict choice)
1129 //      conflictChoice = predecessor.getChoice();
1130 //      conflictExecution = predecessor.getExecution();
1131 //      // Check if a conflict is found
1132 //      if (isConflictFound(execution, currentChoice, conflictExecution, conflictChoice, currRWSet)) {
1133 //        createBacktrackingPoint(execution, currentChoice, conflictExecution, conflictChoice);
1134 //      }
1135 //      // Continue performing DFS if conflict is not found
1136 //      updateBacktrackSetRecursive(execution, currentChoice, conflictExecution, conflictChoice, currRWSet, visited);
1137 //    }
1138 //  }
1139
1140   // TODO: This is the version of the method with pushing up happens-before transitions
1141   private void updateBacktrackSetRecursive(Execution execution, int currentChoice,
1142                                            Execution conflictExecution, int conflictChoice,
1143                                            Execution hbExecution, int hbChoice,
1144                                            ReadWriteSet currRWSet, HashSet<TransitionEvent> visited) {
1145     // Halt when we have found the first read/write conflicts for all memory locations
1146     if (currRWSet.isEmpty()) {
1147       return;
1148     }
1149     TransitionEvent confTrans = conflictExecution.getExecutionTrace().get(conflictChoice);
1150     // Halt when we have visited this transition (in a cycle)
1151     if (visited.contains(confTrans)) {
1152       return;
1153     }
1154     visited.add(confTrans);
1155     // Explore all predecessors
1156     for (Predecessor predecessor : confTrans.getPredecessors()) {
1157       // Get the predecessor (previous conflict choice)
1158       conflictChoice = predecessor.getChoice();
1159       conflictExecution = predecessor.getExecution();
1160       // Push up one happens-before transition
1161       int pushedChoice = hbChoice;
1162       Execution pushedExecution = hbExecution;
1163       // Check if a conflict is found
1164       if (isConflictFound(execution, currentChoice, conflictExecution, conflictChoice, currRWSet)) {
1165         createBacktrackingPoint(pushedExecution, pushedChoice, conflictExecution, conflictChoice);
1166         pushedChoice = conflictChoice;
1167         pushedExecution = conflictExecution;
1168       }
1169       // Continue performing DFS if conflict is not found
1170       updateBacktrackSetRecursive(execution, currentChoice, conflictExecution, conflictChoice,
1171               pushedExecution, pushedChoice, currRWSet, visited);
1172     }
1173     // Remove the transition after being explored
1174     // TODO: Seems to cause a lot of loops---commented out for now
1175     //visited.remove(confTrans);
1176   }
1177
1178   // --- Functions related to the reachability analysis when there is a state match
1179
1180   private void analyzeReachabilityAndCreateBacktrackPoints(VM vm, int stateId) {
1181     // Perform this analysis only when:
1182     // 1) this is not during a switch to a new execution,
1183     // 2) at least 2 choices/events have been explored (choiceCounter > 1),
1184     // 3) state > 0 (state 0 is for boolean CG)
1185     if (!isEndOfExecution && choiceCounter > 1 && stateId > 0) {
1186       if (currVisitedStates.contains(stateId) || prevVisitedStates.contains(stateId)) {
1187         // Update reachable transitions in the graph with a predecessor
1188         HashSet<TransitionEvent> reachableTransitions = rGraph.getReachableTransitionsAtState(stateId);
1189         for(TransitionEvent transition : reachableTransitions) {
1190           transition.recordPredecessor(currentExecution, choiceCounter - 1);
1191         }
1192         updateBacktrackSetsFromPreviousExecution(stateId);
1193       }
1194     }
1195   }
1196
1197   // Update the backtrack sets from previous executions
1198   private void updateBacktrackSetsFromPreviousExecution(int stateId) {
1199     // Collect all the reachable transitions from R-Graph
1200     HashSet<TransitionEvent> reachableTransitions = rGraph.getReachableTransitions(stateId);
1201     for(TransitionEvent transition : reachableTransitions) {
1202       Execution execution = transition.getExecution();
1203       int currentChoice = transition.getChoiceCounter();
1204       updateBacktrackSet(execution, currentChoice);
1205     }
1206   }
1207 }