fixes
[IRC.git] / Robust / src / Analysis / SSJava / DefinitelyWrittenCheck.java
index 237cacd41ab7ad90665acca1826f66f500e7a94f..594952b90a16a863abea016ee1bd1b0631367694 100644 (file)
@@ -57,7 +57,7 @@ public class DefinitelyWrittenCheck {
   private Hashtable<Descriptor, NTuple<Descriptor>> mapHeapPath;
 
   // maps a temp descriptor to its composite location
-  private Hashtable<Descriptor, NTuple<Location>> mapDescriptorToLocationPath;
+  private Hashtable<TempDescriptor, NTuple<Location>> mapDescriptorToLocationPath;
 
   // maps a flat method to the READ that is the set of heap path that is
   // expected to be written before method invocation
@@ -95,18 +95,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,16 +109,12 @@ 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;
@@ -146,8 +130,8 @@ public class DefinitelyWrittenCheck {
   private Set<NTuple<Descriptor>> calleeUnionBoundReadSet;
   private Set<NTuple<Descriptor>> calleeIntersectBoundMustWriteSet;
   private Set<NTuple<Descriptor>> calleeUnionBoundMayWriteSet;
-  private Set<NTuple<Descriptor>> calleeUnionBoundDeleteSet;
-  private Hashtable<NTuple<Location>, Set<Descriptor>> calleeIntersectBoundSharedSet;
+  private SharedLocMap calleeUnionBoundDeleteSet;
+  private SharedLocMap calleeIntersectBoundSharedSet;
 
   private Hashtable<Descriptor, Location> mapDescToLocation;
 
@@ -162,7 +146,7 @@ public class DefinitelyWrittenCheck {
     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<Descriptor, NTuple<Location>>();
+    this.mapDescriptorToLocationPath = new Hashtable<TempDescriptor, NTuple<Location>>();
     this.mapFlatMethodToReadSet = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
     this.mapFlatMethodToMustWriteSet = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
     this.mapFlatMethodToMayWriteSet = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
@@ -172,13 +156,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>();
@@ -190,35 +169,25 @@ public class DefinitelyWrittenCheck {
     this.mapSharedLocationToCoverSet = new Hashtable<Location, Set<Descriptor>>();
     this.mapFlatNodeToSharedLocMapping = new Hashtable<FlatNode, SharedLocMap>();
     this.mapFlatMethodToDeleteSet = new Hashtable<FlatMethod, SharedLocMap>();
-    this.calleeUnionBoundDeleteSet = new HashSet<NTuple<Descriptor>>();
-    this.calleeIntersectBoundSharedSet = new Hashtable<NTuple<Location>, Set<Descriptor>>();
+    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>();
   }
 
   public void definitelyWrittenCheck() {
     if (!ssjava.getAnnotationRequireSet().isEmpty()) {
       initialize();
-      computeSharedCoverSet();
-
-      System.out.println("#");
-      System.out.println(mapLocationPathToMayWrittenSet);
 
       methodReadWriteSetAnalysis();
+      computeSharedCoverSet();
+
       sharedLocAnalysis();
 
-      // eventLoopAnalysis();
+      eventLoopAnalysis();
 
-      // XXXXXXX
-      // methodReadWriteSetAnalysis();
-      // methodReadWriteSetAnalysisToEventLoopBody();
-      // eventLoopAnalysis();
-      // XXXXXXX
-      // sharedLocationAnalysis();
-      // checkSharedLocationResult();
     }
   }
 
@@ -289,6 +258,7 @@ public class DefinitelyWrittenCheck {
     SharedLocMap deleteSet = new SharedLocMap();
     sharedLoc_analyzeBody(state.getMethodFlat(methodContainingSSJavaLoop), ssjavaLoopEntrance,
         sharedLocMap, deleteSet, true);
+
   }
 
   private void sharedLoc_analyzeMethod(FlatMethod fm, SharedLocMap sharedLocMap,
@@ -376,33 +346,32 @@ public class DefinitelyWrittenCheck {
 
             Location dstLoc = getLocation(lhs);
             if (dstLoc != null && ssjava.isSharedLocation(dstLoc)) {
-              System.out.println("FlatOpNode=" + fon);
-            }
+              NTuple<Descriptor> lhsHeapPath = computePath(lhs);
+              NTuple<Location> lhsLocTuple = mapDescriptorToLocationPath.get(lhs);
 
-            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);
+              }
 
-            System.out.println("VAR WRITE:" + fn);
-            System.out.println("lhsLocTuple=" + lhsLocTuple + " lhsHeapPath=" + lhsHeapPath);
-            System.out.println("dstLoc=" + dstLoc + " srcLoc=" + srcLoc);
+              // 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);
 
-            // computing gen/kill set
-            computeKILLSetForWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
-            if (!dstLoc.equals(srcLoc)) {
-              System.out.println("LOC IS DIFFERENT");
-              computeGENSetForHigherWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
-              updateDeleteSetForHigherWrite(currDeleteSet, lhsLocTuple, lhsHeapPath);
-            } else {
-              computeGENSetForSameHeightWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
-              updateDeleteSetForSameHeightWrite(currDeleteSet, lhsLocTuple, lhsHeapPath);
             }
 
-            System.out.println("KILLSET=" + killSet);
-            System.out.println("GENSet=" + genSet);
-            System.out.println("DELETESET=" + currDeleteSet);
-
           }
         }
 
@@ -414,47 +383,54 @@ public class DefinitelyWrittenCheck {
     case FKind.FlatSetFieldNode:
     case FKind.FlatSetElementNode: {
 
+      Location fieldLoc;
       if (fn.kind() == FKind.FlatSetFieldNode) {
         FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
         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);
+
+        NTuple<Location> locTuple = mapDescriptorToLocationPath.get(lhs);
+        fieldLoc = locTuple.get(locTuple.size() - 1);
       }
 
       // 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 = mapDescriptorToLocationPath.get(fld);
+        NTuple<Location> fieldLocTuple = new NTuple<Location>();
+        fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs));
+        fieldLocTuple.add(fieldLoc);
+
         NTuple<Descriptor> fldHeapPath = computePath(fld);
 
         // computing gen/kill set
         computeKILLSetForWrite(curr, killSet, fieldLocTuple, fldHeapPath);
         if (!fieldLoc.equals(srcLoc)) {
-          System.out.println("LOC IS DIFFERENT");
-          computeGENSetForHigherWrite(curr, killSet, fieldLocTuple, fldHeapPath);
+          computeGENSetForHigherWrite(curr, genSet, fieldLocTuple, fldHeapPath);
           updateDeleteSetForHigherWrite(currDeleteSet, fieldLocTuple, fldHeapPath);
         } else {
-          computeGENSetForSameHeightWrite(curr, killSet, fieldLocTuple, fldHeapPath);
+          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);
+        // 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);
       }
 
     }
