Make a change in ConflictTracker analysis
[jpf-core.git] / src / main / gov / nasa / jpf / listener / ConflictTracker.java
index 1cd281dcd3823f1b25c9383d9b6219067ae82987..8b4e28486c6bb972e14ba9834db430cb3c6b10ef 100644 (file)
@@ -89,12 +89,13 @@ public class ConflictTracker extends ListenerAdapter {
 
   boolean propagateTheChange(Node currentNode) {
     HashSet<Node> changed = new HashSet<Node>(currentNode.getSuccessors());
-    HashMap<Node, HashSet<Node>> parentQueueMap = new HashMap<Node, HashSet<Node>>();
-    HashSet<Node> parents = new HashSet<Node>();
-    parents.add(currentNode);
+    boolean isChanged = false;
 
     for (Node node : currentNode.getSuccessors()) {
-      parentQueueMap.put(node, parents);
+      isChanged = false;
+      isChanged = updateTheOutSet(currentNode, node);
+      if (isChanged)
+        changed.add(node);
     }
 
     while(!changed.isEmpty()) {
@@ -102,47 +103,15 @@ public class ConflictTracker extends ListenerAdapter {
       Node nodeToProcess = changed.iterator().next();
       changed.remove(nodeToProcess);
 
-      // Update the changed parents
-      parents.clear();
-      parents = parentQueueMap.get(nodeToProcess);
-      boolean isChanged = false;
-
-      for (Node node : parents) {
-        // Update the edge
-       isChanged |= updateTheOutSet(node, nodeToProcess);
-      }
-
-      // All the changes in parents are propagated
-      parentQueueMap.get(nodeToProcess).clear();
-
-      // Check for a conflict if the outSet of nodeToProcess is changed
-      if (isChanged) {
-        for (Node node : nodeToProcess.getSuccessors()) {
-         HashMap<Transition, ArrayList<NameValuePair>> setSets = nodeToProcess.getOutgoingEdges().get(node).getSetSetMap();
-         for (Map.Entry mapElement : setSets.entrySet()) {
-           Transition transition = (Transition)mapElement.getKey();
-           if (checkForConflict(nodeToProcess, node, transition))
-             return true;
-         }
-        }
-      }
-
-      // Update the parents list for the successors of the current node
-      parents.clear();
-      parents.add(nodeToProcess);
-
-      // 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);
-
-         // Update the list of updated parents for the current node
-         if (parentQueueMap.containsKey(i))
-            parentQueueMap.get(i).add(nodeToProcess);
-         else
-           parentQueueMap.put(i, parents);
-        }
+      // Update all the successors of the node
+      for (Node node : nodeToProcess.getSuccessors()) {
+       isChanged = false;
+       isChanged = updateTheOutSet(nodeToProcess, node);
+       if (isChanged) {
+          changed.add(node);
+          if (checkAllSuccForConflict(node))
+            return true;
+       }
       }
     }
     return false;
@@ -158,6 +127,18 @@ public class ConflictTracker extends ListenerAdapter {
     return message;
   }
 
+  boolean checkAllSuccForConflict(Node currentNode) {
+    for (Node node : currentNode.getSuccessors()) {
+      HashMap<Transition, ArrayList<NameValuePair>> setSets = currentNode.getOutgoingEdges().get(node).getSetSetMap();
+      for (Map.Entry mapElement : setSets.entrySet()) {
+        Transition transition = (Transition)mapElement.getKey();
+       if (checkForConflict(currentNode, node, transition))
+         return true;
+      }
+    }
+    return false;
+  }
+
   boolean checkForConflict(Node parentNode, Node currentNode, Transition currentTransition) {
     ArrayList<NameValuePair> setSet = parentNode.getOutgoingEdges().get(currentNode).getSetSetMap().get(currentTransition);
     HashMap<String, String> valueMap = new HashMap<String, String>(); // HashMap from varName to value
@@ -420,6 +401,11 @@ public class ConflictTracker extends ListenerAdapter {
 
     out.println("The state is restored to state with id: "+id+", depth: "+depth);
   
+    if (id == 24 && depth == 5) {
+           System.out.println("*****************************************");
+           System.out.println("*****************************************");
+           System.out.println("*****************************************");
+    }
     // Update the parent node
     if (nodes.containsKey(id)) {
       parentNode = nodes.get(id);
@@ -484,17 +470,17 @@ public class ConflictTracker extends ListenerAdapter {
     // Update the outset of the current node and check if it is changed or not to propagate the change
     boolean isChanged = updateTheOutSet(parentNode, currentNode);
 
+
+    System.out.println("######################### The outset is:");
+    for (NameValuePair nvp : currentNode.getOutSet()) {
+       System.out.println("writer: "+nvp.getAppNum());
+       System.out.println("value: "+nvp.getValue());
+       System.out.println("var : "+nvp.getVarName());
+    }      
     // Check if the outSet of this state has changed, update all of its successors' sets if any
-    if (isChanged) {
-      for (Node node : currentNode.getSuccessors()) {
-        HashMap<Transition, ArrayList<NameValuePair>> setSets = currentNode.getOutgoingEdges().get(node).getSetSetMap();
-       for (Map.Entry mapElement : setSets.entrySet()) {
-         Transition currentTransition = (Transition)mapElement.getKey();
-         conflictFound = conflictFound || checkForConflict(currentNode, node, currentTransition);
-       }
-      }
-      conflictFound = conflictFound || propagateTheChange(currentNode);
-    }
+    if (isChanged)
+      conflictFound = conflictFound || checkAllSuccForConflict(currentNode) || propagateTheChange(currentNode);
+    
     // Update the parent node
     if (nodes.containsKey(id)) {
       parentNode = nodes.get(id);
@@ -512,6 +498,12 @@ public class ConflictTracker extends ListenerAdapter {
 
     out.println("The state is backtracked to state with id: "+id+", depth: "+depth);
 
+    if (id == 24 && depth == 5) {
+            System.out.println("*****************************************");
+            System.out.println("*****************************************");
+            System.out.println("*****************************************");
+    }
+
     // Update the parent node
     if (nodes.containsKey(id)) {
       parentNode = nodes.get(id);
@@ -716,7 +708,10 @@ public class ConflictTracker extends ListenerAdapter {
 
               if (getWriter(ti.getStack(), manualSet) != null)
                 manual = true;
-
+             
+             System.out.println("############################## writer: "+writer);
+             System.out.println("############################## value: "+value);
+             System.out.println("############################## var: "+var);
               // Update the temporary Set set.
               writeWriterAndValue(writer, value, var);
             }