Fixing a bug in ConflictTracker.java
[jpf-core.git] / src / main / gov / nasa / jpf / listener / ConflictTracker.java
index 435a29a0a7505850384781699ab9d9b1d3cab8b7..ca405b25dacf78abaec4f885cbef1ef0c7852956 100644 (file)
@@ -100,15 +100,12 @@ public class ConflictTracker extends ListenerAdapter {
                boolean isChanged = updateEdge(currentNode, nodeToProcess);
 
                // Check for a conflict in this transition(currentNode -> nodeToProcess)
-               if (checkForConflict(currentNode))
+               if (checkForConflict(nodeToProcess))
                                return true;
 
                // Checking if the out set has changed or not(Add its successors to the change list!)
                if (isChanged) {
-                       for (Node i : nodeToProcess.getSuccessors()) {
-                               if (!changed.contains(i))
-                                       changed.add(i);
-                       }
+                       propagateTheChange(nodeToProcess);
                }
       }
 
@@ -121,6 +118,7 @@ public class ConflictTracker extends ListenerAdapter {
                         " to the variable: "+pair.getVarName()+" while App"+
                         writerMap.get(pair.getVarName())+" is overwriting the value: "
                         +valueMap.get(pair.getVarName())+" to the same variable!";
+       System.out.println(message);    
        return message;
   }
 
@@ -174,12 +172,12 @@ public class ConflictTracker extends ListenerAdapter {
   boolean updateEdge(Node parentNode, Node currentNode) {
        ArrayList<NameValuePair> setSet = currentNode.getSetSetMap().get(parentNode);
        HashSet<String> updatedVarNames = new HashSet<String>();
-       HashMap<String, Integer> lastWriter = new HashMap<String, Integer>(); // Store the last writer of each variable
        boolean isChanged = false;
-
-       for (int i = 0;i < setSet.size();i++) {
-               updatedVarNames.add(setSet.get(i).getVarName());
-               lastWriter.put(setSet.get(i).getVarName(), setSet.get(i).getAppNum());
+       
+       if (setSet != null) {
+               for (int i = 0;i < setSet.size();i++) {
+                       updatedVarNames.add(setSet.get(i).getVarName());
+               }
        }
 
        for (NameValuePair i : parentNode.getOutSet()) {
@@ -187,9 +185,12 @@ public class ConflictTracker extends ListenerAdapter {
                        isChanged |= currentNode.getOutSet().add(i);
        }
 
-       for (int i = 0;i < setSet.size();i++) {
-               if (setSet.get(i).getAppNum().equals(lastWriter.get(setSet.get(i).getVarName()))) // Add the last writer of each variable to outSet
+       if (setSet != null) {
+               for (int i = 0;i < setSet.size();i++) {
+                       if (currentNode.getOutSet().contains(setSet.get(i)))
+                               currentNode.getOutSet().remove(setSet.get(i));
                        isChanged |= currentNode.getOutSet().add(setSet.get(i));
+               }
        }
 
        return isChanged;
@@ -342,11 +343,10 @@ public class ConflictTracker extends ListenerAdapter {
     depth = search.getDepth();
     operation = "forward";
 
-    // Check for the conflict in this new transition
-    conflictFound = checkForConflict(parentNode);
+    // Add the node to the list of nodes
+    if (nodes.get(id) == null)
+       nodes.put(id, new Node(id));
 
-    // Add the node to the list of nodes       
-    nodes.put(id, new Node(id));
     Node currentNode = nodes.get(id);
 
     // Update the setSet for this new node
@@ -386,6 +386,9 @@ public class ConflictTracker extends ListenerAdapter {
     // Update the edge and check if the outset of the current node is changed or not to propagate the change
     boolean isChanged = updateEdge(parentNode, currentNode);
 
+    // Check for the conflict in this edge
+    conflictFound = checkForConflict(currentNode);
+    
     // Check if the outSet of this state has changed, update all of its successors' sets if any
     if (isChanged)
        conflictFound = conflictFound || propagateTheChange(currentNode);
@@ -565,7 +568,6 @@ public class ConflictTracker extends ListenerAdapter {
 
   @Override
   public void instructionExecuted(VM vm, ThreadInfo ti, Instruction nextInsn, Instruction executedInsn) {
-    // Instantiate timeoutTimer
     if (timeout > 0) {
       if (System.currentTimeMillis() - startTime > timeout) {
         StringBuilder sbTimeOut = new StringBuilder();
@@ -599,6 +601,7 @@ public class ConflictTracker extends ListenerAdapter {
       } else {
         if (executedInsn instanceof WriteInstruction) {
           String varId = ((WriteInstruction) executedInsn).getFieldInfo().getFullName();
+
           for (String var : conflictSet) {
             if (varId.contains(var)) {
               // Get variable info