@@ -463,34 +439,20 @@ public class DefinitelyWrittenCheck {
     case FKind.FlatCall: {
       FlatCall fc = (FlatCall) fn;
 
-      bindHeapPathCallerArgWithCaleeParamForSharedLoc(fc);
-
-      // generateKILLSetForFlatCall(fc, curr, readWriteKillSet);
-      // generateGENSetForFlatCall(fc, readWriteGenSet);
-
-      // System.out.println
-      // // only care the case that loc(f) is shared location
-      // // write(field)
-      // NTuple<Descriptor> lhsHeapPath = computePath(lhs);
-      // NTuple<Descriptor> fldHeapPath = new
-      // NTuple<Descriptor>(lhsHeapPath.getList());
-      // fldHeapPath.add(fld);
-      //
-      // // computing gen/kill set
-      // computeKILLSetForWrite(curr, lhsHeapPath, fieldLoc, killSet);
-      // if (!fieldLoc.equals(srcLoc)) {
-      // System.out.println("LOC IS DIFFERENT");
-      // computeGENSetForHigherWrite(curr, lhsHeapPath, fieldLoc, fld, genSet);
-      // deleteSet.remove(fldHeapPath);
-      // } else {
-      // computeGENSetForSharedWrite(curr, lhsHeapPath, fieldLoc, fld, genSet);
-      // deleteSet.add(fldHeapPath);
-      // }
-      // ("FLATCALL:" + fn);
+      if (ssjava.needTobeAnnotated(fc.getMethod())) {
+
+        bindHeapPathCallerArgWithCaleeParamForSharedLoc(fm.getMethod(), fc);
+
+        // computing gen/kill set
+        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);
-      // // System.out.println("KILLSET=" + KILLSet);
-      // // System.out.println("GENSet=" + GENSet);
-      //
+
     }
       break;
 
@@ -499,12 +461,37 @@ public class DefinitelyWrittenCheck {
       mergeSharedLocMap(sharedLocMap, curr);
       mergeDeleteSet(deleteSet, currDeleteSet);
 
+      // System.out.println("#FLATEXIT sharedLocMap=" + sharedLocMap);
     }
+      break;
 
     }
 
     computeNewMapping(curr, killSet, genSet);
-    System.out.println("#######" + curr);
+    // System.out.println("#######" + curr);
+
+  }
+
+  private void generateGENSetForFlatCall(SharedLocMap curr, SharedLocMap genSet) {
+
+    Set<NTuple<Location>> locTupleSet = calleeIntersectBoundSharedSet.keySet();
+    for (Iterator iterator = locTupleSet.iterator(); iterator.hasNext();) {
+      NTuple<Location> locTupleKey = (NTuple<Location>) iterator.next();
+      genSet.addWrite(locTupleKey, curr.get(locTupleKey));
+      genSet.addWrite(locTupleKey, calleeIntersectBoundSharedSet.get(locTupleKey));
+
+      genSet.removeWriteAll(locTupleKey, calleeUnionBoundDeleteSet.get(locTupleKey));
+    }
+
+  }
+
+  private void generateKILLSetForFlatCall(SharedLocMap curr, SharedLocMap killSet) {
+
+    Set<NTuple<Location>> locTupleSet = calleeIntersectBoundSharedSet.keySet();
+    for (Iterator iterator = locTupleSet.iterator(); iterator.hasNext();) {
+      NTuple<Location> locTupleKey = (NTuple<Location>) iterator.next();
+      killSet.addWrite(locTupleKey, curr.get(locTupleKey));
+    }
 
   }
 
