changes: now Inference engine works fine with the EyeTracking benchmark.
[IRC.git] / Robust / src / Analysis / SSJava / DefinitelyWrittenCheck.java
index d14c5e2c515c9b82cf5a519aa096ef4034ed77fb..fabdf9dbbdbe09f2fb0f0f7c7c9b9618d53be0de 100644 (file)
@@ -1,8 +1,5 @@
 package Analysis.SSJava;
 
-import java.io.BufferedWriter;
-import java.io.FileWriter;
-import java.io.IOException;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -11,6 +8,7 @@ import java.util.LinkedList;
 import java.util.Set;
 import java.util.Stack;
 
+import Analysis.Liveness;
 import Analysis.CallGraph.CallGraph;
 import Analysis.Loops.LoopFinder;
 import IR.Descriptor;
@@ -26,13 +24,13 @@ import IR.Flat.FlatElementNode;
 import IR.Flat.FlatFieldNode;
 import IR.Flat.FlatLiteralNode;
 import IR.Flat.FlatMethod;
+import IR.Flat.FlatNew;
 import IR.Flat.FlatNode;
 import IR.Flat.FlatOpNode;
 import IR.Flat.FlatSetElementNode;
 import IR.Flat.FlatSetFieldNode;
 import IR.Flat.TempDescriptor;
 import IR.Tree.Modifiers;
