Making field exclusion checks more efficient.
[jpf-core.git] / src / main / gov / nasa / jpf / listener / ConflictTracker.java
index 435a29a0a7505850384781699ab9d9b1d3cab8b7..620d1be410597f8ef34963696a895ca7c3e1592b 100644 (file)
@@ -27,6 +27,7 @@ import gov.nasa.jpf.vm.bytecode.LocalVariableInstruction;
 import gov.nasa.jpf.vm.bytecode.ReadInstruction;
 import gov.nasa.jpf.vm.bytecode.StoreInstruction;
 import gov.nasa.jpf.vm.bytecode.WriteInstruction;
+import gov.nasa.jpf.vm.choice.IntChoiceFromSet;
 
 import java.io.PrintWriter;
 
@@ -39,27 +40,33 @@ import java.util.*;
 public class ConflictTracker extends ListenerAdapter {
 
   private final PrintWriter out;
+  private final HashMap<Integer, Node> nodes = new HashMap<Integer, Node>(); // Nodes of a graph
   private final HashSet<String> conflictSet = new HashSet<String>(); // Variables we want to track
   private final HashSet<String> appSet = new HashSet<String>(); // Apps we want to find their conflicts
   private final HashSet<String> manualSet = new HashSet<String>(); // Writer classes with manual inputs to detect direct-direct(No Conflict) interactions
-  private final HashMap<Integer, Node> nodes = new HashMap<Integer, Node>(); // Nodes of a graph
-  private ArrayList<NameValuePair> tempSetSet = new ArrayList<NameValuePair>();
+  private HashSet<Transition> transitions = new HashSet<Transition>();
+  private ArrayList<Update> currUpdates = new ArrayList<Update>();
   private long timeout;
   private long startTime;
   private Node parentNode = new Node(-2);
   private String operation;
   private String detail;
   private String errorMessage;
+  private String varName;
   private int depth;
   private int id;
-  private boolean conflictFound = false;
   private boolean manual = false;
+  private boolean conflictFound = false;
+  private int currentEvent = -1;
+  private boolean debugMode = false;
+  private int popRef = 0;
 
   private final String SET_LOCATION_METHOD = "setLocationMode";
   private final String LOCATION_VAR = "locationMode";
-  
+
   public ConflictTracker(Config config, JPF jpf) {
     out = new PrintWriter(System.out, true);
+    debugMode = config.getBoolean("debug_mode", false);
 
     String[] conflictVars = config.getStringArray("variables");
     // We are not tracking anything if it is null
@@ -75,243 +82,260 @@ public class ConflictTracker extends ListenerAdapter {
         appSet.add(var);
       }
     }
-    String[] manualClasses = config.getStringArray("manualClasses");
-    // We are not tracking anything if it is null
-    if (manualClasses != null) {
-      for (String var : manualClasses) {
-        manualSet.add(var);
-      }
-    }
 
     // Timeout input from config is in minutes, so we need to convert into millis
     timeout = config.getInt("timeout", 0) * 60 * 1000;
     startTime = System.currentTimeMillis();
   }
 