@@ -585,555 +572,6 @@ 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();
-
-    // current descriptors to visit in fixed-point interprocedural analysis,
-    // prioritized by
-    // dependency in the call graph
-    methodDescriptorsToVisitStack.clear();
-
-    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();
-
-      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();
-
-      }
-
-    }
-
-  }
-
-  private ClearingSummary sharedLocation_analyzeMethod(MethodDescriptor md,
-      boolean onlyVisitSSJavaLoop) {
-
-    if (state.SSJAVADEBUG) {
-      System.out.println("SSJAVA: Definite clearance for shared locations Analyzing: " + md);
-    }
-
-    FlatMethod fm = state.getMethodFlat(md);
-
-    // intraprocedural analysis
-    Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
-
-    // start a new mapping of partial results for each flat node
-    mapFlatNodeToClearingSummary = new Hashtable<FlatNode, ClearingSummary>();
-
-    if (onlyVisitSSJavaLoop) {
-      flatNodesToVisit.add(ssjavaLoopEntrance);
-    } else {
-      flatNodesToVisit.add(fm);
-    }
-
-    Set<FlatNode> returnNodeSet = new HashSet<FlatNode>();
-
-    while (!flatNodesToVisit.isEmpty()) {
-      FlatNode fn = flatNodesToVisit.iterator().next();
-      flatNodesToVisit.remove(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);
-
-        for (int i = 0; i < fn.numNext(); i++) {
-          FlatNode nn = fn.getNext(i);
-
-          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) {
-
-    TempDescriptor lhs;
-    TempDescriptor rhs;
-    FieldDescriptor fld;
-    switch (fn.kind()) {
-
-    case FKind.FlatMethod: {
-      FlatMethod fm = (FlatMethod) fn;
-
-      ClearingSummary summaryFromCaller =
-          mapMethodDescriptorToInitialClearingSummary.get(fm.getMethod());
-
-      Set<ClearingSummary> inSet = new HashSet<ClearingSummary>();
-      if (summaryFromCaller != null) {
-        inSet.add(summaryFromCaller);
-        mergeSharedLocationAnaylsis(curr, inSet);
-      }
-
-    }
-      break;
-
-    case FKind.FlatOpNode: {
-      FlatOpNode fon = (FlatOpNode) fn;
-      lhs = fon.getDest();
-      rhs = fon.getLeft();
-
-      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);
-          }
-        }
-      }
-
-    }
-      break;
-
-    case FKind.FlatSetFieldNode:
-    case FKind.FlatSetElementNode: {
-
-      // 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);
-      }
-
-      // 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));
-        }
-
-      } else {
-        // updates reference field case:
-        fldHeapPath.add(fld);
-        updateWriteEffectOnReferenceField(curr, fldHeapPath);
-      }
-
-    }
-      break;
-
-    case FKind.FlatCall: {
-
-      FlatCall fc = (FlatCall) fn;
-
-      if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
-        // ssjava util case!
-        // have write effects on the first argument
-
-        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));
-
-          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;
-
-          writeLocation(md, curr, argHeapPath, loc, fld);
-        }
-
-      } 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));
-
-        possibleCalleeCompleteSummarySetToCaller.clear();
-
-        for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
-          MethodDescriptor mdPossibleCallee = (MethodDescriptor) iterator.next();
-          FlatMethod calleeFlatMethod = state.getMethodFlat(mdPossibleCallee);
-
-          addDependent(mdPossibleCallee, // callee
-              md); // caller
-
-          calleesToEnqueue.add(mdPossibleCallee);
-
-          // updates possible callee's initial summary using caller's current
-          // writing status
-          ClearingSummary prevCalleeInitSummary =
-              mapMethodDescriptorToInitialClearingSummary.get(mdPossibleCallee);
-
-          ClearingSummary calleeInitSummary =
-              bindHeapPathOfCalleeCallerEffects(fc, calleeFlatMethod, curr);
-
-          Set<ClearingSummary> inSet = new HashSet<ClearingSummary>();
-          if (prevCalleeInitSummary != null) {
-            inSet.add(prevCalleeInitSummary);
-            mergeSharedLocationAnaylsis(calleeInitSummary, inSet);
-          }
-
-          // if changes, update the init summary
-          // and reschedule the callee for analysis
-          if (!calleeInitSummary.equals(prevCalleeInitSummary)) {
-
-            if (!methodDescriptorsToVisitStack.contains(mdPossibleCallee)) {
-              methodDescriptorsToVisitStack.add(mdPossibleCallee);
-            }
-
-            mapMethodDescriptorToInitialClearingSummary.put(mdPossibleCallee, calleeInitSummary);
-          }
-
-        }
-
-        // contribute callee's writing effects to the caller
-        mergeSharedLocationAnaylsis(curr, possibleCalleeCompleteSummarySetToCaller);
-
-      }
-
-    }
-      break;
-
-    case FKind.FlatReturnNode: {
-      returnNodeSet.add(fn);
-    }
-      break;
-
-    }
-
-  }
-
-  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();
@@ -1214,6 +652,10 @@ public class DefinitelyWrittenCheck {
       FlatLiteralNode fln = (FlatLiteralNode) fn;
       lhs = fln.getDst();
 
+      NTuple<Location> lhsLocTuple = new NTuple<Location>();
+      lhsLocTuple.add(Location.createTopLocation(md));
+      mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
+
       if (lhs.getType().isPrimitive() && !lhs.getSymbol().startsWith("neverused")
           && !lhs.getSymbol().startsWith("srctmp")) {
         // only need to care about composite location case here
@@ -1238,24 +680,46 @@ public class DefinitelyWrittenCheck {
         rhs = fon.getLeft();
         lhs = fon.getDest();
 
+        if (mapDescriptorToLocationPath.containsKey(rhs)) {
+          mapDescriptorToLocationPath.put(lhs, mapDescriptorToLocationPath.get(rhs));
+        } else {
+          // lhs side
+          if (lhs.getType().getExtension() != null
+              && lhs.getType().getExtension() instanceof SSJavaType) {
+            NTuple<Location> lhsLocTuple = new NTuple<Location>();
+            lhsLocTuple.addAll(((SSJavaType) lhs.getType().getExtension()).getCompLoc().getTuple());
+
+            mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
+          }
+
+          // rhs side
+          if (rhs.getType().getExtension() != null
+              && rhs.getType().getExtension() instanceof SSJavaType) {
+
+            if (((SSJavaType) rhs.getType().getExtension()).getCompLoc() != null) {
+              NTuple<Location> rhsLocTuple = new NTuple<Location>();
+              rhsLocTuple.addAll(((SSJavaType) rhs.getType().getExtension()).getCompLoc()
+                  .getTuple());
+              mapDescriptorToLocationPath.put(rhs, rhsLocTuple);
+            }
+
+          }
+
+        }
+
         if (lhs.getType().isPrimitive() && !lhs.getSymbol().startsWith("neverused")
             && !lhs.getSymbol().startsWith("srctmp") && !lhs.getSymbol().startsWith("leftop")
             && !lhs.getSymbol().startsWith("rightop")) {
 
-          NTuple<Location> locTuple = deriveLocationTuple(md, rhs);
-          mapLocationPathToMayWrittenSet.put(locTuple, null, lhs);
-          addMayWrittenSet(md, locTuple, lhs);
+          // NTuple<Location> lhsLocTuple = new NTuple<Location>();
+          // System.out.println("fon=" + fn);
+          // System.out.println("rhs=" + rhs);
+          // lhsLocTuple.addAll(deriveLocationTuple(md, rhs));
 
-        }
+          NTuple<Descriptor> lhsHeapPath = computePath(lhs);
+
+          addMayWrittenSet(md, mapDescriptorToLocationPath.get(lhs), lhsHeapPath);
 
-        if (mapDescriptorToLocationPath.containsKey(rhs)) {
-          mapDescriptorToLocationPath.put(lhs, mapDescriptorToLocationPath.get(rhs));
-        } else {
-          if (rhs.getType().getExtension() instanceof SSJavaType) {
-            NTuple<Location> locTuple =
-                ((SSJavaType) rhs.getType().getExtension()).getCompLoc().getTuple();
-            mapDescriptorToLocationPath.put(lhs, locTuple);
-          }
         }
 
       }
@@ -1267,32 +731,38 @@ public class DefinitelyWrittenCheck {
 
       // x.f=y;
 
+      Location fieldLocation;
       if (fn.kind() == FKind.FlatSetFieldNode) {
         FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
         lhs = fsfn.getDst();
         fld = fsfn.getField();
         rhs = fsfn.getSrc();
+        fieldLocation = (Location) fld.getType().getExtension();
       } else {
         FlatSetElementNode fsen = (FlatSetElementNode) fn;
         lhs = fsen.getDst();
         rhs = fsen.getSrc();
         TypeDescriptor td = lhs.getType().dereference();
         fld = getArrayField(td);
+
+        NTuple<Location> locTuple = mapDescriptorToLocationPath.get(lhs);
+        fieldLocation = locTuple.get(locTuple.size() - 1);
       }
 
-      Location fieldLocation = (Location) fld.getType().getExtension();
       if (ssjava.isSharedLocation(fieldLocation)) {
         addSharedLocDescriptor(fieldLocation, fld);
 
-        // System.out.println("FIELD WRITE FN=" + fn);
-        NTuple<Location> locTuple = deriveLocationTuple(md, lhs);
-        locTuple.addAll(deriveLocationTuple(md, fld));
-        // System.out.println("LOC TUPLE=" + locTuple);
+        NTuple<Location> locTuple = new NTuple<Location>();
+        locTuple.addAll(deriveLocationTuple(md, lhs));
+        locTuple.add(fieldLocation);
+
+        NTuple<Descriptor> fieldHeapPath = new NTuple<Descriptor>();
+        fieldHeapPath.addAll(computePath(lhs));
+        fieldHeapPath.add(fld);
 
         // mapLocationPathToMayWrittenSet.put(locTuple, null, fld);
-        addMayWrittenSet(md, locTuple, fld);
+        addMayWrittenSet(md, locTuple, fieldHeapPath);
 
-        mapDescriptorToLocationPath.put(fld, locTuple);
       }
 
     }
@@ -1321,8 +791,10 @@ public class DefinitelyWrittenCheck {
         break;
       }
 
-      NTuple<Location> locTuple = deriveLocationTuple(md, rhs);
-      locTuple.addAll(deriveLocationTuple(md, fld));
+      NTuple<Location> locTuple = new NTuple<Location>();
+      locTuple.addAll(deriveLocationTuple(md, rhs));
+      locTuple.add((Location) fld.getType().getExtension());
+
       mapDescriptorToLocationPath.put(lhs, locTuple);
 
     }
@@ -1330,9 +802,11 @@ public class DefinitelyWrittenCheck {
 
     case FKind.FlatCall: {
 
-      // System.out.println("###FLATCALL=" + fn);
       FlatCall fc = (FlatCall) fn;
-      bindLocationPathCallerArgWithCalleeParam(md, fc);
+
+      if (ssjava.needTobeAnnotated(fc.getMethod())) {
+        bindLocationPathCallerArgWithCalleeParam(md, fc);
+      }
 
     }
       break;
@@ -1340,22 +814,22 @@ public class DefinitelyWrittenCheck {
     }
   }
 
-  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) {
@@ -1366,9 +840,7 @@ 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));
-
+      addMayWrittenSet(mdCaller, argLocationPath, argHeapPath);
     } else {
 
       // if arg is not primitive type, we need to propagate maywritten set to
@@ -1379,26 +851,51 @@ 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) {
+        // loc path for 'this'
         NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
-        mapArgIdx2CallerAgLocationStrPath.put(Integer.valueOf(0), thisLocationPath);
-      }
-
-      Hashtable<Integer, Set<Descriptor>> mapParamIdx2WriteSet =
-          new Hashtable<Integer, Set<Descriptor>>();
+        if (thisLocationPath != null) {
+          mapArgIdx2CallerArgLocationPath.put(Integer.valueOf(0), thisLocationPath);
+
+          // heap path for 'this'
+          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() + 1; i++) {
-        mapParamIdx2WriteSet.put(Integer.valueOf(i), new HashSet<Descriptor>());
       }
 
       for (int i = 0; i < fc.numArgs(); i++) {
         TempDescriptor arg = fc.getArg(i);
+        // create mapping arg to loc path
         NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
-        mapArgIdx2CallerAgLocationStrPath.put(Integer.valueOf(i + 1), argLocationPath);
+        if (argLocationPath != null) {
+          mapArgIdx2CallerArgLocationPath.put(Integer.valueOf(i + 1), argLocationPath);
+          // create mapping arg to heap path
+          NTuple<Descriptor> argHeapPath = computePath(arg);
+          mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
+        }
+
+      }
+
+      Hashtable<Integer, Set<NTuple<Descriptor>>> mapParamIdx2WriteSet =
+          new Hashtable<Integer, Set<NTuple<Descriptor>>>();
+
+      for (int i = 0; i < fc.numArgs() + 1; i++) {
+        mapParamIdx2WriteSet.put(Integer.valueOf(i), new HashSet<NTuple<Descriptor>>());
       }
 
       for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
