1 package Analysis.SSJava;
3 import java.util.Enumeration;
4 import java.util.HashSet;
5 import java.util.Hashtable;
6 import java.util.Iterator;
7 import java.util.LinkedList;
9 import java.util.Stack;
11 import Analysis.CallGraph.CallGraph;
12 import Analysis.Loops.LoopFinder;
14 import IR.FieldDescriptor;
15 import IR.MethodDescriptor;
18 import IR.TypeDescriptor;
19 import IR.TypeExtension;
21 import IR.Flat.FlatCall;
22 import IR.Flat.FlatElementNode;
23 import IR.Flat.FlatFieldNode;
24 import IR.Flat.FlatLiteralNode;
25 import IR.Flat.FlatMethod;
26 import IR.Flat.FlatNew;
27 import IR.Flat.FlatNode;
28 import IR.Flat.FlatOpNode;
29 import IR.Flat.FlatSetElementNode;
30 import IR.Flat.FlatSetFieldNode;
31 import IR.Flat.TempDescriptor;
32 import IR.Tree.Modifiers;
34 public class DefinitelyWrittenCheck {
36 SSJavaAnalysis ssjava;
42 // maps a descriptor to its known dependents: namely
43 // methods or tasks that call the descriptor's method
44 // AND are part of this analysis (reachable from main)
45 private Hashtable<Descriptor, Set<MethodDescriptor>> mapDescriptorToSetDependents;
47 // maps a flat node to its WrittenSet: this keeps all heap path overwritten
49 private Hashtable<FlatNode, Set<NTuple<Descriptor>>> mapFlatNodeToMustWriteSet;
51 // maps a temp descriptor to its heap path
52 // each temp descriptor has a unique heap path since we do not allow any
54 private Hashtable<Descriptor, NTuple<Descriptor>> mapHeapPath;
56 // maps a temp descriptor to its composite location
57 private Hashtable<TempDescriptor, NTuple<Location>> mapDescriptorToLocationPath;
59 // maps a flat method to the READ that is the set of heap path that is
60 // expected to be written before method invocation
61 private Hashtable<FlatMethod, Set<NTuple<Descriptor>>> mapFlatMethodToReadSet;
63 // maps a flat method to the must-write set that is the set of heap path that
64 // is overwritten on every possible path during method invocation
65 private Hashtable<FlatMethod, Set<NTuple<Descriptor>>> mapFlatMethodToMustWriteSet;
67 // maps a flat method to the DELETE SET that is a set of heap path to shared
69 // written to but not overwritten by the higher value
70 private Hashtable<FlatMethod, SharedLocMap> mapFlatMethodToDeleteSet;
72 // maps a flat method to the S SET that is a set of heap path to shared
73 // locations that are overwritten by the higher value
74 private Hashtable<FlatMethod, SharedLocMap> mapFlatMethodToSharedLocMap;
76 // maps a flat method to the may-wirte set that is the set of heap path that
77 // might be written to
78 private Hashtable<FlatMethod, Set<NTuple<Descriptor>>> mapFlatMethodToMayWriteSet;
80 // maps a call site to the read set contributed by all callees
81 private Hashtable<FlatNode, Set<NTuple<Descriptor>>> mapFlatNodeToBoundReadSet;
83 // maps a call site to the must write set contributed by all callees
84 private Hashtable<FlatNode, Set<NTuple<Descriptor>>> mapFlatNodeToBoundMustWriteSet;
86 // maps a call site to the may read set contributed by all callees
87 private Hashtable<FlatNode, Set<NTuple<Descriptor>>> mapFlatNodeToBoundMayWriteSet;
89 // points to method containing SSJAVA Loop
90 private MethodDescriptor methodContainingSSJavaLoop;
92 // maps a flatnode to definitely written analysis mapping M
93 private Hashtable<FlatNode, Hashtable<NTuple<Descriptor>, Set<WriteAge>>> mapFlatNodetoEventLoopMap;
95 // maps shared location to the set of descriptors which belong to the shared
98 // keep current descriptors to visit in fixed-point interprocedural analysis,
99 private Stack<MethodDescriptor> methodDescriptorsToVisitStack;
101 // when analyzing flatcall, need to re-schedule set of callee
102 private Set<MethodDescriptor> calleesToEnqueue;
104 private Set<ReadSummary> possibleCalleeReadSummarySetToCaller;
106 public static final String arrayElementFieldName = "___element_";
107 static protected Hashtable<TypeDescriptor, FieldDescriptor> mapTypeToArrayField;
109 // maps a method descriptor to the merged incoming caller's current
111 // it is for setting clearance flag when all read set is overwritten
112 private Hashtable<MethodDescriptor, ReadSummary> mapMethodDescriptorToReadSummary;
114 private Hashtable<MethodDescriptor, MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>> mapMethodToSharedLocCoverSet;
116 private Hashtable<FlatNode, SharedLocMap> mapFlatNodeToSharedLocMapping;
117 private Hashtable<FlatNode, SharedLocMap> mapFlatNodeToDeleteSet;
119 private LinkedList<MethodDescriptor> sortedDescriptors;
121 private LoopFinder ssjavaLoop;
122 private Set<FlatNode> loopIncElements;
124 private Set<NTuple<Descriptor>> calleeUnionBoundReadSet;
125 private Set<NTuple<Descriptor>> calleeIntersectBoundMustWriteSet;
126 private Set<NTuple<Descriptor>> calleeUnionBoundMayWriteSet;
127 private SharedLocMap calleeUnionBoundDeleteSet;
128 private SharedLocMap calleeIntersectBoundSharedSet;
130 private Hashtable<Descriptor, Location> mapDescToLocation;
132 private TempDescriptor LOCAL;
134 public static int MAXAGE = 1;
136 public DefinitelyWrittenCheck(SSJavaAnalysis ssjava, State state) {
138 this.ssjava = ssjava;
139 this.callGraph = ssjava.getCallGraph();
140 this.mapFlatNodeToMustWriteSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
141 this.mapDescriptorToSetDependents = new Hashtable<Descriptor, Set<MethodDescriptor>>();
142 this.mapHeapPath = new Hashtable<Descriptor, NTuple<Descriptor>>();
143 this.mapDescriptorToLocationPath = new Hashtable<TempDescriptor, NTuple<Location>>();
144 this.mapFlatMethodToReadSet = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
145 this.mapFlatMethodToMustWriteSet = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
146 this.mapFlatMethodToMayWriteSet = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
147 this.mapFlatNodetoEventLoopMap =
148 new Hashtable<FlatNode, Hashtable<NTuple<Descriptor>, Set<WriteAge>>>();
149 this.calleeUnionBoundReadSet = new HashSet<NTuple<Descriptor>>();
150 this.calleeIntersectBoundMustWriteSet = new HashSet<NTuple<Descriptor>>();
151 this.calleeUnionBoundMayWriteSet = new HashSet<NTuple<Descriptor>>();
153 this.methodDescriptorsToVisitStack = new Stack<MethodDescriptor>();
154 this.calleesToEnqueue = new HashSet<MethodDescriptor>();
155 this.mapTypeToArrayField = new Hashtable<TypeDescriptor, FieldDescriptor>();
156 this.LOCAL = new TempDescriptor("LOCAL");
157 this.mapDescToLocation = new Hashtable<Descriptor, Location>();
158 this.possibleCalleeReadSummarySetToCaller = new HashSet<ReadSummary>();
159 this.mapMethodDescriptorToReadSummary = new Hashtable<MethodDescriptor, ReadSummary>();
160 this.mapFlatNodeToBoundReadSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
161 this.mapFlatNodeToBoundMustWriteSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
162 this.mapFlatNodeToBoundMayWriteSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
163 this.mapFlatNodeToSharedLocMapping = new Hashtable<FlatNode, SharedLocMap>();
164 this.mapFlatMethodToDeleteSet = new Hashtable<FlatMethod, SharedLocMap>();
165 this.calleeUnionBoundDeleteSet = new SharedLocMap();
166 this.calleeIntersectBoundSharedSet = new SharedLocMap();
167 this.mapFlatMethodToSharedLocMap = new Hashtable<FlatMethod, SharedLocMap>();
168 this.mapMethodToSharedLocCoverSet =
169 new Hashtable<MethodDescriptor, MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>>();
170 this.mapFlatNodeToDeleteSet = new Hashtable<FlatNode, SharedLocMap>();
173 public void definitelyWrittenCheck() {
174 if (!ssjava.getAnnotationRequireSet().isEmpty()) {
177 methodReadWriteSetAnalysis();
178 computeSharedCoverSet();
180 // System.out.println("$$$=" +
181 // mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop));
191 private void sharedLocAnalysis() {
193 // perform method READ/OVERWRITE analysis
194 LinkedList<MethodDescriptor> descriptorListToAnalyze =
195 (LinkedList<MethodDescriptor>) sortedDescriptors.clone();
197 // current descriptors to visit in fixed-point interprocedural analysis,
199 // dependency in the call graph
200 methodDescriptorsToVisitStack.clear();
202 descriptorListToAnalyze.removeFirst();
204 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
205 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
207 while (!descriptorListToAnalyze.isEmpty()) {
208 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
209 methodDescriptorsToVisitStack.add(md);
212 // analyze scheduled methods until there are no more to visit
213 while (!methodDescriptorsToVisitStack.isEmpty()) {
214 // start to analyze leaf node
215 MethodDescriptor md = methodDescriptorsToVisitStack.pop();
216 FlatMethod fm = state.getMethodFlat(md);
218 SharedLocMap sharedLocMap = new SharedLocMap();
219 SharedLocMap deleteSet = new SharedLocMap();
221 sharedLoc_analyzeMethod(fm, sharedLocMap, deleteSet);
222 SharedLocMap prevSharedLocMap = mapFlatMethodToSharedLocMap.get(fm);
223 SharedLocMap prevDeleteSet = mapFlatMethodToDeleteSet.get(fm);
225 if (!(deleteSet.equals(prevDeleteSet) && sharedLocMap.equals(prevSharedLocMap))) {
226 mapFlatMethodToSharedLocMap.put(fm, sharedLocMap);
227 mapFlatMethodToDeleteSet.put(fm, deleteSet);
229 // results for callee changed, so enqueue dependents caller for
232 Iterator<MethodDescriptor> depsItr = getDependents(md).iterator();
233 while (depsItr.hasNext()) {
234 MethodDescriptor methodNext = depsItr.next();
235 if (!methodDescriptorsToVisitStack.contains(methodNext)
236 && methodDescriptorToVistSet.contains(methodNext)) {
237 methodDescriptorsToVisitStack.add(methodNext);
246 sharedLoc_analyzeEventLoop();
250 private void sharedLoc_analyzeEventLoop() {
251 if (state.SSJAVADEBUG) {
252 System.out.println("SSJAVA: Definite clearance for shared locations Analyzing: eventloop");
254 SharedLocMap sharedLocMap = new SharedLocMap();
255 SharedLocMap deleteSet = new SharedLocMap();
256 sharedLoc_analyzeBody(state.getMethodFlat(methodContainingSSJavaLoop),
257 ssjava.getSSJavaLoopEntrance(), sharedLocMap, deleteSet, true);
261 private void sharedLoc_analyzeMethod(FlatMethod fm, SharedLocMap sharedLocMap,
262 SharedLocMap deleteSet) {
263 if (state.SSJAVADEBUG) {
264 System.out.println("SSJAVA: Definite clearance for shared locations Analyzing: " + fm);
267 sharedLoc_analyzeBody(fm, fm, sharedLocMap, deleteSet, false);
271 private void sharedLoc_analyzeBody(FlatMethod fm, FlatNode startNode, SharedLocMap sharedLocMap,
272 SharedLocMap deleteSet, boolean isEventLoopBody) {
274 // intraprocedural analysis
275 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
276 flatNodesToVisit.add(startNode);
278 while (!flatNodesToVisit.isEmpty()) {
279 FlatNode fn = flatNodesToVisit.iterator().next();
280 flatNodesToVisit.remove(fn);
282 SharedLocMap currSharedSet = new SharedLocMap();
283 SharedLocMap currDeleteSet = new SharedLocMap();
285 for (int i = 0; i < fn.numPrev(); i++) {
286 FlatNode prevFn = fn.getPrev(i);
287 SharedLocMap inSharedLoc = mapFlatNodeToSharedLocMapping.get(prevFn);
288 if (inSharedLoc != null) {
289 mergeSharedLocMap(currSharedSet, inSharedLoc);
292 SharedLocMap inDeleteLoc = mapFlatNodeToDeleteSet.get(prevFn);
293 if (inDeleteLoc != null) {
294 mergeDeleteSet(currDeleteSet, inDeleteLoc);
298 sharedLoc_nodeActions(fm, fn, currSharedSet, currDeleteSet, sharedLocMap, deleteSet,
301 SharedLocMap prevSharedSet = mapFlatNodeToSharedLocMapping.get(fn);
302 SharedLocMap prevDeleteSet = mapFlatNodeToDeleteSet.get(fn);
304 if (!(currSharedSet.equals(prevSharedSet) && currDeleteSet.equals(prevDeleteSet))) {
305 mapFlatNodeToSharedLocMapping.put(fn, currSharedSet);
306 mapFlatNodeToDeleteSet.put(fn, currDeleteSet);
307 for (int i = 0; i < fn.numNext(); i++) {
308 FlatNode nn = fn.getNext(i);
309 if ((!isEventLoopBody) || loopIncElements.contains(nn)) {
310 flatNodesToVisit.add(nn);
320 private void sharedLoc_nodeActions(FlatMethod fm, FlatNode fn, SharedLocMap curr,
321 SharedLocMap currDeleteSet, SharedLocMap sharedLocMap, SharedLocMap deleteSet,
322 boolean isEventLoopBody) {
324 MethodDescriptor md = fm.getMethod();
326 SharedLocMap killSet = new SharedLocMap();
327 SharedLocMap genSet = new SharedLocMap();
335 case FKind.FlatOpNode: {
337 if (isEventLoopBody) {
338 FlatOpNode fon = (FlatOpNode) fn;
340 if (fon.getOp().getOp() == Operation.ASSIGN) {
344 if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop")
345 && !lhs.getSymbol().startsWith("rightop") && rhs.getType().isImmutable()) {
347 Location dstLoc = getLocation(lhs);
348 if (dstLoc != null && ssjava.isSharedLocation(dstLoc)) {
349 NTuple<Descriptor> lhsHeapPath = computePath(lhs);
350 NTuple<Location> lhsLocTuple = mapDescriptorToLocationPath.get(lhs);
352 Location srcLoc = getLocation(lhs);
354 // computing gen/kill set
355 computeKILLSetForWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
356 if (!dstLoc.equals(srcLoc)) {
357 computeGENSetForHigherWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
358 updateDeleteSetForHigherWrite(currDeleteSet, lhsLocTuple, lhsHeapPath);
360 computeGENSetForSameHeightWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
361 updateDeleteSetForSameHeightWrite(currDeleteSet, lhsLocTuple, lhsHeapPath);
364 // System.out.println("VAR WRITE:" + fn);
365 // System.out.println("lhsLocTuple=" + lhsLocTuple +
366 // " lhsHeapPath=" + lhsHeapPath);
367 // System.out.println("dstLoc=" + dstLoc + " srcLoc=" + srcLoc);
368 // System.out.println("KILLSET=" + killSet);
369 // System.out.println("GENSet=" + genSet);
370 // System.out.println("DELETESET=" + currDeleteSet);
383 case FKind.FlatSetFieldNode:
384 case FKind.FlatSetElementNode: {
387 if (fn.kind() == FKind.FlatSetFieldNode) {
388 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
390 fld = fsfn.getField();
392 fieldLoc = (Location) fld.getType().getExtension();
397 if (!isEventLoopBody && fieldLoc.getDescriptor().equals(md)) {
398 // if the field belongs to the local lattice, no reason to calculate
403 NTuple<Location> fieldLocTuple = new NTuple<Location>();
404 if (fld.isStatic()) {
406 // in this case, fld has TOP location
407 Location topLocation = Location.createTopLocation(md);
408 fieldLocTuple.add(topLocation);
410 fieldLocTuple.addAll(deriveGlobalLocationTuple(md));
411 if (fn.kind() == FKind.FlatSetFieldNode) {
412 fieldLocTuple.add((Location) fld.getType().getExtension());
417 fieldLocTuple.addAll(deriveLocationTuple(md, lhs));
418 if (fn.kind() == FKind.FlatSetFieldNode) {
419 fieldLocTuple.add((Location) fld.getType().getExtension());
423 // shared loc extension
424 Location srcLoc = getLocation(rhs);
425 if (ssjava.isSharedLocation(fieldLoc)) {
426 // only care the case that loc(f) is shared location
429 // NTuple<Location> fieldLocTuple = new NTuple<Location>();
430 // fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs));
431 // fieldLocTuple.add(fieldLoc);
433 NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>();
434 fldHeapPath.addAll(computePath(lhs));
435 if (fn.kind() == FKind.FlatSetFieldNode) {
436 fldHeapPath.add(fld);
439 // computing gen/kill set
440 computeKILLSetForWrite(curr, killSet, fieldLocTuple, fldHeapPath);
441 if (!fieldLoc.equals(srcLoc)) {
442 computeGENSetForHigherWrite(curr, genSet, fieldLocTuple, fldHeapPath);
443 updateDeleteSetForHigherWrite(currDeleteSet, fieldLocTuple, fldHeapPath);
445 computeGENSetForSameHeightWrite(curr, genSet, fieldLocTuple, fldHeapPath);
446 updateDeleteSetForSameHeightWrite(currDeleteSet, fieldLocTuple, fldHeapPath);
449 // System.out.println("################");
450 // System.out.println("FIELD WRITE:" + fn);
451 // System.out.println("FldHeapPath=" + fldHeapPath);
452 // System.out.println("fieldLocTuple=" + fieldLocTuple + " srcLoc=" +
454 // System.out.println("KILLSET=" + killSet);
455 // System.out.println("GENSet=" + genSet);
456 // System.out.println("DELETESET=" + currDeleteSet);
462 case FKind.FlatCall: {
463 FlatCall fc = (FlatCall) fn;
465 bindHeapPathCallerArgWithCaleeParamForSharedLoc(fm.getMethod(), fc);
467 // computing gen/kill set
468 generateKILLSetForFlatCall(curr, killSet);
469 generateGENSetForFlatCall(curr, genSet);
471 // System.out.println("#FLATCALL=" + fc);
472 // System.out.println("KILLSET=" + killSet);
473 // System.out.println("GENSet=" + genSet);
474 // System.out.println("bound DELETE Set=" + calleeUnionBoundDeleteSet);
479 case FKind.FlatExit: {
480 // merge the current delete/shared loc mapping
481 mergeSharedLocMap(sharedLocMap, curr);
482 mergeDeleteSet(deleteSet, currDeleteSet);
484 // System.out.println("#FLATEXIT sharedLocMap=" + sharedLocMap);
490 computeNewMapping(curr, killSet, genSet);
491 if (!curr.map.isEmpty()) {
492 // System.out.println(fn + "#######" + curr);
497 private void generateGENSetForFlatCall(SharedLocMap curr, SharedLocMap genSet) {
499 Set<NTuple<Location>> locTupleSet = calleeIntersectBoundSharedSet.keySet();
500 for (Iterator iterator = locTupleSet.iterator(); iterator.hasNext();) {
501 NTuple<Location> locTupleKey = (NTuple<Location>) iterator.next();
502 genSet.addWrite(locTupleKey, curr.get(locTupleKey));
503 genSet.addWrite(locTupleKey, calleeIntersectBoundSharedSet.get(locTupleKey));
505 genSet.removeWriteAll(locTupleKey, calleeUnionBoundDeleteSet.get(locTupleKey));
510 private void generateKILLSetForFlatCall(SharedLocMap curr, SharedLocMap killSet) {
512 Set<NTuple<Location>> locTupleSet = calleeIntersectBoundSharedSet.keySet();
513 for (Iterator iterator = locTupleSet.iterator(); iterator.hasNext();) {
514 NTuple<Location> locTupleKey = (NTuple<Location>) iterator.next();
515 killSet.addWrite(locTupleKey, curr.get(locTupleKey));
520 private void mergeDeleteSet(SharedLocMap currDeleteSet, SharedLocMap inDeleteLoc) {
522 Set<NTuple<Location>> locTupleKeySet = inDeleteLoc.keySet();
524 for (Iterator iterator = locTupleKeySet.iterator(); iterator.hasNext();) {
525 NTuple<Location> locTupleKey = (NTuple<Location>) iterator.next();
527 Set<NTuple<Descriptor>> inSet = inDeleteLoc.get(locTupleKey);
528 currDeleteSet.addWrite(locTupleKey, inSet);
533 private void computeNewMapping(SharedLocMap curr, SharedLocMap killSet, SharedLocMap genSet) {
538 private void updateDeleteSetForHigherWrite(SharedLocMap currDeleteSet, NTuple<Location> locTuple,
539 NTuple<Descriptor> hp) {
540 currDeleteSet.removeWrite(locTuple, hp);
543 private void updateDeleteSetForSameHeightWrite(SharedLocMap currDeleteSet,
544 NTuple<Location> locTuple, NTuple<Descriptor> hp) {
545 currDeleteSet.addWrite(locTuple, hp);
548 private void computeGENSetForHigherWrite(SharedLocMap curr, SharedLocMap genSet,
549 NTuple<Location> locTuple, NTuple<Descriptor> hp) {
550 Set<NTuple<Descriptor>> currWriteSet = curr.get(locTuple);
552 if (currWriteSet != null) {
553 genSet.addWrite(locTuple, currWriteSet);
556 genSet.addWrite(locTuple, hp);
559 private void computeGENSetForSameHeightWrite(SharedLocMap curr, SharedLocMap genSet,
560 NTuple<Location> locTuple, NTuple<Descriptor> hp) {
561 Set<NTuple<Descriptor>> currWriteSet = curr.get(locTuple);
563 if (currWriteSet != null) {
564 genSet.addWrite(locTuple, currWriteSet);
566 genSet.removeWrite(locTuple, hp);
569 private void computeKILLSetForWrite(SharedLocMap curr, SharedLocMap killSet,
570 NTuple<Location> locTuple, NTuple<Descriptor> hp) {
572 Set<NTuple<Descriptor>> writeSet = curr.get(locTuple);
573 if (writeSet != null) {
574 killSet.addWrite(locTuple, writeSet);
579 private void mergeSharedLocMap(SharedLocMap currSharedSet, SharedLocMap in) {
581 Set<NTuple<Location>> locTupleKeySet = in.keySet();
582 for (Iterator iterator = locTupleKeySet.iterator(); iterator.hasNext();) {
583 NTuple<Location> locTupleKey = (NTuple<Location>) iterator.next();
585 Set<NTuple<Descriptor>> inSet = in.get(locTupleKey);
586 Set<NTuple<Descriptor>> currSet = currSharedSet.get(locTupleKey);
587 if (currSet == null) {
588 currSet = new HashSet<NTuple<Descriptor>>();
589 currSet.addAll(inSet);
590 currSharedSet.addWrite(locTupleKey, currSet);
592 currSet.retainAll(inSet);
597 private void computeSharedCoverSet() {
598 LinkedList<MethodDescriptor> descriptorListToAnalyze =
599 (LinkedList<MethodDescriptor>) sortedDescriptors.clone();
601 // current descriptors to visit in fixed-point interprocedural analysis,
603 // dependency in the call graph
604 methodDescriptorsToVisitStack.clear();
606 descriptorListToAnalyze.removeFirst();
608 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
609 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
611 while (!descriptorListToAnalyze.isEmpty()) {
612 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
613 methodDescriptorsToVisitStack.add(md);
616 // analyze scheduled methods until there are no more to visit
617 while (!methodDescriptorsToVisitStack.isEmpty()) {
618 MethodDescriptor md = methodDescriptorsToVisitStack.pop();
619 FlatMethod fm = state.getMethodFlat(md);
620 computeSharedCoverSet_analyzeMethod(fm, md.equals(methodContainingSSJavaLoop));
623 computeSharedCoverSetForEventLoop();
627 private void computeSharedCoverSetForEventLoop() {
628 computeSharedCoverSet_analyzeMethod(state.getMethodFlat(methodContainingSSJavaLoop), true);
631 private void computeSharedCoverSet_analyzeMethod(FlatMethod fm, boolean onlyVisitSSJavaLoop) {
633 System.out.println("\n###");
634 System.out.println("computeSharedCoverSet_analyzeMethod=" + fm);
635 MethodDescriptor md = fm.getMethod();
637 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
639 Set<FlatNode> visited = new HashSet<FlatNode>();
641 if (onlyVisitSSJavaLoop) {
642 flatNodesToVisit.add(ssjava.getSSJavaLoopEntrance());
644 flatNodesToVisit.add(fm);
647 while (!flatNodesToVisit.isEmpty()) {
648 FlatNode fn = flatNodesToVisit.iterator().next();
649 flatNodesToVisit.remove(fn);
652 computeSharedCoverSet_nodeActions(md, fn, onlyVisitSSJavaLoop);
654 for (int i = 0; i < fn.numNext(); i++) {
655 FlatNode nn = fn.getNext(i);
657 if (!visited.contains(nn)) {
658 if (!onlyVisitSSJavaLoop || (onlyVisitSSJavaLoop && loopIncElements.contains(nn))) {
659 flatNodesToVisit.add(nn);
669 private void computeSharedCoverSet_nodeActions(MethodDescriptor md, FlatNode fn,
670 boolean isEventLoopBody) {
677 case FKind.FlatLiteralNode: {
678 FlatLiteralNode fln = (FlatLiteralNode) fn;
681 NTuple<Location> lhsLocTuple = new NTuple<Location>();
682 lhsLocTuple.add(Location.createTopLocation(md));
683 mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
685 if (lhs.getType().isPrimitive() && !lhs.getSymbol().startsWith("neverused")
686 && !lhs.getSymbol().startsWith("srctmp")) {
687 // only need to care about composite location case here
688 if (lhs.getType().getExtension() instanceof SSJavaType) {
689 CompositeLocation compLoc = ((SSJavaType) lhs.getType().getExtension()).getCompLoc();
690 Location lastLocElement = compLoc.get(compLoc.getSize() - 1);
697 case FKind.FlatOpNode: {
698 FlatOpNode fon = (FlatOpNode) fn;
699 // for a normal assign node, need to propagate lhs's location path to
701 if (fon.getOp().getOp() == Operation.ASSIGN) {
705 if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop")
706 && !lhs.getSymbol().startsWith("rightop")) {
708 NTuple<Location> rhsLocTuple = new NTuple<Location>();
709 NTuple<Location> lhsLocTuple = new NTuple<Location>();
710 if (mapDescriptorToLocationPath.containsKey(rhs)) {
711 mapDescriptorToLocationPath.put(lhs, deriveLocationTuple(md, rhs));
712 lhsLocTuple = mapDescriptorToLocationPath.get(lhs);
715 if (rhs.getType().getExtension() != null
716 && rhs.getType().getExtension() instanceof SSJavaType) {
718 if (((SSJavaType) rhs.getType().getExtension()).getCompLoc() != null) {
719 rhsLocTuple.addAll(((SSJavaType) rhs.getType().getExtension()).getCompLoc()
724 NTuple<Location> locTuple = deriveLocationTuple(md, rhs);
725 if (locTuple != null) {
726 rhsLocTuple.addAll(locTuple);
729 if (rhsLocTuple.size() > 0) {
730 mapDescriptorToLocationPath.put(rhs, rhsLocTuple);
734 if (lhs.getType().getExtension() != null
735 && lhs.getType().getExtension() instanceof SSJavaType) {
736 lhsLocTuple.addAll(((SSJavaType) lhs.getType().getExtension()).getCompLoc()
738 mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
739 } else if (mapDescriptorToLocationPath.get(rhs) != null) {
740 // propagate rhs's location to lhs
741 lhsLocTuple.addAll(mapDescriptorToLocationPath.get(rhs));
742 mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
746 if (isEventLoopBody && lhs.getType().isPrimitive()
747 && !lhs.getSymbol().startsWith("srctmp")) {
749 NTuple<Descriptor> lhsHeapPath = computePath(lhs);
751 if (lhsLocTuple != null) {
752 addMayWrittenSet(md, lhsLocTuple, lhsHeapPath);
762 case FKind.FlatSetFieldNode:
763 case FKind.FlatSetElementNode: {
767 if (fn.kind() == FKind.FlatSetFieldNode) {
768 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
770 fld = fsfn.getField();
773 FlatSetElementNode fsen = (FlatSetElementNode) fn;
776 TypeDescriptor td = lhs.getType().dereference();
777 fld = getArrayField(td);
780 NTuple<Location> fieldLocTuple = new NTuple<Location>();
781 fieldLocTuple.addAll(deriveLocationTuple(md, lhs));
782 if (fn.kind() == FKind.FlatSetFieldNode) {
783 fieldLocTuple.add((Location) fld.getType().getExtension());
786 if (mapHeapPath.containsKey(lhs)) {
787 // fields reachable from the param can have heap path entry.
788 NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
789 lhsHeapPath.addAll(mapHeapPath.get(lhs));
791 Location fieldLocation;
792 if (fn.kind() == FKind.FlatSetFieldNode) {
793 fieldLocation = getLocation(fld);
795 fieldLocation = getLocation(lhsHeapPath.get(getArrayBaseDescriptorIdx(lhsHeapPath)));
798 // Location fieldLocation = getLocation(lhs);
799 if (!isEventLoopBody && fieldLocation.getDescriptor().equals(md)) {
800 // if the field belongs to the local lattice, no reason to calculate
805 if (ssjava.isSharedLocation(fieldLocation)) {
807 NTuple<Descriptor> fieldHeapPath = new NTuple<Descriptor>();
808 fieldHeapPath.addAll(computePath(lhs));
809 if (fn.kind() == FKind.FlatSetFieldNode) {
810 fieldHeapPath.add(fld);
813 addMayWrittenSet(md, fieldLocTuple, fieldHeapPath);
821 case FKind.FlatElementNode:
822 case FKind.FlatFieldNode: {
826 if (fn.kind() == FKind.FlatFieldNode) {
827 FlatFieldNode ffn = (FlatFieldNode) fn;
830 fld = ffn.getField();
832 FlatElementNode fen = (FlatElementNode) fn;
835 TypeDescriptor td = rhs.getType().dereference();
836 fld = getArrayField(td);
839 NTuple<Location> locTuple = new NTuple<Location>();
841 if (fld.isStatic()) {
844 // in this case, fld has TOP location
845 Location topLocation = Location.createTopLocation(md);
846 locTuple.add(topLocation);
848 locTuple.addAll(deriveGlobalLocationTuple(md));
849 if (fn.kind() == FKind.FlatFieldNode) {
850 locTuple.add((Location) fld.getType().getExtension());
855 locTuple.addAll(deriveLocationTuple(md, rhs));
856 if (fn.kind() == FKind.FlatFieldNode) {
857 locTuple.add((Location) fld.getType().getExtension());
861 mapDescriptorToLocationPath.put(lhs, locTuple);
866 case FKind.FlatCall: {
868 FlatCall fc = (FlatCall) fn;
870 bindLocationPathCallerArgWithCalleeParam(md, fc);
875 case FKind.FlatNew: {
877 FlatNew fnew = (FlatNew) fn;
878 TempDescriptor dst = fnew.getDst();
879 NTuple<Location> locTuple = deriveLocationTuple(md, dst);
881 if (locTuple != null) {
882 NTuple<Location> dstLocTuple = new NTuple<Location>();
883 dstLocTuple.addAll(locTuple);
884 mapDescriptorToLocationPath.put(dst, dstLocTuple);
892 private void addMayWrittenSet(MethodDescriptor md, NTuple<Location> locTuple,
893 NTuple<Descriptor> heapPath) {
895 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> map = mapMethodToSharedLocCoverSet.get(md);
897 map = new MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>();
898 mapMethodToSharedLocCoverSet.put(md, map);
901 Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
902 if (writeSet == null) {
903 writeSet = new HashSet<NTuple<Descriptor>>();
904 map.put(locTuple, writeSet);
906 writeSet.add(heapPath);
910 private void bindLocationPathCallerArgWithCalleeParam(MethodDescriptor mdCaller, FlatCall fc) {
912 if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
914 // have write effects on the first argument
915 TempDescriptor arg = fc.getArg(0);
916 NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
917 NTuple<Descriptor> argHeapPath = computePath(arg);
918 addMayWrittenSet(mdCaller, argLocationPath, argHeapPath);
919 } else if (ssjava.needTobeAnnotated(fc.getMethod())) {
921 // if arg is not primitive type, we need to propagate maywritten set to
922 // the caller's location path
924 MethodDescriptor mdCallee = fc.getMethod();
925 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
926 setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
928 // create mapping from arg idx to its heap paths
929 Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
930 new Hashtable<Integer, NTuple<Descriptor>>();
932 // create mapping from arg idx to its location paths
933 Hashtable<Integer, NTuple<Location>> mapArgIdx2CallerArgLocationPath =
934 new Hashtable<Integer, NTuple<Location>>();
936 if (fc.getThis() != null) {
938 if (mapHeapPath.containsKey(fc.getThis())) {
940 // setup heap path for 'this'
941 NTuple<Descriptor> thisHeapPath = new NTuple<Descriptor>();
942 thisHeapPath.addAll(mapHeapPath.get(fc.getThis()));
943 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
945 // setup location path for 'this'
946 NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
947 mapArgIdx2CallerArgLocationPath.put(Integer.valueOf(0), thisLocationPath);
952 for (int i = 0; i < fc.numArgs(); i++) {
953 TempDescriptor arg = fc.getArg(i);
954 // create mapping arg to loc path
956 if (mapHeapPath.containsKey(arg)) {
958 NTuple<Descriptor> argHeapPath = mapHeapPath.get(arg);
959 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
961 NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
962 mapArgIdx2CallerArgLocationPath.put(Integer.valueOf(i + 1), argLocationPath);
967 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
968 MethodDescriptor callee = (MethodDescriptor) iterator.next();
969 FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
971 // binding caller's args and callee's params
973 Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath =
974 new Hashtable<NTuple<Descriptor>, NTuple<Descriptor>>();
976 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
977 new Hashtable<Integer, TempDescriptor>();
979 if (calleeFlatMethod.getMethod().isStatic()) {
980 // static method does not have implicit 'this' arg
984 for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
985 TempDescriptor param = calleeFlatMethod.getParameter(i);
986 mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
988 NTuple<Descriptor> calleeHeapPath = computePath(param);
990 NTuple<Descriptor> argHeapPath =
991 mapArgIdx2CallerArgHeapPath.get(Integer.valueOf(i + offset));
993 if (argHeapPath != null) {
994 mapParamHeapPathToCallerArgHeapPath.put(calleeHeapPath, argHeapPath);
1000 Set<Integer> keySet = mapArgIdx2CallerArgLocationPath.keySet();
1001 for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
1002 Integer idx = (Integer) iterator2.next();
1004 NTuple<Location> callerArgLocationPath = mapArgIdx2CallerArgLocationPath.get(idx);
1006 TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
1007 NTuple<Location> calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam);
1009 NTuple<Descriptor> callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx);
1010 NTuple<Descriptor> calleeHeapPath = computePath(calleeParam);
1012 if (!calleeParam.getType().isPrimitive()) {
1013 createNewMappingOfMayWrittenSet(mdCaller, callee, callerArgHeapPath,
1014 callerArgLocationPath, calleeHeapPath, calleeLocationPath,
1015 mapParamHeapPathToCallerArgHeapPath);
1025 private Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> getMappingByStartedWith(
1026 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> map, NTuple<Location> in) {
1028 Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> matchedMapping =
1029 new Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>>();
1031 Set<NTuple<Location>> keySet = map.keySet();
1033 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1034 NTuple<Location> key = (NTuple<Location>) iterator.next();
1035 if (key.startsWith(in)) {
1036 matchedMapping.put(key, map.get(key));
1040 return matchedMapping;
1044 private void createNewMappingOfMayWrittenSet(MethodDescriptor caller, MethodDescriptor callee,
1045 NTuple<Descriptor> callerArgHeapPath, NTuple<Location> callerArgLocPath,
1046 NTuple<Descriptor> calleeParamHeapPath, NTuple<Location> calleeParamLocPath,
1047 Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath) {
1049 // propagate may-written-set associated with the key that is started with
1050 // calleepath to the caller
1051 // 1) makes a new key by combining caller path and callee path(except local
1052 // loc element of param)
1053 // 2) create new mapping of may-written-set of callee path to caller path
1055 // extract all may written effect accessed through callee param path
1056 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> calleeMapping =
1057 mapMethodToSharedLocCoverSet.get(callee);
1059 if (calleeMapping == null) {
1063 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> callerMapping =
1064 mapMethodToSharedLocCoverSet.get(caller);
1066 if (callerMapping == null) {
1067 callerMapping = new MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>();
1068 mapMethodToSharedLocCoverSet.put(caller, callerMapping);
1071 Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> paramMapping =
1072 getMappingByStartedWith(calleeMapping, calleeParamLocPath);
1074 Set<NTuple<Location>> calleeKeySet = paramMapping.keySet();
1076 for (Iterator iterator = calleeKeySet.iterator(); iterator.hasNext();) {
1077 NTuple<Location> calleeKey = (NTuple<Location>) iterator.next();
1079 Set<NTuple<Descriptor>> calleeMayWriteSet = paramMapping.get(calleeKey);
1081 if (calleeMayWriteSet != null) {
1083 Set<NTuple<Descriptor>> boundMayWriteSet = new HashSet<NTuple<Descriptor>>();
1085 Set<NTuple<Descriptor>> boundSet =
1086 convertToCallerMayWriteSet(calleeParamHeapPath, calleeMayWriteSet, callerMapping,
1087 mapParamHeapPathToCallerArgHeapPath);
1089 boundMayWriteSet.addAll(boundSet);
1091 NTuple<Location> newKey = new NTuple<Location>();
1092 newKey.addAll(callerArgLocPath);
1093 // need to replace the local location with the caller's path so skip the
1094 // local location of the parameter
1095 for (int i = 1; i < calleeKey.size(); i++) {
1096 newKey.add(calleeKey.get(i));
1099 callerMapping.union(newKey, boundMayWriteSet);
1106 private Set<NTuple<Descriptor>> convertToCallerMayWriteSet(
1107 NTuple<Descriptor> calleeParamHeapPath, Set<NTuple<Descriptor>> calleeMayWriteSet,
1108 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> callerMapping,
1109 Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath) {
1111 Set<NTuple<Descriptor>> boundSet = new HashSet<NTuple<Descriptor>>();
1113 // replace callee's param path with caller's arg path
1114 for (Iterator iterator = calleeMayWriteSet.iterator(); iterator.hasNext();) {
1115 NTuple<Descriptor> calleeWriteHeapPath = (NTuple<Descriptor>) iterator.next();
1117 NTuple<Descriptor> writeHeapPathParamHeapPath = calleeWriteHeapPath.subList(0, 1);
1119 NTuple<Descriptor> callerArgHeapPath =
1120 mapParamHeapPathToCallerArgHeapPath.get(writeHeapPathParamHeapPath);
1122 NTuple<Descriptor> boundHeapPath = new NTuple<Descriptor>();
1123 boundHeapPath.addAll(callerArgHeapPath);
1125 for (int i = 1; i < calleeWriteHeapPath.size(); i++) {
1126 boundHeapPath.add(calleeWriteHeapPath.get(i));
1129 boundSet.add(boundHeapPath);
1136 private Location getLocation(Descriptor d) {
1138 if (d instanceof FieldDescriptor) {
1139 TypeExtension te = ((FieldDescriptor) d).getType().getExtension();
1141 return (Location) te;
1144 assert d instanceof TempDescriptor;
1145 TempDescriptor td = (TempDescriptor) d;
1147 TypeExtension te = td.getType().getExtension();
1149 if (te instanceof SSJavaType) {
1150 SSJavaType ssType = (SSJavaType) te;
1151 if (ssType.getCompLoc() != null) {
1152 CompositeLocation comp = ssType.getCompLoc();
1153 return comp.get(comp.getSize() - 1);
1158 return (Location) te;
1163 return mapDescToLocation.get(d);
1166 private void eventLoopAnalysis() {
1167 // perform second stage analysis: intraprocedural analysis ensure that
1169 // variables are definitely written in-between the same read
1171 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
1172 flatNodesToVisit.add(ssjava.getSSJavaLoopEntrance());
1174 while (!flatNodesToVisit.isEmpty()) {
1175 FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
1176 flatNodesToVisit.remove(fn);
1178 Hashtable<NTuple<Descriptor>, Set<WriteAge>> prev = mapFlatNodetoEventLoopMap.get(fn);
1180 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr =
1181 new Hashtable<NTuple<Descriptor>, Set<WriteAge>>();
1182 for (int i = 0; i < fn.numPrev(); i++) {
1183 FlatNode nn = fn.getPrev(i);
1184 Hashtable<NTuple<Descriptor>, Set<WriteAge>> in = mapFlatNodetoEventLoopMap.get(nn);
1190 eventLoopAnalysis_nodeAction(fn, curr, ssjava.getSSJavaLoopEntrance());
1192 // if a new result, schedule forward nodes for analysis
1193 if (!curr.equals(prev)) {
1194 mapFlatNodetoEventLoopMap.put(fn, curr);
1196 for (int i = 0; i < fn.numNext(); i++) {
1197 FlatNode nn = fn.getNext(i);
1198 if (loopIncElements.contains(nn)) {
1199 flatNodesToVisit.add(nn);
1207 private void union(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1208 Hashtable<NTuple<Descriptor>, Set<WriteAge>> in) {
1210 Set<NTuple<Descriptor>> inKeySet = in.keySet();
1211 for (Iterator iterator = inKeySet.iterator(); iterator.hasNext();) {
1212 NTuple<Descriptor> inKey = (NTuple<Descriptor>) iterator.next();
1213 Set<WriteAge> inSet = in.get(inKey);
1215 Set<WriteAge> currSet = curr.get(inKey);
1217 if (currSet == null) {
1218 currSet = new HashSet<WriteAge>();
1219 curr.put(inKey, currSet);
1221 currSet.addAll(inSet);
1226 private void eventLoopAnalysis_nodeAction(FlatNode fn,
1227 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, FlatNode loopEntrance) {
1229 Hashtable<NTuple<Descriptor>, Set<WriteAge>> readWriteKillSet =
1230 new Hashtable<NTuple<Descriptor>, Set<WriteAge>>();
1231 Hashtable<NTuple<Descriptor>, Set<WriteAge>> readWriteGenSet =
1232 new Hashtable<NTuple<Descriptor>, Set<WriteAge>>();
1234 if (fn.equals(loopEntrance)) {
1235 // it reaches loop entrance: changes all flag to true
1236 Set<NTuple<Descriptor>> keySet = curr.keySet();
1237 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1238 NTuple<Descriptor> key = (NTuple<Descriptor>) iterator.next();
1239 Set<WriteAge> writeAgeSet = curr.get(key);
1241 Set<WriteAge> incSet = new HashSet<WriteAge>();
1242 incSet.addAll(writeAgeSet);
1243 writeAgeSet.clear();
1245 for (Iterator iterator2 = incSet.iterator(); iterator2.hasNext();) {
1246 WriteAge writeAge = (WriteAge) iterator2.next();
1247 WriteAge newWriteAge = writeAge.copy();
1249 writeAgeSet.add(newWriteAge);
1257 FieldDescriptor fld;
1259 switch (fn.kind()) {
1261 case FKind.FlatOpNode: {
1262 FlatOpNode fon = (FlatOpNode) fn;
1263 lhs = fon.getDest();
1264 rhs = fon.getLeft();
1266 if (fon.getOp().getOp() == Operation.ASSIGN) {
1268 if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop")
1269 && !lhs.getSymbol().startsWith("rightop")) {
1271 boolean hasWriteEffect = false;
1273 if (rhs.getType().getExtension() instanceof SSJavaType
1274 && lhs.getType().getExtension() instanceof SSJavaType) {
1276 CompositeLocation rhsCompLoc =
1277 ((SSJavaType) rhs.getType().getExtension()).getCompLoc();
1279 CompositeLocation lhsCompLoc =
1280 ((SSJavaType) lhs.getType().getExtension()).getCompLoc();
1282 if (lhsCompLoc != rhsCompLoc) {
1283 // have a write effect!
1284 hasWriteEffect = true;
1287 } else if (lhs.getType().isImmutable()) {
1288 hasWriteEffect = true;
1291 if (hasWriteEffect) {
1293 NTuple<Descriptor> rhsHeapPath = computePath(rhs);
1294 NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
1295 lhsHeapPath.addAll(rhsHeapPath);
1297 Location lhsLoc = getLocation(lhs);
1298 if (ssjava.isSharedLocation(lhsLoc)) {
1300 NTuple<Descriptor> varHeapPath = computePath(lhs);
1301 NTuple<Location> varLocTuple = mapDescriptorToLocationPath.get(lhs);
1303 Set<NTuple<Descriptor>> writtenSet =
1304 mapFlatNodeToSharedLocMapping.get(fn).get(varLocTuple);
1306 if (isCovered(varLocTuple, writtenSet)) {
1307 computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet);
1308 computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet);
1310 computeGENSetForSharedNonCoverWrite(curr, varHeapPath, readWriteGenSet);
1315 computeKILLSetForWrite(curr, lhsHeapPath, readWriteKillSet);
1316 computeGENSetForWrite(lhsHeapPath, readWriteGenSet);
1319 // System.out.println("write effect on =" + lhsHeapPath);
1320 // System.out.println("#KILLSET=" + readWriteKillSet);
1321 // System.out.println("#GENSet=" + readWriteGenSet + "\n");
1323 Set<WriteAge> writeAgeSet = curr.get(lhsHeapPath);
1324 checkWriteAgeSet(writeAgeSet, lhsHeapPath, fn);
1334 case FKind.FlatFieldNode:
1335 case FKind.FlatElementNode: {
1337 if (fn.kind() == FKind.FlatFieldNode) {
1338 FlatFieldNode ffn = (FlatFieldNode) fn;
1341 fld = ffn.getField();
1343 FlatElementNode fen = (FlatElementNode) fn;
1346 TypeDescriptor td = rhs.getType().dereference();
1347 fld = getArrayField(td);
1351 NTuple<Descriptor> srcHeapPath = mapHeapPath.get(rhs);
1352 NTuple<Descriptor> fldHeapPath;
1353 if (srcHeapPath != null) {
1354 fldHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
1356 // if srcHeapPath is null, it is static reference
1357 fldHeapPath = new NTuple<Descriptor>();
1358 fldHeapPath.add(rhs);
1360 fldHeapPath.add(fld);
1362 Set<WriteAge> writeAgeSet = curr.get(fldHeapPath);
1364 checkWriteAgeSet(writeAgeSet, fldHeapPath, fn);
1369 case FKind.FlatSetFieldNode:
1370 case FKind.FlatSetElementNode: {
1372 if (fn.kind() == FKind.FlatSetFieldNode) {
1373 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
1374 lhs = fsfn.getDst();
1375 fld = fsfn.getField();
1377 FlatSetElementNode fsen = (FlatSetElementNode) fn;
1378 lhs = fsen.getDst();
1379 rhs = fsen.getSrc();
1380 TypeDescriptor td = lhs.getType().dereference();
1381 fld = getArrayField(td);
1385 NTuple<Descriptor> lhsHeapPath = computePath(lhs);
1386 NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
1387 if (fn.kind() == FKind.FlatSetFieldNode) {
1388 fldHeapPath.add(fld);
1391 // shared loc extension
1393 if (fn.kind() == FKind.FlatSetFieldNode) {
1394 fieldLoc = (Location) fld.getType().getExtension();
1396 NTuple<Location> locTuple = mapDescriptorToLocationPath.get(lhs);
1397 fieldLoc = locTuple.get(locTuple.size() - 1);
1400 if (ssjava.isSharedLocation(fieldLoc)) {
1402 NTuple<Location> fieldLocTuple = new NTuple<Location>();
1403 fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs));
1404 if (fn.kind() == FKind.FlatSetFieldNode) {
1405 fieldLocTuple.add(fieldLoc);
1408 Set<NTuple<Descriptor>> writtenSet =
1409 mapFlatNodeToSharedLocMapping.get(fn).get(fieldLocTuple);
1411 if (isCovered(fieldLocTuple, writtenSet)) {
1412 computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet);
1413 computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet);
1415 computeGENSetForSharedNonCoverWrite(curr, fldHeapPath, readWriteGenSet);
1419 computeKILLSetForWrite(curr, fldHeapPath, readWriteKillSet);
1420 computeGENSetForWrite(fldHeapPath, readWriteGenSet);
1423 // System.out.println("KILLSET=" + readWriteKillSet);
1424 // System.out.println("GENSet=" + readWriteGenSet);
1429 case FKind.FlatCall: {
1430 FlatCall fc = (FlatCall) fn;
1432 SharedLocMap sharedLocMap = mapFlatNodeToSharedLocMapping.get(fc);
1433 // System.out.println("FLATCALL:" + fn);
1434 generateKILLSetForFlatCall(fc, curr, sharedLocMap, readWriteKillSet);
1435 generateGENSetForFlatCall(fc, sharedLocMap, readWriteGenSet);
1437 // System.out.println("KILLSET=" + readWriteKillSet);
1438 // System.out.println("GENSet=" + readWriteGenSet);
1440 checkManyRead(fc, curr);
1446 computeNewMapping(curr, readWriteKillSet, readWriteGenSet);
1447 // System.out.println("#######" + curr);
1453 private void computeGENSetForSharedNonCoverWrite(
1454 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, NTuple<Descriptor> heapPath,
1455 Hashtable<NTuple<Descriptor>, Set<WriteAge>> genSet) {
1457 Set<WriteAge> writeAgeSet = genSet.get(heapPath);
1458 if (writeAgeSet == null) {
1459 writeAgeSet = new HashSet<WriteAge>();
1460 genSet.put(heapPath, writeAgeSet);
1463 writeAgeSet.add(new WriteAge(1));
1467 private void computeGENSetForSharedAllCoverWrite(
1468 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, Set<NTuple<Descriptor>> writtenSet,
1469 Hashtable<NTuple<Descriptor>, Set<WriteAge>> genSet) {
1471 for (Iterator iterator = writtenSet.iterator(); iterator.hasNext();) {
1472 NTuple<Descriptor> writeHeapPath = (NTuple<Descriptor>) iterator.next();
1474 Set<WriteAge> writeAgeSet = new HashSet<WriteAge>();
1475 writeAgeSet.add(new WriteAge(0));
1477 genSet.put(writeHeapPath, writeAgeSet);
1482 private void computeKILLSetForSharedWrite(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1483 Set<NTuple<Descriptor>> writtenSet, Hashtable<NTuple<Descriptor>, Set<WriteAge>> killSet) {
1485 for (Iterator iterator = writtenSet.iterator(); iterator.hasNext();) {
1486 NTuple<Descriptor> writeHeapPath = (NTuple<Descriptor>) iterator.next();
1487 Set<WriteAge> writeSet = curr.get(writeHeapPath);
1488 if (writeSet != null) {
1489 killSet.put(writeHeapPath, writeSet);
1495 private boolean isCovered(NTuple<Location> locTuple, Set<NTuple<Descriptor>> inSet) {
1497 if (inSet == null) {
1501 Set<NTuple<Descriptor>> coverSet =
1502 mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locTuple);
1504 return inSet.containsAll(coverSet);
1507 private void checkManyRead(FlatCall fc, Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr) {
1509 Set<NTuple<Descriptor>> boundReadSet = mapFlatNodeToBoundReadSet.get(fc);
1511 for (Iterator iterator = boundReadSet.iterator(); iterator.hasNext();) {
1512 NTuple<Descriptor> readHeapPath = (NTuple<Descriptor>) iterator.next();
1513 Set<WriteAge> writeAgeSet = curr.get(readHeapPath);
1514 checkWriteAgeSet(writeAgeSet, readHeapPath, fc);
1519 private void checkWriteAgeSet(Set<WriteAge> writeAgeSet, NTuple<Descriptor> path, FlatNode fn) {
1521 // System.out.println("# CHECK WRITE AGE of " + path + " from set=" +
1524 if (writeAgeSet != null) {
1525 for (Iterator iterator = writeAgeSet.iterator(); iterator.hasNext();) {
1526 WriteAge writeAge = (WriteAge) iterator.next();
1527 if (writeAge.getAge() > MAXAGE) {
1528 generateErrorMessage(path, fn);
1534 private void generateErrorMessage(NTuple<Descriptor> path, FlatNode fn) {
1536 Descriptor lastDesc = path.get(getArrayBaseDescriptorIdx(path));
1537 if (ssjava.isSharedLocation(getLocation(lastDesc))) {
1539 NTuple<Location> locPathTuple = getLocationTuple(path);
1540 Set<NTuple<Descriptor>> coverSet =
1541 mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locPathTuple);
1542 throw new Error("Shared memory locations, which is reachable through references " + path
1543 + ", are not completely overwritten by the higher values at "
1544 + methodContainingSSJavaLoop.getClassDesc().getSourceFileName() + "::" + fn.getNumLine()
1545 + ".\nThe following memory locations belong to the same shared locations:" + coverSet);
1549 "Memory location, which is reachable through references "
1551 + ", who comes back to the same read statement without being overwritten at the out-most iteration at "
1552 + methodContainingSSJavaLoop.getClassDesc().getSourceFileName() + "::"
1558 private void generateGENSetForFlatCall(FlatCall fc, SharedLocMap sharedLocMap,
1559 Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
1561 Set<NTuple<Descriptor>> boundMayWriteSet = mapFlatNodeToBoundMayWriteSet.get(fc);
1562 // System.out.println("boundMayWriteSet=" + boundMayWriteSet);
1564 for (Iterator iterator = boundMayWriteSet.iterator(); iterator.hasNext();) {
1565 NTuple<Descriptor> heapPath = (NTuple<Descriptor>) iterator.next();
1567 if (!isSharedLocation(heapPath)) {
1568 addWriteAgeToSet(heapPath, GENSet, new WriteAge(0));
1570 // if the current heap path is shared location
1572 NTuple<Location> locTuple = getLocationTuple(heapPath);
1574 Set<NTuple<Descriptor>> sharedWriteHeapPathSet = sharedLocMap.get(locTuple);
1576 if (isCovered(locTuple, sharedLocMap.get(locTuple))) {
1577 // if it is covered, add all of heap paths belong to the same shared
1578 // loc with write age 0
1580 for (Iterator iterator2 = sharedWriteHeapPathSet.iterator(); iterator2.hasNext();) {
1581 NTuple<Descriptor> sharedHeapPath = (NTuple<Descriptor>) iterator2.next();
1582 addWriteAgeToSet(sharedHeapPath, GENSet, new WriteAge(0));
1586 // if not covered, add write age 1 to the heap path that is
1587 // may-written but not covered
1588 addWriteAgeToSet(heapPath, GENSet, new WriteAge(1));
1597 private void addWriteAgeToSet(NTuple<Descriptor> heapPath,
1598 Hashtable<NTuple<Descriptor>, Set<WriteAge>> map, WriteAge age) {
1600 Set<WriteAge> currSet = map.get(heapPath);
1601 if (currSet == null) {
1602 currSet = new HashSet<WriteAge>();
1603 map.put(heapPath, currSet);
1609 private void generateKILLSetForFlatCall(FlatCall fc,
1610 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, SharedLocMap sharedLocMap,
1611 Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet) {
1613 Set<NTuple<Descriptor>> boundMustWriteSet = mapFlatNodeToBoundMustWriteSet.get(fc);
1614 System.out.println("boundMustWriteSet=" + boundMustWriteSet);
1616 for (Iterator iterator = boundMustWriteSet.iterator(); iterator.hasNext();) {
1617 NTuple<Descriptor> heapPath = (NTuple<Descriptor>) iterator.next();
1619 if (isSharedLocation(heapPath)) {
1620 NTuple<Location> locTuple = getLocationTuple(heapPath);
1622 if (isCovered(locTuple, sharedLocMap.get(locTuple))) {
1623 // if it is shared loc and corresponding shared loc has been covered
1624 KILLSet.put(heapPath, curr.get(heapPath));
1628 for (Enumeration<NTuple<Descriptor>> e = curr.keys(); e.hasMoreElements();) {
1629 NTuple<Descriptor> key = e.nextElement();
1630 if (key.startsWith(heapPath)) {
1631 KILLSet.put(key, curr.get(key));
1641 private int getArrayBaseDescriptorIdx(NTuple<Descriptor> heapPath) {
1643 for (int i = heapPath.size() - 1; i >= 0; i--) {
1644 if (!heapPath.get(i).getSymbol().equals(arrayElementFieldName)) {
1653 private boolean isSharedLocation(NTuple<Descriptor> heapPath) {
1655 Descriptor d = heapPath.get(getArrayBaseDescriptorIdx(heapPath));
1657 return ssjava.isSharedLocation(getLocation(heapPath.get(getArrayBaseDescriptorIdx(heapPath))));
1661 private NTuple<Location> getLocationTuple(NTuple<Descriptor> heapPath) {
1663 NTuple<Location> locTuple = new NTuple<Location>();
1665 locTuple.addAll(mapDescriptorToLocationPath.get(heapPath.get(0)));
1667 for (int i = 1; i <= getArrayBaseDescriptorIdx(heapPath); i++) {
1668 locTuple.add(getLocation(heapPath.get(i)));
1674 private void computeNewMapping(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1675 Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet,
1676 Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
1678 for (Enumeration<NTuple<Descriptor>> e = KILLSet.keys(); e.hasMoreElements();) {
1679 NTuple<Descriptor> key = e.nextElement();
1681 Set<WriteAge> writeAgeSet = curr.get(key);
1682 if (writeAgeSet == null) {
1683 writeAgeSet = new HashSet<WriteAge>();
1684 curr.put(key, writeAgeSet);
1686 writeAgeSet.removeAll(KILLSet.get(key));
1689 for (Enumeration<NTuple<Descriptor>> e = GENSet.keys(); e.hasMoreElements();) {
1690 NTuple<Descriptor> key = e.nextElement();
1692 Set<WriteAge> currWriteAgeSet = curr.get(key);
1693 if (currWriteAgeSet == null) {
1694 currWriteAgeSet = new HashSet<WriteAge>();
1695 curr.put(key, currWriteAgeSet);
1697 currWriteAgeSet.addAll(GENSet.get(key));
1702 private void computeGENSetForWrite(NTuple<Descriptor> fldHeapPath,
1703 Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
1705 // generate write age 0 for the field being written to
1706 Set<WriteAge> writeAgeSet = new HashSet<WriteAge>();
1707 writeAgeSet.add(new WriteAge(0));
1708 GENSet.put(fldHeapPath, writeAgeSet);
1712 private void computeKILLSetForWrite(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1713 NTuple<Descriptor> hp, Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet) {
1715 // removes all of heap path that starts with prefix 'hp'
1716 // since any reference overwrite along heap path gives overwriting side
1717 // effects on the value
1719 Set<NTuple<Descriptor>> keySet = curr.keySet();
1720 for (Iterator<NTuple<Descriptor>> iter = keySet.iterator(); iter.hasNext();) {
1721 NTuple<Descriptor> key = iter.next();
1722 if (key.startsWith(hp)) {
1723 KILLSet.put(key, curr.get(key));
1729 private void bindHeapPathCallerArgWithCalleeParam(FlatCall fc) {
1730 // compute all possible callee set
1731 // transform all READ/WRITE set from the any possible
1732 // callees to the caller
1733 calleeUnionBoundReadSet.clear();
1734 calleeIntersectBoundMustWriteSet.clear();
1735 calleeUnionBoundMayWriteSet.clear();
1737 if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
1738 // ssjava util case!
1739 // have write effects on the first argument
1740 TempDescriptor arg = fc.getArg(0);
1741 NTuple<Descriptor> argHeapPath = computePath(arg);
1742 calleeIntersectBoundMustWriteSet.add(argHeapPath);
1743 calleeUnionBoundMayWriteSet.add(argHeapPath);
1745 MethodDescriptor mdCallee = fc.getMethod();
1746 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
1747 setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
1749 // create mapping from arg idx to its heap paths
1750 Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
1751 new Hashtable<Integer, NTuple<Descriptor>>();
1753 // arg idx is starting from 'this' arg
1754 if (fc.getThis() != null) {
1755 NTuple<Descriptor> thisHeapPath = mapHeapPath.get(fc.getThis());
1756 if (thisHeapPath != null) {
1757 // if 'this' does not have heap path, it is local reference
1758 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
1762 for (int i = 0; i < fc.numArgs(); i++) {
1763 TempDescriptor arg = fc.getArg(i);
1764 NTuple<Descriptor> argHeapPath = computePath(arg);
1765 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
1768 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
1769 MethodDescriptor callee = (MethodDescriptor) iterator.next();
1770 FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
1772 // binding caller's args and callee's params
1774 Set<NTuple<Descriptor>> calleeReadSet = mapFlatMethodToReadSet.get(calleeFlatMethod);
1775 if (calleeReadSet == null) {
1776 calleeReadSet = new HashSet<NTuple<Descriptor>>();
1777 mapFlatMethodToReadSet.put(calleeFlatMethod, calleeReadSet);
1780 Set<NTuple<Descriptor>> calleeMustWriteSet =
1781 mapFlatMethodToMustWriteSet.get(calleeFlatMethod);
1783 if (calleeMustWriteSet == null) {
1784 calleeMustWriteSet = new HashSet<NTuple<Descriptor>>();
1785 mapFlatMethodToMustWriteSet.put(calleeFlatMethod, calleeMustWriteSet);
1788 Set<NTuple<Descriptor>> calleeMayWriteSet =
1789 mapFlatMethodToMayWriteSet.get(calleeFlatMethod);
1791 if (calleeMayWriteSet == null) {
1792 calleeMayWriteSet = new HashSet<NTuple<Descriptor>>();
1793 mapFlatMethodToMayWriteSet.put(calleeFlatMethod, calleeMayWriteSet);
1796 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
1797 new Hashtable<Integer, TempDescriptor>();
1799 if (calleeFlatMethod.getMethod().isStatic()) {
1800 // static method does not have implicit 'this' arg
1803 for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
1804 TempDescriptor param = calleeFlatMethod.getParameter(i);
1805 mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
1808 Set<NTuple<Descriptor>> calleeBoundReadSet =
1809 bindSet(calleeReadSet, mapParamIdx2ParamTempDesc, mapArgIdx2CallerArgHeapPath);
1810 // union of the current read set and the current callee's
1812 calleeUnionBoundReadSet.addAll(calleeBoundReadSet);
1814 Set<NTuple<Descriptor>> calleeBoundMustWriteSet =
1815 bindSet(calleeMustWriteSet, mapParamIdx2ParamTempDesc, mapArgIdx2CallerArgHeapPath);
1816 // intersection of the current overwrite set and the current
1819 merge(calleeIntersectBoundMustWriteSet, calleeBoundMustWriteSet);
1821 Set<NTuple<Descriptor>> boundWriteSetFromCallee =
1822 bindSet(calleeMayWriteSet, mapParamIdx2ParamTempDesc, mapArgIdx2CallerArgHeapPath);
1823 calleeUnionBoundMayWriteSet.addAll(boundWriteSetFromCallee);
1830 private void bindHeapPathCallerArgWithCaleeParamForSharedLoc(MethodDescriptor mdCaller,
1833 calleeIntersectBoundSharedSet.clear();
1834 calleeUnionBoundDeleteSet.clear();
1836 if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
1837 // ssjava util case!
1838 // have write effects on the first argument
1839 TempDescriptor arg = fc.getArg(0);
1840 NTuple<Descriptor> argHeapPath = computePath(arg);
1842 // convert heap path to location path
1843 NTuple<Location> argLocTuple = new NTuple<Location>();
1844 argLocTuple.addAll(deriveLocationTuple(mdCaller, (TempDescriptor) argHeapPath.get(0)));
1845 for (int i = 1; i < argHeapPath.size(); i++) {
1846 argLocTuple.add(getLocation(argHeapPath.get(i)));
1849 calleeIntersectBoundSharedSet.addWrite(argLocTuple, argHeapPath);
1851 } else if (ssjava.needTobeAnnotated(fc.getMethod())) {
1853 // if arg is not primitive type, we need to propagate maywritten set to
1854 // the caller's location path
1856 MethodDescriptor mdCallee = fc.getMethod();
1857 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
1858 setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
1860 // create mapping from arg idx to its heap paths
1861 Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
1862 new Hashtable<Integer, NTuple<Descriptor>>();
1864 // arg idx is starting from 'this' arg
1865 if (fc.getThis() != null) {
1866 NTuple<Descriptor> thisHeapPath = mapHeapPath.get(fc.getThis());
1867 if (thisHeapPath == null) {
1868 // method is called without creating new flat node representing 'this'
1869 thisHeapPath = new NTuple<Descriptor>();
1870 thisHeapPath.add(fc.getThis());
1873 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
1876 for (int i = 0; i < fc.numArgs(); i++) {
1877 TempDescriptor arg = fc.getArg(i);
1878 NTuple<Descriptor> argHeapPath = computePath(arg);
1879 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
1882 // create mapping from arg idx to its location paths
1883 Hashtable<Integer, NTuple<Location>> mapArgIdx2CallerAgLocationPath =
1884 new Hashtable<Integer, NTuple<Location>>();
1886 // arg idx is starting from 'this' arg
1887 if (fc.getThis() != null) {
1888 NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
1889 if (thisLocationPath != null) {
1890 mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath);
1894 for (int i = 0; i < fc.numArgs(); i++) {
1895 TempDescriptor arg = fc.getArg(i);
1896 NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
1897 if (argLocationPath != null) {
1898 mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(i + 1), argLocationPath);
1902 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
1903 MethodDescriptor callee = (MethodDescriptor) iterator.next();
1904 FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
1906 // binding caller's args and callee's params
1908 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
1909 new Hashtable<Integer, TempDescriptor>();
1911 if (calleeFlatMethod.getMethod().isStatic()) {
1912 // static method does not have implicit 'this' arg
1915 for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
1916 TempDescriptor param = calleeFlatMethod.getParameter(i);
1917 mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
1920 Set<Integer> keySet = mapArgIdx2CallerAgLocationPath.keySet();
1921 for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
1922 Integer idx = (Integer) iterator2.next();
1923 NTuple<Location> callerArgLocationPath = mapArgIdx2CallerAgLocationPath.get(idx);
1924 NTuple<Descriptor> callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx);
1926 TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
1927 NTuple<Location> calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam);
1928 SharedLocMap calleeDeleteSet = mapFlatMethodToDeleteSet.get(calleeFlatMethod);
1929 SharedLocMap calleeSharedLocMap = mapFlatMethodToSharedLocMap.get(calleeFlatMethod);
1931 if (calleeDeleteSet != null) {
1932 createNewMappingOfDeleteSet(callerArgLocationPath, callerArgHeapPath,
1933 calleeLocationPath, calleeDeleteSet);
1936 if (calleeSharedLocMap != null) {
1937 createNewMappingOfSharedSet(callerArgLocationPath, callerArgHeapPath,
1938 calleeLocationPath, calleeSharedLocMap);
1948 private void createNewMappingOfDeleteSet(NTuple<Location> callerArgLocationPath,
1949 NTuple<Descriptor> callerArgHeapPath, NTuple<Location> calleeLocationPath,
1950 SharedLocMap calleeDeleteSet) {
1952 SharedLocMap calleeParamDeleteSet = calleeDeleteSet.getHeapPathStartedWith(calleeLocationPath);
1954 Set<NTuple<Location>> keySet = calleeParamDeleteSet.keySet();
1955 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1956 NTuple<Location> calleeLocTupleKey = (NTuple<Location>) iterator.next();
1957 Set<NTuple<Descriptor>> heapPathSet = calleeParamDeleteSet.get(calleeLocTupleKey);
1958 for (Iterator iterator2 = heapPathSet.iterator(); iterator2.hasNext();) {
1959 NTuple<Descriptor> calleeHeapPath = (NTuple<Descriptor>) iterator2.next();
1960 calleeUnionBoundDeleteSet.addWrite(
1961 bindLocationPath(callerArgLocationPath, calleeLocTupleKey),
1962 bindHeapPath(callerArgHeapPath, calleeHeapPath));
1968 private void createNewMappingOfSharedSet(NTuple<Location> callerArgLocationPath,
1969 NTuple<Descriptor> callerArgHeapPath, NTuple<Location> calleeLocationPath,
1970 SharedLocMap calleeSharedLocMap) {
1972 SharedLocMap calleeParamSharedSet =
1973 calleeSharedLocMap.getHeapPathStartedWith(calleeLocationPath);
1975 Set<NTuple<Location>> keySet = calleeParamSharedSet.keySet();
1976 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1977 NTuple<Location> calleeLocTupleKey = (NTuple<Location>) iterator.next();
1978 Set<NTuple<Descriptor>> heapPathSet = calleeParamSharedSet.get(calleeLocTupleKey);
1979 Set<NTuple<Descriptor>> boundHeapPathSet = new HashSet<NTuple<Descriptor>>();
1980 for (Iterator iterator2 = heapPathSet.iterator(); iterator2.hasNext();) {
1981 NTuple<Descriptor> calleeHeapPath = (NTuple<Descriptor>) iterator2.next();
1982 boundHeapPathSet.add(bindHeapPath(callerArgHeapPath, calleeHeapPath));
1984 calleeIntersectBoundSharedSet.intersect(
1985 bindLocationPath(callerArgLocationPath, calleeLocTupleKey), boundHeapPathSet);
1990 private NTuple<Location> bindLocationPath(NTuple<Location> start, NTuple<Location> end) {
1991 NTuple<Location> locPath = new NTuple<Location>();
1992 locPath.addAll(start);
1993 for (int i = 1; i < end.size(); i++) {
1994 locPath.add(end.get(i));
1999 private NTuple<Descriptor> bindHeapPath(NTuple<Descriptor> start, NTuple<Descriptor> end) {
2000 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
2001 heapPath.addAll(start);
2002 for (int i = 1; i < end.size(); i++) {
2003 heapPath.add(end.get(i));
2008 private void initialize() {
2009 // First, identify ssjava loop entrace
2011 // no need to analyze method having ssjava loop
2012 methodContainingSSJavaLoop = ssjava.getMethodContainingSSJavaLoop();
2014 FlatMethod fm = state.getMethodFlat(methodContainingSSJavaLoop);
2015 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
2016 flatNodesToVisit.add(fm);
2018 LoopFinder loopFinder = new LoopFinder(fm);
2020 while (!flatNodesToVisit.isEmpty()) {
2021 FlatNode fn = flatNodesToVisit.iterator().next();
2022 flatNodesToVisit.remove(fn);
2024 String label = (String) state.fn2labelMap.get(fn);
2025 if (label != null) {
2027 if (label.equals(ssjava.SSJAVA)) {
2028 ssjava.setSSJavaLoopEntrance(fn);
2033 for (int i = 0; i < fn.numNext(); i++) {
2034 FlatNode nn = fn.getNext(i);
2035 flatNodesToVisit.add(nn);
2039 assert ssjava.getSSJavaLoopEntrance() != null;
2041 // assume that ssjava loop is top-level loop in method, not nested loop
2042 Set nestedLoop = loopFinder.nestedLoops();
2043 for (Iterator loopIter = nestedLoop.iterator(); loopIter.hasNext();) {
2044 LoopFinder lf = (LoopFinder) loopIter.next();
2045 if (lf.loopEntrances().iterator().next().equals(ssjava.getSSJavaLoopEntrance())) {
2050 assert ssjavaLoop != null;
2052 loopIncElements = (Set<FlatNode>) ssjavaLoop.loopIncElements();
2054 // perform topological sort over the set of methods accessed by the main
2056 Set<MethodDescriptor> methodDescriptorsToAnalyze = new HashSet<MethodDescriptor>();
2057 methodDescriptorsToAnalyze.addAll(ssjava.getAnnotationRequireSet());
2058 sortedDescriptors = topologicalSort(methodDescriptorsToAnalyze);
2061 private void methodReadWriteSetAnalysis() {
2062 // perform method READ/OVERWRITE analysis
2063 LinkedList<MethodDescriptor> descriptorListToAnalyze =
2064 (LinkedList<MethodDescriptor>) sortedDescriptors.clone();
2066 // current descriptors to visit in fixed-point interprocedural analysis,
2068 // dependency in the call graph
2069 methodDescriptorsToVisitStack.clear();
2071 descriptorListToAnalyze.removeFirst();
2073 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
2074 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
2076 while (!descriptorListToAnalyze.isEmpty()) {
2077 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
2078 methodDescriptorsToVisitStack.add(md);
2081 // analyze scheduled methods until there are no more to visit
2082 while (!methodDescriptorsToVisitStack.isEmpty()) {
2083 // start to analyze leaf node
2084 MethodDescriptor md = methodDescriptorsToVisitStack.pop();
2085 FlatMethod fm = state.getMethodFlat(md);
2087 Set<NTuple<Descriptor>> readSet = new HashSet<NTuple<Descriptor>>();
2088 Set<NTuple<Descriptor>> mustWriteSet = new HashSet<NTuple<Descriptor>>();
2089 Set<NTuple<Descriptor>> mayWriteSet = new HashSet<NTuple<Descriptor>>();
2091 methodReadWriteSet_analyzeMethod(fm, readSet, mustWriteSet, mayWriteSet);
2093 Set<NTuple<Descriptor>> prevRead = mapFlatMethodToReadSet.get(fm);
2094 Set<NTuple<Descriptor>> prevMustWrite = mapFlatMethodToMustWriteSet.get(fm);
2095 Set<NTuple<Descriptor>> prevMayWrite = mapFlatMethodToMayWriteSet.get(fm);
2097 if (!(readSet.equals(prevRead) && mustWriteSet.equals(prevMustWrite) && mayWriteSet
2098 .equals(prevMayWrite))) {
2099 mapFlatMethodToReadSet.put(fm, readSet);
2100 mapFlatMethodToMustWriteSet.put(fm, mustWriteSet);
2101 mapFlatMethodToMayWriteSet.put(fm, mayWriteSet);
2103 // results for callee changed, so enqueue dependents caller for
2106 Iterator<MethodDescriptor> depsItr = getDependents(md).iterator();
2107 while (depsItr.hasNext()) {
2108 MethodDescriptor methodNext = depsItr.next();
2109 if (!methodDescriptorsToVisitStack.contains(methodNext)
2110 && methodDescriptorToVistSet.contains(methodNext)) {
2111 methodDescriptorsToVisitStack.add(methodNext);
2120 methodReadWriteSetAnalysisToEventLoopBody();
2124 private void methodReadWriteSet_analyzeMethod(FlatMethod fm, Set<NTuple<Descriptor>> readSet,
2125 Set<NTuple<Descriptor>> mustWriteSet, Set<NTuple<Descriptor>> mayWriteSet) {
2126 if (state.SSJAVADEBUG) {
2127 System.out.println("SSJAVA: Definitely written Analyzing: " + fm);
2130 methodReadWriteSet_analyzeBody(fm, readSet, mustWriteSet, mayWriteSet, false);
2134 private void methodReadWriteSetAnalysisToEventLoopBody() {
2136 // perform method read/write analysis for Event Loop Body
2138 FlatMethod flatMethodContainingSSJavaLoop = state.getMethodFlat(methodContainingSSJavaLoop);
2140 if (state.SSJAVADEBUG) {
2141 System.out.println("SSJAVA: Definitely written Event Loop Analyzing: "
2142 + flatMethodContainingSSJavaLoop);
2145 Set<NTuple<Descriptor>> readSet = new HashSet<NTuple<Descriptor>>();
2146 Set<NTuple<Descriptor>> mustWriteSet = new HashSet<NTuple<Descriptor>>();
2147 Set<NTuple<Descriptor>> mayWriteSet = new HashSet<NTuple<Descriptor>>();
2149 mapFlatMethodToReadSet.put(flatMethodContainingSSJavaLoop, readSet);
2150 mapFlatMethodToMustWriteSet.put(flatMethodContainingSSJavaLoop, mustWriteSet);
2151 mapFlatMethodToMayWriteSet.put(flatMethodContainingSSJavaLoop, mayWriteSet);
2153 methodReadWriteSet_analyzeBody(ssjava.getSSJavaLoopEntrance(), readSet, mustWriteSet,
2158 private void methodReadWriteSet_analyzeBody(FlatNode startNode, Set<NTuple<Descriptor>> readSet,
2159 Set<NTuple<Descriptor>> mustWriteSet, Set<NTuple<Descriptor>> mayWriteSet,
2160 boolean isEventLoopBody) {
2162 // intraprocedural analysis
2163 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
2164 flatNodesToVisit.add(startNode);
2166 while (!flatNodesToVisit.isEmpty()) {
2167 FlatNode fn = flatNodesToVisit.iterator().next();
2168 flatNodesToVisit.remove(fn);
2170 Set<NTuple<Descriptor>> currMustWriteSet = new HashSet<NTuple<Descriptor>>();
2172 for (int i = 0; i < fn.numPrev(); i++) {
2173 FlatNode prevFn = fn.getPrev(i);
2174 Set<NTuple<Descriptor>> in = mapFlatNodeToMustWriteSet.get(prevFn);
2176 merge(currMustWriteSet, in);
2180 methodReadWriteSet_nodeActions(fn, currMustWriteSet, readSet, mustWriteSet, mayWriteSet,
2183 Set<NTuple<Descriptor>> mustSetPrev = mapFlatNodeToMustWriteSet.get(fn);
2185 if (!currMustWriteSet.equals(mustSetPrev)) {
2186 mapFlatNodeToMustWriteSet.put(fn, currMustWriteSet);
2187 for (int i = 0; i < fn.numNext(); i++) {
2188 FlatNode nn = fn.getNext(i);
2189 if ((!isEventLoopBody) || loopIncElements.contains(nn)) {
2190 flatNodesToVisit.add(nn);
2200 private void methodReadWriteSet_nodeActions(FlatNode fn,
2201 Set<NTuple<Descriptor>> currMustWriteSet, Set<NTuple<Descriptor>> readSet,
2202 Set<NTuple<Descriptor>> mustWriteSet, Set<NTuple<Descriptor>> mayWriteSet,
2203 boolean isEventLoopBody) {
2207 FieldDescriptor fld;
2209 switch (fn.kind()) {
2210 case FKind.FlatMethod: {
2212 // set up initial heap paths for method parameters
2213 FlatMethod fm = (FlatMethod) fn;
2214 for (int i = 0; i < fm.numParameters(); i++) {
2215 TempDescriptor param = fm.getParameter(i);
2216 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
2217 heapPath.add(param);
2218 mapHeapPath.put(param, heapPath);
2223 case FKind.FlatOpNode: {
2224 FlatOpNode fon = (FlatOpNode) fn;
2225 // for a normal assign node, need to propagate lhs's heap path to
2228 if (fon.getOp().getOp() == Operation.ASSIGN) {
2229 rhs = fon.getLeft();
2230 lhs = fon.getDest();
2232 NTuple<Descriptor> rhsHeapPath = mapHeapPath.get(rhs);
2234 // if (lhs.getType().isPrimitive()) {
2235 // NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
2236 // lhsHeapPath.add(lhs);
2237 // mapHeapPath.put(lhs, lhsHeapPath);
2240 if (rhsHeapPath != null) {
2241 mapHeapPath.put(lhs, mapHeapPath.get(rhs));
2243 if (isEventLoopBody) {
2244 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
2246 mapHeapPath.put(lhs, heapPath);
2252 // shared loc extension
2253 if (isEventLoopBody) {
2254 if (!lhs.getSymbol().startsWith("neverused") && rhs.getType().isImmutable()) {
2256 if (rhs.getType().getExtension() instanceof Location
2257 && lhs.getType().getExtension() instanceof CompositeLocation) {
2259 Location rhsLoc = (Location) rhs.getType().getExtension();
2261 CompositeLocation lhsCompLoc = (CompositeLocation) lhs.getType().getExtension();
2262 Location dstLoc = lhsCompLoc.get(lhsCompLoc.getSize() - 1);
2264 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
2265 for (int i = 0; i < rhsHeapPath.size() - 1; i++) {
2266 heapPath.add(rhsHeapPath.get(i));
2269 NTuple<Descriptor> writeHeapPath = new NTuple<Descriptor>();
2270 writeHeapPath.addAll(heapPath);
2271 writeHeapPath.add(lhs);
2281 case FKind.FlatElementNode:
2282 case FKind.FlatFieldNode: {
2286 if (fn.kind() == FKind.FlatFieldNode) {
2287 FlatFieldNode ffn = (FlatFieldNode) fn;
2290 fld = ffn.getField();
2292 FlatElementNode fen = (FlatElementNode) fn;
2295 TypeDescriptor td = rhs.getType().dereference();
2296 fld = getArrayField(td);
2299 if (fld.isFinal()) {
2300 // if field is final no need to check
2305 NTuple<Descriptor> srcHeapPath = mapHeapPath.get(rhs);
2306 if (srcHeapPath != null) {
2307 // if lhs srcHeapPath is null, it means that it is not reachable from
2308 // callee's parameters. so just ignore it
2310 NTuple<Descriptor> readingHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
2311 if (fn.kind() == FKind.FlatFieldNode) {
2312 readingHeapPath.add(fld);
2315 mapHeapPath.put(lhs, readingHeapPath);
2318 if (fld.getType().isImmutable()) {
2319 // if WT doesnot have hp(x.f), add hp(x.f) to READ
2320 if (!currMustWriteSet.contains(readingHeapPath)) {
2321 readSet.add(readingHeapPath);
2325 // no need to kill hp(x.f) from WT
2331 case FKind.FlatSetFieldNode:
2332 case FKind.FlatSetElementNode: {
2336 if (fn.kind() == FKind.FlatSetFieldNode) {
2337 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
2338 lhs = fsfn.getDst();
2339 fld = fsfn.getField();
2340 rhs = fsfn.getSrc();
2342 FlatSetElementNode fsen = (FlatSetElementNode) fn;
2343 lhs = fsen.getDst();
2344 rhs = fsen.getSrc();
2345 TypeDescriptor td = lhs.getType().dereference();
2346 fld = getArrayField(td);
2350 NTuple<Descriptor> lhsHeapPath = mapHeapPath.get(lhs);
2352 if (lhsHeapPath != null) {
2353 // if lhs heap path is null, it means that it is not reachable from
2354 // callee's parameters. so just ignore it
2355 NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
2356 if (fn.kind() != FKind.FlatSetElementNode) {
2357 fldHeapPath.add(fld);
2359 // mapHeapPath.put(fld, fldHeapPath);
2362 // need to add hp(y) to WT
2363 if (fn.kind() != FKind.FlatSetElementNode) {
2364 currMustWriteSet.add(fldHeapPath);
2366 mayWriteSet.add(fldHeapPath);
2373 case FKind.FlatCall: {
2375 FlatCall fc = (FlatCall) fn;
2377 bindHeapPathCallerArgWithCalleeParam(fc);
2379 Set<NTuple<Descriptor>> boundReadSet = new HashSet<NTuple<Descriptor>>();
2380 boundReadSet.addAll(calleeUnionBoundReadSet);
2382 Set<NTuple<Descriptor>> boundMustWriteSet = new HashSet<NTuple<Descriptor>>();
2383 boundMustWriteSet.addAll(calleeIntersectBoundMustWriteSet);
2385 Set<NTuple<Descriptor>> boundMayWriteSet = new HashSet<NTuple<Descriptor>>();
2386 boundMayWriteSet.addAll(calleeUnionBoundMayWriteSet);
2388 mapFlatNodeToBoundReadSet.put(fn, boundReadSet);
2389 mapFlatNodeToBoundMustWriteSet.put(fn, boundMustWriteSet);
2390 mapFlatNodeToBoundMayWriteSet.put(fn, boundMayWriteSet);
2392 // add heap path, which is an element of READ_bound set and is not
2394 // element of WT set, to the caller's READ set
2395 for (Iterator iterator = calleeUnionBoundReadSet.iterator(); iterator.hasNext();) {
2396 NTuple<Descriptor> read = (NTuple<Descriptor>) iterator.next();
2397 if (!currMustWriteSet.contains(read)) {
2402 // add heap path, which is an element of OVERWRITE_bound set, to the
2404 for (Iterator iterator = calleeIntersectBoundMustWriteSet.iterator(); iterator.hasNext();) {
2405 NTuple<Descriptor> write = (NTuple<Descriptor>) iterator.next();
2406 currMustWriteSet.add(write);
2409 // add heap path, which is an element of WRITE_BOUND set, to the
2410 // caller's writeSet
2411 for (Iterator iterator = calleeUnionBoundMayWriteSet.iterator(); iterator.hasNext();) {
2412 NTuple<Descriptor> write = (NTuple<Descriptor>) iterator.next();
2413 mayWriteSet.add(write);
2419 case FKind.FlatExit: {
2420 // merge the current written set with OVERWRITE set
2421 merge(mustWriteSet, currMustWriteSet);
2429 static public FieldDescriptor getArrayField(TypeDescriptor td) {
2430 FieldDescriptor fd = mapTypeToArrayField.get(td);
2433 new FieldDescriptor(new Modifiers(Modifiers.PUBLIC), td, arrayElementFieldName, null,
2435 mapTypeToArrayField.put(td, fd);
2440 private void merge(Set<NTuple<Descriptor>> curr, Set<NTuple<Descriptor>> in) {
2441 if (curr.isEmpty()) {
2442 // set has a special initial value which covers all possible
2444 // For the first time of intersection, we can take all previous set
2447 // otherwise, current set is the intersection of the two sets
2453 // combine two heap path
2454 private NTuple<Descriptor> combine(NTuple<Descriptor> callerIn, NTuple<Descriptor> calleeIn) {
2455 NTuple<Descriptor> combined = new NTuple<Descriptor>();
2457 for (int i = 0; i < callerIn.size(); i++) {
2458 combined.add(callerIn.get(i));
2461 // the first element of callee's heap path represents parameter
2462 // so we skip the first one since it is already added from caller's heap
2464 for (int i = 1; i < calleeIn.size(); i++) {
2465 combined.add(calleeIn.get(i));
2471 private Set<NTuple<Descriptor>> bindSet(Set<NTuple<Descriptor>> calleeSet,
2472 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc,
2473 Hashtable<Integer, NTuple<Descriptor>> mapCallerArgIdx2HeapPath) {
2475 Set<NTuple<Descriptor>> boundedCalleeSet = new HashSet<NTuple<Descriptor>>();
2477 Set<Integer> keySet = mapCallerArgIdx2HeapPath.keySet();
2478 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2479 Integer idx = (Integer) iterator.next();
2481 NTuple<Descriptor> callerArgHeapPath = mapCallerArgIdx2HeapPath.get(idx);
2482 TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
2483 for (Iterator iterator2 = calleeSet.iterator(); iterator2.hasNext();) {
2484 NTuple<Descriptor> element = (NTuple<Descriptor>) iterator2.next();
2485 if (element.startsWith(calleeParam)) {
2486 NTuple<Descriptor> boundElement = combine(callerArgHeapPath, element);
2487 boundedCalleeSet.add(boundElement);
2493 return boundedCalleeSet;
2497 // Borrowed it from disjoint analysis
2498 private LinkedList<MethodDescriptor> topologicalSort(Set<MethodDescriptor> toSort) {
2500 Set<MethodDescriptor> discovered = new HashSet<MethodDescriptor>();
2502 LinkedList<MethodDescriptor> sorted = new LinkedList<MethodDescriptor>();
2504 Iterator<MethodDescriptor> itr = toSort.iterator();
2505 while (itr.hasNext()) {
2506 MethodDescriptor d = itr.next();
2508 if (!discovered.contains(d)) {
2509 dfsVisit(d, toSort, sorted, discovered);
2516 // While we're doing DFS on call graph, remember
2517 // dependencies for efficient queuing of methods
2518 // during interprocedural analysis:
2520 // a dependent of a method decriptor d for this analysis is:
2521 // 1) a method or task that invokes d
2522 // 2) in the descriptorsToAnalyze set
2523 private void dfsVisit(MethodDescriptor md, Set<MethodDescriptor> toSort,
2524 LinkedList<MethodDescriptor> sorted, Set<MethodDescriptor> discovered) {
2528 Iterator itr = callGraph.getCallerSet(md).iterator();
2529 while (itr.hasNext()) {
2530 MethodDescriptor dCaller = (MethodDescriptor) itr.next();
2531 // only consider callers in the original set to analyze
2532 if (!toSort.contains(dCaller)) {
2535 if (!discovered.contains(dCaller)) {
2536 addDependent(md, // callee
2540 dfsVisit(dCaller, toSort, sorted, discovered);
2544 // for leaf-nodes last now!
2548 // a dependent of a method decriptor d for this analysis is:
2549 // 1) a method or task that invokes d
2550 // 2) in the descriptorsToAnalyze set
2551 private void addDependent(MethodDescriptor callee, MethodDescriptor caller) {
2552 Set<MethodDescriptor> deps = mapDescriptorToSetDependents.get(callee);
2554 deps = new HashSet<MethodDescriptor>();
2557 mapDescriptorToSetDependents.put(callee, deps);
2560 private Set<MethodDescriptor> getDependents(MethodDescriptor callee) {
2561 Set<MethodDescriptor> deps = mapDescriptorToSetDependents.get(callee);
2563 deps = new HashSet<MethodDescriptor>();
2564 mapDescriptorToSetDependents.put(callee, deps);
2569 private NTuple<Descriptor> computePath(Descriptor td) {
2570 // generate proper path fot input td
2571 // if td is local variable, it just generate one element tuple path
2572 if (mapHeapPath.containsKey(td)) {
2573 NTuple<Descriptor> rtrHeapPath = new NTuple<Descriptor>();
2574 rtrHeapPath.addAll(mapHeapPath.get(td));
2577 NTuple<Descriptor> rtrHeapPath = new NTuple<Descriptor>();
2578 rtrHeapPath.add(td);
2583 private NTuple<Location> deriveThisLocationTuple(MethodDescriptor md) {
2584 String thisLocIdentifier = ssjava.getMethodLattice(md).getThisLoc();
2585 Location thisLoc = new Location(md, thisLocIdentifier);
2586 NTuple<Location> locTuple = new NTuple<Location>();
2587 locTuple.add(thisLoc);
2591 private NTuple<Location> deriveGlobalLocationTuple(MethodDescriptor md) {
2592 String globalLocIdentifier = ssjava.getMethodLattice(md).getGlobalLoc();
2593 Location globalLoc = new Location(md, globalLocIdentifier);
2594 NTuple<Location> locTuple = new NTuple<Location>();
2595 locTuple.add(globalLoc);
2599 private NTuple<Location> deriveLocationTuple(MethodDescriptor md, TempDescriptor td) {
2601 assert td.getType() != null;
2603 if (mapDescriptorToLocationPath.containsKey(td)) {
2604 NTuple<Location> locPath = mapDescriptorToLocationPath.get(td);
2605 NTuple<Location> rtrPath = new NTuple<Location>();
2606 rtrPath.addAll(locPath);
2609 if (td.getSymbol().startsWith("this")) {
2610 NTuple<Location> thisPath = deriveThisLocationTuple(md);
2611 NTuple<Location> rtrPath = new NTuple<Location>();
2612 rtrPath.addAll(thisPath);
2616 if (td.getType().getExtension() != null) {
2617 SSJavaType ssJavaType = (SSJavaType) td.getType().getExtension();
2618 if (ssJavaType.getCompLoc() != null) {
2619 NTuple<Location> rtrPath = new NTuple<Location>();
2620 rtrPath.addAll(ssJavaType.getCompLoc().getTuple());