// Initialize with necessary information from the CG
if (nextCG instanceof IntChoiceFromSet) {
IntChoiceFromSet icsCG = (IntChoiceFromSet) nextCG;
+ // Tell JPF that we are performing DPOR
+ icsCG.setDpor();
if (!isEndOfExecution) {
// Check if CG has been initialized, otherwise initialize it
Integer[] cgChoices = icsCG.getAllChoices();
private ArrayList<TransitionEvent> executionTrace; // The BacktrackPoint objects of this execution
private boolean isNew; // Track if this is the first time it is accessed
private HashMap<Integer, ReadWriteSet> readWriteFieldsMap; // Record fields that are accessed
- private HashMap<Integer, TransitionEvent> stateToTransitionMap; // For O(1) access to backtrack point
public Execution() {
cgToChoiceMap = new HashMap<>();
executionTrace = new ArrayList<>();
isNew = true;
readWriteFieldsMap = new HashMap<>();
- stateToTransitionMap = new HashMap<>();
}
public void addTransition(TransitionEvent newBacktrackPoint) {
return executionTrace.get(0);
}
- public HashMap<Integer, ReadWriteSet> getReadWriteFieldsMap() {
- return readWriteFieldsMap;
+ public TransitionEvent getLastTransition() {
+ return executionTrace.get(executionTrace.size() - 1);
}
- public TransitionEvent getTransitionFromState(int stateId) {
- if (stateToTransitionMap.containsKey(stateId)) {
- return stateToTransitionMap.get(stateId);
- }
- // Return the latest transition for unseen states (that have just been encountered in this transition)
- return executionTrace.get(executionTrace.size() - 1);
+ public HashMap<Integer, ReadWriteSet> getReadWriteFieldsMap() {
+ return readWriteFieldsMap;
}
public boolean isNew() {
public void mapCGToChoice(IntChoiceFromSet icsCG, int choice) {
cgToChoiceMap.put(icsCG, choice);
}
-
- public void mapStateToTransition(int stateId, TransitionEvent backtrackPoint) {
- stateToTransitionMap.put(stateId, backtrackPoint);
- }
}
// This class compactly stores a predecessor
}
public HashSet<TransitionEvent> getReachableTransitionsAtState(int stateId) {
+ if (!graph.containsKey(stateId)) {
+ // This is a loop from a transition to itself, so just return the current transition
+ HashSet<TransitionEvent> transitionSet = new HashSet<>();
+ transitionSet.add(currentExecution.getLastTransition());
+ return transitionSet;
+ }
return graph.get(stateId);
}
HashSet<TransitionEvent> reachableTransitions = new HashSet<>();
// All transitions from states higher than the given state ID (until the highest state ID) are reachable
for(int stId = stateId; stId <= hiStateId; stId++) {
- reachableTransitions.addAll(graph.get(stId));
+ // We might encounter state IDs from the first round of Boolean CG
+ // The second round of Boolean CG should consider these new states
+ if (graph.containsKey(stId)) {
+ reachableTransitions.addAll(graph.get(stId));
+ }
}
return reachableTransitions;
}
// Add new transition to the current execution and map it in R-Graph
for (Integer stId : justVisitedStates) { // Map this transition to all the previously passed states
rGraph.addReachableTransition(stId, transition);
- currentExecution.mapStateToTransition(stId, transition);
}
currentExecution.mapCGToChoice(icsCG, choiceCounter);
// Store restorable state object for this state (always store the latest)
private boolean isConflictFound(Execution execution, int reachableChoice, Execution conflictExecution, int conflictChoice,
ReadWriteSet currRWSet) {
ArrayList<TransitionEvent> executionTrace = execution.getExecutionTrace();
- HashMap<Integer, ReadWriteSet> execRWFieldsMap = execution.getReadWriteFieldsMap();
ArrayList<TransitionEvent> conflictTrace = conflictExecution.getExecutionTrace();
+ HashMap<Integer, ReadWriteSet> confRWFieldsMap = conflictExecution.getReadWriteFieldsMap();
// Skip if this event does not have any Read/Write set or the two events are basically the same event (number)
- if (!execRWFieldsMap.containsKey(conflictChoice) ||
+ if (!confRWFieldsMap.containsKey(conflictChoice) ||
executionTrace.get(reachableChoice).getChoice() == conflictTrace.get(conflictChoice).getChoice()) {
return false;
}
// R/W set of choice/event that may have a potential conflict
- ReadWriteSet evtRWSet = execRWFieldsMap.get(conflictChoice);
+ ReadWriteSet confRWSet = confRWFieldsMap.get(conflictChoice);
// Check for conflicts with Read and Write fields for Write instructions
Set<String> currWriteSet = currRWSet.getWriteSet();
for(String writeField : currWriteSet) {
int currObjId = currRWSet.writeFieldObjectId(writeField);
- if ((evtRWSet.readFieldExists(writeField) && evtRWSet.readFieldObjectId(writeField) == currObjId) ||
- (evtRWSet.writeFieldExists(writeField) && evtRWSet.writeFieldObjectId(writeField) == currObjId)) {
+ if ((confRWSet.readFieldExists(writeField) && confRWSet.readFieldObjectId(writeField) == currObjId) ||
+ (confRWSet.writeFieldExists(writeField) && confRWSet.writeFieldObjectId(writeField) == currObjId)) {
// Remove this from the write set as we are tracking per memory location
currRWSet.removeWriteField(writeField);
return true;
Set<String> currReadSet = currRWSet.getReadSet();
for(String readField : currReadSet) {
int currObjId = currRWSet.readFieldObjectId(readField);
- if (evtRWSet.writeFieldExists(readField) && evtRWSet.writeFieldObjectId(readField) == currObjId) {
+ if (confRWSet.writeFieldExists(readField) && confRWSet.writeFieldObjectId(readField) == currObjId) {
// Remove this from the read set as we are tracking per memory location
currRWSet.removeReadField(readField);
return true;
updateBacktrackSetRecursive(execution, currentChoice, conflictExecution, conflictChoice,
pushedExecution, pushedChoice, currRWSet, visited);
}
+ // Remove the transition after being explored
+ // TODO: Seems to cause a lot of loops---commented out for now
+ //visited.remove(confTrans);
}
// --- Functions related to the reachability analysis when there is a state match
// 2) at least 2 choices/events have been explored (choiceCounter > 1),
// 3) state > 0 (state 0 is for boolean CG)
if (!isEndOfExecution && choiceCounter > 1 && stateId > 0) {
- if (currVisitedStates.contains(stateId)) {
- // Get the backtrack point from the current execution
- TransitionEvent transition = currentExecution.getTransitionFromState(stateId);
- transition.recordPredecessor(currentExecution, choiceCounter - 1);
- updateBacktrackSetsFromPreviousExecution(stateId);
- } else if (prevVisitedStates.contains(stateId)) { // We visit a state in a previous execution
- // Update past executions with a predecessor
+ if (currVisitedStates.contains(stateId) || prevVisitedStates.contains(stateId)) {
+ // Update reachable transitions in the graph with a predecessor
HashSet<TransitionEvent> reachableTransitions = rGraph.getReachableTransitionsAtState(stateId);
for(TransitionEvent transition : reachableTransitions) {
transition.recordPredecessor(currentExecution, choiceCounter - 1);