@@ -1419,21 +916,19 @@ public class DefinitelyWrittenCheck {
           mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
         }
 
-        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<Descriptor> callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx);
           NTuple<Location> calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam);
+          NTuple<Descriptor> calleeHeapPath = computePath(calleeParam);
 
-          // System.out.println("#createNewMappingOfMayWrittenSet callee=" +
-          // callee
-          // + " callerArgLocationStrPath=" + callerArgLocationStrPath +
-          // "calleeLocationPath="
-          // + calleeLocationPath + " idx=" + idx + " writeset=" +
-          // mapParamIdx2WriteSet.get(idx));
-          createNewMappingOfMayWrittenSet(callee, callerArgLocationStrPath, calleeLocationPath,
+          createNewMappingOfMayWrittenSet(mdCaller, callee, callerArgHeapPath,
+              callerArgLocationPath, calleeHeapPath, calleeLocationPath,
               mapParamIdx2WriteSet.get(idx));
 
         }
@@ -1444,8 +939,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,
+      Set<NTuple<Descriptor>> writeSet) {
 
     // propagate may-written-set associated with the key that is started with
     // calleepath to the caller
@@ -1454,40 +970,72 @@ 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) {
+    MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> callerMapping =
+        mapMethodToSharedLocCoverSet.get(caller);
+
+    if (calleeMapping == null) {
       return;
     }
 
-    Hashtable<NTuple<Location>, Set<Descriptor>> paramMapping =
-        mapping.getMappingByStartedWith(calleeParamPath);
+    Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> paramMapping =
+        getMappingByStartedWith(calleeMapping, calleeParamLocPath);
 
-    Set<NTuple<Location>> calleeKeySet = mapping.keySet();
+    Set<NTuple<Location>> calleeKeySet = calleeMapping.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>> boundWriteSet =
+            convertCallerMayWriteSet(callerArgHeapPath, calleeParamHeapPath, calleeMayWriteSet);
+
+        writeSet.addAll(boundWriteSet);
 
         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));
         }
 