-  boolean propagateTheChange(Node currentNode) {
-       HashSet<Node> changed = new HashSet<Node>(currentNode.getSuccessors());
+  void propagateChange(Edge newEdge) {
+    HashSet<Edge> changed = new HashSet<Edge>();
 
-       while(!changed.isEmpty()) {
-               // Get the first element of HashSet and remove it from the changed set
-               Node nodeToProcess = changed.iterator().next();
-               changed.remove(nodeToProcess);
+    // Add the current node to the changed set
+    changed.add(newEdge);
 
-               // Update the edge
-               boolean isChanged = updateEdge(currentNode, nodeToProcess);
+    while(!changed.isEmpty()) {
+      // Get the first element of the changed set and remove it
+      Edge edgeToProcess = changed.iterator().next();
+      changed.remove(edgeToProcess);
 
-               // Check for a conflict in this transition(currentNode -> nodeToProcess)
-               if (checkForConflict(currentNode))
-                               return true;
+      //If propagating change on edge causes change, enqueue all the target node's out edges
+      if (propagateEdge(edgeToProcess)) {
+        Node dst = edgeToProcess.getDst();
+        for (Edge e : dst.getOutEdges()) {
+          changed.add(e);
+        }
+      }
+    }
+  }
 
-               // 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);
-                       }
-               }
+  boolean propagateEdge(Edge e) {
+    HashMap<IndexObject, HashSet<Update>> srcUpdates = e.getSrc().getLastUpdates();
+    HashMap<IndexObject, HashSet<Update>> dstUpdates = e.getDst().getLastUpdates();
+    ArrayList<Update> edgeUpdates = e.getUpdates();
+    HashMap<IndexObject, Update> lastupdate = new HashMap<IndexObject, Update>();
+    boolean changed = false;
+    
+    //Go through each update on the current transition
+    for(int i=0; i<edgeUpdates.size(); i++) {
+      Update u = edgeUpdates.get(i);
+      IndexObject io = u.getIndex();
+      HashSet<Update> confupdates = null;
+
+      //See if we have already updated this device attribute
+      if (lastupdate.containsKey(io)) {
+        confupdates = new HashSet<Update>();
+        confupdates.add(lastupdate.get(io));
+      } else if (srcUpdates.containsKey(io)){
+        confupdates = srcUpdates.get(io);
       }
 
-      return false;
+      //Check for conflict with the appropriate update set if we are not a manual transition
+      //If this is debug mode, then we do not report any conflicts
+      if (!debugMode && confupdates != null && !u.isManual()) {
+        for(Update u2: confupdates) {
+          if (conflicts(u, u2)) {
+            //throw new RuntimeException(createErrorMessage(u, u2));
+            conflictFound = true;
+               errorMessage = createErrorMessage(u, u2);
+          }
+        }
+      }
+      lastupdate.put(io, u);
+    }
+    for(IndexObject io: srcUpdates.keySet()) {
+      //Only propagate src changes if the transition doesn't update the device attribute
+      if (!lastupdate.containsKey(io)) {
+        //Make sure destination has hashset in map
+        if (!dstUpdates.containsKey(io))
+          dstUpdates.put(io, new HashSet<Update>());
+
+        changed |= dstUpdates.get(io).addAll(srcUpdates.get(io));
+      }
+    }
+    for(IndexObject io: lastupdate.keySet()) {
+      //Make sure destination has hashset in map
+      if (!dstUpdates.containsKey(io))
+        dstUpdates.put(io, new HashSet<Update>());
+      
+      changed |= dstUpdates.get(io).add(lastupdate.get(io));
+    }
+    return changed;
   }
 
