import gov.nasa.jpf.ListenerAdapter;
import gov.nasa.jpf.jvm.bytecode.INVOKEINTERFACE;
import gov.nasa.jpf.jvm.bytecode.JVMFieldInstruction;
+import gov.nasa.jpf.report.Publisher;
import gov.nasa.jpf.search.Search;
import gov.nasa.jpf.vm.*;
import gov.nasa.jpf.vm.bytecode.ReadInstruction;
private HashSet<ClassInfo> nonRelevantClasses;// Class info objects of non-relevant classes
private HashSet<FieldInfo> nonRelevantFields; // Field info objects of non-relevant fields
private HashSet<FieldInfo> relevantFields; // Field info objects of relevant fields
- private HashMap<Integer, HashSet<Integer>> stateToEventMap;
+ private HashMap<Integer, HashSet<Integer>> stateToEventMap; // Map state ID to events
// Data structure to analyze field Read/Write accesses and conflicts
private HashMap<Integer, LinkedList<BacktrackExecution>> backtrackMap; // Track created backtracking points
private PriorityQueue<Integer> backtrackStateQ; // Heap that returns the latest state
// Statistics
private int numOfTransitions;
+ private HashMap<Integer, HashSet<Integer>> stateToUniqueEventMap;
public DPORStateReducerWithSummary(Config config, JPF jpf) {
verboseMode = config.getBoolean("printout_state_transition", false);
relevantFields = new HashSet<>();
restorableStateMap = new HashMap<>();
stateToPredInfo = new HashMap<>();
+ stateToUniqueEventMap = new HashMap<>();
initializeStatesVariables();
}
public void searchFinished(Search search) {
if (verboseMode) {
out.println("\n==> DEBUG: ----------------------------------- search finished");
- out.println("\n==> DEBUG: State reduction mode : " + stateReductionMode);
- out.println("\n==> DEBUG: Number of transitions : " + numOfTransitions);
+ out.println("\n==> DEBUG: State reduction mode : " + stateReductionMode);
+ out.println("\n==> DEBUG: Number of transitions : " + numOfTransitions);
+ out.println("\n==> DEBUG: Number of unique transitions (DPOR) : " + summarizeUniqueStateIds());
out.println("\n==> DEBUG: ----------------------------------- search finished" + "\n");
- fileWriter.println("==> DEBUG: State reduction mode : " + stateReductionMode);
- fileWriter.println("==> DEBUG: Number of transitions : " + numOfTransitions);
+ fileWriter.println("==> DEBUG: State reduction mode : " + stateReductionMode);
+ fileWriter.println("==> DEBUG: Number of transitions : " + numOfTransitions);
+ fileWriter.println("==> DEBUG: Number of unique transitions : " + summarizeUniqueStateIds());
fileWriter.println();
fileWriter.close();
}
IntChoiceFromSet icsCG = (IntChoiceFromSet) nextCG;
Integer[] cgChoices = icsCG.getAllChoices();
if (cgChoices.length == 2 && cgChoices[0] == 0 && cgChoices[1] == -1) {
+ // This means the benchmark only has 2 choices, i.e., 0 and -1 which means that it has no events
stateReductionMode = false;
}
isNotCheckedForEventsYet = false;
exploreNextBacktrackPoints(vm, icsCG);
} else {
numOfTransitions++;
+ countUniqueStateId(vm.getStateId(), icsCG.getNextChoice());
}
// Map state to event
mapStateToEvent(icsCG.getNextChoice());
}
}
+ // Count unique state IDs
+ private void countUniqueStateId(int stateId, int nextChoiceValue) {
+ HashSet<Integer> events;
+ // Get the set of events
+ if (!stateToUniqueEventMap.containsKey(stateId)) {
+ events = new HashSet<>();
+ stateToUniqueEventMap.put(stateId, events);
+ } else {
+ events = stateToUniqueEventMap.get(stateId);
+ }
+ // Insert the event
+ if (!events.contains(nextChoiceValue)) {
+ events.add(nextChoiceValue);
+ }
+ }
+
+ // Summarize unique state IDs
+ private int summarizeUniqueStateIds() {
+ // Just count the set size of each of entry map and sum them up
+ int numOfUniqueTransitions = 0;
+ for (Map.Entry<Integer,HashSet<Integer>> entry : stateToUniqueEventMap.entrySet()) {
+ numOfUniqueTransitions = numOfUniqueTransitions + entry.getValue().size();
+ }
+ // We also need to count root and boolean CG if this is in state reduction mode (DPOR)
+ if (stateReductionMode) {
+ numOfUniqueTransitions = numOfUniqueTransitions + 3;
+ }
+
+ return numOfUniqueTransitions;
+ }
+
@Override
public void instructionExecuted(VM vm, ThreadInfo ti, Instruction nextInsn, Instruction executedInsn) {
if (stateReductionMode) {
Set<Integer> eventChoicesAtStateId = mainSummary.getEventChoicesAtStateId(stateId);
for (Integer eventChoice : eventChoicesAtStateId) {
// Get the ReadWriteSet object for this event at state ID
- ReadWriteSet rwSet = mainSummary.getRWSetForEventChoiceAtState(eventChoice, stateId);
+ ReadWriteSet rwSet = mainSummary.getRWSetForEventChoiceAtState(eventChoice, stateId).getCopy();
+ // We have to first check for conflicts between the event and the current transition
+ // Push up one happens-before transition
+ int conflictEventChoice = eventChoice;
+ if (isConflictFound(eventChoice, currExecution, currChoice, rwSet)) {
+ createBacktrackingPoint(eventChoice, currExecution, currChoice);
+ // We need to extract the pushed happens-before event choice from the predecessor execution and choice
+ conflictEventChoice = currExecution.getExecutionTrace().get(currChoice).getChoice();
+ }
// Memorize visited TransitionEvent object while performing backward DFS to avoid getting caught up in a cycle
HashSet<TransitionEvent> visited = new HashSet<>();
// Update the backtrack sets recursively
- updateBacktrackSetDFS(currExecution, currChoice, eventChoice, rwSet.getCopy(), visited);
+ updateBacktrackSetDFS(currExecution, currChoice, conflictEventChoice, rwSet, visited);
}
}
}