-        System.out.println("calleeParamPath=" + calleeParamPath + " newKey=" + newKey
-            + " maywriteSet=" + writeSet);
-        mapLocationPathToMayWrittenSet.put(calleeKey, newKey, writeSet);
+        callerMapping.union(newKey, writeSet);
+        // mapLocationPathToMayWrittenSet.put(calleeKey, newKey, writeSet);
       }
 
     }
 
   }
 
+  private Set<NTuple<Descriptor>> convertCallerMayWriteSet(NTuple<Descriptor> callerArgHeapPath,
+      NTuple<Descriptor> calleeParamHeapPath, Set<NTuple<Descriptor>> calleeMayWriteSet) {
+
+    Set<NTuple<Descriptor>> boundSet = new HashSet<NTuple<Descriptor>>();
+
+    // 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> boundHeapPath = new NTuple<Descriptor>();
+      boundHeapPath.addAll(callerArgHeapPath);
+
+      int startIdx = calleeParamHeapPath.size();
+
+      for (int i = startIdx; i < calleeWriteHeapPath.size(); i++) {
+        boundHeapPath.add(calleeWriteHeapPath.get(i));
+      }
+
+      boundSet.add(boundHeapPath);
+
+    }
+
+    return boundSet;
+  }
+
   private void addSharedLocDescriptor(Location sharedLoc, Descriptor desc) {
 
     Set<Descriptor> descSet = mapSharedLocationToCoverSet.get(sharedLoc);
@@ -1500,28 +1048,8 @@ public class DefinitelyWrittenCheck {
 
   }
 
-  private boolean hasReadingEffectOnSharedLocation(MethodDescriptor md, NTuple<Descriptor> hp,
-      Location loc, Descriptor d) {
-
-    ReadSummary summary = mapMethodDescriptorToReadSummary.get(md);
-
-    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);
-        }
-      }
-    }
-    return false;
-
-  }
-
   private Location getLocation(Descriptor d) {
 
-    System.out.println("GETLOCATION d=" + d + " d=" + d.getClass());
-
     if (d instanceof FieldDescriptor) {
       TypeExtension te = ((FieldDescriptor) d).getType().getExtension();
       if (te != null) {
@@ -1546,60 +1074,6 @@ 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
@@ -1701,26 +1175,48 @@ 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) {
+
+          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);
+
+              // System.out.println("#VARIABLE WRITE:" + fn);
+
+              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);
 
-            // System.out.println("WRITE VARIABLE=" + path + " from=" + lhs);
+                if (isCovered(varLocTuple, writtenSet)) {
+                  computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet);
+                  computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet);
+                } else {
+                  computeGENSetForSharedNonCoverWrite(curr, varHeapPath, readWriteGenSet);
+                }
+              } else {
 
-            computeKILLSetForWrite(curr, path, readWriteKillSet);
-            computeGENSetForWrite(path, readWriteGenSet);
+                computeKILLSetForWrite(curr, path, readWriteKillSet);
+                computeGENSetForWrite(path, readWriteGenSet);
+              }
+
+              // System.out.println("#KILLSET=" + readWriteKillSet);
+              // System.out.println("#GENSet=" + readWriteGenSet);
 