-  String createErrorMessage(NameValuePair pair, HashMap<String, String> valueMap, HashMap<String, Integer> writerMap) {
-       String message = "Conflict found between the two apps. App"+pair.getAppNum()+
-                        " has written the value: "+pair.getValue()+
-                        " to the variable: "+pair.getVarName()+" while App"+
-                        writerMap.get(pair.getVarName())+" is overwriting the value: "
-                        +valueMap.get(pair.getVarName())+" to the same variable!";
-       return message;
+  //Method to check for conflicts between two updates
+  //Have conflict if same device, same attribute, different app, different vaalue
+  boolean conflicts(Update u, Update u2) {
+    return (!u.getApp().equals(u2.getApp())) &&
+      u.getDeviceId().equals(u2.getDeviceId()) &&
+      u.getAttribute().equals(u2.getAttribute()) &&
+      (!u.getValue().equals(u2.getValue()));
   }
-
-  boolean checkForConflict(Node nodeToProcess) {
-       HashMap<String, String> valueMap = new HashMap<String, String>(); // HashMap from varName to value
-       HashMap<String, Integer> writerMap = new HashMap<String, Integer>(); // HashMap from varName to appNum
-
-       // Update the valueMap
-       for (int i = 0;i < nodeToProcess.getSetSet().size();i++) {
-               NameValuePair nameValuePair = nodeToProcess.getSetSet().get(i);
-
-               if (valueMap.containsKey(nameValuePair.getVarName())) {
-                       // Check if we have a same writer
-                       if (!writerMap.get(nameValuePair.getVarName()).equals(nameValuePair.getAppNum())) {
-                               // Check if we have a conflict or not
-                               if (!valueMap.get(nameValuePair.getVarName()).equals(nameValuePair.getValue())) {
-                                       errorMessage = createErrorMessage(nameValuePair, valueMap, writerMap);
-                                       return true;
-                               } else { // We have two writers writing the same value
-                                       writerMap.put(nameValuePair.getVarName(), 3); // 3 represents both apps
-                               }       
-                       } else {
-                               // Check if we have more than one value with the same writer
-                               if (!valueMap.get(nameValuePair.getVarName()).equals(nameValuePair.getValue())) {
-                                       valueMap.put(nameValuePair.getVarName(), "twoValue"); // We have one writer writing more than one value in a same event
-                               }
-                       }       
-               } else {
-                       valueMap.put(nameValuePair.getVarName(), nameValuePair.getValue());
-                       writerMap.put(nameValuePair.getVarName(), nameValuePair.getAppNum());
-               }
-       }
-
-       // Comparing the outSet to setSet
-       for (NameValuePair i : nodeToProcess.getOutSet()) {
-               if (valueMap.containsKey(i.getVarName())) {
-                       String value = valueMap.get(i.getVarName());
-                       Integer writer = writerMap.get(i.getVarName());
-                       if ((value != null)&&(writer != null)) {
-                               if (!value.equals(i.getValue())&&!writer.equals(i.getAppNum())) { // We have different values
-                                       errorMessage = createErrorMessage(i, valueMap, writerMap);
-                                       return true;
-                               }
-                       }
-               }
-       }
-
-       return false;
+  
+  String createErrorMessage(Update u, Update u2) {
+    String message = "Conflict found between the two apps. "+u.getApp()+
+                    " has written the value: "+u.getValue()+
+      " to the attribute: "+u.getAttribute()+" while "
+      +u2.getApp()+" is writing the value: "
+      +u2.getValue()+" to the same variable!";
+    System.out.println(message);       
+    return message;
   }
 
-  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;
+  Edge createEdge(Node parent, Node current, Transition transition, int evtNum) {
+    //Check if this transition is explored.  If so, just skip everything
+    if (transitions.contains(transition))
+      return null;
 
-       for (int i = 0;i < setSet.size();i++) {
-               updatedVarNames.add(setSet.get(i).getVarName());
-               lastWriter.put(setSet.get(i).getVarName(), setSet.get(i).getAppNum());
-       }
-
-       for (NameValuePair i : parentNode.getOutSet()) {
-               if (!updatedVarNames.contains(i.getVarName()))
-                       isChanged |= currentNode.getOutSet().add(i);
-       }
+    //Create edge
+    Edge e = new Edge(parent, current, transition, evtNum, currUpdates);
+    parent.addOutEdge(e);
 
-       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
-                       isChanged |= currentNode.getOutSet().add(setSet.get(i));
-       }
-
-       return isChanged;
+    //Mark transition as explored
+    transitions.add(transition);
+    return e;
   }
 
   static class Node {
-        Integer id;
-       HashSet<Node> predecessors = new HashSet<Node>();
-       HashSet<Node> successors = new HashSet<Node>();
-       HashSet<NameValuePair> outSet = new HashSet<NameValuePair>();
-       HashMap<Node, ArrayList<NameValuePair>> setSetMap = new HashMap<Node, ArrayList<NameValuePair>>();
-       ArrayList<NameValuePair> setSet = new ArrayList<NameValuePair>();
-
-
-       Node(Integer id) {
-         this.id = id;
-       }
-
-       void addPredecessor(Node node) {
-         predecessors.add(node);
-       }
+    Integer id;
+    Vector<Edge> outEdges = new Vector<Edge>();
+    HashMap<IndexObject, HashSet<Update>> lastUpdates = new HashMap<IndexObject,  HashSet<Update>>();
+    
+    Node(Integer id) {
+      this.id = id;
+    }
 
-       void addSuccessor(Node node) {
-         successors.add(node);
-       }
+    Integer getId() {
+      return id;
+    }
 
-       void setSetSet(ArrayList<NameValuePair> setSet, boolean isManual) {
-         if (isManual)
-           this.setSet = new ArrayList<NameValuePair>();
+    Vector<Edge> getOutEdges() {
+      return outEdges;
+    }
 
-         for (int i = 0;i < setSet.size();i++) {
-           this.setSet.add(new NameValuePair(setSet.get(i).getAppNum(), setSet.get(i).getValue(), 
-                                             setSet.get(i).getVarName(), setSet.get(i).getIsManual()));
-           }
-       }
+    void addOutEdge(Edge e) {
+      outEdges.add(e);
+    }
+    
+    HashMap<IndexObject, HashSet<Update>> getLastUpdates() {
+      return lastUpdates;
+    }
+  }
 
-       Integer getId() {
-               return id;
-       }
+  //Each Edge corresponds to a transition
+  static class Edge {
+    Node source, destination;
+    Transition transition;
+    int eventNumber;
+    ArrayList<Update> updates = new ArrayList<Update>();
+    
+    Edge(Node src, Node dst, Transition t, int evtNum, ArrayList<Update> _updates) {
+      this.source = src;
+      this.destination = dst;
+      this.transition = t;
+      this.eventNumber = evtNum;
+      this.updates.addAll(_updates);
+    }
 
-       HashSet<Node> getPredecessors() {
-               return predecessors;
-       }
+    Node getSrc() {
+      return source;
+    }
 
-       HashSet<Node> getSuccessors() {
-               return successors;
-       }
+    Node getDst() {
+      return destination;
+    }
 
-       ArrayList<NameValuePair> getSetSet() {
-               return setSet;
-       }
+    Transition getTransition() {
+      return transition;
+    }
 
-       HashSet<NameValuePair> getOutSet() {
-               return outSet;
-       }
+    int getEventNumber() { return eventNumber; }
 
-       HashMap<Node, ArrayList<NameValuePair>> getSetSetMap() {
-               return setSetMap;
-       }
+    ArrayList<Update> getUpdates() {
+      return updates;
+    }
   }
 
-  static class NameValuePair {
-       Integer appNum;
-       String value;
-       String varName;
-       boolean isManual;
-
-       NameValuePair(Integer appNum, String value, String varName, boolean isManual) {
-               this.appNum = appNum;
-               this.value = value;
-               this.varName = varName;
-               this.isManual = isManual;
-       }
-
-       void setAppNum(Integer appNum) {
-               this.appNum = appNum;
-       }
-
-       void setValue(String value) {
-               this.value = value;
-       }
-
-       void setVarName(String varName) {
-               this.varName = varName;
-       }
+  static class Update {
+    String appName;
+    String deviceId;
+    String attribute;
+    String value;
+    boolean ismanual;
+    
+    Update(String _appName, String _deviceId, String _attribute, String _value, boolean _ismanual) {
+      this.appName = _appName;
+      this.deviceId = _deviceId;
+      this.attribute = _attribute;
+      this.value = _value;
+      this.ismanual = _ismanual;
+    }
 
-    void setIsManual(String varName) {
-               this.isManual = isManual;
-       }
+    boolean isManual() {
+      return ismanual;
+    }
+    
+    String getApp() {
+      return appName;
+    }
 
-       Integer getAppNum() {
-               return appNum;
-       }
+    String getDeviceId() {
+      return deviceId;
+    }
 
-       String getValue() {
-               return value;
-       }
+    String getAttribute() {
+      return attribute;
+    }
+    
+    String getValue() {
+      return value;
+    }
 
-       String getVarName() {
-               return varName;
-       }
+    //Gets an index object for indexing updates by just device and attribute
+    IndexObject getIndex() {
+      return new IndexObject(this);
+    }
 
-       boolean getIsManual() {
-               return isManual;
-       }
+    public boolean equals(Object o) {
+      if (!(o instanceof Update))
+        return false;
+      Update u=(Update)o;
+      return (getDeviceId().equals(u.getDeviceId()) &&
+              getAttribute().equals(u.getAttribute()) &&
+              getApp().equals(u.getApp()) &&
+              getValue().equals(u.getValue()));
+    }
 
-       @Override
-       public boolean equals(Object o) {
-      if (o instanceof NameValuePair) {
-        NameValuePair other = (NameValuePair) o;
-        if (varName.equals(other.getVarName()))
-          return appNum.equals(other.getAppNum());
-      }
-      return false;
-       }
+    public int hashCode() {
+      return (getDeviceId().hashCode() << 3) ^
+        (getAttribute().hashCode() << 2) ^
+        (getApp().hashCode() << 1) ^
+        getValue().hashCode();
+    }
 
-       @Override
-       public int hashCode() {
-               return appNum.hashCode() * 31 + varName.hashCode();
-       }
+    public String toString() {
+      return "<"+getAttribute()+", "+getValue()+", "+getApp()+", "+ismanual+">";
+    }
   }
 
+  static class IndexObject {
+    Update u;
+    IndexObject(Update _u) {
+      this.u = _u;
+    }
+    
+    public boolean equals(Object o) {
+      if (!(o instanceof IndexObject))
+        return false;
+      IndexObject io=(IndexObject)o;
+      return (u.getDeviceId().equals(io.u.getDeviceId()) &&
+              u.getAttribute().equals(io.u.getAttribute()));
+    }
+    public int hashCode() {
+      return (u.getDeviceId().hashCode() << 1) ^ u.getAttribute().hashCode();
+    }
+  }
+  
   @Override
   public void stateRestored(Search search) {
     id = search.getStateId();
@@ -322,38 +346,75 @@ public class ConflictTracker extends ListenerAdapter {
     out.println("The state is restored to state with id: "+id+", depth: "+depth);
   
     // Update the parent node
-    if (nodes.containsKey(id)) {
-         parentNode = nodes.get(id);
-    } else {
-         parentNode = new Node(id);
-    }
+    parentNode = getNode(id);
   }
 
   @Override
   public void searchStarted(Search search) {
     out.println("----------------------------------- search started");
   }
 
+  private Node getNode(Integer id) {
+    if (!nodes.containsKey(id))
+      nodes.put(id, new Node(id));
+    return nodes.get(id);
+  }
+
+  public void printGraph() {
+    System.out.println("digraph testgraph {");
+    for(Integer i : nodes.keySet()) {
+      Node n = nodes.get(i);
+      System.out.print("N"+i+"[label=\"");
+
+      for(IndexObject io:n.lastUpdates.keySet()) {
+        for(Update u:n.lastUpdates.get(io)) {
+          System.out.print(u.toString().replace("\"", "\\\"")+", ");
+        }
+      }
+      System.out.println("\"];");
+      for(Edge e:n.outEdges) {
+        System.out.print("N"+e.getSrc().getId()+"->N"+e.getDst().getId()+"[label=\"");
+        for(Update u:e.getUpdates()) {
+          System.out.print(u.toString().replace("\"", "\\\"")+", ");
+        }
+        System.out.println("\"];");
+      }
+    }
+
+    System.out.println("}");
+  }
+
+  @Override
+  public void choiceGeneratorAdvanced(VM vm, ChoiceGenerator<?> currentCG) {
+
+    if (currentCG instanceof IntChoiceFromSet) {
+      IntChoiceFromSet icsCG = (IntChoiceFromSet) currentCG;
+      currentEvent = icsCG.getNextChoice();
+    }
+  }
+  
   @Override
   public void stateAdvanced(Search search) {
     String theEnd = null;
+    Transition transition = search.getTransition();
     id = search.getStateId();
     depth = search.getDepth();
     operation = "forward";
 
-    // Check for the conflict in this new transition
-    conflictFound = checkForConflict(parentNode);
+    // Add the node to the list of nodes
+    Node currentNode = getNode(id);
 
-    // Add the node to the list of nodes       
-    nodes.put(id, new Node(id));
-    Node currentNode = nodes.get(id);
+    // Create an edge based on the current transition
+    Edge newEdge = createEdge(parentNode, currentNode, transition, currentEvent);
 
-    // Update the setSet for this new node
-    currentNode.setSetSet(tempSetSet, manual);
-    tempSetSet = new ArrayList<NameValuePair>(); 
+    // Reset the temporary variables and flags
+    currUpdates.clear();
     manual = false;
 
+    // If we have a new Edge, check for conflicts
+    if (newEdge != null)
+      propagateChange(newEdge);
+
     if (search.isNewState()) {
       detail = "new";
     } else {
@@ -367,35 +428,8 @@ public class ConflictTracker extends ListenerAdapter {
 
     out.println("The state is forwarded to state with id: "+id+", depth: "+depth+" which is "+detail+" state: "+"% "+theEnd);
     
-    // Updating the predecessors for this node
-    // Check if parent node is already in successors of the current node or not
-    if (!(currentNode.getPredecessors().contains(parentNode)))
-       currentNode.addPredecessor(parentNode);
-
-    // Update the successors for this node
-    // Check if current node is already in successors of the parent node or not
-    if (!(parentNode.getSuccessors().contains(currentNode)))
-        parentNode.addSuccessor(currentNode);
-
-
-    // Update the setSetMap of the current node
-    for (Node i : currentNode.getPredecessors()) {
-       currentNode.getSetSetMap().put(i, i.getSetSet());
-    }
-
-    // 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 if the outSet of this state has changed, update all of its successors' sets if any
-    if (isChanged)
-       conflictFound = conflictFound || propagateTheChange(currentNode);
-
     // Update the parent node
-    if (nodes.containsKey(id)) {
-         parentNode = nodes.get(id);
-    } else {
-         parentNode = new Node(id);
-    }
+    parentNode = currentNode;
   }
 
   @Override
@@ -408,16 +442,15 @@ public class ConflictTracker extends ListenerAdapter {
     out.println("The state is backtracked to state with id: "+id+", depth: "+depth);
 
     // Update the parent node
-    if (nodes.containsKey(id)) {
-         parentNode = nodes.get(id);
-    } else {
-         parentNode = new Node(id);
-    }
+    parentNode = getNode(id);
   }
 
   @Override
   public void searchFinished(Search search) {
     out.println("----------------------------------- search finished");
+
+    //Comment out the following line to print the explored graph
+    printGraph();
   }
 
   private String getValue(ThreadInfo ti, Instruction inst, byte type) {
@@ -435,6 +468,16 @@ public class ConflictTracker extends ListenerAdapter {
       lo = frame.peek();
       hi = frame.getTopPos() >= 1 ? frame.peek(1) : 0;
 
+      // TODO: Fix for integer values (need to dig deeper into the stack frame to find the right value other than 0)
+      // TODO: Seems to be a problem since this is Groovy (not Java)
+      if (type == Types.T_INT || type == Types.T_LONG || type == Types.T_SHORT) {
+        int offset = 0;
+        while (lo == 0) {
+          lo = frame.peek(offset);
+          offset++;
+        }
+      }
+
       return(decodeValue(type, lo, hi));
     }
 
@@ -469,7 +512,7 @@ public class ConflictTracker extends ListenerAdapter {
 
         if (ci.getName().equals("java.lang.String"))
           return('"' + ei.asString() + '"');
-
+       
         return(ei.toString());
 
       default:
@@ -554,18 +597,13 @@ public class ConflictTracker extends ListenerAdapter {
     return null;
   }
 
-  private void writeWriterAndValue(String writer, String value, String var) {
-    // Update the temporary Set set.
-    NameValuePair temp = new NameValuePair(1, value, var, manual);
-    if (writer.equals("App2"))
-       temp = new NameValuePair(2, value, var, manual);
-    
-    tempSetSet.add(temp);
+  private void writeWriterAndValue(String writer, String attribute, String value) {
+    Update u = new Update(writer, "DEVICE", attribute, value, manual);
+    currUpdates.add(u);
   }
 
   @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();
@@ -581,43 +619,53 @@ public class ConflictTracker extends ListenerAdapter {
       Instruction nextIns = ti.createAndThrowException("java.lang.RuntimeException", sb.toString());
       ti.setNextPC(nextIns);
     } else {
-      if (conflictSet.contains(LOCATION_VAR)) {
-        MethodInfo mi = executedInsn.getMethodInfo();
-        // Find the last load before return and get the value here
-        if (mi.getName().equals(SET_LOCATION_METHOD) &&
-                executedInsn instanceof ALOAD && nextInsn instanceof ARETURN) {
-          byte type  = getType(ti, executedInsn);
-          String value = getValue(ti, executedInsn, type);
+      // Check if we are ready to pop the values
+      if (popRef == 2) {
+       byte type = getType(ti, executedInsn);
+        varName = getValue(ti, executedInsn, type);
+       String writer = getWriter(ti.getStack(), appSet);
+
+       popRef = popRef-1;
+      } else if (popRef == 1) {
+       byte type = getType(ti, executedInsn);
+       String value = getValue(ti, executedInsn, type);
+       String writer = getWriter(ti.getStack(), appSet);       
+
+       for (String var: conflictSet) {
+               if (varName.contains(var)) {
+                       if (writer != null)
+                               writeWriterAndValue(writer, varName, value);
+               }
+       }
 
-          // Extract the writer app name
-          ClassInfo ci = mi.getClassInfo();
-          String writer = ci.getName();
+       popRef = popRef-1;
+      }
 
-          // Update the temporary Set set.
-          writeWriterAndValue(writer, value, LOCATION_VAR);
-        }
-      } else {
-        if (executedInsn instanceof WriteInstruction) {
-          String varId = ((WriteInstruction) executedInsn).getFieldInfo().getFullName();
-          for (String var : conflictSet) {
-            if (varId.contains(var)) {
-              // Get variable info
-              byte type = getType(ti, executedInsn);
-              String value = getValue(ti, executedInsn, type);
-              String writer = getWriter(ti.getStack(), appSet);
-              // Just return if the writer is not one of the listed apps in the .jpf file
-              if (writer == null)
-                return;
-
-              if (getWriter(ti.getStack(), manualSet) != null)
-                manual = true;
-
-              // Update the temporary Set set.
-              writeWriterAndValue(writer, value, var);
-            }
-          }
+
+      if (executedInsn.getMnemonic().equals("getfield")) {
+       if (executedInsn.toString().contains("deviceValueSmartThing") || 
+           executedInsn.toString().contains("deviceIntValueSmartThing")) {
+               if (executedInsn.getNext() != null) {
+                       if (executedInsn.getNext().getMnemonic().contains("load")) {
+
+                               if (executedInsn.getNext().getNext() != null)
+                                       if (executedInsn.getNext().getNext().getMnemonic().contains("load"))
+                                               popRef = 2;
+                       }
+               }
+       }
+      }
+
+      if (executedInsn instanceof WriteInstruction) {
+        String varId = ((WriteInstruction) executedInsn).getFieldInfo().getFullName();
+        // Check if we have an update to isManualTransaction to update manual field
+        if (varId.contains("isManualTransaction")) {
+          byte type = getType(ti, executedInsn);
+          String value = getValue(ti, executedInsn, type);
+
+          manual = (value.equals("true"))?true:false;
         }
       }
-    }
+    }    
   }
 }