-import Util.Pair;
 
 public class DefinitelyWrittenCheck {
 
@@ -40,12 +38,9 @@ public class DefinitelyWrittenCheck {
   State state;
   CallGraph callGraph;
 
-  int debugcount = 0;
+  Liveness liveness;
 
-  // maps a descriptor to its known dependents: namely
-  // methods or tasks that call the descriptor's method
-  // AND are part of this analysis (reachable from main)
-  private Hashtable<Descriptor, Set<MethodDescriptor>> mapDescriptorToSetDependents;
+  int debugcount = 0;
 
   // maps a flat node to its WrittenSet: this keeps all heap path overwritten
   // previously.
@@ -72,6 +67,8 @@ public class DefinitelyWrittenCheck {
   // written to but not overwritten by the higher value
   private Hashtable<FlatMethod, SharedLocMap> mapFlatMethodToDeleteSet;
 
+  private Hashtable<FlatMethod, SharedLocMap> mapFlatMethodToMustClearMap;
+
   // maps a flat method to the S SET that is a set of heap path to shared
   // locations that are overwritten by the higher value
   private Hashtable<FlatMethod, SharedLocMap> mapFlatMethodToSharedLocMap;
@@ -95,18 +92,6 @@ public class DefinitelyWrittenCheck {
   // maps a flatnode to definitely written analysis mapping M
   private Hashtable<FlatNode, Hashtable<NTuple<Descriptor>, Set<WriteAge>>> mapFlatNodetoEventLoopMap;
 
-  // maps a method descriptor to its current summary during the analysis
-  // then analysis reaches fixed-point, this mapping will have the final summary
-  // for each method descriptor
-  private Hashtable<MethodDescriptor, ClearingSummary> mapMethodDescriptorToCompleteClearingSummary;
-
-  // maps a method descriptor to the merged incoming caller's current
-  // overwritten status
-  private Hashtable<MethodDescriptor, ClearingSummary> mapMethodDescriptorToInitialClearingSummary;
-
-  // maps a flat node to current partial results
-  private Hashtable<FlatNode, ClearingSummary> mapFlatNodeToClearingSummary;
-
   // maps shared location to the set of descriptors which belong to the shared
   // location
 
@@ -121,25 +106,17 @@ public class DefinitelyWrittenCheck {
   public static final String arrayElementFieldName = "___element_";
   static protected Hashtable<TypeDescriptor, FieldDescriptor> mapTypeToArrayField;
 
-  private Set<ClearingSummary> possibleCalleeCompleteSummarySetToCaller;
-
   // maps a method descriptor to the merged incoming caller's current
   // reading status
   // it is for setting clearance flag when all read set is overwritten
   private Hashtable<MethodDescriptor, ReadSummary> mapMethodDescriptorToReadSummary;
 
-  private MultiSourceMap<Location, Descriptor> mapLocationPathToMayWrittenSet;
-
-  private Hashtable<MethodDescriptor, MultiSourceMap<Location, Descriptor>> mapMethodToSharedWriteMapping;
+  private Hashtable<MethodDescriptor, MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>> mapMethodToSharedLocCoverSet;
 
   private Hashtable<FlatNode, SharedLocMap> mapFlatNodeToSharedLocMapping;
   private Hashtable<FlatNode, SharedLocMap> mapFlatNodeToDeleteSet;
+  private Hashtable<FlatNode, SharedLocMap> mapFlatNodeToMustClearMap;
 
-  private Hashtable<Location, Set<Descriptor>> mapSharedLocationToCoverSet;
-
-  private LinkedList<MethodDescriptor> sortedDescriptors;
-
-  private FlatNode ssjavaLoopEntrance;
   private LoopFinder ssjavaLoop;
   private Set<FlatNode> loopIncElements;
 
@@ -148,6 +125,9 @@ public class DefinitelyWrittenCheck {
   private Set<NTuple<Descriptor>> calleeUnionBoundMayWriteSet;
   private SharedLocMap calleeUnionBoundDeleteSet;
   private SharedLocMap calleeIntersectBoundSharedSet;
+  private SharedLocMap calleeIntersectBoundMustClearSet;
+
+  Set<TempDescriptor> liveInTempSetToEventLoop;
 
   private Hashtable<Descriptor, Location> mapDescToLocation;
 
@@ -160,7 +140,6 @@ public class DefinitelyWrittenCheck {
     this.ssjava = ssjava;
     this.callGraph = ssjava.getCallGraph();
     this.mapFlatNodeToMustWriteSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
-    this.mapDescriptorToSetDependents = new Hashtable<Descriptor, Set<MethodDescriptor>>();
     this.mapHeapPath = new Hashtable<Descriptor, NTuple<Descriptor>>();
     this.mapDescriptorToLocationPath = new Hashtable<TempDescriptor, NTuple<Location>>();
     this.mapFlatMethodToReadSet = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
@@ -172,13 +151,8 @@ public class DefinitelyWrittenCheck {
     this.calleeIntersectBoundMustWriteSet = new HashSet<NTuple<Descriptor>>();
     this.calleeUnionBoundMayWriteSet = new HashSet<NTuple<Descriptor>>();
 
-    this.mapMethodDescriptorToCompleteClearingSummary =
-        new Hashtable<MethodDescriptor, ClearingSummary>();
-    this.mapMethodDescriptorToInitialClearingSummary =
-        new Hashtable<MethodDescriptor, ClearingSummary>();
     this.methodDescriptorsToVisitStack = new Stack<MethodDescriptor>();
     this.calleesToEnqueue = new HashSet<MethodDescriptor>();
-    this.possibleCalleeCompleteSummarySetToCaller = new HashSet<ClearingSummary>();
     this.mapTypeToArrayField = new Hashtable<TypeDescriptor, FieldDescriptor>();
     this.LOCAL = new TempDescriptor("LOCAL");
     this.mapDescToLocation = new Hashtable<Descriptor, Location>();
@@ -187,27 +161,28 @@ public class DefinitelyWrittenCheck {
     this.mapFlatNodeToBoundReadSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
     this.mapFlatNodeToBoundMustWriteSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
     this.mapFlatNodeToBoundMayWriteSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
-    this.mapSharedLocationToCoverSet = new Hashtable<Location, Set<Descriptor>>();
     this.mapFlatNodeToSharedLocMapping = new Hashtable<FlatNode, SharedLocMap>();
     this.mapFlatMethodToDeleteSet = new Hashtable<FlatMethod, SharedLocMap>();
     this.calleeUnionBoundDeleteSet = new SharedLocMap();
     this.calleeIntersectBoundSharedSet = new SharedLocMap();
     this.mapFlatMethodToSharedLocMap = new Hashtable<FlatMethod, SharedLocMap>();
-    this.mapLocationPathToMayWrittenSet = new MultiSourceMap<Location, Descriptor>();
-    this.mapMethodToSharedWriteMapping =
-        new Hashtable<MethodDescriptor, MultiSourceMap<Location, Descriptor>>();
+    this.mapMethodToSharedLocCoverSet =
+        new Hashtable<MethodDescriptor, MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>>();
     this.mapFlatNodeToDeleteSet = new Hashtable<FlatNode, SharedLocMap>();
+    this.liveness = new Liveness();
+    this.liveInTempSetToEventLoop = new HashSet<TempDescriptor>();
+    this.mapFlatNodeToMustClearMap = new Hashtable<FlatNode, SharedLocMap>();
+    this.calleeIntersectBoundMustClearSet = new SharedLocMap();
+    this.mapFlatMethodToMustClearMap = new Hashtable<FlatMethod, SharedLocMap>();
   }
 
   public void definitelyWrittenCheck() {
     if (!ssjava.getAnnotationRequireSet().isEmpty()) {
       initialize();
-      computeSharedCoverSet();
-
-      // System.out.println("#");
-      // System.out.println(mapLocationPathToMayWrittenSet);
 
       methodReadWriteSetAnalysis();
+      computeSharedCoverSet();
+
       sharedLocAnalysis();
 
       eventLoopAnalysis();
@@ -218,8 +193,7 @@ public class DefinitelyWrittenCheck {
   private void sharedLocAnalysis() {
 
     // perform method READ/OVERWRITE analysis
-    LinkedList<MethodDescriptor> descriptorListToAnalyze =
-        (LinkedList<MethodDescriptor>) sortedDescriptors.clone();
+    LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
 
     // current descriptors to visit in fixed-point interprocedural analysis,
     // prioritized by
@@ -244,19 +218,23 @@ public class DefinitelyWrittenCheck {
 
       SharedLocMap sharedLocMap = new SharedLocMap();
       SharedLocMap deleteSet = new SharedLocMap();
+      SharedLocMap mustClearMap = new SharedLocMap();
 
-      sharedLoc_analyzeMethod(fm, sharedLocMap, deleteSet);
+      sharedLoc_analyzeMethod(fm, sharedLocMap, deleteSet, mustClearMap);
       SharedLocMap prevSharedLocMap = mapFlatMethodToSharedLocMap.get(fm);
       SharedLocMap prevDeleteSet = mapFlatMethodToDeleteSet.get(fm);
+      SharedLocMap prevMustClearMap = mapFlatMethodToMustClearMap.get(fm);
 
-      if (!(deleteSet.equals(prevDeleteSet) && sharedLocMap.equals(prevSharedLocMap))) {
+      if (!(deleteSet.equals(prevDeleteSet) && sharedLocMap.equals(prevSharedLocMap) && mustClearMap
+          .equals(prevMustClearMap))) {
         mapFlatMethodToSharedLocMap.put(fm, sharedLocMap);
         mapFlatMethodToDeleteSet.put(fm, deleteSet);
+        mapFlatMethodToMustClearMap.put(fm, mustClearMap);
 
         // results for callee changed, so enqueue dependents caller for
         // further
         // analysis
-        Iterator<MethodDescriptor> depsItr = getDependents(md).iterator();
+        Iterator<MethodDescriptor> depsItr = ssjava.getDependents(md).iterator();
         while (depsItr.hasNext()) {
           MethodDescriptor methodNext = depsItr.next();
           if (!methodDescriptorsToVisitStack.contains(methodNext)
@@ -280,22 +258,24 @@ public class DefinitelyWrittenCheck {
     }
     SharedLocMap sharedLocMap = new SharedLocMap();
     SharedLocMap deleteSet = new SharedLocMap();
-    sharedLoc_analyzeBody(state.getMethodFlat(methodContainingSSJavaLoop), ssjavaLoopEntrance,
-        sharedLocMap, deleteSet, true);
+    SharedLocMap mustClearMap = new SharedLocMap();
+    sharedLoc_analyzeBody(state.getMethodFlat(methodContainingSSJavaLoop),
+        ssjava.getSSJavaLoopEntrance(), sharedLocMap, deleteSet, mustClearMap, true);
+
   }
 
   private void sharedLoc_analyzeMethod(FlatMethod fm, SharedLocMap sharedLocMap,
-      SharedLocMap deleteSet) {
+      SharedLocMap deleteSet, SharedLocMap mustClearMap) {
     if (state.SSJAVADEBUG) {
       System.out.println("SSJAVA: Definite clearance for shared locations Analyzing: " + fm);
     }
 
-    sharedLoc_analyzeBody(fm, fm, sharedLocMap, deleteSet, false);
+    sharedLoc_analyzeBody(fm, fm, sharedLocMap, deleteSet, mustClearMap, false);
 
   }
 
   private void sharedLoc_analyzeBody(FlatMethod fm, FlatNode startNode, SharedLocMap sharedLocMap,
-      SharedLocMap deleteSet, boolean isEventLoopBody) {
+      SharedLocMap deleteSet, SharedLocMap mustClearMap, boolean isEventLoopBody) {
 
     // intraprocedural analysis
     Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
@@ -307,6 +287,7 @@ public class DefinitelyWrittenCheck {
 
       SharedLocMap currSharedSet = new SharedLocMap();
       SharedLocMap currDeleteSet = new SharedLocMap();
+      SharedLocMap currMustClearMap = new SharedLocMap();
 
       for (int i = 0; i < fn.numPrev(); i++) {
         FlatNode prevFn = fn.getPrev(i);
@@ -319,17 +300,26 @@ public class DefinitelyWrittenCheck {
         if (inDeleteLoc != null) {
           mergeDeleteSet(currDeleteSet, inDeleteLoc);
         }
+
+        SharedLocMap inMustClearMap = mapFlatNodeToMustClearMap.get(prevFn);
+        if (inMustClearMap != null) {
+          mergeSharedLocMap(currMustClearMap, inMustClearMap);
+        }
+
       }
 
-      sharedLoc_nodeActions(fm, fn, currSharedSet, currDeleteSet, sharedLocMap, deleteSet,
-          isEventLoopBody);
+      sharedLoc_nodeActions(fm, fn, currSharedSet, currDeleteSet, currMustClearMap, sharedLocMap,
+          deleteSet, mustClearMap, isEventLoopBody);
 
       SharedLocMap prevSharedSet = mapFlatNodeToSharedLocMapping.get(fn);
       SharedLocMap prevDeleteSet = mapFlatNodeToDeleteSet.get(fn);
+      SharedLocMap prevMustClearMap = mapFlatNodeToMustClearMap.get(fn);
 
-      if (!(currSharedSet.equals(prevSharedSet) && currDeleteSet.equals(prevDeleteSet))) {
+      if (!(currSharedSet.equals(prevSharedSet) && currDeleteSet.equals(prevDeleteSet) && currMustClearMap
+          .equals(prevMustClearMap))) {
         mapFlatNodeToSharedLocMapping.put(fn, currSharedSet);
         mapFlatNodeToDeleteSet.put(fn, currDeleteSet);
+        mapFlatNodeToMustClearMap.put(fn, currMustClearMap);
         for (int i = 0; i < fn.numNext(); i++) {
           FlatNode nn = fn.getNext(i);
           if ((!isEventLoopBody) || loopIncElements.contains(nn)) {
@@ -344,8 +334,10 @@ public class DefinitelyWrittenCheck {
   }
 
   private void sharedLoc_nodeActions(FlatMethod fm, FlatNode fn, SharedLocMap curr,
-      SharedLocMap currDeleteSet, SharedLocMap sharedLocMap, SharedLocMap deleteSet,
-      boolean isEventLoopBody) {
+      SharedLocMap currDeleteSet, SharedLocMap currMustClearMap, SharedLocMap sharedLocMap,
+      SharedLocMap deleteSet, SharedLocMap mustClearMap, boolean isEventLoopBody) {
+
+    MethodDescriptor md = fm.getMethod();
 
     SharedLocMap killSet = new SharedLocMap();
     SharedLocMap genSet = new SharedLocMap();
@@ -354,6 +346,10 @@ public class DefinitelyWrittenCheck {
     TempDescriptor rhs;
     FieldDescriptor fld;
 
+    NTuple<Location> fieldLocTuple = null;
+    Location fieldLoc = null;
+    boolean isHigherWriteCase = false;
+
     switch (fn.kind()) {
 
     case FKind.FlatOpNode: {
@@ -365,37 +361,35 @@ public class DefinitelyWrittenCheck {
           lhs = fon.getDest();
           rhs = fon.getLeft();
 
-          if (!lhs.getSymbol().startsWith("neverused") && rhs.getType().isImmutable()) {
+          if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop")
+              && !lhs.getSymbol().startsWith("rightop") && rhs.getType().isImmutable()) {
 
-            Location dstLoc = getLocation(lhs);
-            if (dstLoc != null && ssjava.isSharedLocation(dstLoc)) {
-              NTuple<Descriptor> lhsHeapPath = computePath(lhs);
-              NTuple<Location> lhsLocTuple = mapDescriptorToLocationPath.get(lhs);
+            if (mapHeapPath.containsKey(rhs)) {
+              Location dstLoc = getLocation(lhs);
+              if (dstLoc != null && ssjava.isSharedLocation(dstLoc)) {
+                NTuple<Descriptor> lhsHeapPath = computePath(lhs);
+                NTuple<Location> lhsLocTuple = mapDescriptorToLocationPath.get(lhs);
 
-              Location srcLoc = getLocation(lhs);
+                Location srcLoc = getLocation(lhs);
 
-              // computing gen/kill set
-              computeKILLSetForWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
-              if (!dstLoc.equals(srcLoc)) {
-                computeGENSetForHigherWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
-                updateDeleteSetForHigherWrite(currDeleteSet, lhsLocTuple, lhsHeapPath);
-              } else {
-                computeGENSetForSameHeightWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
-                updateDeleteSetForSameHeightWrite(currDeleteSet, lhsLocTuple, lhsHeapPath);
-              }
+                // computing gen/kill set
+                computeKILLSetForWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
 
-              // System.out.println("VAR WRITE:" + fn);
-              // System.out.println("lhsLocTuple=" + lhsLocTuple +
-              // " lhsHeapPath="
-              // + lhsHeapPath);
-              // System.out.println("dstLoc=" + dstLoc + " srcLoc=" + srcLoc);
-              // System.out.println("KILLSET=" + killSet);
-              // System.out.println("GENSet=" + genSet);
-              // System.out.println("DELETESET=" + currDeleteSet);
+                if (!ssjava.isSameHeightWrite(fn)) {
+                  computeGENSetForHigherWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
+                  updateDeleteSetForHigherWrite(currDeleteSet, lhsLocTuple, lhsHeapPath);
+                } else {
+                  computeGENSetForSameHeightWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
+                  updateDeleteSetForSameHeightWrite(currDeleteSet, lhsLocTuple, lhsHeapPath);
+                }
 
+              }
+            } else {
+              break;
             }
 
           }
+
         }
 
       }
@@ -411,45 +405,67 @@ public class DefinitelyWrittenCheck {
         lhs = fsfn.getDst();
         fld = fsfn.getField();
         rhs = fsfn.getSrc();
+        fieldLoc = (Location) fld.getType().getExtension();
       } else {
-        FlatSetElementNode fsen = (FlatSetElementNode) fn;
-        lhs = fsen.getDst();
-        rhs = fsen.getSrc();
-        TypeDescriptor td = lhs.getType().dereference();
-        fld = getArrayField(td);
+        break;
+      }
+
+      if (!isEventLoopBody && fieldLoc.getDescriptor().equals(md)) {
+        // if the field belongs to the local lattice, no reason to calculate
+        // shared location
+        break;
+      }
+
+      fieldLocTuple = new NTuple<Location>();
+      if (fld.isStatic()) {
+        if (fld.isFinal()) {
+          // in this case, fld has TOP location
+          Location topLocation = Location.createTopLocation(md);
+          fieldLocTuple.add(topLocation);
+        } else {
+          fieldLocTuple.addAll(deriveGlobalLocationTuple(md));
+          if (fn.kind() == FKind.FlatSetFieldNode) {
+            fieldLocTuple.add((Location) fld.getType().getExtension());
+          }
+        }
+
+      } else {
+        fieldLocTuple.addAll(deriveLocationTuple(md, lhs));
+        if (fn.kind() == FKind.FlatSetFieldNode) {
+          fieldLocTuple.add((Location) fld.getType().getExtension());
+        }
       }
 
       // shared loc extension
       Location srcLoc = getLocation(rhs);
-      Location fieldLoc = (Location) fld.getType().getExtension();
       if (ssjava.isSharedLocation(fieldLoc)) {
         // only care the case that loc(f) is shared location
         // write(field)
 
-        NTuple<Location> fieldLocTuple = new NTuple<Location>();
-        fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs));
-        fieldLocTuple.add(fieldLoc);
+        // NTuple<Location> fieldLocTuple = new NTuple<Location>();
+        // fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs));
+        // fieldLocTuple.add(fieldLoc);
 
-        NTuple<Descriptor> fldHeapPath = computePath(fld);
+        NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>();
+        fldHeapPath.addAll(computePath(lhs));
+        if (fn.kind() == FKind.FlatSetFieldNode) {
+          fldHeapPath.add(fld);
+        }
 
         // computing gen/kill set
         computeKILLSetForWrite(curr, killSet, fieldLocTuple, fldHeapPath);
-        if (!fieldLoc.equals(srcLoc)) {
+
+        if (!ssjava.isSameHeightWrite(fn)) {
           computeGENSetForHigherWrite(curr, genSet, fieldLocTuple, fldHeapPath);
           updateDeleteSetForHigherWrite(currDeleteSet, fieldLocTuple, fldHeapPath);
+
+          isHigherWriteCase = true;
+
         } else {
           computeGENSetForSameHeightWrite(curr, genSet, fieldLocTuple, fldHeapPath);
           updateDeleteSetForSameHeightWrite(currDeleteSet, fieldLocTuple, fldHeapPath);
         }
 
-        // System.out.println("################");
-        // System.out.println("FIELD WRITE:" + fn);
-        // System.out.println("FldHeapPath=" + fldHeapPath);
-        // System.out.println("fieldLocTuple=" + fieldLocTuple + " srcLoc=" +
-        // srcLoc);
-        // System.out.println("KILLSET=" + killSet);
-        // System.out.println("GENSet=" + genSet);
-        // System.out.println("DELETESET=" + currDeleteSet);
       }
 
     }
@@ -464,10 +480,11 @@ public class DefinitelyWrittenCheck {
       generateKILLSetForFlatCall(curr, killSet);
       generateGENSetForFlatCall(curr, genSet);
 
-      // System.out.println("#FLATCALL=" + fc);
-      // System.out.println("KILLSET=" + killSet);
-      // System.out.println("GENSet=" + genSet);
-      // System.out.println("bound DELETE Set=" + calleeUnionBoundDeleteSet);
+      Set<NTuple<Location>> locTupleSet = calleeIntersectBoundMustClearSet.keySet();
+      for (Iterator iterator = locTupleSet.iterator(); iterator.hasNext();) {
+        NTuple<Location> locTupleKey = (NTuple<Location>) iterator.next();
+        currMustClearMap.addWrite(locTupleKey, calleeIntersectBoundMustClearSet.get(locTupleKey));
+      }
 
     }
       break;
@@ -476,15 +493,38 @@ public class DefinitelyWrittenCheck {
       // merge the current delete/shared loc mapping
       mergeSharedLocMap(sharedLocMap, curr);
       mergeDeleteSet(deleteSet, currDeleteSet);
-
-      // System.out.println("#FLATEXIT sharedLocMap=" + sharedLocMap);
+      mergeSharedLocMap(mustClearMap, currMustClearMap);
     }
       break;
 
     }
 
     computeNewMapping(curr, killSet, genSet);
-    // System.out.println("#######" + curr);
+    if (isHigherWriteCase) {
+      // check all locations with the same shared location are cleared out at this point
+      Set<NTuple<Descriptor>> writtenSet = curr.get(fieldLocTuple);
+      Set<Descriptor> requirementSet = ssjava.getSharedDescSet(fieldLoc);
+
+      if (checkAllSharedLocationsAreOverwritten(requirementSet, writtenSet)) {
+        currMustClearMap.addWrite(fieldLocTuple, writtenSet);
+      }
+    }
+  }
+
+  private boolean checkAllSharedLocationsAreOverwritten(Set<Descriptor> sharedDescSet,
+      Set<NTuple<Descriptor>> writtenSet) {
+
+    if (sharedDescSet == null || writtenSet == null) {
+      return false;
+    }
+    Set<Descriptor> writtenDescSet = new HashSet<Descriptor>();
+    for (Iterator iterator = writtenSet.iterator(); iterator.hasNext();) {
+      NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
+      writtenDescSet.add(tuple.get(tuple.size() - 1));
+    }
+
+    return writtenDescSet.containsAll(sharedDescSet);
+    // return sharedDescSet.containsAll(writtenDescSet);
 
   }
 
@@ -546,7 +586,6 @@ public class DefinitelyWrittenCheck {
     if (currWriteSet != null) {
       genSet.addWrite(locTuple, currWriteSet);
     }
-
     genSet.addWrite(locTuple, hp);
   }
 
@@ -588,92 +627,16 @@ public class DefinitelyWrittenCheck {
 
   }
 
-  private void checkSharedLocationResult() {
-
-    // mapping of method containing ssjava loop has the final result of
-    // shared location analysis
-
-    ClearingSummary result =
-        mapMethodDescriptorToCompleteClearingSummary.get(methodContainingSSJavaLoop);
-
-    String str = generateNotClearedResult(result);
-    if (str.length() > 0) {
-      throw new Error(
-          "Following concrete locations of the shared abstract location are not cleared at the same time:\n"
-              + str);
-    }
-
-  }
-
-  private String generateNotClearedResult(ClearingSummary result) {
-    Set<NTuple<Descriptor>> keySet = result.keySet();
-
-    StringBuffer str = new StringBuffer();
-    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
-      NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
-      SharedStatus status = result.get(hpKey);
-      Hashtable<Location, Pair<Set<Descriptor>, Boolean>> map = status.getMap();
-      Set<Location> locKeySet = map.keySet();
-      for (Iterator iterator2 = locKeySet.iterator(); iterator2.hasNext();) {
-        Location locKey = (Location) iterator2.next();
-        if (status.haveWriteEffect(locKey)) {
-          Pair<Set<Descriptor>, Boolean> pair = map.get(locKey);
-          if (!pair.getSecond().booleanValue()) {
-            // not cleared!
-            str.append("- Concrete locations of the shared location '" + locKey
-                + "' are not cleared out, which are reachable through the heap path '" + hpKey
-                + ".\n");
-          }
-        }
-      }
-    }
-
-    return str.toString();
-
-  }
-
-  private void writeReadMapFile() {
-
-    String fileName = "SharedLocationReadMap";
-
-    try {
-      BufferedWriter bw = new BufferedWriter(new FileWriter(fileName + ".txt"));
-
-      Set<MethodDescriptor> keySet = mapMethodDescriptorToReadSummary.keySet();
-      for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
-        MethodDescriptor mdKey = (MethodDescriptor) iterator.next();
-        ReadSummary summary = mapMethodDescriptorToReadSummary.get(mdKey);
-        bw.write("Method " + mdKey + "::\n");
-        bw.write(summary + "\n\n");
-      }
-      bw.close();
-    } catch (IOException e) {
-      e.printStackTrace();
-    }
-
-  }
-
-  private void sharedLocationAnalysis() {
-    // verify that all concrete locations of shared location are cleared out at
-    // the same time once per the out-most loop
-
-    computeSharedCoverSet();
-
-    if (state.SSJAVADEBUG) {
-      writeReadMapFile();
-    }
-
-    // methodDescriptorsToVisitStack.clear();
-    // methodDescriptorsToVisitStack.add(sortedDescriptors.peekFirst());
-
-    LinkedList<MethodDescriptor> descriptorListToAnalyze =
-        (LinkedList<MethodDescriptor>) sortedDescriptors.clone();
+  private void computeSharedCoverSet() {
+    LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
 
     // current descriptors to visit in fixed-point interprocedural analysis,
     // prioritized by
     // dependency in the call graph
     methodDescriptorsToVisitStack.clear();
 
+    descriptorListToAnalyze.removeFirst();
+
     Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
     methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
 
@@ -685,147 +648,77 @@ public class DefinitelyWrittenCheck {
     // analyze scheduled methods until there are no more to visit
     while (!methodDescriptorsToVisitStack.isEmpty()) {
       MethodDescriptor md = methodDescriptorsToVisitStack.pop();
-
-      ClearingSummary completeSummary =
-          sharedLocation_analyzeMethod(md, (md.equals(methodContainingSSJavaLoop)));
-
-      ClearingSummary prevCompleteSummary = mapMethodDescriptorToCompleteClearingSummary.get(md);
-
-      if (!completeSummary.equals(prevCompleteSummary)) {
-
-        mapMethodDescriptorToCompleteClearingSummary.put(md, completeSummary);
-
-        // results for callee changed, so enqueue dependents caller for
-        // further analysis
-        Iterator<MethodDescriptor> depsItr = getDependents(md).iterator();
-        while (depsItr.hasNext()) {
-          MethodDescriptor methodNext = depsItr.next();
-          if (!methodDescriptorsToVisitStack.contains(methodNext)) {
-            methodDescriptorsToVisitStack.add(methodNext);
-          }
-        }
-
-        // if there is set of callee to be analyzed,
-        // add this set into the top of stack
-        Iterator<MethodDescriptor> calleeIter = calleesToEnqueue.iterator();
-        while (calleeIter.hasNext()) {
-          MethodDescriptor mdNext = calleeIter.next();
-          if (!methodDescriptorsToVisitStack.contains(mdNext)) {
-            methodDescriptorsToVisitStack.add(mdNext);
-          }
-        }
-        calleesToEnqueue.clear();
-
-      }
-
+      FlatMethod fm = state.getMethodFlat(md);
+      computeSharedCoverSet_analyzeMethod(fm, md.equals(methodContainingSSJavaLoop));
     }
 
+    computeSharedCoverSetForEventLoop();
+
   }
 
-  private ClearingSummary sharedLocation_analyzeMethod(MethodDescriptor md,
-      boolean onlyVisitSSJavaLoop) {
+  private void computeSharedCoverSetForEventLoop() {
+    computeSharedCoverSet_analyzeMethod(state.getMethodFlat(methodContainingSSJavaLoop), true);
+  }
 
-    if (state.SSJAVADEBUG) {
-      System.out.println("SSJAVA: Definite clearance for shared locations Analyzing: " + md);
-    }
+  private void computeSharedCoverSet_analyzeMethod(FlatMethod fm, boolean onlyVisitSSJavaLoop) {
 
-    FlatMethod fm = state.getMethodFlat(md);
+    MethodDescriptor md = fm.getMethod();
 
-    // intraprocedural analysis
     Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
 
-    // start a new mapping of partial results for each flat node
-    mapFlatNodeToClearingSummary = new Hashtable<FlatNode, ClearingSummary>();
+    Set<FlatNode> visited = new HashSet<FlatNode>();
 
     if (onlyVisitSSJavaLoop) {
-      flatNodesToVisit.add(ssjavaLoopEntrance);
+      flatNodesToVisit.add(ssjava.getSSJavaLoopEntrance());
     } else {
       flatNodesToVisit.add(fm);
     }
 
-    Set<FlatNode> returnNodeSet = new HashSet<FlatNode>();
-
     while (!flatNodesToVisit.isEmpty()) {
       FlatNode fn = flatNodesToVisit.iterator().next();
       flatNodesToVisit.remove(fn);
+      visited.add(fn);
 
-      ClearingSummary curr = new ClearingSummary();
-
-      Set<ClearingSummary> prevSet = new HashSet<ClearingSummary>();
-      for (int i = 0; i < fn.numPrev(); i++) {
-        FlatNode prevFn = fn.getPrev(i);
-        ClearingSummary in = mapFlatNodeToClearingSummary.get(prevFn);
-        if (in != null) {
-          prevSet.add(in);
-        }
-      }
-      mergeSharedLocationAnaylsis(curr, prevSet);
-
-      sharedLocation_nodeActions(md, fn, curr, returnNodeSet, onlyVisitSSJavaLoop);
-      ClearingSummary clearingPrev = mapFlatNodeToClearingSummary.get(fn);
-
-      if (!curr.equals(clearingPrev)) {
-        mapFlatNodeToClearingSummary.put(fn, curr);
+      computeSharedCoverSet_nodeActions(md, fn, onlyVisitSSJavaLoop);
 
-        for (int i = 0; i < fn.numNext(); i++) {
-          FlatNode nn = fn.getNext(i);
+      for (int i = 0; i < fn.numNext(); i++) {
+        FlatNode nn = fn.getNext(i);
 
+        if (!visited.contains(nn)) {
           if (!onlyVisitSSJavaLoop || (onlyVisitSSJavaLoop && loopIncElements.contains(nn))) {
             flatNodesToVisit.add(nn);
           }
-
         }
-      }
-
-    }
-
-    ClearingSummary completeSummary = new ClearingSummary();
-    Set<ClearingSummary> summarySet = new HashSet<ClearingSummary>();
 
-    if (onlyVisitSSJavaLoop) {
-      // when analyzing ssjava loop,
-      // complete summary is merging of all previous nodes of ssjava loop
-      // entrance
-      for (int i = 0; i < ssjavaLoopEntrance.numPrev(); i++) {
-        ClearingSummary frnSummary =
-            mapFlatNodeToClearingSummary.get(ssjavaLoopEntrance.getPrev(i));
-        if (frnSummary != null) {
-          summarySet.add(frnSummary);
-        }
-      }
-    } else {
-      // merging all exit node summary into the complete summary
-      if (!returnNodeSet.isEmpty()) {
-        for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
-          FlatNode frn = (FlatNode) iterator.next();
-          ClearingSummary frnSummary = mapFlatNodeToClearingSummary.get(frn);
-          summarySet.add(frnSummary);
-        }
       }
+
     }
-    mergeSharedLocationAnaylsis(completeSummary, summarySet);
 
-    return completeSummary;
   }
 
-  private void sharedLocation_nodeActions(MethodDescriptor md, FlatNode fn, ClearingSummary curr,
-      Set<FlatNode> returnNodeSet, boolean isSSJavaLoop) {
-
+  private void computeSharedCoverSet_nodeActions(MethodDescriptor md, FlatNode fn,
+      boolean isEventLoopBody) {
     TempDescriptor lhs;
     TempDescriptor rhs;
     FieldDescriptor fld;
+
     switch (fn.kind()) {
 
-    case FKind.FlatMethod: {
-      FlatMethod fm = (FlatMethod) fn;
+    case FKind.FlatLiteralNode: {
+      FlatLiteralNode fln = (FlatLiteralNode) fn;
+      lhs = fln.getDst();
 
-      ClearingSummary summaryFromCaller =
-          mapMethodDescriptorToInitialClearingSummary.get(fm.getMethod());
+      NTuple<Location> lhsLocTuple = new NTuple<Location>();
+      lhsLocTuple.add(Location.createTopLocation(md));
+      mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
 
-      Set<ClearingSummary> inSet = new HashSet<ClearingSummary>();
-      if (summaryFromCaller != null) {
-        inSet.add(summaryFromCaller);
-        mergeSharedLocationAnaylsis(curr, inSet);
+      if (lhs.getType().isPrimitive() && !lhs.getSymbol().startsWith("neverused")
+          && !lhs.getSymbol().startsWith("srctmp")) {
+        // only need to care about composite location case here
+        if (lhs.getType().getExtension() instanceof SSJavaType) {
+          CompositeLocation compLoc = ((SSJavaType) lhs.getType().getExtension()).getCompLoc();
+          Location lastLocElement = compLoc.get(compLoc.getSize() - 1);
+        }
       }
 
     }
@@ -833,30 +726,78 @@ public class DefinitelyWrittenCheck {
 
     case FKind.FlatOpNode: {
       FlatOpNode fon = (FlatOpNode) fn;
-      lhs = fon.getDest();
-      rhs = fon.getLeft();
-
+      // for a normal assign node, need to propagate lhs's location path to
+      // rhs
       if (fon.getOp().getOp() == Operation.ASSIGN) {
-        if (rhs.getType().isImmutable() && isSSJavaLoop) {
-          // in ssjavaloop, we need to take care about reading local variables!
-          NTuple<Descriptor> rhsHeapPath = new NTuple<Descriptor>();
-          NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
-          rhsHeapPath.add(LOCAL);
-          lhsHeapPath.add(LOCAL);
-          if (!lhs.getSymbol().startsWith("neverused")) {
-            readLocation(md, curr, rhsHeapPath, getLocation(rhs), rhs);
-            writeLocation(md, curr, lhsHeapPath, getLocation(lhs), lhs);
+        rhs = fon.getLeft();
+        lhs = fon.getDest();
+
+        if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop")
+            && !lhs.getSymbol().startsWith("rightop")) {
+
+          if (mapHeapPath.containsKey(rhs)) {
+            NTuple<Location> rhsLocTuple = new NTuple<Location>();
+            NTuple<Location> lhsLocTuple = new NTuple<Location>();
+            if (mapDescriptorToLocationPath.containsKey(rhs)) {
+              mapDescriptorToLocationPath.put(lhs, deriveLocationTuple(md, rhs));
+              lhsLocTuple = mapDescriptorToLocationPath.get(lhs);
+            } else {
+              // rhs side
+              if (rhs.getType().getExtension() != null
+                  && rhs.getType().getExtension() instanceof SSJavaType) {
+
+                if (((SSJavaType) rhs.getType().getExtension()).getCompLoc() != null) {
+                  rhsLocTuple.addAll(((SSJavaType) rhs.getType().getExtension()).getCompLoc()
+                      .getTuple());
+                }
+
+              } else {
+                NTuple<Location> locTuple = deriveLocationTuple(md, rhs);
+                if (locTuple != null) {
+                  rhsLocTuple.addAll(locTuple);
+                }
+              }
+              if (rhsLocTuple.size() > 0) {
+                mapDescriptorToLocationPath.put(rhs, rhsLocTuple);
+              }
+
+              // lhs side
+              if (lhs.getType().getExtension() != null
+                  && lhs.getType().getExtension() instanceof SSJavaType) {
+                lhsLocTuple.addAll(((SSJavaType) lhs.getType().getExtension()).getCompLoc()
+                    .getTuple());
+                mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
+              } else if (mapDescriptorToLocationPath.get(rhs) != null) {
+                // propagate rhs's location to lhs
+                lhsLocTuple.addAll(mapDescriptorToLocationPath.get(rhs));
+                mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
+              }
+            }
+
+            if (isEventLoopBody && lhs.getType().isPrimitive()
+                && !lhs.getSymbol().startsWith("srctmp")) {
+
+              NTuple<Descriptor> lhsHeapPath = computePath(lhs);
+
+              if (lhsLocTuple != null) {
+                addMayWrittenSet(md, lhsLocTuple, lhsHeapPath);
+              }
+
+            }
+          } else {
+            break;
           }
+
         }
-      }
 
+      }
     }
       break;
 
     case FKind.FlatSetFieldNode:
     case FKind.FlatSetElementNode: {
 
-      // x.f=y
+      // x.f=y;
 
       if (fn.kind() == FKind.FlatSetFieldNode) {
         FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
@@ -871,501 +812,150 @@ public class DefinitelyWrittenCheck {
         fld = getArrayField(td);
       }
 
-      // write(field)
-      NTuple<Descriptor> lhsHeapPath = computePath(lhs);
-      NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
-      if (fld.getType().isImmutable()) {
-
-        writeLocation(md, curr, fldHeapPath, getLocation(fld), fld);
-
-        Descriptor desc = fldHeapPath.get(fldHeapPath.size() - 1);
-        if (desc instanceof FieldDescriptor) {
-          NTuple<Descriptor> arrayPath = new NTuple<Descriptor>();
-          for (int i = 0; i < fldHeapPath.size() - 1; i++) {
-            arrayPath.add(fldHeapPath.get(i));
-          }
-          SharedStatus state = getState(curr, arrayPath);
-          state.setWriteEffect(getLocation(desc));
+      NTuple<Location> lhsLocTuple = new NTuple<Location>();
+      if (fld.isStatic()) {
+        if (fld.isFinal()) {
+          // in this case, fld has TOP location
+          Location topLocation = Location.createTopLocation(md);
+          lhsLocTuple.add(topLocation);
+        } else {
+          lhsLocTuple.addAll(deriveGlobalLocationTuple(md));
         }
-
       } else {
-        // updates reference field case:
-        fldHeapPath.add(fld);
-        updateWriteEffectOnReferenceField(curr, fldHeapPath);
+        lhsLocTuple.addAll(deriveLocationTuple(md, lhs));
       }
 
-    }
-      break;
-
-    case FKind.FlatCall: {
+      mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
 
-      FlatCall fc = (FlatCall) fn;
+      NTuple<Location> fieldLocTuple = new NTuple<Location>();
+      fieldLocTuple.addAll(lhsLocTuple);
 
-      if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
-        // ssjava util case!
-        // have write effects on the first argument
+      if (fn.kind() == FKind.FlatSetFieldNode) {
+        fieldLocTuple.add((Location) fld.getType().getExtension());
+      }
 
-        if (fc.getArg(0).getType().isArray()) {
-          // updates reference field case:
-          // 2. if there exists a tuple t in sharing summary that starts with
-          // hp(x) then, set flag of tuple t to 'true'
-          NTuple<Descriptor> argHeapPath = computePath(fc.getArg(0));
+      if (mapHeapPath.containsKey(lhs)) {
+        // fields reachable from the param can have heap path entry.
+        NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
+        lhsHeapPath.addAll(mapHeapPath.get(lhs));
 
-          Location loc = getLocation(fc.getArg(0));
-          NTuple<Descriptor> newHeapPath = new NTuple<Descriptor>();
-          for (int i = 0; i < argHeapPath.size() - 1; i++) {
-            newHeapPath.add(argHeapPath.get(i));
-          }
-          fld = (FieldDescriptor) argHeapPath.get(argHeapPath.size() - 1);
-          argHeapPath = newHeapPath;
+        Location fieldLocation;
+        if (fn.kind() == FKind.FlatSetFieldNode) {
+          fieldLocation = getLocation(fld);
+        } else {
+          fieldLocation = getLocation(lhsHeapPath.get(getArrayBaseDescriptorIdx(lhsHeapPath)));
+        }
 
-          writeLocation(md, curr, argHeapPath, loc, fld);
+        // Location fieldLocation = getLocation(lhs);
+        if (!isEventLoopBody && fieldLocation.getDescriptor().equals(md)) {
+          // if the field belongs to the local lattice, no reason to calculate
+          // shared location
+          break;
         }
 
-      } else {
-        // find out the set of callees
-        MethodDescriptor mdCallee = fc.getMethod();
-        FlatMethod fmCallee = state.getMethodFlat(mdCallee);
-        Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
-        setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
+        if (ssjava.isSharedLocation(fieldLocation)) {
 
-        possibleCalleeCompleteSummarySetToCaller.clear();
+          NTuple<Descriptor> fieldHeapPath = new NTuple<Descriptor>();
+          fieldHeapPath.addAll(computePath(lhs));
+          if (fn.kind() == FKind.FlatSetFieldNode) {
+            fieldHeapPath.add(fld);
+          }
 
-        for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
-          MethodDescriptor mdPossibleCallee = (MethodDescriptor) iterator.next();
-          FlatMethod calleeFlatMethod = state.getMethodFlat(mdPossibleCallee);
+          addMayWrittenSet(md, fieldLocTuple, fieldHeapPath);
 
-          addDependent(mdPossibleCallee, // callee
-              md); // caller
+        }
+      }
 
-          calleesToEnqueue.add(mdPossibleCallee);
+    }
+      break;
 
-          // updates possible callee's initial summary using caller's current
-          // writing status
-          ClearingSummary prevCalleeInitSummary =
-              mapMethodDescriptorToInitialClearingSummary.get(mdPossibleCallee);
+    case FKind.FlatElementNode:
+    case FKind.FlatFieldNode: {
 
-          ClearingSummary calleeInitSummary =
-              bindHeapPathOfCalleeCallerEffects(fc, calleeFlatMethod, curr);
+      // x=y.f;
 
-          Set<ClearingSummary> inSet = new HashSet<ClearingSummary>();
-          if (prevCalleeInitSummary != null) {
-            inSet.add(prevCalleeInitSummary);
-            mergeSharedLocationAnaylsis(calleeInitSummary, inSet);
-          }
+      if (fn.kind() == FKind.FlatFieldNode) {
+        FlatFieldNode ffn = (FlatFieldNode) fn;
+        lhs = ffn.getDst();
+        rhs = ffn.getSrc();
+        fld = ffn.getField();
+      } else {
+        FlatElementNode fen = (FlatElementNode) fn;
+        lhs = fen.getDst();
+        rhs = fen.getSrc();
+        TypeDescriptor td = rhs.getType().dereference();
+        fld = getArrayField(td);
+      }
 
-          // if changes, update the init summary
-          // and reschedule the callee for analysis
-          if (!calleeInitSummary.equals(prevCalleeInitSummary)) {
+      NTuple<Location> locTuple = new NTuple<Location>();
 
-            if (!methodDescriptorsToVisitStack.contains(mdPossibleCallee)) {
-              methodDescriptorsToVisitStack.add(mdPossibleCallee);
-            }
+      if (fld.isStatic()) {
 
-            mapMethodDescriptorToInitialClearingSummary.put(mdPossibleCallee, calleeInitSummary);
+        if (fld.isFinal()) {
+          // in this case, fld has TOP location
+          Location topLocation = Location.createTopLocation(md);
+          locTuple.add(topLocation);
+        } else {
+          locTuple.addAll(deriveGlobalLocationTuple(md));
+          if (fn.kind() == FKind.FlatFieldNode) {
+            locTuple.add((Location) fld.getType().getExtension());
           }
-
         }
 
-        // contribute callee's writing effects to the caller
-        mergeSharedLocationAnaylsis(curr, possibleCalleeCompleteSummarySetToCaller);
-
+      } else {
+        locTuple.addAll(deriveLocationTuple(md, rhs));
+        if (fn.kind() == FKind.FlatFieldNode) {
+          locTuple.add((Location) fld.getType().getExtension());
+        }
       }
 
-    }
-      break;
+      mapDescriptorToLocationPath.put(lhs, locTuple);
 
-    case FKind.FlatReturnNode: {
-      returnNodeSet.add(fn);
     }
       break;
 
-    }
+    case FKind.FlatCall: {
 
-  }
+      FlatCall fc = (FlatCall) fn;
 
-  private void updateWriteEffectOnReferenceField(ClearingSummary curr, NTuple<Descriptor> heapPath) {
-
-    // 2. if there exists a tuple t in sharing summary that starts with
-    // hp(x) then, set flag of tuple t to 'true'
-    Set<NTuple<Descriptor>> hpKeySet = curr.keySet();
-    for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) {
-      NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
-      if (hpKey.startsWith(heapPath)) {
-        curr.get(hpKey).updateFlag(true);
-      }
-    }
-
-  }
-
-  private ClearingSummary bindHeapPathOfCalleeCallerEffects(FlatCall fc,
-      FlatMethod calleeFlatMethod, ClearingSummary curr) {
-
-    ClearingSummary boundSet = new ClearingSummary();
-
-    // create mapping from arg idx to its heap paths
-    Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
-        new Hashtable<Integer, NTuple<Descriptor>>();
-
-    if (fc.getThis() != null) {
-      // arg idx is starting from 'this' arg
-      NTuple<Descriptor> thisHeapPath = mapHeapPath.get(fc.getThis());
-      if (thisHeapPath == null) {
-        // method is called without creating new flat node representing 'this'
-        thisHeapPath = new NTuple<Descriptor>();
-        thisHeapPath.add(fc.getThis());
-      }
-
-      mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
-    }
-
-    for (int i = 0; i < fc.numArgs(); i++) {
-      TempDescriptor arg = fc.getArg(i);
-      NTuple<Descriptor> argHeapPath = computePath(arg);
-      mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
-    }
-
-    Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
-        new Hashtable<Integer, TempDescriptor>();
-    int offset = 0;
-    if (calleeFlatMethod.getMethod().isStatic()) {
-      // static method does not have implicit 'this' arg
-      offset = 1;
-    }
-    for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
-      TempDescriptor param = calleeFlatMethod.getParameter(i);
-      mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
-    }
-
-    // binding caller's writing effects to callee's params
-    for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
-      NTuple<Descriptor> argHeapPath = mapArgIdx2CallerArgHeapPath.get(Integer.valueOf(i));
-
-      if (argHeapPath != null) {
-        // if method is static, the first argument is nulll because static
-        // method does not have implicit "THIS" arg
-        TempDescriptor calleeParamHeapPath = mapParamIdx2ParamTempDesc.get(Integer.valueOf(i));
-
-        // iterate over caller's writing effect set
-        Set<NTuple<Descriptor>> hpKeySet = curr.keySet();
-        for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) {
-          NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
-          // current element is reachable caller's arg
-          // so need to bind it to the caller's side and add it to the
-          // callee's
-          // init summary
-          if (hpKey.startsWith(argHeapPath)) {
-            NTuple<Descriptor> boundHeapPath = replace(hpKey, argHeapPath, calleeParamHeapPath);
-            boundSet.put(boundHeapPath, curr.get(hpKey).clone());
-          }
-
-        }
-      }
-
-    }
-
-    // contribute callee's complete summary into the caller's current summary
-    ClearingSummary calleeCompleteSummary =
-        mapMethodDescriptorToCompleteClearingSummary.get(calleeFlatMethod.getMethod());
-    if (calleeCompleteSummary != null) {
-      ClearingSummary boundCalleeEfffects = new ClearingSummary();
-      for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
-        NTuple<Descriptor> argHeapPath = mapArgIdx2CallerArgHeapPath.get(Integer.valueOf(i));
-
-        if (argHeapPath != null) {
-          // if method is static, the first argument is nulll because static
-          // method does not have implicit "THIS" arg
-          TempDescriptor calleeParamHeapPath = mapParamIdx2ParamTempDesc.get(Integer.valueOf(i));
-
-          // iterate over callee's writing effect set
-          Set<NTuple<Descriptor>> hpKeySet = calleeCompleteSummary.keySet();
-          for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) {
-            NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
-            // current element is reachable caller's arg
-            // so need to bind it to the caller's side and add it to the
-            // callee's
-            // init summary
-            if (hpKey.startsWith(calleeParamHeapPath)) {
-
-              NTuple<Descriptor> boundHeapPathForCaller = replace(hpKey, argHeapPath);
-
-              boundCalleeEfffects.put(boundHeapPathForCaller, calleeCompleteSummary.get(hpKey)
-                  .clone());
-
-            }
-          }
-
-        }
-
-      }
-      possibleCalleeCompleteSummarySetToCaller.add(boundCalleeEfffects);
-    }
-
-    return boundSet;
-  }
-
-  private NTuple<Descriptor> replace(NTuple<Descriptor> hpKey, NTuple<Descriptor> argHeapPath) {
-
-    // replace the head of heap path with caller's arg path
-    // for example, heap path 'param.a.b' in callee's side will be replaced with
-    // (corresponding arg heap path).a.b for caller's side
-
-    NTuple<Descriptor> bound = new NTuple<Descriptor>();
-
-    for (int i = 0; i < argHeapPath.size(); i++) {
-      bound.add(argHeapPath.get(i));
-    }
-
-    for (int i = 1; i < hpKey.size(); i++) {
-      bound.add(hpKey.get(i));
-    }
-
-    return bound;
-  }
-
-  private NTuple<Descriptor> replace(NTuple<Descriptor> effectHeapPath,
-      NTuple<Descriptor> argHeapPath, TempDescriptor calleeParamHeapPath) {
-    // replace the head of caller's heap path with callee's param heap path
-
-    NTuple<Descriptor> boundHeapPath = new NTuple<Descriptor>();
-    boundHeapPath.add(calleeParamHeapPath);
-
-    for (int i = argHeapPath.size(); i < effectHeapPath.size(); i++) {
-      boundHeapPath.add(effectHeapPath.get(i));
-    }
-
-    return boundHeapPath;
-  }
-
-  private void computeSharedCoverSet() {
-    LinkedList<MethodDescriptor> descriptorListToAnalyze =
-        (LinkedList<MethodDescriptor>) sortedDescriptors.clone();
-
-    // current descriptors to visit in fixed-point interprocedural analysis,
-    // prioritized by
-    // dependency in the call graph
-    methodDescriptorsToVisitStack.clear();
-
-    descriptorListToAnalyze.removeFirst();
-
-    Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
-    methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
-
-    while (!descriptorListToAnalyze.isEmpty()) {
-      MethodDescriptor md = descriptorListToAnalyze.removeFirst();
-      methodDescriptorsToVisitStack.add(md);
-    }
-
-    // analyze scheduled methods until there are no more to visit
-    while (!methodDescriptorsToVisitStack.isEmpty()) {
-      MethodDescriptor md = methodDescriptorsToVisitStack.pop();
-      FlatMethod fm = state.getMethodFlat(md);
-      computeSharedCoverSet_analyzeMethod(fm, md.equals(methodContainingSSJavaLoop));
-    }
-
-    computeSharedCoverSetForEventLoop();
-
-  }
-
-  private void computeSharedCoverSetForEventLoop() {
-    computeSharedCoverSet_analyzeMethod(state.getMethodFlat(methodContainingSSJavaLoop), true);
-  }
-
-  private void computeSharedCoverSet_analyzeMethod(FlatMethod fm, boolean onlyVisitSSJavaLoop) {
-
-    MethodDescriptor md = fm.getMethod();
-    Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
-
-    Set<FlatNode> visited = new HashSet<FlatNode>();
-
-    if (onlyVisitSSJavaLoop) {
-      flatNodesToVisit.add(ssjavaLoopEntrance);
-    } else {
-      flatNodesToVisit.add(fm);
-    }
-
-    while (!flatNodesToVisit.isEmpty()) {
-      FlatNode fn = flatNodesToVisit.iterator().next();
-      flatNodesToVisit.remove(fn);
-      visited.add(fn);
-
-      computeSharedCoverSet_nodeActions(md, fn);
-
-      for (int i = 0; i < fn.numNext(); i++) {
-        FlatNode nn = fn.getNext(i);
-
-        if (!visited.contains(nn)) {
-          if (!onlyVisitSSJavaLoop || (onlyVisitSSJavaLoop && loopIncElements.contains(nn))) {
-            flatNodesToVisit.add(nn);
-          }
-        }
-
-      }
-
-    }
-
-  }
-
-  private void computeSharedCoverSet_nodeActions(MethodDescriptor md, FlatNode fn) {
-    TempDescriptor lhs;
-    TempDescriptor rhs;
-    FieldDescriptor fld;
-
-    switch (fn.kind()) {
-
-    case FKind.FlatLiteralNode: {
-      FlatLiteralNode fln = (FlatLiteralNode) fn;
-      lhs = fln.getDst();
-
-      if (lhs.getType().isPrimitive() && !lhs.getSymbol().startsWith("neverused")
-          && !lhs.getSymbol().startsWith("srctmp")) {
-        // only need to care about composite location case here
-        if (lhs.getType().getExtension() instanceof SSJavaType) {
-          CompositeLocation compLoc = ((SSJavaType) lhs.getType().getExtension()).getCompLoc();
-          Location lastLocElement = compLoc.get(compLoc.getSize() - 1);
-          // check if the last one is shared loc
-          if (ssjava.isSharedLocation(lastLocElement)) {
-            addSharedLocDescriptor(lastLocElement, lhs);
-          }
-        }
-      }
-
-    }
-      break;
-
-    case FKind.FlatOpNode: {
-      FlatOpNode fon = (FlatOpNode) fn;
-      // for a normal assign node, need to propagate lhs's location path to
-      // rhs
-      if (fon.getOp().getOp() == Operation.ASSIGN) {
-        rhs = fon.getLeft();
-        lhs = fon.getDest();
-
-        if (lhs.getType().isPrimitive() && !lhs.getSymbol().startsWith("neverused")
-            && !lhs.getSymbol().startsWith("srctmp") && !lhs.getSymbol().startsWith("leftop")
-            && !lhs.getSymbol().startsWith("rightop")) {
-
-          NTuple<Location> lhsLocTuple = new NTuple<Location>();
-          lhsLocTuple.addAll(deriveLocationTuple(md, rhs));
-
-          mapLocationPathToMayWrittenSet.put(lhsLocTuple, null, lhs);
-          addMayWrittenSet(md, lhsLocTuple, lhs);
-
-        }
-
-        if (mapDescriptorToLocationPath.containsKey(rhs)) {
-          mapDescriptorToLocationPath.put(lhs, mapDescriptorToLocationPath.get(rhs));
-        } else {
-          if (rhs.getType().getExtension() instanceof SSJavaType) {
-            NTuple<Location> rhsLocTuple =
-                ((SSJavaType) rhs.getType().getExtension()).getCompLoc().getTuple();
-
-            NTuple<Location> lhsLocTuple = new NTuple<Location>();
-            lhsLocTuple.addAll(rhsLocTuple);
-
-            mapDescriptorToLocationPath.put(rhs, rhsLocTuple);
-            mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
-
-          }
-        }
+      bindLocationPathCallerArgWithCalleeParam(md, fc);
 
-      }
     }
       break;
 
-    case FKind.FlatSetFieldNode:
-    case FKind.FlatSetElementNode: {
+    case FKind.FlatNew: {
 
-      // x.f=y;
-
-      if (fn.kind() == FKind.FlatSetFieldNode) {
-        FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
-        lhs = fsfn.getDst();
-        fld = fsfn.getField();
-        rhs = fsfn.getSrc();
-      } else {
-        FlatSetElementNode fsen = (FlatSetElementNode) fn;
-        lhs = fsen.getDst();
-        rhs = fsen.getSrc();
-        TypeDescriptor td = lhs.getType().dereference();
-        fld = getArrayField(td);
-      }
-
-      Location fieldLocation = (Location) fld.getType().getExtension();
-      if (ssjava.isSharedLocation(fieldLocation)) {
-        addSharedLocDescriptor(fieldLocation, fld);
-
-        NTuple<Location> locTuple = new NTuple<Location>();
-        locTuple.addAll(deriveLocationTuple(md, lhs));
-        locTuple.add(fieldLocation);
-
-        // mapLocationPathToMayWrittenSet.put(locTuple, null, fld);
-        addMayWrittenSet(md, locTuple, fld);
+      FlatNew fnew = (FlatNew) fn;
+      TempDescriptor dst = fnew.getDst();
+      NTuple<Location> locTuple = deriveLocationTuple(md, dst);
 
+      if (locTuple != null) {
+        NTuple<Location> dstLocTuple = new NTuple<Location>();
+        dstLocTuple.addAll(locTuple);
+        mapDescriptorToLocationPath.put(dst, dstLocTuple);
       }
 
     }
       break;
-
-    case FKind.FlatElementNode:
-    case FKind.FlatFieldNode: {
-
-      // x=y.f;
-
-      if (fn.kind() == FKind.FlatFieldNode) {
-        FlatFieldNode ffn = (FlatFieldNode) fn;
-        lhs = ffn.getDst();
-        rhs = ffn.getSrc();
-        fld = ffn.getField();
-      } else {
-        FlatElementNode fen = (FlatElementNode) fn;
-        lhs = fen.getDst();
-        rhs = fen.getSrc();
-        TypeDescriptor td = rhs.getType().dereference();
-        fld = getArrayField(td);
-      }
-
-      if (fld.isFinal()) {
-        // if field is final no need to check
-        break;
-      }
-
-      NTuple<Location> locTuple = new NTuple<Location>();
-      locTuple.addAll(deriveLocationTuple(md, rhs));
-      locTuple.add((Location) fld.getType().getExtension());
-
-      mapDescriptorToLocationPath.put(lhs, locTuple);
-
-    }
-      break;
-
-    case FKind.FlatCall: {
-
-      FlatCall fc = (FlatCall) fn;
-      bindLocationPathCallerArgWithCalleeParam(md, fc);
-
-    }
-      break;
-
     }
   }
 
-  private void addMayWrittenSet(MethodDescriptor md, NTuple<Location> locTuple, Descriptor d) {
+  private void addMayWrittenSet(MethodDescriptor md, NTuple<Location> locTuple,
+      NTuple<Descriptor> heapPath) {
 
-    MultiSourceMap<Location, Descriptor> map = mapMethodToSharedWriteMapping.get(md);
+    MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> map = mapMethodToSharedLocCoverSet.get(md);
     if (map == null) {
-      map = new MultiSourceMap<Location, Descriptor>();
-      mapMethodToSharedWriteMapping.put(md, map);
+      map = new MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>();
+      mapMethodToSharedLocCoverSet.put(md, map);
     }
 
-    Set<Descriptor> writeSet = map.get(locTuple);
+    Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
     if (writeSet == null) {
-      writeSet = new HashSet<Descriptor>();
+      writeSet = new HashSet<NTuple<Descriptor>>();
       map.put(locTuple, writeSet);
     }
-    writeSet.add(d);
+    writeSet.add(heapPath);
 
-    // System.out.println("ADD WRITE DESC=" + d + " TO locTuple=" + locTuple);
   }
 
   private void bindLocationPathCallerArgWithCalleeParam(MethodDescriptor mdCaller, FlatCall fc) {
@@ -1376,10 +966,8 @@ public class DefinitelyWrittenCheck {
       TempDescriptor arg = fc.getArg(0);
       NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
       NTuple<Descriptor> argHeapPath = computePath(arg);
-      mapLocationPathToMayWrittenSet.put(argLocationPath, null,
-          argHeapPath.get(argHeapPath.size() - 1));
-
-    } else {
+      addMayWrittenSet(mdCaller, argLocationPath, argHeapPath);
+    } else if (ssjava.needTobeAnnotated(fc.getMethod())) {
 
       // if arg is not primitive type, we need to propagate maywritten set to
       // the caller's location path
@@ -1389,26 +977,42 @@ public class DefinitelyWrittenCheck {
       setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
 
       // create mapping from arg idx to its heap paths
-      Hashtable<Integer, NTuple<Location>> mapArgIdx2CallerAgLocationStrPath =
+      Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
+          new Hashtable<Integer, NTuple<Descriptor>>();
+
+      // create mapping from arg idx to its location paths
+      Hashtable<Integer, NTuple<Location>> mapArgIdx2CallerArgLocationPath =
           new Hashtable<Integer, NTuple<Location>>();
 
-      // arg idx is starting from 'this' arg
       if (fc.getThis() != null) {
-        NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
-        mapArgIdx2CallerAgLocationStrPath.put(Integer.valueOf(0), thisLocationPath);
-      }
 
-      Hashtable<Integer, Set<Descriptor>> mapParamIdx2WriteSet =
-          new Hashtable<Integer, Set<Descriptor>>();
+        if (mapHeapPath.containsKey(fc.getThis())) {
 
-      for (int i = 0; i < fc.numArgs() + 1; i++) {
-        mapParamIdx2WriteSet.put(Integer.valueOf(i), new HashSet<Descriptor>());
+          // setup heap path for 'this'
+          NTuple<Descriptor> thisHeapPath = new NTuple<Descriptor>();
+          thisHeapPath.addAll(mapHeapPath.get(fc.getThis()));
+          mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
+
+          // setup location path for 'this'
+          NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
+          mapArgIdx2CallerArgLocationPath.put(Integer.valueOf(0), thisLocationPath);
+
+        }
       }
 
       for (int i = 0; i < fc.numArgs(); i++) {
         TempDescriptor arg = fc.getArg(i);
-        NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
-        mapArgIdx2CallerAgLocationStrPath.put(Integer.valueOf(i + 1), argLocationPath);
+        // create mapping arg to loc path
+
+        if (mapHeapPath.containsKey(arg)) {
+          // setup heap path
+          NTuple<Descriptor> argHeapPath = mapHeapPath.get(arg);
+          mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
+          // setup loc path
+          NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
+          mapArgIdx2CallerArgLocationPath.put(Integer.valueOf(i + 1), argLocationPath);
+        }
+
       }
 
       for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
@@ -1417,6 +1021,9 @@ public class DefinitelyWrittenCheck {
 
         // binding caller's args and callee's params
 
+        Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath =
+            new Hashtable<NTuple<Descriptor>, NTuple<Descriptor>>();
+
         Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
             new Hashtable<Integer, TempDescriptor>();
         int offset = 0;
@@ -1424,28 +1031,40 @@ public class DefinitelyWrittenCheck {
           // static method does not have implicit 'this' arg
           offset = 1;
         }
+
         for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
           TempDescriptor param = calleeFlatMethod.getParameter(i);
           mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
+
+          NTuple<Descriptor> calleeHeapPath = computePath(param);
+
+          NTuple<Descriptor> argHeapPath =
+              mapArgIdx2CallerArgHeapPath.get(Integer.valueOf(i + offset));
+
+          if (argHeapPath != null) {
+            mapParamHeapPathToCallerArgHeapPath.put(calleeHeapPath, argHeapPath);
+
+          }
+
         }
 
-        Set<Integer> keySet = mapArgIdx2CallerAgLocationStrPath.keySet();
+        Set<Integer> keySet = mapArgIdx2CallerArgLocationPath.keySet();
         for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
           Integer idx = (Integer) iterator2.next();
-          NTuple<Location> callerArgLocationStrPath = mapArgIdx2CallerAgLocationStrPath.get(idx);
+
+          NTuple<Location> callerArgLocationPath = mapArgIdx2CallerArgLocationPath.get(idx);
 
           TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
           NTuple<Location> calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam);
 
-          // System.out.println("#createNewMappingOfMayWrittenSet callee=" +
-          // callee
-          // + " callerArgLocationStrPath=" + callerArgLocationStrPath +
-          // "calleeLocationPath="
-          // + calleeLocationPath + " idx=" + idx + " writeset=" +
-          // mapParamIdx2WriteSet.get(idx));
-          createNewMappingOfMayWrittenSet(callee, callerArgLocationStrPath, calleeLocationPath,
-              mapParamIdx2WriteSet.get(idx));
+          NTuple<Descriptor> callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx);
+          NTuple<Descriptor> calleeHeapPath = computePath(calleeParam);
 
+          if (!calleeParam.getType().isPrimitive()) {
+            createNewMappingOfMayWrittenSet(mdCaller, callee, callerArgHeapPath,
+                callerArgLocationPath, calleeHeapPath, calleeLocationPath,
+                mapParamHeapPathToCallerArgHeapPath);
+          }
         }
 
       }
@@ -1454,8 +1073,29 @@ public class DefinitelyWrittenCheck {
 
   }
 
-  private void createNewMappingOfMayWrittenSet(MethodDescriptor callee,
-      NTuple<Location> callerPath, NTuple<Location> calleeParamPath, Set<Descriptor> writeSet) {
+  private Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> getMappingByStartedWith(
+      MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> map, NTuple<Location> in) {
+
+    Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> matchedMapping =
+        new Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>>();
+
+    Set<NTuple<Location>> keySet = map.keySet();
+
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      NTuple<Location> key = (NTuple<Location>) iterator.next();
+      if (key.startsWith(in)) {
+        matchedMapping.put(key, map.get(key));
+      }
+    }
+
+    return matchedMapping;
+
+  }
+
+  private void createNewMappingOfMayWrittenSet(MethodDescriptor caller, MethodDescriptor callee,
+      NTuple<Descriptor> callerArgHeapPath, NTuple<Location> callerArgLocPath,
+      NTuple<Descriptor> calleeParamHeapPath, NTuple<Location> calleeParamLocPath,
+      Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath) {
 
     // propagate may-written-set associated with the key that is started with
     // calleepath to the caller
@@ -1464,66 +1104,84 @@ public class DefinitelyWrittenCheck {
     // 2) create new mapping of may-written-set of callee path to caller path
 
     // extract all may written effect accessed through callee param path
-    MultiSourceMap<Location, Descriptor> mapping = mapMethodToSharedWriteMapping.get(callee);
+    MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> calleeMapping =
+        mapMethodToSharedLocCoverSet.get(callee);
 
-    if (mapping == null) {
+    if (calleeMapping == null) {
       return;
     }
 
-    Hashtable<NTuple<Location>, Set<Descriptor>> paramMapping =
-        mapping.getMappingByStartedWith(calleeParamPath);
+    MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> callerMapping =
+        mapMethodToSharedLocCoverSet.get(caller);
+
+    if (callerMapping == null) {
+      callerMapping = new MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>();
+      mapMethodToSharedLocCoverSet.put(caller, callerMapping);
+    }
+
+    Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> paramMapping =
+        getMappingByStartedWith(calleeMapping, calleeParamLocPath);
+
+    Set<NTuple<Location>> calleeKeySet = paramMapping.keySet();
 
-    Set<NTuple<Location>> calleeKeySet = mapping.keySet();
     for (Iterator iterator = calleeKeySet.iterator(); iterator.hasNext();) {
       NTuple<Location> calleeKey = (NTuple<Location>) iterator.next();
-      Set<Descriptor> calleeMayWriteSet = paramMapping.get(calleeKey);
+
+      Set<NTuple<Descriptor>> calleeMayWriteSet = paramMapping.get(calleeKey);
 
       if (calleeMayWriteSet != null) {
-        writeSet.addAll(calleeMayWriteSet);
+
+        Set<NTuple<Descriptor>> boundMayWriteSet = new HashSet<NTuple<Descriptor>>();
+
+        Set<NTuple<Descriptor>> boundSet =
+            convertToCallerMayWriteSet(calleeParamHeapPath, calleeMayWriteSet, callerMapping,
+                mapParamHeapPathToCallerArgHeapPath);
+
+        boundMayWriteSet.addAll(boundSet);
 
         NTuple<Location> newKey = new NTuple<Location>();
-        newKey.addAll(callerPath);
+        newKey.addAll(callerArgLocPath);
         // need to replace the local location with the caller's path so skip the
         // local location of the parameter
         for (int i = 1; i < calleeKey.size(); i++) {
           newKey.add(calleeKey.get(i));
         }
 
-        mapLocationPathToMayWrittenSet.put(calleeKey, newKey, writeSet);
+        callerMapping.union(newKey, boundMayWriteSet);
       }
 
     }
 
   }
 
-  private void addSharedLocDescriptor(Location sharedLoc, Descriptor desc) {
+  private Set<NTuple<Descriptor>> convertToCallerMayWriteSet(
+      NTuple<Descriptor> calleeParamHeapPath, Set<NTuple<Descriptor>> calleeMayWriteSet,
+      MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> callerMapping,
+      Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath) {
 
-    Set<Descriptor> descSet = mapSharedLocationToCoverSet.get(sharedLoc);
-    if (descSet == null) {
-      descSet = new HashSet<Descriptor>();
-      mapSharedLocationToCoverSet.put(sharedLoc, descSet);
-    }
+    Set<NTuple<Descriptor>> boundSet = new HashSet<NTuple<Descriptor>>();
 
-    descSet.add(desc);
+    // replace callee's param path with caller's arg path
+    for (Iterator iterator = calleeMayWriteSet.iterator(); iterator.hasNext();) {
+      NTuple<Descriptor> calleeWriteHeapPath = (NTuple<Descriptor>) iterator.next();
 
-  }
+      NTuple<Descriptor> writeHeapPathParamHeapPath = calleeWriteHeapPath.subList(0, 1);
 
-  private boolean hasReadingEffectOnSharedLocation(MethodDescriptor md, NTuple<Descriptor> hp,
-      Location loc, Descriptor d) {
+      NTuple<Descriptor> callerArgHeapPath =
+          mapParamHeapPathToCallerArgHeapPath.get(writeHeapPathParamHeapPath);
 
-    ReadSummary summary = mapMethodDescriptorToReadSummary.get(md);
+      NTuple<Descriptor> boundHeapPath = new NTuple<Descriptor>();
+      boundHeapPath.addAll(callerArgHeapPath);
 
-    if (summary != null) {
-      Hashtable<Location, Set<Descriptor>> map = summary.get(hp);
-      if (map != null) {
-        Set<Descriptor> descSec = map.get(loc);
-        if (descSec != null) {
-          return descSec.contains(d);
-        }
+      for (int i = 1; i < calleeWriteHeapPath.size(); i++) {
+        boundHeapPath.add(calleeWriteHeapPath.get(i));
       }
+
+      boundSet.add(boundHeapPath);
+
     }
-    return false;
 
+    return boundSet;
   }
 
   private Location getLocation(Descriptor d) {
@@ -1541,8 +1199,12 @@ public class DefinitelyWrittenCheck {
       if (te != null) {
         if (te instanceof SSJavaType) {
           SSJavaType ssType = (SSJavaType) te;
-          CompositeLocation comp = ssType.getCompLoc();
-          return comp.get(comp.getSize() - 1);
+          if (ssType.getCompLoc() != null) {
+            CompositeLocation comp = ssType.getCompLoc();
+            return comp.get(comp.getSize() - 1);
+          } else {
+            return null;
+          }
         } else {
           return (Location) te;
         }
@@ -1552,67 +1214,13 @@ public class DefinitelyWrittenCheck {
     return mapDescToLocation.get(d);
   }
 
-  private void writeLocation(MethodDescriptor md, ClearingSummary curr, NTuple<Descriptor> hp,
-      Location loc, Descriptor d) {
-
-    SharedStatus state = getState(curr, hp);
-    if (loc != null && hasReadingEffectOnSharedLocation(md, hp, loc, d)) {
-      // 1. add field x to the clearing set
-
-      state.addVar(loc, d);
-
-      // 3. if the set v contains all of variables belonging to the shared
-      // location, set flag to true
-      if (isOverWrittenAllDescsOfSharedLoc(md, hp, loc, state.getVarSet(loc))) {
-        state.updateFlag(loc, true);
-      }
-    }
-    state.setWriteEffect(loc);
-
-  }
-
-  private boolean isOverWrittenAllDescsOfSharedLoc(MethodDescriptor md, NTuple<Descriptor> hp,
-      Location loc, Set<Descriptor> writtenSet) {
-
-    ReadSummary summary = mapMethodDescriptorToReadSummary.get(md);
-
-    if (summary != null) {
-      Hashtable<Location, Set<Descriptor>> map = summary.get(hp);
-      if (map != null) {
-        Set<Descriptor> descSet = map.get(loc);
-        if (descSet != null) {
-          return writtenSet.containsAll(descSet);
-        }
-      }
-    }
-    return false;
-  }
-
-  private void readLocation(MethodDescriptor md, ClearingSummary curr, NTuple<Descriptor> hp,
-      Location loc, Descriptor d) {
-    // remove reading var x from written set
-    if (loc != null && hasReadingEffectOnSharedLocation(md, hp, loc, d)) {
-      SharedStatus state = getState(curr, hp);
-      state.removeVar(loc, d);
-    }
-  }
-
-  private SharedStatus getState(ClearingSummary curr, NTuple<Descriptor> hp) {
-    SharedStatus state = curr.get(hp);
-    if (state == null) {
-      state = new SharedStatus();
-      curr.put(hp, state);
-    }
-    return state;
-  }
-
   private void eventLoopAnalysis() {
     // perform second stage analysis: intraprocedural analysis ensure that
     // all
     // variables are definitely written in-between the same read
 
     Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
-    flatNodesToVisit.add(ssjavaLoopEntrance);
+    flatNodesToVisit.add(ssjava.getSSJavaLoopEntrance());
 
     while (!flatNodesToVisit.isEmpty()) {
       FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
@@ -1630,7 +1238,7 @@ public class DefinitelyWrittenCheck {
         }
       }
 
-      eventLoopAnalysis_nodeAction(fn, curr, ssjavaLoopEntrance);
+      eventLoopAnalysis_nodeAction(fn, curr, ssjava.getSSJavaLoopEntrance());
 
       // if a new result, schedule forward nodes for analysis
       if (!curr.equals(prev)) {
@@ -1693,7 +1301,6 @@ public class DefinitelyWrittenCheck {
         }
 
       }
-      // System.out.println("EVENT LOOP ENTRY=" + curr);
 
     } else {
       TempDescriptor lhs;
@@ -1707,26 +1314,67 @@ public class DefinitelyWrittenCheck {
         lhs = fon.getDest();
         rhs = fon.getLeft();
 
-        if (!lhs.getSymbol().startsWith("neverused")) {
-          NTuple<Descriptor> rhsHeapPath = computePath(rhs);
-          if (!rhs.getType().isImmutable()) {
-            mapHeapPath.put(lhs, rhsHeapPath);
-          } else {
-            // write(lhs)
-            // NTuple<Descriptor> lhsHeapPath = computePath(lhs);
-            NTuple<Descriptor> path = new NTuple<Descriptor>();
-            path.add(lhs);
+        if (fon.getOp().getOp() == Operation.ASSIGN) {
 
-            // System.out.println("WRITE VARIABLE=" + path + " from=" + lhs);
+          if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop")
+              && !lhs.getSymbol().startsWith("rightop")) {
 
-            computeKILLSetForWrite(curr, path, readWriteKillSet);
-            computeGENSetForWrite(path, readWriteGenSet);
+            boolean hasWriteEffect = false;
 
-            // System.out.println("#VARIABLE WRITE:" + fn);
-            // System.out.println("#KILLSET=" + KILLSet);
-            // System.out.println("#GENSet=" + GENSet);
+            if (rhs.getType().getExtension() instanceof SSJavaType
+                && lhs.getType().getExtension() instanceof SSJavaType) {
+
+              CompositeLocation rhsCompLoc =
+                  ((SSJavaType) rhs.getType().getExtension()).getCompLoc();
+
+              CompositeLocation lhsCompLoc =
+                  ((SSJavaType) lhs.getType().getExtension()).getCompLoc();
+
+              if (lhsCompLoc != rhsCompLoc) {
+                // have a write effect!
+                hasWriteEffect = true;
+              }
+
+            } else if (lhs.getType().isImmutable()) {
+              hasWriteEffect = true;
+            }
+
+            if (hasWriteEffect && mapHeapPath.containsKey(lhs)) {
+              // write(lhs)
+              NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
+              lhsHeapPath.addAll(mapHeapPath.get(lhs));
+
+              Location lhsLoc = getLocation(lhs);
+              if (ssjava.isSharedLocation(lhsLoc)) {
+
+                NTuple<Descriptor> varHeapPath = computePath(lhs);
+                NTuple<Location> varLocTuple = mapDescriptorToLocationPath.get(lhs);
+
+                Set<NTuple<Descriptor>> writtenSet =
+                    mapFlatNodeToSharedLocMapping.get(fn).get(varLocTuple);
+
+                Set<NTuple<Descriptor>> mustClearSet =
+                    mapFlatNodeToMustClearMap.get(fn).get(varLocTuple);
+
+                if (isCovered(varLocTuple, writtenSet, mustClearSet)) {
+                  computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet);
+                  computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet);
+                } else {
+                  computeGENSetForSharedNonCoverWrite(curr, varHeapPath, readWriteGenSet);
+                }
+
+              } else {
+
+                computeKILLSetForWrite(curr, lhsHeapPath, readWriteKillSet);
+                computeGENSetForWrite(lhsHeapPath, readWriteGenSet);
+              }
+
+              Set<WriteAge> writeAgeSet = curr.get(lhsHeapPath);
+              checkWriteAgeSet(writeAgeSet, lhsHeapPath, fn);
+            }
 
           }
+
         }
 
       }
@@ -1761,6 +1409,7 @@ public class DefinitelyWrittenCheck {
         fldHeapPath.add(fld);
 
         Set<WriteAge> writeAgeSet = curr.get(fldHeapPath);
+
         checkWriteAgeSet(writeAgeSet, fldHeapPath, fn);
 
       }
@@ -1781,103 +1430,301 @@ public class DefinitelyWrittenCheck {
           fld = getArrayField(td);
         }
 
-        // write(field)
-        NTuple<Descriptor> lhsHeapPath = computePath(lhs);
-        NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
-        fldHeapPath.add(fld);
+        // set up heap path
+        NTuple<Descriptor> lhsHeapPath = mapHeapPath.get(lhs);
+        if (lhsHeapPath != null) {
+          // write(field)
+          NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
+          if (fn.kind() == FKind.FlatSetFieldNode) {
+            fldHeapPath.add(fld);
+          }
+
+          // shared loc extension
+          Location fieldLoc;
+          if (fn.kind() == FKind.FlatSetFieldNode) {
+            fieldLoc = (Location) fld.getType().getExtension();
+          } else {
+            NTuple<Location> locTuple = mapDescriptorToLocationPath.get(lhs);
+            fieldLoc = locTuple.get(locTuple.size() - 1);
+          }
+
+          if (ssjava.isSharedLocation(fieldLoc)) {
+
+            NTuple<Location> fieldLocTuple = new NTuple<Location>();
+            fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs));
+            if (fn.kind() == FKind.FlatSetFieldNode) {
+              fieldLocTuple.add(fieldLoc);
+            }
+
+            Set<NTuple<Descriptor>> writtenSet =
+                mapFlatNodeToSharedLocMapping.get(fn).get(fieldLocTuple);
+            if (isCovered(fieldLocTuple, writtenSet)) {
+              computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet);
+              computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet);
+            } else {
+              computeGENSetForSharedNonCoverWrite(curr, fldHeapPath, readWriteGenSet);
+            }
+
+          } else {
+            computeKILLSetForWrite(curr, fldHeapPath, readWriteKillSet);
+            computeGENSetForWrite(fldHeapPath, readWriteGenSet);
+          }
+
+        }
+
+      }
+        break;
+
+      case FKind.FlatCall: {
+        FlatCall fc = (FlatCall) fn;
+        SharedLocMap sharedLocMap = mapFlatNodeToSharedLocMapping.get(fc);
+        SharedLocMap mustClearMap = mapFlatNodeToMustClearMap.get(fc);
+        generateKILLSetForFlatCall(fc, curr, sharedLocMap, mustClearMap, readWriteKillSet);
+        generateGENSetForFlatCall(fc, sharedLocMap, mustClearMap, readWriteGenSet);
+
+      }
+        break;
+
+      }
+
+      computeNewMapping(curr, readWriteKillSet, readWriteGenSet);
+      if (fn instanceof FlatCall) {
+        checkManyRead((FlatCall) fn, curr);
+      }
+
+    }
+
+  }
+
+  private void computeGENSetForSharedNonCoverWrite(
+      Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, NTuple<Descriptor> heapPath,
+      Hashtable<NTuple<Descriptor>, Set<WriteAge>> genSet) {
+
+    Set<WriteAge> writeAgeSet = genSet.get(heapPath);
+    if (writeAgeSet == null) {
+      writeAgeSet = new HashSet<WriteAge>();
+      genSet.put(heapPath, writeAgeSet);
+    }
+
+    writeAgeSet.add(new WriteAge(1));
+
+  }
+
+  private void computeGENSetForSharedAllCoverWrite(
+      Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, Set<NTuple<Descriptor>> writtenSet,
+      Hashtable<NTuple<Descriptor>, Set<WriteAge>> genSet) {
+
+    for (Iterator iterator = writtenSet.iterator(); iterator.hasNext();) {
+      NTuple<Descriptor> writeHeapPath = (NTuple<Descriptor>) iterator.next();
+
+      Set<WriteAge> writeAgeSet = new HashSet<WriteAge>();
+      writeAgeSet.add(new WriteAge(0));
+
+      genSet.put(writeHeapPath, writeAgeSet);
+    }
+
+  }
+
+  private void computeKILLSetForSharedWrite(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
+      Set<NTuple<Descriptor>> writtenSet, Hashtable<NTuple<Descriptor>, Set<WriteAge>> killSet) {
+
+    for (Iterator iterator = writtenSet.iterator(); iterator.hasNext();) {
+      NTuple<Descriptor> writeHeapPath = (NTuple<Descriptor>) iterator.next();
+      Set<WriteAge> writeSet = curr.get(writeHeapPath);
+      if (writeSet != null) {
+        killSet.put(writeHeapPath, writeSet);
+      }
+    }
+
+  }
+
+  private boolean isCovered(NTuple<Location> locTuple, Set<NTuple<Descriptor>> curWrittenSet) {
+
+    Set<NTuple<Descriptor>> coverSet =
+        mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locTuple);
+
+    if (curWrittenSet == null) {
+      return false;
+    }
+
+    return curWrittenSet.containsAll(coverSet);
+  }
+
+  private boolean isCovered(NTuple<Location> locTuple, Set<NTuple<Descriptor>> curWrittenSet,
+      Set<NTuple<Descriptor>> mustClearSet) {
+
+    Set<NTuple<Descriptor>> coverSet =
+        mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locTuple);
+
+    if (mustClearSet != null && mustClearSet.containsAll(coverSet)) {
+      return true;
+    }
+
+    if (curWrittenSet == null) {
+      return false;
+    }
+
+    return curWrittenSet.containsAll(coverSet);
+  }
+
+  private void checkManyRead(FlatCall fc, Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr) {
+    Set<NTuple<Descriptor>> boundReadSet = mapFlatNodeToBoundReadSet.get(fc);
+    for (Iterator iterator = boundReadSet.iterator(); iterator.hasNext();) {
+      NTuple<Descriptor> readHeapPath = (NTuple<Descriptor>) iterator.next();
+      Set<WriteAge> writeAgeSet = curr.get(readHeapPath);
+      checkWriteAgeSet(writeAgeSet, readHeapPath, fc);
+    }
+
+  }
+
+  private void checkWriteAgeSet(Set<WriteAge> writeAgeSet, NTuple<Descriptor> path, FlatNode fn) {
+
+    if (writeAgeSet != null) {
+      for (Iterator iterator = writeAgeSet.iterator(); iterator.hasNext();) {
+        WriteAge writeAge = (WriteAge) iterator.next();
+        if (writeAge.getAge() > MAXAGE) {
+          generateErrorMessage(path, fn);
+        }
+      }
+    }
+  }
+
+  private void generateErrorMessage(NTuple<Descriptor> path, FlatNode fn) {
+
+    Descriptor lastDesc = path.get(getArrayBaseDescriptorIdx(path));
+    if (ssjava.isSharedLocation(getLocation(lastDesc))) {
+
+      NTuple<Location> locPathTuple = getLocationTuple(path);
+      Set<NTuple<Descriptor>> coverSet =
+          mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locPathTuple);
+      throw new Error("Shared memory locations, which is reachable through references " + path
+          + ", are not completely overwritten by the higher values at "
+          + methodContainingSSJavaLoop.getClassDesc().getSourceFileName() + "::" + fn.getNumLine()
+          + ".\nThe following memory locations belong to the same shared locations:" + coverSet);
+
+    } else {
+      throw new Error(
+          "Memory location, which is reachable through references "
+              + path
+              + ", who comes back to the same read statement without being overwritten at the out-most iteration at "
+              + methodContainingSSJavaLoop.getClassDesc().getSourceFileName() + "::"
+              + fn.getNumLine());
+    }
+
+  }
 
-        computeKILLSetForWrite(curr, fldHeapPath, readWriteKillSet);
-        computeGENSetForWrite(fldHeapPath, readWriteGenSet);
+  private void generateGENSetForFlatCall(FlatCall fc, SharedLocMap sharedLocMap,
+      SharedLocMap mustClearMap, Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
 
-        // System.out.println("FIELD WRITE:" + fn);
-        // System.out.println("KILLSET=" + KILLSet);
-        // System.out.println("GENSet=" + GENSet);
+    Set<NTuple<Descriptor>> boundMayWriteSet = mapFlatNodeToBoundMayWriteSet.get(fc);
 
-      }
-        break;
+    for (Iterator iterator = boundMayWriteSet.iterator(); iterator.hasNext();) {
+      NTuple<Descriptor> heapPath = (NTuple<Descriptor>) iterator.next();
 
-      case FKind.FlatCall: {
-        FlatCall fc = (FlatCall) fn;
+      if (!isSharedLocation(heapPath)) {
+        addWriteAgeToSet(heapPath, GENSet, new WriteAge(0));
+      } else {
+        // if the current heap path is shared location
 
-        // System.out.println("FLATCALL:" + fn);
+        NTuple<Location> locTuple = getLocationTuple(heapPath);
 
-        generateKILLSetForFlatCall(fc, curr, readWriteKillSet);
-        generateGENSetForFlatCall(fc, readWriteGenSet);
+        Set<NTuple<Descriptor>> sharedWriteHeapPathSet = sharedLocMap.get(locTuple);
 
-        checkManyRead(fc, curr);
+        if (isCovered(locTuple, sharedLocMap.get(locTuple), mustClearMap.get(locTuple))) {
+          // if it is covered, add all of heap paths belong to the same shared
+          // loc with write age 0
+          for (Iterator iterator2 = sharedWriteHeapPathSet.iterator(); iterator2.hasNext();) {
+            NTuple<Descriptor> sharedHeapPath = (NTuple<Descriptor>) iterator2.next();
+            addWriteAgeToSet(sharedHeapPath, GENSet, new WriteAge(0));
+          }
 
-        // System.out.println("KILLSET=" + readWriteKillSet);
-        // System.out.println("GENSet=" + readWriteGenSet);
+        } else {
+          // if not covered, add write age 1 to the heap path that is
+          // may-written but not covered
+          addWriteAgeToSet(heapPath, GENSet, new WriteAge(1));
+        }
 
       }
-        break;
 
-      }
+    }
 
-      computeNewMapping(curr, readWriteKillSet, readWriteGenSet);
-      // System.out.println("#######" + curr);
+  }
+
+  private void addWriteAgeToSet(NTuple<Descriptor> heapPath,
+      Hashtable<NTuple<Descriptor>, Set<WriteAge>> map, WriteAge age) {
 
+    Set<WriteAge> currSet = map.get(heapPath);
+    if (currSet == null) {
+      currSet = new HashSet<WriteAge>();
+      map.put(heapPath, currSet);
     }
 
+    currSet.add(age);
   }
 
-  private void checkManyRead(FlatCall fc, Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr) {
+  private void generateKILLSetForFlatCall(FlatCall fc,
+      Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, SharedLocMap sharedLocMap,
+      SharedLocMap mustClearMap, Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet) {
 
-    Set<NTuple<Descriptor>> boundReadSet = mapFlatNodeToBoundReadSet.get(fc);
+    Set<NTuple<Descriptor>> boundMustWriteSet = mapFlatNodeToBoundMustWriteSet.get(fc);
+
+    for (Iterator iterator = boundMustWriteSet.iterator(); iterator.hasNext();) {
+      NTuple<Descriptor> heapPath = (NTuple<Descriptor>) iterator.next();
+
+      if (isSharedLocation(heapPath)) {
+        NTuple<Location> locTuple = getLocationTuple(heapPath);
+
+        if (isCovered(locTuple, sharedLocMap.get(locTuple), mustClearMap.get(locTuple))
+            && curr.containsKey(heapPath)) {
+          // if it is shared loc and corresponding shared loc has been covered
+          KILLSet.put(heapPath, curr.get(heapPath));
+        }
+      } else {
+
+        for (Enumeration<NTuple<Descriptor>> e = curr.keys(); e.hasMoreElements();) {
+          NTuple<Descriptor> key = e.nextElement();
+          if (key.startsWith(heapPath)) {
+            KILLSet.put(key, curr.get(key));
+          }
+        }
+
+      }
 
-    for (Iterator iterator = boundReadSet.iterator(); iterator.hasNext();) {
-      NTuple<Descriptor> readHeapPath = (NTuple<Descriptor>) iterator.next();
-      Set<WriteAge> writeAgeSet = curr.get(readHeapPath);
-      checkWriteAgeSet(writeAgeSet, readHeapPath, fc);
     }
 
   }
 
-  private void checkWriteAgeSet(Set<WriteAge> writeAgeSet, NTuple<Descriptor> path, FlatNode fn) {
-    if (writeAgeSet != null) {
-      for (Iterator iterator = writeAgeSet.iterator(); iterator.hasNext();) {
-        WriteAge writeAge = (WriteAge) iterator.next();
-        if (writeAge.getAge() >= MAXAGE) {
-          throw new Error(
-              "Memory location, which is reachable through references "
-                  + path
-                  + ", who comes back to the same read statement without being overwritten at the out-most iteration at "
-                  + methodContainingSSJavaLoop.getClassDesc().getSourceFileName() + "::"
-                  + fn.getNumLine());
-        }
+  private int getArrayBaseDescriptorIdx(NTuple<Descriptor> heapPath) {
+
+    for (int i = heapPath.size() - 1; i >= 0; i--) {
+      if (!heapPath.get(i).getSymbol().equals(arrayElementFieldName)) {
+        return i;
       }
     }
+
+    return -1;
+
   }
 
-  private void generateGENSetForFlatCall(FlatCall fc,
-      Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
+  private boolean isSharedLocation(NTuple<Descriptor> heapPath) {
 
-    Set<NTuple<Descriptor>> boundMayWriteSet = mapFlatNodeToBoundMayWriteSet.get(fc);
+    Descriptor d = heapPath.get(getArrayBaseDescriptorIdx(heapPath));
 
-    for (Iterator iterator = boundMayWriteSet.iterator(); iterator.hasNext();) {
-      NTuple<Descriptor> key = (NTuple<Descriptor>) iterator.next();
-      // TODO: shared location
-      Set<WriteAge> set = new HashSet<WriteAge>();
-      set.add(new WriteAge(0));
-      GENSet.put(key, set);
-    }
+    return ssjava.isSharedLocation(getLocation(heapPath.get(getArrayBaseDescriptorIdx(heapPath))));
 
   }
 
-  private void generateKILLSetForFlatCall(FlatCall fc,
-      Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
-      Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet) {
+  private NTuple<Location> getLocationTuple(NTuple<Descriptor> heapPath) {
 
-    Set<NTuple<Descriptor>> boundMustWriteSet = mapFlatNodeToBoundMustWriteSet.get(fc);
+    NTuple<Location> locTuple = new NTuple<Location>();
 
-    for (Iterator iterator = boundMustWriteSet.iterator(); iterator.hasNext();) {
-      NTuple<Descriptor> key = (NTuple<Descriptor>) iterator.next();
-      // TODO: shared location
-      if (curr.get(key) != null) {
-        KILLSet.put(key, curr.get(key));
-      }
+    locTuple.addAll(mapDescriptorToLocationPath.get(heapPath.get(0)));
+
+    for (int i = 1; i <= getArrayBaseDescriptorIdx(heapPath); i++) {
+      locTuple.add(getLocation(heapPath.get(i)));
     }
 
+    return locTuple;
   }
 
   private void computeNewMapping(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
@@ -1918,22 +1765,6 @@ public class DefinitelyWrittenCheck {
 
   }
 
-  private void readValue(FlatNode fn, NTuple<Descriptor> hp,
-      Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>> curr) {
-    Hashtable<FlatNode, Boolean> gen = curr.get(hp);
-    if (gen == null) {
-      gen = new Hashtable<FlatNode, Boolean>();
-      curr.put(hp, gen);
-    }
-    Boolean currentStatus = gen.get(fn);
-    if (currentStatus == null) {
-      gen.put(fn, Boolean.FALSE);
-    } else {
-      checkFlag(currentStatus.booleanValue(), fn, hp);
-    }
-
-  }
-
   private void computeKILLSetForWrite(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
       NTuple<Descriptor> hp, Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet) {
 
@@ -1978,13 +1809,10 @@ public class DefinitelyWrittenCheck {
       // arg idx is starting from 'this' arg
       if (fc.getThis() != null) {
         NTuple<Descriptor> thisHeapPath = mapHeapPath.get(fc.getThis());
-        if (thisHeapPath == null) {
-          // method is called without creating new flat node representing 'this'
-          thisHeapPath = new NTuple<Descriptor>();
-          thisHeapPath.add(fc.getThis());
+        if (thisHeapPath != null) {
+          // if 'this' does not have heap path, it is local reference
+          mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
         }
-
-        mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
       }
 
       for (int i = 0; i < fc.numArgs(); i++) {
@@ -2061,92 +1889,142 @@ public class DefinitelyWrittenCheck {
     calleeIntersectBoundSharedSet.clear();
     calleeUnionBoundDeleteSet.clear();
 
-    // if arg is not primitive type, we need to propagate maywritten set to
-    // the caller's location path
+    if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
+      // ssjava util case!
+      // have write effects on the first argument
+      TempDescriptor arg = fc.getArg(0);
+      NTuple<Descriptor> argHeapPath = computePath(arg);
 
-    MethodDescriptor mdCallee = fc.getMethod();
-    Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
-    setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
+      // convert heap path to location path
+      NTuple<Location> argLocTuple = new NTuple<Location>();
+      argLocTuple.addAll(deriveLocationTuple(mdCaller, (TempDescriptor) argHeapPath.get(0)));
+      for (int i = 1; i < argHeapPath.size(); i++) {
+        argLocTuple.add(getLocation(argHeapPath.get(i)));
+      }
 
-    // create mapping from arg idx to its heap paths
-    Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
-        new Hashtable<Integer, NTuple<Descriptor>>();
+      calleeIntersectBoundSharedSet.addWrite(argLocTuple, argHeapPath);
 
-    // arg idx is starting from 'this' arg
-    if (fc.getThis() != null) {
-      NTuple<Descriptor> thisHeapPath = mapHeapPath.get(fc.getThis());
-      if (thisHeapPath == null) {
-        // method is called without creating new flat node representing 'this'
-        thisHeapPath = new NTuple<Descriptor>();
-        thisHeapPath.add(fc.getThis());
-      }
+    } else if (ssjava.needTobeAnnotated(fc.getMethod())) {
 
-      mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
-    }
+      // if arg is not primitive type, we need to propagate maywritten set to
+      // the caller's location path
 
-    for (int i = 0; i < fc.numArgs(); i++) {
-      TempDescriptor arg = fc.getArg(i);
-      NTuple<Descriptor> argHeapPath = computePath(arg);
-      mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
-    }
+      MethodDescriptor mdCallee = fc.getMethod();
+      Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
+      setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
 
-    // create mapping from arg idx to its location paths
-    Hashtable<Integer, NTuple<Location>> mapArgIdx2CallerAgLocationPath =
-        new Hashtable<Integer, NTuple<Location>>();
+      // create mapping from arg idx to its heap paths
+      Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
+          new Hashtable<Integer, NTuple<Descriptor>>();
 
-    // arg idx is starting from 'this' arg
-    if (fc.getThis() != null) {
-      NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
-      mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath);
-    }
+      // arg idx is starting from 'this' arg
+      if (fc.getThis() != null) {
+        NTuple<Descriptor> thisHeapPath = mapHeapPath.get(fc.getThis());
+        if (thisHeapPath == null) {
+          // method is called without creating new flat node representing 'this'
+          thisHeapPath = new NTuple<Descriptor>();
+          thisHeapPath.add(fc.getThis());
+        }
 
-    for (int i = 0; i < fc.numArgs(); i++) {
-      TempDescriptor arg = fc.getArg(i);
-      NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
-      mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(i + 1), argLocationPath);
-    }
+        mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
+      }
 
-    for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
-      MethodDescriptor callee = (MethodDescriptor) iterator.next();
-      FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
+      for (int i = 0; i < fc.numArgs(); i++) {
+        TempDescriptor arg = fc.getArg(i);
+        NTuple<Descriptor> argHeapPath = computePath(arg);
+        mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
+      }
 
-      // binding caller's args and callee's params
+      // create mapping from arg idx to its location paths
+      Hashtable<Integer, NTuple<Location>> mapArgIdx2CallerAgLocationPath =
+          new Hashtable<Integer, NTuple<Location>>();
 
-      Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
-          new Hashtable<Integer, TempDescriptor>();
-      int offset = 0;
-      if (calleeFlatMethod.getMethod().isStatic()) {
-        // static method does not have implicit 'this' arg
-        offset = 1;
+      // arg idx is starting from 'this' arg
+      if (fc.getThis() != null) {
+        NTuple<Location> thisLocationPath = deriveLocationTuple(fc.getMethod(), fc.getThis());
+        if (thisLocationPath != null) {
+          mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath);
+        }
       }
-      for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
-        TempDescriptor param = calleeFlatMethod.getParameter(i);
-        mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
+
+      for (int i = 0; i < fc.numArgs(); i++) {
+        TempDescriptor arg = fc.getArg(i);
+        NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
+        if (argLocationPath != null) {
+          mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(i + 1), argLocationPath);
+        }
       }
 
-      Set<Integer> keySet = mapArgIdx2CallerAgLocationPath.keySet();
-      for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
-        Integer idx = (Integer) iterator2.next();
-        NTuple<Location> callerArgLocationPath = mapArgIdx2CallerAgLocationPath.get(idx);
-        NTuple<Descriptor> callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx);
+      for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
+        MethodDescriptor callee = (MethodDescriptor) iterator.next();
+        FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
 
-        TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
-        NTuple<Location> calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam);
-        SharedLocMap calleeDeleteSet = mapFlatMethodToDeleteSet.get(calleeFlatMethod);
-        SharedLocMap calleeSharedLocMap = mapFlatMethodToSharedLocMap.get(calleeFlatMethod);
+        // binding caller's args and callee's params
 
-        if (calleeDeleteSet != null) {
-          createNewMappingOfDeleteSet(callerArgLocationPath, callerArgHeapPath, calleeLocationPath,
-              calleeDeleteSet);
+        Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
+            new Hashtable<Integer, TempDescriptor>();
+        int offset = 0;
+        if (calleeFlatMethod.getMethod().isStatic()) {
+          // static method does not have implicit 'this' arg
+          offset = 1;
+        }
+        for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
+          TempDescriptor param = calleeFlatMethod.getParameter(i);
+          mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
         }
 
-        if (calleeSharedLocMap != null) {
-          createNewMappingOfSharedSet(callerArgLocationPath, callerArgHeapPath, calleeLocationPath,
-              calleeSharedLocMap);
+        Set<Integer> keySet = mapArgIdx2CallerAgLocationPath.keySet();
+        for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
+          Integer idx = (Integer) iterator2.next();
+          NTuple<Location> callerArgLocationPath = mapArgIdx2CallerAgLocationPath.get(idx);
+          NTuple<Descriptor> callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx);
+
+          TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
+          NTuple<Location> calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam);
+          SharedLocMap calleeDeleteSet = mapFlatMethodToDeleteSet.get(calleeFlatMethod);
+          SharedLocMap calleeSharedLocMap = mapFlatMethodToSharedLocMap.get(calleeFlatMethod);
+          SharedLocMap calleeMustClearMap = mapFlatMethodToMustClearMap.get(calleeFlatMethod);
+
+          if (calleeDeleteSet != null) {
+            createNewMappingOfDeleteSet(callerArgLocationPath, callerArgHeapPath,
+                calleeLocationPath, calleeDeleteSet);
+          }
+
+          if (calleeSharedLocMap != null) {
+            createNewMappingOfSharedSet(callerArgLocationPath, callerArgHeapPath,
+                calleeLocationPath, calleeSharedLocMap);
+          }
+
+          if (calleeMustClearMap != null) {
+            createNewMappingOfMustClearMap(callerArgLocationPath, callerArgHeapPath,
+                calleeLocationPath, calleeMustClearMap);
+          }
+
         }
 
       }
+    }
+
+  }
+
+  private void createNewMappingOfMustClearMap(NTuple<Location> callerArgLocationPath,
+      NTuple<Descriptor> callerArgHeapPath, NTuple<Location> calleeLocationPath,
+      SharedLocMap calleeMustClearMap) {
+
+    SharedLocMap calleeParamSharedSet =
+        calleeMustClearMap.getHeapPathStartedWith(calleeLocationPath);
 
+    Set<NTuple<Location>> keySet = calleeParamSharedSet.keySet();
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      NTuple<Location> calleeLocTupleKey = (NTuple<Location>) iterator.next();
+      Set<NTuple<Descriptor>> heapPathSet = calleeParamSharedSet.get(calleeLocTupleKey);
+      Set<NTuple<Descriptor>> boundHeapPathSet = new HashSet<NTuple<Descriptor>>();
+      for (Iterator iterator2 = heapPathSet.iterator(); iterator2.hasNext();) {
+        NTuple<Descriptor> calleeHeapPath = (NTuple<Descriptor>) iterator2.next();
+        boundHeapPathSet.add(bindHeapPath(callerArgHeapPath, calleeHeapPath));
+      }
+      calleeIntersectBoundMustClearSet.intersect(
+          bindLocationPath(callerArgLocationPath, calleeLocTupleKey), boundHeapPathSet);
     }
 
   }
@@ -2211,45 +2089,6 @@ public class DefinitelyWrittenCheck {
     return heapPath;
   }
 
-  private NTuple<Descriptor> bind(NTuple<Descriptor> calleeHeapPathKey,
-      Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc,
-      Hashtable<Integer, NTuple<Descriptor>> mapCallerArgIdx2HeapPath) {
-
-    Set<Integer> keySet = mapCallerArgIdx2HeapPath.keySet();
-    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
-      Integer idx = (Integer) iterator.next();
-      NTuple<Descriptor> callerArgHeapPath = mapCallerArgIdx2HeapPath.get(idx);
-      TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
-      if (calleeHeapPathKey.startsWith(calleeParam)) {
-        NTuple<Descriptor> boundElement = combine(callerArgHeapPath, calleeHeapPathKey);
-        return boundElement;
-      }
-    }
-    return null;
-  }
-
-  private void checkFlag(boolean booleanValue, FlatNode fn, NTuple<Descriptor> hp) {
-    if (booleanValue) {
-      // the definitely written analysis only takes care about locations that
-      // are written to inside of the SSJava loop
-      for (Iterator iterator = calleeUnionBoundMayWriteSet.iterator(); iterator.hasNext();) {
-        NTuple<Descriptor> write = (NTuple<Descriptor>) iterator.next();
-        if (hp.startsWith(write)) {
-          // it has write effect!
-          // throw new Error(
-          System.out
-              .println("###"
-                  + "There is a variable, which is reachable through references "
-                  + hp
-                  + ", who comes back to the same read statement without being overwritten at the out-most iteration at "
-                  + methodContainingSSJavaLoop.getClassDesc().getSourceFileName() + "::"
-                  + fn.getNumLine());
-          debugcount++;
-        }
-      }
-    }
-  }
-
   private void initialize() {
     // First, identify ssjava loop entrace
 
@@ -2270,7 +2109,7 @@ public class DefinitelyWrittenCheck {
       if (label != null) {
 
         if (label.equals(ssjava.SSJAVA)) {
-          ssjavaLoopEntrance = fn;
+          ssjava.setSSJavaLoopEntrance(fn);
           break;
         }
       }
@@ -2281,13 +2120,13 @@ public class DefinitelyWrittenCheck {
       }
     }
 
-    assert ssjavaLoopEntrance != null;
+    assert ssjava.getSSJavaLoopEntrance() != null;
 
     // assume that ssjava loop is top-level loop in method, not nested loop
     Set nestedLoop = loopFinder.nestedLoops();
     for (Iterator loopIter = nestedLoop.iterator(); loopIter.hasNext();) {
       LoopFinder lf = (LoopFinder) loopIter.next();
-      if (lf.loopEntrances().iterator().next().equals(ssjavaLoopEntrance)) {
+      if (lf.loopEntrances().iterator().next().equals(ssjava.getSSJavaLoopEntrance())) {
         ssjavaLoop = lf;
       }
     }
@@ -2298,15 +2137,19 @@ public class DefinitelyWrittenCheck {
 
     // perform topological sort over the set of methods accessed by the main
     // event loop
-    Set<MethodDescriptor> methodDescriptorsToAnalyze = new HashSet<MethodDescriptor>();
-    methodDescriptorsToAnalyze.addAll(ssjava.getAnnotationRequireSet());
-    sortedDescriptors = topologicalSort(methodDescriptorsToAnalyze);
+    // Set<MethodDescriptor> methodDescriptorsToAnalyze = new
+    // HashSet<MethodDescriptor>();
+    // methodDescriptorsToAnalyze.addAll(ssjava.getAnnotationRequireSet());
+    // sortedDescriptors = topologicalSort(methodDescriptorsToAnalyze);
+
+    liveInTempSetToEventLoop =
+        liveness.getLiveInTemps(state.getMethodFlat(methodContainingSSJavaLoop),
+            ssjava.getSSJavaLoopEntrance());
   }
 
   private void methodReadWriteSetAnalysis() {
     // perform method READ/OVERWRITE analysis
-    LinkedList<MethodDescriptor> descriptorListToAnalyze =
-        (LinkedList<MethodDescriptor>) sortedDescriptors.clone();
+    LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
 
     // current descriptors to visit in fixed-point interprocedural analysis,
     // prioritized by
@@ -2348,7 +2191,7 @@ public class DefinitelyWrittenCheck {
         // results for callee changed, so enqueue dependents caller for
         // further
         // analysis
-        Iterator<MethodDescriptor> depsItr = getDependents(md).iterator();
+        Iterator<MethodDescriptor> depsItr = ssjava.getDependents(md).iterator();
         while (depsItr.hasNext()) {
           MethodDescriptor methodNext = depsItr.next();
           if (!methodDescriptorsToVisitStack.contains(methodNext)
@@ -2395,7 +2238,15 @@ public class DefinitelyWrittenCheck {
     mapFlatMethodToMustWriteSet.put(flatMethodContainingSSJavaLoop, mustWriteSet);
     mapFlatMethodToMayWriteSet.put(flatMethodContainingSSJavaLoop, mayWriteSet);
 
-    methodReadWriteSet_analyzeBody(ssjavaLoopEntrance, readSet, mustWriteSet, mayWriteSet, true);
+    for (Iterator iterator = liveInTempSetToEventLoop.iterator(); iterator.hasNext();) {
+      TempDescriptor liveIn = (TempDescriptor) iterator.next();
+      NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
+      heapPath.add(liveIn);
+      mapHeapPath.put(liveIn, heapPath);
+    }
+
+    methodReadWriteSet_analyzeBody(ssjava.getSSJavaLoopEntrance(), readSet, mustWriteSet,
+        mayWriteSet, true);
 
   }
 
@@ -2468,17 +2319,30 @@ public class DefinitelyWrittenCheck {
       FlatOpNode fon = (FlatOpNode) fn;
       // for a normal assign node, need to propagate lhs's heap path to
       // rhs
+
       if (fon.getOp().getOp() == Operation.ASSIGN) {
         rhs = fon.getLeft();
         lhs = fon.getDest();
 
         NTuple<Descriptor> rhsHeapPath = mapHeapPath.get(rhs);
-        if (rhsHeapPath != null) {
+
+        // if (lhs.getType().isPrimitive()) {
+        // NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
+        // lhsHeapPath.add(lhs);
+        // mapHeapPath.put(lhs, lhsHeapPath);
+        // } else
+
+        if (rhsHeapPath != null && (!lhs.getType().isPrimitive())) {
           mapHeapPath.put(lhs, mapHeapPath.get(rhs));
         } else {
-          NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
-          heapPath.add(rhs);
-          mapHeapPath.put(lhs, heapPath);
+          break;
+          // if (isEventLoopBody) {
+          // NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
+          // lhsHeapPath.add(rhs);
+          // mapHeapPath.put(lhs, lhsHeapPath);
+          // } else {
+          // break;
+          // }
         }
 
         // shared loc extension
@@ -2502,27 +2366,6 @@ public class DefinitelyWrittenCheck {
               writeHeapPath.addAll(heapPath);
               writeHeapPath.add(lhs);
 
-              System.out.println("VAR WRITE:" + fn);
-              System.out.println("LHS TYPE EXTENSION=" + lhs.getType().getExtension());
-              System.out.println("RHS TYPE EXTENSION=" + rhs.getType().getExtension()
-                  + " HEAPPATH=" + rhsHeapPath);
-
-              // TODO
-              // computing gen/kill set
-              // computeKILLSetForWrite(currSharedLocMapping, heapPath, dstLoc,
-              // killSetSharedLoc);
-              // if (!dstLoc.equals(rhsLoc)) {
-              // computeGENSetForHigherWrite(currSharedLocMapping, heapPath,
-              // dstLoc, lhs,
-              // genSetSharedLoc);
-              // deleteSet.remove(writeHeapPath);
-              // } else {
-              // computeGENSetForSharedWrite(currSharedLocMapping, heapPath,
-              // dstLoc, lhs,
-              // genSetSharedLoc);
-              // deleteSet.add(writeHeapPath);
-              // }
-
             }
           }
         }
@@ -2561,7 +2404,10 @@ public class DefinitelyWrittenCheck {
         // callee's parameters. so just ignore it
 
         NTuple<Descriptor> readingHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
-        readingHeapPath.add(fld);
+        if (fn.kind() == FKind.FlatFieldNode) {
+          readingHeapPath.add(fld);
+        }
+
         mapHeapPath.put(lhs, readingHeapPath);
 
         // read (x.f)
@@ -2603,12 +2449,16 @@ public class DefinitelyWrittenCheck {
         // if lhs heap path is null, it means that it is not reachable from
         // callee's parameters. so just ignore it
         NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
-        fldHeapPath.add(fld);
-        mapHeapPath.put(fld, fldHeapPath);
+        if (fn.kind() != FKind.FlatSetElementNode) {
+          fldHeapPath.add(fld);
+        }
+        // mapHeapPath.put(fld, fldHeapPath);
 
         // write(x.f)
         // need to add hp(y) to WT
-        currMustWriteSet.add(fldHeapPath);
+        if (fn.kind() != FKind.FlatSetElementNode) {
+          currMustWriteSet.add(fldHeapPath);
+        }
         mayWriteSet.add(fldHeapPath);
 
       }
@@ -2622,9 +2472,18 @@ public class DefinitelyWrittenCheck {
 
       bindHeapPathCallerArgWithCalleeParam(fc);
 
-      mapFlatNodeToBoundReadSet.put(fn, calleeUnionBoundReadSet);
-      mapFlatNodeToBoundMustWriteSet.put(fn, calleeIntersectBoundMustWriteSet);
-      mapFlatNodeToBoundMayWriteSet.put(fn, calleeUnionBoundMayWriteSet);
+      Set<NTuple<Descriptor>> boundReadSet = new HashSet<NTuple<Descriptor>>();
+      boundReadSet.addAll(calleeUnionBoundReadSet);
+
+      Set<NTuple<Descriptor>> boundMustWriteSet = new HashSet<NTuple<Descriptor>>();
+      boundMustWriteSet.addAll(calleeIntersectBoundMustWriteSet);
+
+      Set<NTuple<Descriptor>> boundMayWriteSet = new HashSet<NTuple<Descriptor>>();
+      boundMayWriteSet.addAll(calleeUnionBoundMayWriteSet);
+
+      mapFlatNodeToBoundReadSet.put(fn, boundReadSet);
+      mapFlatNodeToBoundMustWriteSet.put(fn, boundMustWriteSet);
+      mapFlatNodeToBoundMayWriteSet.put(fn, boundMayWriteSet);
 
       // add heap path, which is an element of READ_bound set and is not
       // an
@@ -2663,14 +2522,6 @@ public class DefinitelyWrittenCheck {
 
   }
 
-  public NTuple<Descriptor> getPrefix(NTuple<Descriptor> in) {
-    return in.subList(0, in.size() - 1);
-  }
-
-  public NTuple<Descriptor> getSuffix(NTuple<Descriptor> in) {
-    return in.subList(in.size() - 1, in.size());
-  }
-
   static public FieldDescriptor getArrayField(TypeDescriptor td) {
     FieldDescriptor fd = mapTypeToArrayField.get(td);
     if (fd == null) {
@@ -2682,72 +2533,6 @@ public class DefinitelyWrittenCheck {
     return fd;
   }
 
-  private void mergeSharedLocationAnaylsis(ClearingSummary curr, Set<ClearingSummary> inSet) {
-    if (inSet.size() == 0) {
-      return;
-    }
-    Hashtable<Pair<NTuple<Descriptor>, Location>, Boolean> mapHeapPathLoc2Flag =
-        new Hashtable<Pair<NTuple<Descriptor>, Location>, Boolean>();
-
-    for (Iterator inIterator = inSet.iterator(); inIterator.hasNext();) {
-
-      ClearingSummary inTable = (ClearingSummary) inIterator.next();
-
-      Set<NTuple<Descriptor>> keySet = inTable.keySet();
-
-      for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
-        NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
-        SharedStatus inState = inTable.get(hpKey);
-        SharedStatus currState = curr.get(hpKey);
-        if (currState == null) {
-          currState = new SharedStatus();
-          curr.put(hpKey, currState);
-        }
-
-        currState.merge(inState);
-
-        Set<Location> locSet = inState.getMap().keySet();
-        for (Iterator iterator2 = locSet.iterator(); iterator2.hasNext();) {
-          Location loc = (Location) iterator2.next();
-          Pair<Set<Descriptor>, Boolean> pair = inState.getMap().get(loc);
-          boolean inFlag = pair.getSecond().booleanValue();
-
-          Pair<NTuple<Descriptor>, Location> flagKey =
-              new Pair<NTuple<Descriptor>, Location>(hpKey, loc);
-          Boolean current = mapHeapPathLoc2Flag.get(flagKey);
-          if (current == null) {
-            current = new Boolean(true);
-          }
-          boolean newInFlag = current.booleanValue() & inFlag;
-          mapHeapPathLoc2Flag.put(flagKey, Boolean.valueOf(newInFlag));
-        }
-
-      }
-
-    }
-
-    // merge flag status
-    Set<NTuple<Descriptor>> hpKeySet = curr.keySet();
-    for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) {
-      NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
-      SharedStatus currState = curr.get(hpKey);
-      Set<Location> locKeySet = currState.getMap().keySet();
-      for (Iterator iterator2 = locKeySet.iterator(); iterator2.hasNext();) {
-        Location locKey = (Location) iterator2.next();
-        Pair<Set<Descriptor>, Boolean> pair = currState.getMap().get(locKey);
-        boolean currentFlag = pair.getSecond().booleanValue();
-        Boolean inFlag = mapHeapPathLoc2Flag.get(new Pair(hpKey, locKey));
-        if (inFlag != null) {
-          boolean newFlag = currentFlag | inFlag.booleanValue();
-          if (currentFlag != newFlag) {
-            currState.getMap().put(locKey, new Pair(pair.getFirst(), new Boolean(newFlag)));
-          }
-        }
-      }
-    }
-
-  }
-
   private void merge(Set<NTuple<Descriptor>> curr, Set<NTuple<Descriptor>> in) {
     if (curr.isEmpty()) {
       // set has a special initial value which covers all possible
@@ -2805,87 +2590,17 @@ public class DefinitelyWrittenCheck {
 
   }
 
-  // Borrowed it from disjoint analysis
-  private LinkedList<MethodDescriptor> topologicalSort(Set<MethodDescriptor> toSort) {
-
-    Set<MethodDescriptor> discovered = new HashSet<MethodDescriptor>();
-
-    LinkedList<MethodDescriptor> sorted = new LinkedList<MethodDescriptor>();
-
-    Iterator<MethodDescriptor> itr = toSort.iterator();
-    while (itr.hasNext()) {
-      MethodDescriptor d = itr.next();
-
-      if (!discovered.contains(d)) {
-        dfsVisit(d, toSort, sorted, discovered);
-      }
-    }
-
-    return sorted;
-  }
-
-  // While we're doing DFS on call graph, remember
-  // dependencies for efficient queuing of methods
-  // during interprocedural analysis:
-  //
-  // a dependent of a method decriptor d for this analysis is:
-  // 1) a method or task that invokes d
-  // 2) in the descriptorsToAnalyze set
-  private void dfsVisit(MethodDescriptor md, Set<MethodDescriptor> toSort,
-      LinkedList<MethodDescriptor> sorted, Set<MethodDescriptor> discovered) {
-
-    discovered.add(md);
-
-    Iterator itr = callGraph.getCallerSet(md).iterator();
-    while (itr.hasNext()) {
-      MethodDescriptor dCaller = (MethodDescriptor) itr.next();
-      // only consider callers in the original set to analyze
-      if (!toSort.contains(dCaller)) {
-        continue;
-      }
-      if (!discovered.contains(dCaller)) {
-        addDependent(md, // callee
-            dCaller // caller
-        );
-
-        dfsVisit(dCaller, toSort, sorted, discovered);
-      }
-    }
-
-    // for leaf-nodes last now!
-    sorted.addLast(md);
-  }
-
-  // a dependent of a method decriptor d for this analysis is:
-  // 1) a method or task that invokes d
-  // 2) in the descriptorsToAnalyze set
-  private void addDependent(MethodDescriptor callee, MethodDescriptor caller) {
-    Set<MethodDescriptor> deps = mapDescriptorToSetDependents.get(callee);
-    if (deps == null) {
-      deps = new HashSet<MethodDescriptor>();
-    }
-    deps.add(caller);
-    mapDescriptorToSetDependents.put(callee, deps);
-  }
-
-  private Set<MethodDescriptor> getDependents(MethodDescriptor callee) {
-    Set<MethodDescriptor> deps = mapDescriptorToSetDependents.get(callee);
-    if (deps == null) {
-      deps = new HashSet<MethodDescriptor>();
-      mapDescriptorToSetDependents.put(callee, deps);
-    }
-    return deps;
-  }
-
   private NTuple<Descriptor> computePath(Descriptor td) {
     // generate proper path fot input td
     // if td is local variable, it just generate one element tuple path
     if (mapHeapPath.containsKey(td)) {
-      return mapHeapPath.get(td);
+      NTuple<Descriptor> rtrHeapPath = new NTuple<Descriptor>();
+      rtrHeapPath.addAll(mapHeapPath.get(td));
+      return rtrHeapPath;
     } else {
-      NTuple<Descriptor> path = new NTuple<Descriptor>();
-      path.add(td);
-      return path;
+      NTuple<Descriptor> rtrHeapPath = new NTuple<Descriptor>();
+      rtrHeapPath.add(td);
+      return rtrHeapPath;
     }
   }
 
@@ -2897,22 +2612,42 @@ public class DefinitelyWrittenCheck {
     return locTuple;
   }
 
-  private NTuple<Location> deriveLocationTuple(MethodDescriptor md, TempDescriptor td) {
+  private NTuple<Location> deriveGlobalLocationTuple(MethodDescriptor md) {
+    String globalLocIdentifier = ssjava.getMethodLattice(md).getGlobalLoc();
+    Location globalLoc = new Location(md, globalLocIdentifier);
+    NTuple<Location> locTuple = new NTuple<Location>();
+    locTuple.add(globalLoc);
+    return locTuple;
+  }
 
+  private NTuple<Location> deriveLocationTuple(MethodDescriptor md, TempDescriptor td) {
     assert td.getType() != null;
 
     if (mapDescriptorToLocationPath.containsKey(td)) {
-      return mapDescriptorToLocationPath.get(td);
+      NTuple<Location> locPath = mapDescriptorToLocationPath.get(td);
+      NTuple<Location> rtrPath = new NTuple<Location>();
+      rtrPath.addAll(locPath);
+      return rtrPath;
     } else {
       if (td.getSymbol().startsWith("this")) {
-        return deriveThisLocationTuple(md);
+        NTuple<Location> thisPath = deriveThisLocationTuple(md);
+        NTuple<Location> rtrPath = new NTuple<Location>();
+        rtrPath.addAll(thisPath);
+        return rtrPath;
       } else {
-        NTuple<Location> locTuple =
-            ((SSJavaType) td.getType().getExtension()).getCompLoc().getTuple();
-        return locTuple;
+
+        if (td.getType().getExtension() != null) {
+          SSJavaType ssJavaType = (SSJavaType) td.getType().getExtension();
+          if (ssJavaType.getCompLoc() != null) {
+            NTuple<Location> rtrPath = new NTuple<Location>();
+            rtrPath.addAll(ssJavaType.getCompLoc().getTuple());
+            return rtrPath;
+          }
+        }
+
+        return null;
+
       }
     }
-
   }
-
 }
\ No newline at end of file