-            // System.out.println("#VARIABLE WRITE:" + fn);
-            // System.out.println("#KILLSET=" + KILLSet);
-            // System.out.println("#GENSet=" + GENSet);
+            }
 
           }
+
         }
 
       }
@@ -1755,6 +1251,7 @@ public class DefinitelyWrittenCheck {
         fldHeapPath.add(fld);
 
         Set<WriteAge> writeAgeSet = curr.get(fldHeapPath);
+
         checkWriteAgeSet(writeAgeSet, fldHeapPath, fn);
 
       }
@@ -1775,17 +1272,38 @@ public class DefinitelyWrittenCheck {
           fld = getArrayField(td);
         }
 
+        // System.out.println("FIELD WRITE:" + fn);
+
         // write(field)
         NTuple<Descriptor> lhsHeapPath = computePath(lhs);
         NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
         fldHeapPath.add(fld);
 
-        computeKILLSetForWrite(curr, fldHeapPath, readWriteKillSet);
-        computeGENSetForWrite(fldHeapPath, readWriteGenSet);
+        // shared loc extension
+        Location fieldLoc = (Location) fld.getType().getExtension();
+        if (ssjava.isSharedLocation(fieldLoc)) {
+
+          NTuple<Location> fieldLocTuple = new NTuple<Location>();
+          fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs));
+          fieldLocTuple.add(fieldLoc);
 
-        // System.out.println("FIELD WRITE:" + fn);
-        // System.out.println("KILLSET=" + KILLSet);
-        // System.out.println("GENSet=" + GENSet);
+          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);
+        }
+
+        // System.out.println("KILLSET=" + readWriteKillSet);
+        // System.out.println("GENSet=" + readWriteGenSet);
 
       }
         break;
@@ -1793,16 +1311,15 @@ public class DefinitelyWrittenCheck {
       case FKind.FlatCall: {
         FlatCall fc = (FlatCall) fn;
 
+        SharedLocMap sharedLocMap = mapFlatNodeToSharedLocMapping.get(fc);
         // System.out.println("FLATCALL:" + fn);
-
-        generateKILLSetForFlatCall(fc, curr, readWriteKillSet);
-        generateGENSetForFlatCall(fc, readWriteGenSet);
-
-        checkManyRead(fc, curr);
+        generateKILLSetForFlatCall(fc, curr, sharedLocMap, readWriteKillSet);
+        generateGENSetForFlatCall(fc, sharedLocMap, readWriteGenSet);
 
         // System.out.println("KILLSET=" + readWriteKillSet);
         // System.out.println("GENSet=" + readWriteGenSet);
 
+        checkManyRead(fc, curr);
       }
         break;
 
@@ -1815,6 +1332,60 @@ public class DefinitelyWrittenCheck {
 
   }
 
+  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>> inSet) {
+
+    if (inSet == null) {
+      return false;
+    }
+
+    Set<NTuple<Descriptor>> coverSet =
+        mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locTuple);
+
+    return inSet.containsAll(coverSet);
+  }
+
   private void checkManyRead(FlatCall fc, Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr) {
 
     Set<NTuple<Descriptor>> boundReadSet = mapFlatNodeToBoundReadSet.get(fc);
@@ -1831,7 +1402,7 @@ public class DefinitelyWrittenCheck {
     if (writeAgeSet != null) {
       for (Iterator iterator = writeAgeSet.iterator(); iterator.hasNext();) {
         WriteAge writeAge = (WriteAge) iterator.next();
-        if (writeAge.getAge() >= MAXAGE) {
+        if (writeAge.getAge() > MAXAGE) {
           throw new Error(
               "Memory location, which is reachable through references "
                   + path
@@ -1843,35 +1414,99 @@ public class DefinitelyWrittenCheck {
     }
   }
 
-  private void generateGENSetForFlatCall(FlatCall fc,
+  private void generateGENSetForFlatCall(FlatCall fc, SharedLocMap sharedLocMap,
       Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
 
     Set<NTuple<Descriptor>> boundMayWriteSet = mapFlatNodeToBoundMayWriteSet.get(fc);
 
     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);
+      NTuple<Descriptor> heapPath = (NTuple<Descriptor>) iterator.next();
+
+      if (!isSharedLocation(heapPath)) {
+        addWriteAgeToSet(heapPath, GENSet, new WriteAge(0));
+      } else {
+        // if the current heap path is shared location
+
+        System.out.println("heapPath=" + heapPath);
+        NTuple<Location> locTuple = getLocationTuple(heapPath, sharedLocMap);
+
+        Set<NTuple<Descriptor>> sharedWriteHeapPathSet = sharedLocMap.get(locTuple);
+
+        if (isCovered(locTuple, sharedLocMap.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));
+          }
+
+        } 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));
+        }
+
+      }
+
+    }
+
+  }
+
+  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 generateKILLSetForFlatCall(FlatCall fc,
-      Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
+      Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, SharedLocMap sharedLocMap,
       Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet) {
 
     Set<NTuple<Descriptor>> boundMustWriteSet = mapFlatNodeToBoundMustWriteSet.get(fc);
 
     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));
+      NTuple<Descriptor> heapPath = (NTuple<Descriptor>) iterator.next();
+
+      if (isSharedLocation(heapPath)) {
+        NTuple<Location> locTuple = getLocationTuple(heapPath, sharedLocMap);
+
+        if (isCovered(locTuple, sharedLocMap.get(locTuple))) {
+          // if it is shared loc and corresponding shared loc has been covered
+          KILLSet.put(heapPath, curr.get(heapPath));
+        }
+      } else {
+        if (curr.get(heapPath) != null) {
+          KILLSet.put(heapPath, curr.get(heapPath));
+        }
       }
+
+    }
+
+  }
+
+  private boolean isSharedLocation(NTuple<Descriptor> heapPath) {
+    return ssjava.isSharedLocation(getLocation(heapPath.get(heapPath.size() - 1)));
+  }
+
+  private NTuple<Location> getLocationTuple(NTuple<Descriptor> heapPath, SharedLocMap sharedLocMap) {
+
+    NTuple<Location> locTuple = new NTuple<Location>();
+
+    System.out.println("# 0 locPath=" + mapDescriptorToLocationPath.get(heapPath.get(0)));
+
+    locTuple.addAll(mapDescriptorToLocationPath.get(heapPath.get(0)));
+    for (int i = 1; i < heapPath.size(); i++) {
+      locTuple.add(getLocation(heapPath.get(i)));
     }
 
+    return locTuple;
   }
 
   private void computeNewMapping(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
@@ -1912,22 +1547,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) {
 
@@ -2049,146 +1668,162 @@ public class DefinitelyWrittenCheck {
 
   }
 
-  private void bindHeapPathCallerArgWithCaleeParamForSharedLoc(FlatCall fc) {
-    // // compute all possible callee set
-    // // transform all DELETE set from the any possible
-    // // callees to the caller
-    // calleeUnionBoundDeleteSet.clear();
-    // calleeIntersectBoundSharedSet.clear();
-    //
-    // MethodDescriptor mdCallee = fc.getMethod();
-    // Set<MethodDescriptor> setPossibleCallees = new
-    // HashSet<MethodDescriptor>();
-    // setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
-    //
-    // // 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<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);
-    // }
-    //
-    // for (Iterator iterator = setPossibleCallees.iterator();
-    // iterator.hasNext();) {
-    // MethodDescriptor callee = (MethodDescriptor) iterator.next();
-    // FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
-    //
-    // // binding caller's args and callee's params
-    //
-    // Set<NTuple<Descriptor>> calleeReadSet =
-    // mapFlatMethodToDeleteSet.get(calleeFlatMethod);
-    // if (calleeReadSet == null) {
-    // calleeReadSet = new HashSet<NTuple<Descriptor>>();
-    // mapFlatMethodToDeleteSet.put(calleeFlatMethod, calleeReadSet);
-    // }
-    //
-    // 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);
-    // }
-    //
-    // Set<NTuple<Descriptor>> calleeBoundDeleteSet =
-    // bindSet(calleeReadSet, mapParamIdx2ParamTempDesc,
-    // mapArgIdx2CallerArgHeapPath);
-    // // union of the current read set and the current callee's
-    // // read set
-    // calleeUnionBoundDeleteSet.addAll(calleeBoundDeleteSet);
-    //
-    // SharedLocMappingSet calleeSharedLocMap =
-    // mapFlatMethodToSharedLocMappingSet.get(calleeFlatMethod);
-    //
-    // Set<NTuple<Descriptor>> calleeHeapPathKeySet =
-    // calleeSharedLocMap.getHeapPathKeySet();
-    //
-    // for (Iterator iterator2 = calleeHeapPathKeySet.iterator();
-    // iterator2.hasNext();) {
-    // NTuple<Descriptor> calleeHeapPathKey = (NTuple<Descriptor>)
-    // iterator2.next();
-    //
-    // NTuple<Descriptor> calleeBoundHeapPathKey =
-    // bind(calleeHeapPathKey, mapParamIdx2ParamTempDesc,
-    // mapArgIdx2CallerArgHeapPath);
-    //
-    // Set<Location> calleeLocSet =
-    // calleeSharedLocMap.getLocationKeySet(calleeHeapPathKey);
-    //
-    // for (Iterator iterator3 = calleeLocSet.iterator(); iterator3.hasNext();)
-    // {
-    // Location calleeLocKey = (Location) iterator3.next();
-    // Set<Descriptor> calleeWriteSet =
-    // calleeSharedLocMap.getWriteSet(calleeHeapPathKey, calleeLocKey);
-    //
-    // calleeIntersectBoundSharedSet.intersectWriteSet(calleeBoundHeapPathKey,
-    // calleeLocKey,
-    // calleeWriteSet);
-    //
-    // }
-    //
-    // }
-    //
-    // }
-    //
-  }
-
-  private NTuple<Descriptor> bind(NTuple<Descriptor> calleeHeapPathKey,
-      Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc,
-      Hashtable<Integer, NTuple<Descriptor>> mapCallerArgIdx2HeapPath) {
+  private void bindHeapPathCallerArgWithCaleeParamForSharedLoc(MethodDescriptor mdCaller,
+      FlatCall fc) {
 
-    Set<Integer> keySet = mapCallerArgIdx2HeapPath.keySet();
+    calleeIntersectBoundSharedSet.clear();
+    calleeUnionBoundDeleteSet.clear();
+
+    // if arg is not primitive type, we need to propagate maywritten set to
+    // the caller's location path
+
+    MethodDescriptor mdCallee = fc.getMethod();
+    Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
+    setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
+
+    // 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<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);
+    }
+
+    // create mapping from arg idx to its location paths
+    Hashtable<Integer, NTuple<Location>> mapArgIdx2CallerAgLocationPath =
+        new Hashtable<Integer, NTuple<Location>>();
+
+    // arg idx is starting from 'this' arg
+    if (fc.getThis() != null) {
+      NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
+      mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath);
+    }
+
+    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);
+      }
+    }
+
+    for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
+      MethodDescriptor callee = (MethodDescriptor) iterator.next();
+      FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
+
+      // binding caller's args and callee's params
+
+      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);
+      }
+
+      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);
+
+        if (calleeDeleteSet != null) {
+          createNewMappingOfDeleteSet(callerArgLocationPath, callerArgHeapPath, calleeLocationPath,
+              calleeDeleteSet);
+        }
+
+        if (calleeSharedLocMap != null) {
+          createNewMappingOfSharedSet(callerArgLocationPath, callerArgHeapPath, calleeLocationPath,
+              calleeSharedLocMap);
+        }
+
+      }
+
+    }
+
+  }
+
+  private void createNewMappingOfDeleteSet(NTuple<Location> callerArgLocationPath,
+      NTuple<Descriptor> callerArgHeapPath, NTuple<Location> calleeLocationPath,
+      SharedLocMap calleeDeleteSet) {
+
+    SharedLocMap calleeParamDeleteSet = calleeDeleteSet.getHeapPathStartedWith(calleeLocationPath);
+
+    Set<NTuple<Location>> keySet = calleeParamDeleteSet.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;
+      NTuple<Location> calleeLocTupleKey = (NTuple<Location>) iterator.next();
+      Set<NTuple<Descriptor>> heapPathSet = calleeParamDeleteSet.get(calleeLocTupleKey);
+      for (Iterator iterator2 = heapPathSet.iterator(); iterator2.hasNext();) {
+        NTuple<Descriptor> calleeHeapPath = (NTuple<Descriptor>) iterator2.next();
+        calleeUnionBoundDeleteSet.addWrite(
+            bindLocationPath(callerArgLocationPath, calleeLocTupleKey),
+            bindHeapPath(callerArgHeapPath, calleeHeapPath));
       }
     }
-    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 createNewMappingOfSharedSet(NTuple<Location> callerArgLocationPath,
+      NTuple<Descriptor> callerArgHeapPath, NTuple<Location> calleeLocationPath,
+      SharedLocMap calleeSharedLocMap) {
+
+    SharedLocMap calleeParamSharedSet =
+        calleeSharedLocMap.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));
       }
+      calleeIntersectBoundSharedSet.intersect(
+          bindLocationPath(callerArgLocationPath, calleeLocTupleKey), boundHeapPathSet);
     }
+
+  }
+
+  private NTuple<Location> bindLocationPath(NTuple<Location> start, NTuple<Location> end) {
+    NTuple<Location> locPath = new NTuple<Location>();
+    locPath.addAll(start);
+    for (int i = 1; i < end.size(); i++) {
+      locPath.add(end.get(i));
+    }
+    return locPath;
+  }
+
+  private NTuple<Descriptor> bindHeapPath(NTuple<Descriptor> start, NTuple<Descriptor> end) {
+    NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
+    heapPath.addAll(start);
+    for (int i = 1; i < end.size(); i++) {
+      heapPath.add(end.get(i));
+    }
+    return heapPath;
   }
 
   private void initialize() {
@@ -2409,12 +2044,18 @@ 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) {
           mapHeapPath.put(lhs, mapHeapPath.get(rhs));
         } else {
           NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
@@ -2448,7 +2089,6 @@ public class DefinitelyWrittenCheck {
               System.out.println("RHS TYPE EXTENSION=" + rhs.getType().getExtension()
                   + " HEAPPATH=" + rhsHeapPath);
 
-              // TODO
               // computing gen/kill set
               // computeKILLSetForWrite(currSharedLocMapping, heapPath, dstLoc,
               // killSetSharedLoc);
@@ -2563,9 +2203,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
@@ -2604,27 +2253,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());
-  }
-
-  private Set<Descriptor> computeRemoveSet(NTuple<Descriptor> hpKey, Location locKey) {
-    Set<Descriptor> removeSet = new HashSet<Descriptor>();
-
-    for (Iterator iterator = calleeUnionBoundDeleteSet.iterator(); iterator.hasNext();) {
-      NTuple<Descriptor> removeHeapPath = (NTuple<Descriptor>) iterator.next();
-      if (getPrefix(removeHeapPath).equals(hpKey)) {
-        removeSet.add(getSuffix(removeHeapPath).get(0));
-      }
-    }
-
-    return removeSet;
-  }
-
   static public FieldDescriptor getArrayField(TypeDescriptor td) {
     FieldDescriptor fd = mapTypeToArrayField.get(td);
     if (fd == null) {
@@ -2636,72 +2264,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
@@ -2861,6 +2423,9 @@ public class DefinitelyWrittenCheck {
       if (td.getSymbol().startsWith("this")) {
         return deriveThisLocationTuple(md);
       } else {
+        if (td.getType().getExtension() == null) {
+          return null;
+        }
         NTuple<Location> locTuple =
             ((SSJavaType) td.getType().getExtension()).getCompLoc().getTuple();
         return locTuple;
@@ -2868,15 +2433,4 @@ public class DefinitelyWrittenCheck {
     }
 
   }
-
-  private NTuple<Location> deriveLocationTuple(MethodDescriptor md, FieldDescriptor fld) {
-
-    assert fld.getType() != null;
-
-    Location fieldLoc = (Location) fld.getType().getExtension();
-    NTuple<Location> locTuple = new NTuple<Location>();
-    locTuple.add(fieldLoc);
-    return locTuple;
-  }
-
 }
\ No newline at end of file