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 // arg idx is starting from 'this' arg
937 if (fc.getThis() != null) {
938 // loc path for 'this'
939 NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
940 if (thisLocationPath != null) {
941 mapArgIdx2CallerArgLocationPath.put(Integer.valueOf(0), thisLocationPath);
943 // heap path for 'this'
944 NTuple<Descriptor> thisHeapPath = new NTuple<Descriptor>();
945 if (mapHeapPath.containsKey(fc.getThis())) {
946 thisHeapPath.addAll(mapHeapPath.get(fc.getThis()));
948 // method is called without creating new flat node representing
950 thisHeapPath.add(fc.getThis());
952 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
956 for (int i = 0; i < fc.numArgs(); i++) {
957 TempDescriptor arg = fc.getArg(i);
958 // create mapping arg to loc path
959 NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
960 if (argLocationPath != null) {
961 mapArgIdx2CallerArgLocationPath.put(Integer.valueOf(i + 1), argLocationPath);
962 // create mapping arg to heap path
963 NTuple<Descriptor> argHeapPath = computePath(arg);
964 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
969 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
970 MethodDescriptor callee = (MethodDescriptor) iterator.next();
971 FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
973 // binding caller's args and callee's params
975 Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath =
976 new Hashtable<NTuple<Descriptor>, NTuple<Descriptor>>();
978 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
979 new Hashtable<Integer, TempDescriptor>();
981 if (calleeFlatMethod.getMethod().isStatic()) {
982 // static method does not have implicit 'this' arg
986 for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
987 TempDescriptor param = calleeFlatMethod.getParameter(i);
988 mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
990 NTuple<Descriptor> calleeHeapPath = computePath(param);
992 NTuple<Descriptor> argHeapPath =
993 mapArgIdx2CallerArgHeapPath.get(Integer.valueOf(i + offset));
995 if (argHeapPath != null) {
996 mapParamHeapPathToCallerArgHeapPath.put(calleeHeapPath, argHeapPath);
1002 Set<Integer> keySet = mapArgIdx2CallerArgLocationPath.keySet();
1003 for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
1004 Integer idx = (Integer) iterator2.next();
1006 NTuple<Location> callerArgLocationPath = mapArgIdx2CallerArgLocationPath.get(idx);
1008 TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
1009 NTuple<Location> calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam);
1011 NTuple<Descriptor> callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx);
1012 NTuple<Descriptor> calleeHeapPath = computePath(calleeParam);
1014 if (!calleeParam.getType().isPrimitive()) {
1015 createNewMappingOfMayWrittenSet(mdCaller, callee, callerArgHeapPath,
1016 callerArgLocationPath, calleeHeapPath, calleeLocationPath,
1017 mapParamHeapPathToCallerArgHeapPath);
1027 private Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> getMappingByStartedWith(
1028 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> map, NTuple<Location> in) {
1030 Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> matchedMapping =
1031 new Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>>();
1033 Set<NTuple<Location>> keySet = map.keySet();
1035 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1036 NTuple<Location> key = (NTuple<Location>) iterator.next();
1037 if (key.startsWith(in)) {
1038 matchedMapping.put(key, map.get(key));
1042 return matchedMapping;
1046 private void createNewMappingOfMayWrittenSet(MethodDescriptor caller, MethodDescriptor callee,
1047 NTuple<Descriptor> callerArgHeapPath, NTuple<Location> callerArgLocPath,
1048 NTuple<Descriptor> calleeParamHeapPath, NTuple<Location> calleeParamLocPath,
1049 Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath) {
1051 // propagate may-written-set associated with the key that is started with
1052 // calleepath to the caller
1053 // 1) makes a new key by combining caller path and callee path(except local
1054 // loc element of param)
1055 // 2) create new mapping of may-written-set of callee path to caller path
1057 // extract all may written effect accessed through callee param path
1058 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> calleeMapping =
1059 mapMethodToSharedLocCoverSet.get(callee);
1061 if (calleeMapping == null) {
1065 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> callerMapping =
1066 mapMethodToSharedLocCoverSet.get(caller);
1068 if (callerMapping == null) {
1069 callerMapping = new MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>();
1070 mapMethodToSharedLocCoverSet.put(caller, callerMapping);
1073 Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> paramMapping =
1074 getMappingByStartedWith(calleeMapping, calleeParamLocPath);
1076 Set<NTuple<Location>> calleeKeySet = paramMapping.keySet();
1078 for (Iterator iterator = calleeKeySet.iterator(); iterator.hasNext();) {
1079 NTuple<Location> calleeKey = (NTuple<Location>) iterator.next();
1081 Set<NTuple<Descriptor>> calleeMayWriteSet = paramMapping.get(calleeKey);
1083 if (calleeMayWriteSet != null) {
1085 Set<NTuple<Descriptor>> boundMayWriteSet = new HashSet<NTuple<Descriptor>>();
1087 Set<NTuple<Descriptor>> boundSet =
1088 convertToCallerMayWriteSet(calleeParamHeapPath, calleeMayWriteSet, callerMapping,
1089 mapParamHeapPathToCallerArgHeapPath);
1091 boundMayWriteSet.addAll(boundSet);
1093 NTuple<Location> newKey = new NTuple<Location>();
1094 newKey.addAll(callerArgLocPath);
1095 // need to replace the local location with the caller's path so skip the
1096 // local location of the parameter
1097 for (int i = 1; i < calleeKey.size(); i++) {
1098 newKey.add(calleeKey.get(i));
1101 callerMapping.union(newKey, boundMayWriteSet);
1108 private Set<NTuple<Descriptor>> convertToCallerMayWriteSet(
1109 NTuple<Descriptor> calleeParamHeapPath, Set<NTuple<Descriptor>> calleeMayWriteSet,
1110 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> callerMapping,
1111 Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath) {
1113 Set<NTuple<Descriptor>> boundSet = new HashSet<NTuple<Descriptor>>();
1115 // replace callee's param path with caller's arg path
1116 for (Iterator iterator = calleeMayWriteSet.iterator(); iterator.hasNext();) {
1117 NTuple<Descriptor> calleeWriteHeapPath = (NTuple<Descriptor>) iterator.next();
1119 NTuple<Descriptor> writeHeapPathParamHeapPath = calleeWriteHeapPath.subList(0, 1);
1121 NTuple<Descriptor> callerArgHeapPath =
1122 mapParamHeapPathToCallerArgHeapPath.get(writeHeapPathParamHeapPath);
1124 NTuple<Descriptor> boundHeapPath = new NTuple<Descriptor>();
1125 boundHeapPath.addAll(callerArgHeapPath);
1127 for (int i = 1; i < calleeWriteHeapPath.size(); i++) {
1128 boundHeapPath.add(calleeWriteHeapPath.get(i));
1131 boundSet.add(boundHeapPath);
1138 private Location getLocation(Descriptor d) {
1140 if (d instanceof FieldDescriptor) {
1141 TypeExtension te = ((FieldDescriptor) d).getType().getExtension();
1143 return (Location) te;
1146 assert d instanceof TempDescriptor;
1147 TempDescriptor td = (TempDescriptor) d;
1149 TypeExtension te = td.getType().getExtension();
1151 if (te instanceof SSJavaType) {
1152 SSJavaType ssType = (SSJavaType) te;
1153 if (ssType.getCompLoc() != null) {
1154 CompositeLocation comp = ssType.getCompLoc();
1155 return comp.get(comp.getSize() - 1);
1160 return (Location) te;
1165 return mapDescToLocation.get(d);
1168 private void eventLoopAnalysis() {
1169 // perform second stage analysis: intraprocedural analysis ensure that
1171 // variables are definitely written in-between the same read
1173 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
1174 flatNodesToVisit.add(ssjava.getSSJavaLoopEntrance());
1176 while (!flatNodesToVisit.isEmpty()) {
1177 FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
1178 flatNodesToVisit.remove(fn);
1180 Hashtable<NTuple<Descriptor>, Set<WriteAge>> prev = mapFlatNodetoEventLoopMap.get(fn);
1182 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr =
1183 new Hashtable<NTuple<Descriptor>, Set<WriteAge>>();
1184 for (int i = 0; i < fn.numPrev(); i++) {
1185 FlatNode nn = fn.getPrev(i);
1186 Hashtable<NTuple<Descriptor>, Set<WriteAge>> in = mapFlatNodetoEventLoopMap.get(nn);
1192 eventLoopAnalysis_nodeAction(fn, curr, ssjava.getSSJavaLoopEntrance());
1194 // if a new result, schedule forward nodes for analysis
1195 if (!curr.equals(prev)) {
1196 mapFlatNodetoEventLoopMap.put(fn, curr);
1198 for (int i = 0; i < fn.numNext(); i++) {
1199 FlatNode nn = fn.getNext(i);
1200 if (loopIncElements.contains(nn)) {
1201 flatNodesToVisit.add(nn);
1209 private void union(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1210 Hashtable<NTuple<Descriptor>, Set<WriteAge>> in) {
1212 Set<NTuple<Descriptor>> inKeySet = in.keySet();
1213 for (Iterator iterator = inKeySet.iterator(); iterator.hasNext();) {
1214 NTuple<Descriptor> inKey = (NTuple<Descriptor>) iterator.next();
1215 Set<WriteAge> inSet = in.get(inKey);
1217 Set<WriteAge> currSet = curr.get(inKey);
1219 if (currSet == null) {
1220 currSet = new HashSet<WriteAge>();
1221 curr.put(inKey, currSet);
1223 currSet.addAll(inSet);
1228 private void eventLoopAnalysis_nodeAction(FlatNode fn,
1229 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, FlatNode loopEntrance) {
1231 Hashtable<NTuple<Descriptor>, Set<WriteAge>> readWriteKillSet =
1232 new Hashtable<NTuple<Descriptor>, Set<WriteAge>>();
1233 Hashtable<NTuple<Descriptor>, Set<WriteAge>> readWriteGenSet =
1234 new Hashtable<NTuple<Descriptor>, Set<WriteAge>>();
1236 if (fn.equals(loopEntrance)) {
1237 // it reaches loop entrance: changes all flag to true
1238 Set<NTuple<Descriptor>> keySet = curr.keySet();
1239 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1240 NTuple<Descriptor> key = (NTuple<Descriptor>) iterator.next();
1241 Set<WriteAge> writeAgeSet = curr.get(key);
1243 Set<WriteAge> incSet = new HashSet<WriteAge>();
1244 incSet.addAll(writeAgeSet);
1245 writeAgeSet.clear();
1247 for (Iterator iterator2 = incSet.iterator(); iterator2.hasNext();) {
1248 WriteAge writeAge = (WriteAge) iterator2.next();
1249 WriteAge newWriteAge = writeAge.copy();
1251 writeAgeSet.add(newWriteAge);
1259 FieldDescriptor fld;
1261 switch (fn.kind()) {
1263 case FKind.FlatOpNode: {
1264 FlatOpNode fon = (FlatOpNode) fn;
1265 lhs = fon.getDest();
1266 rhs = fon.getLeft();
1268 if (fon.getOp().getOp() == Operation.ASSIGN) {
1270 if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop")
1271 && !lhs.getSymbol().startsWith("rightop")) {
1273 boolean hasWriteEffect = false;
1275 if (rhs.getType().getExtension() instanceof SSJavaType
1276 && lhs.getType().getExtension() instanceof SSJavaType) {
1278 CompositeLocation rhsCompLoc =
1279 ((SSJavaType) rhs.getType().getExtension()).getCompLoc();
1281 CompositeLocation lhsCompLoc =
1282 ((SSJavaType) lhs.getType().getExtension()).getCompLoc();
1284 if (lhsCompLoc != rhsCompLoc) {
1285 // have a write effect!
1286 hasWriteEffect = true;
1289 } else if (lhs.getType().isImmutable()) {
1290 hasWriteEffect = true;
1293 if (hasWriteEffect) {
1295 NTuple<Descriptor> rhsHeapPath = computePath(rhs);
1296 NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
1297 lhsHeapPath.addAll(rhsHeapPath);
1299 Location lhsLoc = getLocation(lhs);
1300 if (ssjava.isSharedLocation(lhsLoc)) {
1302 NTuple<Descriptor> varHeapPath = computePath(lhs);
1303 NTuple<Location> varLocTuple = mapDescriptorToLocationPath.get(lhs);
1305 Set<NTuple<Descriptor>> writtenSet =
1306 mapFlatNodeToSharedLocMapping.get(fn).get(varLocTuple);
1308 if (isCovered(varLocTuple, writtenSet)) {
1309 computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet);
1310 computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet);
1312 computeGENSetForSharedNonCoverWrite(curr, varHeapPath, readWriteGenSet);
1317 computeKILLSetForWrite(curr, lhsHeapPath, readWriteKillSet);
1318 computeGENSetForWrite(lhsHeapPath, readWriteGenSet);
1321 // System.out.println("write effect on =" + lhsHeapPath);
1322 // System.out.println("#KILLSET=" + readWriteKillSet);
1323 // System.out.println("#GENSet=" + readWriteGenSet + "\n");
1325 Set<WriteAge> writeAgeSet = curr.get(lhsHeapPath);
1326 checkWriteAgeSet(writeAgeSet, lhsHeapPath, fn);
1336 case FKind.FlatFieldNode:
1337 case FKind.FlatElementNode: {
1339 if (fn.kind() == FKind.FlatFieldNode) {
1340 FlatFieldNode ffn = (FlatFieldNode) fn;
1343 fld = ffn.getField();
1345 FlatElementNode fen = (FlatElementNode) fn;
1348 TypeDescriptor td = rhs.getType().dereference();
1349 fld = getArrayField(td);
1353 NTuple<Descriptor> srcHeapPath = mapHeapPath.get(rhs);
1354 NTuple<Descriptor> fldHeapPath;
1355 if (srcHeapPath != null) {
1356 fldHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
1358 // if srcHeapPath is null, it is static reference
1359 fldHeapPath = new NTuple<Descriptor>();
1360 fldHeapPath.add(rhs);
1362 fldHeapPath.add(fld);
1364 Set<WriteAge> writeAgeSet = curr.get(fldHeapPath);
1366 checkWriteAgeSet(writeAgeSet, fldHeapPath, fn);
1371 case FKind.FlatSetFieldNode:
1372 case FKind.FlatSetElementNode: {
1374 if (fn.kind() == FKind.FlatSetFieldNode) {
1375 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
1376 lhs = fsfn.getDst();
1377 fld = fsfn.getField();
1379 FlatSetElementNode fsen = (FlatSetElementNode) fn;
1380 lhs = fsen.getDst();
1381 rhs = fsen.getSrc();
1382 TypeDescriptor td = lhs.getType().dereference();
1383 fld = getArrayField(td);
1387 NTuple<Descriptor> lhsHeapPath = computePath(lhs);
1388 NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
1389 if (fn.kind() == FKind.FlatSetFieldNode) {
1390 fldHeapPath.add(fld);
1393 // shared loc extension
1395 if (fn.kind() == FKind.FlatSetFieldNode) {
1396 fieldLoc = (Location) fld.getType().getExtension();
1398 NTuple<Location> locTuple = mapDescriptorToLocationPath.get(lhs);
1399 fieldLoc = locTuple.get(locTuple.size() - 1);
1402 if (ssjava.isSharedLocation(fieldLoc)) {
1404 NTuple<Location> fieldLocTuple = new NTuple<Location>();
1405 fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs));
1406 if (fn.kind() == FKind.FlatSetFieldNode) {
1407 fieldLocTuple.add(fieldLoc);
1410 Set<NTuple<Descriptor>> writtenSet =
1411 mapFlatNodeToSharedLocMapping.get(fn).get(fieldLocTuple);
1413 if (isCovered(fieldLocTuple, writtenSet)) {
1414 computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet);
1415 computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet);
1417 computeGENSetForSharedNonCoverWrite(curr, fldHeapPath, readWriteGenSet);
1421 computeKILLSetForWrite(curr, fldHeapPath, readWriteKillSet);
1422 computeGENSetForWrite(fldHeapPath, readWriteGenSet);
1425 // System.out.println("KILLSET=" + readWriteKillSet);
1426 // System.out.println("GENSet=" + readWriteGenSet);
1431 case FKind.FlatCall: {
1432 FlatCall fc = (FlatCall) fn;
1434 SharedLocMap sharedLocMap = mapFlatNodeToSharedLocMapping.get(fc);
1435 // System.out.println("FLATCALL:" + fn);
1436 generateKILLSetForFlatCall(fc, curr, sharedLocMap, readWriteKillSet);
1437 generateGENSetForFlatCall(fc, sharedLocMap, readWriteGenSet);
1439 // System.out.println("KILLSET=" + readWriteKillSet);
1440 // System.out.println("GENSet=" + readWriteGenSet);
1442 checkManyRead(fc, curr);
1448 computeNewMapping(curr, readWriteKillSet, readWriteGenSet);
1449 // System.out.println("#######" + curr);
1455 private void computeGENSetForSharedNonCoverWrite(
1456 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, NTuple<Descriptor> heapPath,
1457 Hashtable<NTuple<Descriptor>, Set<WriteAge>> genSet) {
1459 Set<WriteAge> writeAgeSet = genSet.get(heapPath);
1460 if (writeAgeSet == null) {
1461 writeAgeSet = new HashSet<WriteAge>();
1462 genSet.put(heapPath, writeAgeSet);
1465 writeAgeSet.add(new WriteAge(1));
1469 private void computeGENSetForSharedAllCoverWrite(
1470 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, Set<NTuple<Descriptor>> writtenSet,
1471 Hashtable<NTuple<Descriptor>, Set<WriteAge>> genSet) {
1473 for (Iterator iterator = writtenSet.iterator(); iterator.hasNext();) {
1474 NTuple<Descriptor> writeHeapPath = (NTuple<Descriptor>) iterator.next();
1476 Set<WriteAge> writeAgeSet = new HashSet<WriteAge>();
1477 writeAgeSet.add(new WriteAge(0));
1479 genSet.put(writeHeapPath, writeAgeSet);
1484 private void computeKILLSetForSharedWrite(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1485 Set<NTuple<Descriptor>> writtenSet, Hashtable<NTuple<Descriptor>, Set<WriteAge>> killSet) {
1487 for (Iterator iterator = writtenSet.iterator(); iterator.hasNext();) {
1488 NTuple<Descriptor> writeHeapPath = (NTuple<Descriptor>) iterator.next();
1489 Set<WriteAge> writeSet = curr.get(writeHeapPath);
1490 if (writeSet != null) {
1491 killSet.put(writeHeapPath, writeSet);
1497 private boolean isCovered(NTuple<Location> locTuple, Set<NTuple<Descriptor>> inSet) {
1499 if (inSet == null) {
1503 Set<NTuple<Descriptor>> coverSet =
1504 mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locTuple);
1506 return inSet.containsAll(coverSet);
1509 private void checkManyRead(FlatCall fc, Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr) {
1511 Set<NTuple<Descriptor>> boundReadSet = mapFlatNodeToBoundReadSet.get(fc);
1513 for (Iterator iterator = boundReadSet.iterator(); iterator.hasNext();) {
1514 NTuple<Descriptor> readHeapPath = (NTuple<Descriptor>) iterator.next();
1515 Set<WriteAge> writeAgeSet = curr.get(readHeapPath);
1516 checkWriteAgeSet(writeAgeSet, readHeapPath, fc);
1521 private void checkWriteAgeSet(Set<WriteAge> writeAgeSet, NTuple<Descriptor> path, FlatNode fn) {
1523 // System.out.println("# CHECK WRITE AGE of " + path + " from set=" +
1526 if (writeAgeSet != null) {
1527 for (Iterator iterator = writeAgeSet.iterator(); iterator.hasNext();) {
1528 WriteAge writeAge = (WriteAge) iterator.next();
1529 if (writeAge.getAge() > MAXAGE) {
1530 generateErrorMessage(path, fn);
1536 private void generateErrorMessage(NTuple<Descriptor> path, FlatNode fn) {
1538 Descriptor lastDesc = path.get(getArrayBaseDescriptorIdx(path));
1539 if (ssjava.isSharedLocation(getLocation(lastDesc))) {
1541 NTuple<Location> locPathTuple = getLocationTuple(path);
1542 Set<NTuple<Descriptor>> coverSet =
1543 mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locPathTuple);
1544 throw new Error("Shared memory locations, which is reachable through references " + path
1545 + ", are not completely overwritten by the higher values at "
1546 + methodContainingSSJavaLoop.getClassDesc().getSourceFileName() + "::" + fn.getNumLine()
1547 + ".\nThe following memory locations belong to the same shared locations:" + coverSet);
1551 "Memory location, which is reachable through references "
1553 + ", who comes back to the same read statement without being overwritten at the out-most iteration at "
1554 + methodContainingSSJavaLoop.getClassDesc().getSourceFileName() + "::"
1560 private void generateGENSetForFlatCall(FlatCall fc, SharedLocMap sharedLocMap,
1561 Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
1563 Set<NTuple<Descriptor>> boundMayWriteSet = mapFlatNodeToBoundMayWriteSet.get(fc);
1564 // System.out.println("boundMayWriteSet=" + boundMayWriteSet);
1566 for (Iterator iterator = boundMayWriteSet.iterator(); iterator.hasNext();) {
1567 NTuple<Descriptor> heapPath = (NTuple<Descriptor>) iterator.next();
1569 if (!isSharedLocation(heapPath)) {
1570 addWriteAgeToSet(heapPath, GENSet, new WriteAge(0));
1572 // if the current heap path is shared location
1574 NTuple<Location> locTuple = getLocationTuple(heapPath);
1576 Set<NTuple<Descriptor>> sharedWriteHeapPathSet = sharedLocMap.get(locTuple);
1578 if (isCovered(locTuple, sharedLocMap.get(locTuple))) {
1579 // if it is covered, add all of heap paths belong to the same shared
1580 // loc with write age 0
1582 for (Iterator iterator2 = sharedWriteHeapPathSet.iterator(); iterator2.hasNext();) {
1583 NTuple<Descriptor> sharedHeapPath = (NTuple<Descriptor>) iterator2.next();
1584 addWriteAgeToSet(sharedHeapPath, GENSet, new WriteAge(0));
1588 // if not covered, add write age 1 to the heap path that is
1589 // may-written but not covered
1590 addWriteAgeToSet(heapPath, GENSet, new WriteAge(1));
1599 private void addWriteAgeToSet(NTuple<Descriptor> heapPath,
1600 Hashtable<NTuple<Descriptor>, Set<WriteAge>> map, WriteAge age) {
1602 Set<WriteAge> currSet = map.get(heapPath);
1603 if (currSet == null) {
1604 currSet = new HashSet<WriteAge>();
1605 map.put(heapPath, currSet);
1611 private void generateKILLSetForFlatCall(FlatCall fc,
1612 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, SharedLocMap sharedLocMap,
1613 Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet) {
1615 Set<NTuple<Descriptor>> boundMustWriteSet = mapFlatNodeToBoundMustWriteSet.get(fc);
1616 System.out.println("boundMustWriteSet=" + boundMustWriteSet);
1618 for (Iterator iterator = boundMustWriteSet.iterator(); iterator.hasNext();) {
1619 NTuple<Descriptor> heapPath = (NTuple<Descriptor>) iterator.next();
1621 if (isSharedLocation(heapPath)) {
1622 NTuple<Location> locTuple = getLocationTuple(heapPath);
1624 if (isCovered(locTuple, sharedLocMap.get(locTuple))) {
1625 // if it is shared loc and corresponding shared loc has been covered
1626 KILLSet.put(heapPath, curr.get(heapPath));
1630 for (Enumeration<NTuple<Descriptor>> e = curr.keys(); e.hasMoreElements();) {
1631 NTuple<Descriptor> key = e.nextElement();
1632 if (key.startsWith(heapPath)) {
1633 KILLSet.put(key, curr.get(key));
1643 private int getArrayBaseDescriptorIdx(NTuple<Descriptor> heapPath) {
1645 for (int i = heapPath.size() - 1; i >= 0; i--) {
1646 if (!heapPath.get(i).getSymbol().equals(arrayElementFieldName)) {
1655 private boolean isSharedLocation(NTuple<Descriptor> heapPath) {
1657 Descriptor d = heapPath.get(getArrayBaseDescriptorIdx(heapPath));
1659 return ssjava.isSharedLocation(getLocation(heapPath.get(getArrayBaseDescriptorIdx(heapPath))));
1663 private NTuple<Location> getLocationTuple(NTuple<Descriptor> heapPath) {
1665 NTuple<Location> locTuple = new NTuple<Location>();
1667 locTuple.addAll(mapDescriptorToLocationPath.get(heapPath.get(0)));
1669 for (int i = 1; i <= getArrayBaseDescriptorIdx(heapPath); i++) {
1670 locTuple.add(getLocation(heapPath.get(i)));
1676 private void computeNewMapping(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1677 Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet,
1678 Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
1680 for (Enumeration<NTuple<Descriptor>> e = KILLSet.keys(); e.hasMoreElements();) {
1681 NTuple<Descriptor> key = e.nextElement();
1683 Set<WriteAge> writeAgeSet = curr.get(key);
1684 if (writeAgeSet == null) {
1685 writeAgeSet = new HashSet<WriteAge>();
1686 curr.put(key, writeAgeSet);
1688 writeAgeSet.removeAll(KILLSet.get(key));
1691 for (Enumeration<NTuple<Descriptor>> e = GENSet.keys(); e.hasMoreElements();) {
1692 NTuple<Descriptor> key = e.nextElement();
1694 Set<WriteAge> currWriteAgeSet = curr.get(key);
1695 if (currWriteAgeSet == null) {
1696 currWriteAgeSet = new HashSet<WriteAge>();
1697 curr.put(key, currWriteAgeSet);
1699 currWriteAgeSet.addAll(GENSet.get(key));
1704 private void computeGENSetForWrite(NTuple<Descriptor> fldHeapPath,
1705 Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
1707 // generate write age 0 for the field being written to
1708 Set<WriteAge> writeAgeSet = new HashSet<WriteAge>();
1709 writeAgeSet.add(new WriteAge(0));
1710 GENSet.put(fldHeapPath, writeAgeSet);
1714 private void computeKILLSetForWrite(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1715 NTuple<Descriptor> hp, Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet) {
1717 // removes all of heap path that starts with prefix 'hp'
1718 // since any reference overwrite along heap path gives overwriting side
1719 // effects on the value
1721 Set<NTuple<Descriptor>> keySet = curr.keySet();
1722 for (Iterator<NTuple<Descriptor>> iter = keySet.iterator(); iter.hasNext();) {
1723 NTuple<Descriptor> key = iter.next();
1724 if (key.startsWith(hp)) {
1725 KILLSet.put(key, curr.get(key));
1731 private void bindHeapPathCallerArgWithCalleeParam(FlatCall fc) {
1732 // compute all possible callee set
1733 // transform all READ/WRITE set from the any possible
1734 // callees to the caller
1735 calleeUnionBoundReadSet.clear();
1736 calleeIntersectBoundMustWriteSet.clear();
1737 calleeUnionBoundMayWriteSet.clear();
1739 if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
1740 // ssjava util case!
1741 // have write effects on the first argument
1742 TempDescriptor arg = fc.getArg(0);
1743 NTuple<Descriptor> argHeapPath = computePath(arg);
1744 calleeIntersectBoundMustWriteSet.add(argHeapPath);
1745 calleeUnionBoundMayWriteSet.add(argHeapPath);
1747 MethodDescriptor mdCallee = fc.getMethod();
1748 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
1749 setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
1751 // create mapping from arg idx to its heap paths
1752 Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
1753 new Hashtable<Integer, NTuple<Descriptor>>();
1755 // arg idx is starting from 'this' arg
1756 if (fc.getThis() != null) {
1757 NTuple<Descriptor> thisHeapPath = mapHeapPath.get(fc.getThis());
1758 if (thisHeapPath == null) {
1759 // method is called without creating new flat node representing 'this'
1760 thisHeapPath = new NTuple<Descriptor>();
1761 thisHeapPath.add(fc.getThis());
1764 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
1767 for (int i = 0; i < fc.numArgs(); i++) {
1768 TempDescriptor arg = fc.getArg(i);
1769 NTuple<Descriptor> argHeapPath = computePath(arg);
1770 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
1773 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
1774 MethodDescriptor callee = (MethodDescriptor) iterator.next();
1775 FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
1777 // binding caller's args and callee's params
1779 Set<NTuple<Descriptor>> calleeReadSet = mapFlatMethodToReadSet.get(calleeFlatMethod);
1780 if (calleeReadSet == null) {
1781 calleeReadSet = new HashSet<NTuple<Descriptor>>();
1782 mapFlatMethodToReadSet.put(calleeFlatMethod, calleeReadSet);
1785 Set<NTuple<Descriptor>> calleeMustWriteSet =
1786 mapFlatMethodToMustWriteSet.get(calleeFlatMethod);
1788 if (calleeMustWriteSet == null) {
1789 calleeMustWriteSet = new HashSet<NTuple<Descriptor>>();
1790 mapFlatMethodToMustWriteSet.put(calleeFlatMethod, calleeMustWriteSet);
1793 Set<NTuple<Descriptor>> calleeMayWriteSet =
1794 mapFlatMethodToMayWriteSet.get(calleeFlatMethod);
1796 if (calleeMayWriteSet == null) {
1797 calleeMayWriteSet = new HashSet<NTuple<Descriptor>>();
1798 mapFlatMethodToMayWriteSet.put(calleeFlatMethod, calleeMayWriteSet);
1801 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
1802 new Hashtable<Integer, TempDescriptor>();
1804 if (calleeFlatMethod.getMethod().isStatic()) {
1805 // static method does not have implicit 'this' arg
1808 for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
1809 TempDescriptor param = calleeFlatMethod.getParameter(i);
1810 mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
1813 Set<NTuple<Descriptor>> calleeBoundReadSet =
1814 bindSet(calleeReadSet, mapParamIdx2ParamTempDesc, mapArgIdx2CallerArgHeapPath);
1815 // union of the current read set and the current callee's
1817 calleeUnionBoundReadSet.addAll(calleeBoundReadSet);
1819 Set<NTuple<Descriptor>> calleeBoundMustWriteSet =
1820 bindSet(calleeMustWriteSet, mapParamIdx2ParamTempDesc, mapArgIdx2CallerArgHeapPath);
1821 // intersection of the current overwrite set and the current
1824 merge(calleeIntersectBoundMustWriteSet, calleeBoundMustWriteSet);
1826 Set<NTuple<Descriptor>> boundWriteSetFromCallee =
1827 bindSet(calleeMayWriteSet, mapParamIdx2ParamTempDesc, mapArgIdx2CallerArgHeapPath);
1828 calleeUnionBoundMayWriteSet.addAll(boundWriteSetFromCallee);
1835 private void bindHeapPathCallerArgWithCaleeParamForSharedLoc(MethodDescriptor mdCaller,
1838 calleeIntersectBoundSharedSet.clear();
1839 calleeUnionBoundDeleteSet.clear();
1841 if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
1842 // ssjava util case!
1843 // have write effects on the first argument
1844 TempDescriptor arg = fc.getArg(0);
1845 NTuple<Descriptor> argHeapPath = computePath(arg);
1847 // convert heap path to location path
1848 NTuple<Location> argLocTuple = new NTuple<Location>();
1849 argLocTuple.addAll(deriveLocationTuple(mdCaller, (TempDescriptor) argHeapPath.get(0)));
1850 for (int i = 1; i < argHeapPath.size(); i++) {
1851 argLocTuple.add(getLocation(argHeapPath.get(i)));
1854 calleeIntersectBoundSharedSet.addWrite(argLocTuple, argHeapPath);
1856 } else if (ssjava.needTobeAnnotated(fc.getMethod())) {
1858 // if arg is not primitive type, we need to propagate maywritten set to
1859 // the caller's location path
1861 MethodDescriptor mdCallee = fc.getMethod();
1862 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
1863 setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
1865 // create mapping from arg idx to its heap paths
1866 Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
1867 new Hashtable<Integer, NTuple<Descriptor>>();
1869 // arg idx is starting from 'this' arg
1870 if (fc.getThis() != null) {
1871 NTuple<Descriptor> thisHeapPath = mapHeapPath.get(fc.getThis());
1872 if (thisHeapPath == null) {
1873 // method is called without creating new flat node representing 'this'
1874 thisHeapPath = new NTuple<Descriptor>();
1875 thisHeapPath.add(fc.getThis());
1878 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
1881 for (int i = 0; i < fc.numArgs(); i++) {
1882 TempDescriptor arg = fc.getArg(i);
1883 NTuple<Descriptor> argHeapPath = computePath(arg);
1884 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
1887 // create mapping from arg idx to its location paths
1888 Hashtable<Integer, NTuple<Location>> mapArgIdx2CallerAgLocationPath =
1889 new Hashtable<Integer, NTuple<Location>>();
1891 // arg idx is starting from 'this' arg
1892 if (fc.getThis() != null) {
1893 NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
1894 if (thisLocationPath != null) {
1895 mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath);
1899 for (int i = 0; i < fc.numArgs(); i++) {
1900 TempDescriptor arg = fc.getArg(i);
1901 NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
1902 if (argLocationPath != null) {
1903 mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(i + 1), argLocationPath);
1907 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
1908 MethodDescriptor callee = (MethodDescriptor) iterator.next();
1909 FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
1911 // binding caller's args and callee's params
1913 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
1914 new Hashtable<Integer, TempDescriptor>();
1916 if (calleeFlatMethod.getMethod().isStatic()) {
1917 // static method does not have implicit 'this' arg
1920 for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
1921 TempDescriptor param = calleeFlatMethod.getParameter(i);
1922 mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
1925 Set<Integer> keySet = mapArgIdx2CallerAgLocationPath.keySet();
1926 for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
1927 Integer idx = (Integer) iterator2.next();
1928 NTuple<Location> callerArgLocationPath = mapArgIdx2CallerAgLocationPath.get(idx);
1929 NTuple<Descriptor> callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx);
1931 TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
1932 NTuple<Location> calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam);
1933 SharedLocMap calleeDeleteSet = mapFlatMethodToDeleteSet.get(calleeFlatMethod);
1934 SharedLocMap calleeSharedLocMap = mapFlatMethodToSharedLocMap.get(calleeFlatMethod);
1936 if (calleeDeleteSet != null) {
1937 createNewMappingOfDeleteSet(callerArgLocationPath, callerArgHeapPath,
1938 calleeLocationPath, calleeDeleteSet);
1941 if (calleeSharedLocMap != null) {
1942 createNewMappingOfSharedSet(callerArgLocationPath, callerArgHeapPath,
1943 calleeLocationPath, calleeSharedLocMap);
1953 private void createNewMappingOfDeleteSet(NTuple<Location> callerArgLocationPath,
1954 NTuple<Descriptor> callerArgHeapPath, NTuple<Location> calleeLocationPath,
1955 SharedLocMap calleeDeleteSet) {
1957 SharedLocMap calleeParamDeleteSet = calleeDeleteSet.getHeapPathStartedWith(calleeLocationPath);
1959 Set<NTuple<Location>> keySet = calleeParamDeleteSet.keySet();
1960 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1961 NTuple<Location> calleeLocTupleKey = (NTuple<Location>) iterator.next();
1962 Set<NTuple<Descriptor>> heapPathSet = calleeParamDeleteSet.get(calleeLocTupleKey);
1963 for (Iterator iterator2 = heapPathSet.iterator(); iterator2.hasNext();) {
1964 NTuple<Descriptor> calleeHeapPath = (NTuple<Descriptor>) iterator2.next();
1965 calleeUnionBoundDeleteSet.addWrite(
1966 bindLocationPath(callerArgLocationPath, calleeLocTupleKey),
1967 bindHeapPath(callerArgHeapPath, calleeHeapPath));
1973 private void createNewMappingOfSharedSet(NTuple<Location> callerArgLocationPath,
1974 NTuple<Descriptor> callerArgHeapPath, NTuple<Location> calleeLocationPath,
1975 SharedLocMap calleeSharedLocMap) {
1977 SharedLocMap calleeParamSharedSet =
1978 calleeSharedLocMap.getHeapPathStartedWith(calleeLocationPath);
1980 Set<NTuple<Location>> keySet = calleeParamSharedSet.keySet();
1981 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1982 NTuple<Location> calleeLocTupleKey = (NTuple<Location>) iterator.next();
1983 Set<NTuple<Descriptor>> heapPathSet = calleeParamSharedSet.get(calleeLocTupleKey);
1984 Set<NTuple<Descriptor>> boundHeapPathSet = new HashSet<NTuple<Descriptor>>();
1985 for (Iterator iterator2 = heapPathSet.iterator(); iterator2.hasNext();) {
1986 NTuple<Descriptor> calleeHeapPath = (NTuple<Descriptor>) iterator2.next();
1987 boundHeapPathSet.add(bindHeapPath(callerArgHeapPath, calleeHeapPath));
1989 calleeIntersectBoundSharedSet.intersect(
1990 bindLocationPath(callerArgLocationPath, calleeLocTupleKey), boundHeapPathSet);
1995 private NTuple<Location> bindLocationPath(NTuple<Location> start, NTuple<Location> end) {
1996 NTuple<Location> locPath = new NTuple<Location>();
1997 locPath.addAll(start);
1998 for (int i = 1; i < end.size(); i++) {
1999 locPath.add(end.get(i));
2004 private NTuple<Descriptor> bindHeapPath(NTuple<Descriptor> start, NTuple<Descriptor> end) {
2005 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
2006 heapPath.addAll(start);
2007 for (int i = 1; i < end.size(); i++) {
2008 heapPath.add(end.get(i));
2013 private void initialize() {
2014 // First, identify ssjava loop entrace
2016 // no need to analyze method having ssjava loop
2017 methodContainingSSJavaLoop = ssjava.getMethodContainingSSJavaLoop();
2019 FlatMethod fm = state.getMethodFlat(methodContainingSSJavaLoop);
2020 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
2021 flatNodesToVisit.add(fm);
2023 LoopFinder loopFinder = new LoopFinder(fm);
2025 while (!flatNodesToVisit.isEmpty()) {
2026 FlatNode fn = flatNodesToVisit.iterator().next();
2027 flatNodesToVisit.remove(fn);
2029 String label = (String) state.fn2labelMap.get(fn);
2030 if (label != null) {
2032 if (label.equals(ssjava.SSJAVA)) {
2033 ssjava.setSSJavaLoopEntrance(fn);
2038 for (int i = 0; i < fn.numNext(); i++) {
2039 FlatNode nn = fn.getNext(i);
2040 flatNodesToVisit.add(nn);
2044 assert ssjava.getSSJavaLoopEntrance() != null;
2046 // assume that ssjava loop is top-level loop in method, not nested loop
2047 Set nestedLoop = loopFinder.nestedLoops();
2048 for (Iterator loopIter = nestedLoop.iterator(); loopIter.hasNext();) {
2049 LoopFinder lf = (LoopFinder) loopIter.next();
2050 if (lf.loopEntrances().iterator().next().equals(ssjava.getSSJavaLoopEntrance())) {
2055 assert ssjavaLoop != null;
2057 loopIncElements = (Set<FlatNode>) ssjavaLoop.loopIncElements();
2059 // perform topological sort over the set of methods accessed by the main
2061 Set<MethodDescriptor> methodDescriptorsToAnalyze = new HashSet<MethodDescriptor>();
2062 methodDescriptorsToAnalyze.addAll(ssjava.getAnnotationRequireSet());
2063 sortedDescriptors = topologicalSort(methodDescriptorsToAnalyze);
2066 private void methodReadWriteSetAnalysis() {
2067 // perform method READ/OVERWRITE analysis
2068 LinkedList<MethodDescriptor> descriptorListToAnalyze =
2069 (LinkedList<MethodDescriptor>) sortedDescriptors.clone();
2071 // current descriptors to visit in fixed-point interprocedural analysis,
2073 // dependency in the call graph
2074 methodDescriptorsToVisitStack.clear();
2076 descriptorListToAnalyze.removeFirst();
2078 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
2079 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
2081 while (!descriptorListToAnalyze.isEmpty()) {
2082 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
2083 methodDescriptorsToVisitStack.add(md);
2086 // analyze scheduled methods until there are no more to visit
2087 while (!methodDescriptorsToVisitStack.isEmpty()) {
2088 // start to analyze leaf node
2089 MethodDescriptor md = methodDescriptorsToVisitStack.pop();
2090 FlatMethod fm = state.getMethodFlat(md);
2092 Set<NTuple<Descriptor>> readSet = new HashSet<NTuple<Descriptor>>();
2093 Set<NTuple<Descriptor>> mustWriteSet = new HashSet<NTuple<Descriptor>>();
2094 Set<NTuple<Descriptor>> mayWriteSet = new HashSet<NTuple<Descriptor>>();
2096 methodReadWriteSet_analyzeMethod(fm, readSet, mustWriteSet, mayWriteSet);
2098 Set<NTuple<Descriptor>> prevRead = mapFlatMethodToReadSet.get(fm);
2099 Set<NTuple<Descriptor>> prevMustWrite = mapFlatMethodToMustWriteSet.get(fm);
2100 Set<NTuple<Descriptor>> prevMayWrite = mapFlatMethodToMayWriteSet.get(fm);
2102 if (!(readSet.equals(prevRead) && mustWriteSet.equals(prevMustWrite) && mayWriteSet
2103 .equals(prevMayWrite))) {
2104 mapFlatMethodToReadSet.put(fm, readSet);
2105 mapFlatMethodToMustWriteSet.put(fm, mustWriteSet);
2106 mapFlatMethodToMayWriteSet.put(fm, mayWriteSet);
2108 // results for callee changed, so enqueue dependents caller for
2111 Iterator<MethodDescriptor> depsItr = getDependents(md).iterator();
2112 while (depsItr.hasNext()) {
2113 MethodDescriptor methodNext = depsItr.next();
2114 if (!methodDescriptorsToVisitStack.contains(methodNext)
2115 && methodDescriptorToVistSet.contains(methodNext)) {
2116 methodDescriptorsToVisitStack.add(methodNext);
2125 methodReadWriteSetAnalysisToEventLoopBody();
2129 private void methodReadWriteSet_analyzeMethod(FlatMethod fm, Set<NTuple<Descriptor>> readSet,
2130 Set<NTuple<Descriptor>> mustWriteSet, Set<NTuple<Descriptor>> mayWriteSet) {
2131 if (state.SSJAVADEBUG) {
2132 System.out.println("SSJAVA: Definitely written Analyzing: " + fm);
2135 methodReadWriteSet_analyzeBody(fm, readSet, mustWriteSet, mayWriteSet, false);
2139 private void methodReadWriteSetAnalysisToEventLoopBody() {
2141 // perform method read/write analysis for Event Loop Body
2143 FlatMethod flatMethodContainingSSJavaLoop = state.getMethodFlat(methodContainingSSJavaLoop);
2145 if (state.SSJAVADEBUG) {
2146 System.out.println("SSJAVA: Definitely written Event Loop Analyzing: "
2147 + flatMethodContainingSSJavaLoop);
2150 Set<NTuple<Descriptor>> readSet = new HashSet<NTuple<Descriptor>>();
2151 Set<NTuple<Descriptor>> mustWriteSet = new HashSet<NTuple<Descriptor>>();
2152 Set<NTuple<Descriptor>> mayWriteSet = new HashSet<NTuple<Descriptor>>();
2154 mapFlatMethodToReadSet.put(flatMethodContainingSSJavaLoop, readSet);
2155 mapFlatMethodToMustWriteSet.put(flatMethodContainingSSJavaLoop, mustWriteSet);
2156 mapFlatMethodToMayWriteSet.put(flatMethodContainingSSJavaLoop, mayWriteSet);
2158 methodReadWriteSet_analyzeBody(ssjava.getSSJavaLoopEntrance(), readSet, mustWriteSet,
2163 private void methodReadWriteSet_analyzeBody(FlatNode startNode, Set<NTuple<Descriptor>> readSet,
2164 Set<NTuple<Descriptor>> mustWriteSet, Set<NTuple<Descriptor>> mayWriteSet,
2165 boolean isEventLoopBody) {
2167 // intraprocedural analysis
2168 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
2169 flatNodesToVisit.add(startNode);
2171 while (!flatNodesToVisit.isEmpty()) {
2172 FlatNode fn = flatNodesToVisit.iterator().next();
2173 flatNodesToVisit.remove(fn);
2175 Set<NTuple<Descriptor>> currMustWriteSet = new HashSet<NTuple<Descriptor>>();
2177 for (int i = 0; i < fn.numPrev(); i++) {
2178 FlatNode prevFn = fn.getPrev(i);
2179 Set<NTuple<Descriptor>> in = mapFlatNodeToMustWriteSet.get(prevFn);
2181 merge(currMustWriteSet, in);
2185 methodReadWriteSet_nodeActions(fn, currMustWriteSet, readSet, mustWriteSet, mayWriteSet,
2188 Set<NTuple<Descriptor>> mustSetPrev = mapFlatNodeToMustWriteSet.get(fn);
2190 if (!currMustWriteSet.equals(mustSetPrev)) {
2191 mapFlatNodeToMustWriteSet.put(fn, currMustWriteSet);
2192 for (int i = 0; i < fn.numNext(); i++) {
2193 FlatNode nn = fn.getNext(i);
2194 if ((!isEventLoopBody) || loopIncElements.contains(nn)) {
2195 flatNodesToVisit.add(nn);
2205 private void methodReadWriteSet_nodeActions(FlatNode fn,
2206 Set<NTuple<Descriptor>> currMustWriteSet, Set<NTuple<Descriptor>> readSet,
2207 Set<NTuple<Descriptor>> mustWriteSet, Set<NTuple<Descriptor>> mayWriteSet,
2208 boolean isEventLoopBody) {
2212 FieldDescriptor fld;
2214 switch (fn.kind()) {
2215 case FKind.FlatMethod: {
2217 // set up initial heap paths for method parameters
2218 FlatMethod fm = (FlatMethod) fn;
2219 for (int i = 0; i < fm.numParameters(); i++) {
2220 TempDescriptor param = fm.getParameter(i);
2221 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
2222 heapPath.add(param);
2223 mapHeapPath.put(param, heapPath);
2228 case FKind.FlatOpNode: {
2229 FlatOpNode fon = (FlatOpNode) fn;
2230 // for a normal assign node, need to propagate lhs's heap path to
2233 if (fon.getOp().getOp() == Operation.ASSIGN) {
2234 rhs = fon.getLeft();
2235 lhs = fon.getDest();
2237 NTuple<Descriptor> rhsHeapPath = mapHeapPath.get(rhs);
2239 // if (lhs.getType().isPrimitive()) {
2240 // NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
2241 // lhsHeapPath.add(lhs);
2242 // mapHeapPath.put(lhs, lhsHeapPath);
2245 if (rhsHeapPath != null) {
2246 mapHeapPath.put(lhs, mapHeapPath.get(rhs));
2248 if (isEventLoopBody) {
2249 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
2251 mapHeapPath.put(lhs, heapPath);
2257 // shared loc extension
2258 if (isEventLoopBody) {
2259 if (!lhs.getSymbol().startsWith("neverused") && rhs.getType().isImmutable()) {
2261 if (rhs.getType().getExtension() instanceof Location
2262 && lhs.getType().getExtension() instanceof CompositeLocation) {
2264 Location rhsLoc = (Location) rhs.getType().getExtension();
2266 CompositeLocation lhsCompLoc = (CompositeLocation) lhs.getType().getExtension();
2267 Location dstLoc = lhsCompLoc.get(lhsCompLoc.getSize() - 1);
2269 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
2270 for (int i = 0; i < rhsHeapPath.size() - 1; i++) {
2271 heapPath.add(rhsHeapPath.get(i));
2274 NTuple<Descriptor> writeHeapPath = new NTuple<Descriptor>();
2275 writeHeapPath.addAll(heapPath);
2276 writeHeapPath.add(lhs);
2286 case FKind.FlatElementNode:
2287 case FKind.FlatFieldNode: {
2291 if (fn.kind() == FKind.FlatFieldNode) {
2292 FlatFieldNode ffn = (FlatFieldNode) fn;
2295 fld = ffn.getField();
2297 FlatElementNode fen = (FlatElementNode) fn;
2300 TypeDescriptor td = rhs.getType().dereference();
2301 fld = getArrayField(td);
2304 if (fld.isFinal()) {
2305 // if field is final no need to check
2310 NTuple<Descriptor> srcHeapPath = mapHeapPath.get(rhs);
2311 if (srcHeapPath != null) {
2312 // if lhs srcHeapPath is null, it means that it is not reachable from
2313 // callee's parameters. so just ignore it
2315 NTuple<Descriptor> readingHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
2316 if (fn.kind() == FKind.FlatFieldNode) {
2317 readingHeapPath.add(fld);
2320 mapHeapPath.put(lhs, readingHeapPath);
2323 if (fld.getType().isImmutable()) {
2324 // if WT doesnot have hp(x.f), add hp(x.f) to READ
2325 if (!currMustWriteSet.contains(readingHeapPath)) {
2326 readSet.add(readingHeapPath);
2330 // no need to kill hp(x.f) from WT
2336 case FKind.FlatSetFieldNode:
2337 case FKind.FlatSetElementNode: {
2341 if (fn.kind() == FKind.FlatSetFieldNode) {
2342 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
2343 lhs = fsfn.getDst();
2344 fld = fsfn.getField();
2345 rhs = fsfn.getSrc();
2347 FlatSetElementNode fsen = (FlatSetElementNode) fn;
2348 lhs = fsen.getDst();
2349 rhs = fsen.getSrc();
2350 TypeDescriptor td = lhs.getType().dereference();
2351 fld = getArrayField(td);
2355 NTuple<Descriptor> lhsHeapPath = mapHeapPath.get(lhs);
2357 if (lhsHeapPath != null) {
2358 // if lhs heap path is null, it means that it is not reachable from
2359 // callee's parameters. so just ignore it
2360 NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
2361 if (fn.kind() != FKind.FlatSetElementNode) {
2362 fldHeapPath.add(fld);
2364 // mapHeapPath.put(fld, fldHeapPath);
2367 // need to add hp(y) to WT
2368 if (fn.kind() != FKind.FlatSetElementNode) {
2369 currMustWriteSet.add(fldHeapPath);
2371 mayWriteSet.add(fldHeapPath);
2378 case FKind.FlatCall: {
2380 FlatCall fc = (FlatCall) fn;
2382 bindHeapPathCallerArgWithCalleeParam(fc);
2384 Set<NTuple<Descriptor>> boundReadSet = new HashSet<NTuple<Descriptor>>();
2385 boundReadSet.addAll(calleeUnionBoundReadSet);
2387 Set<NTuple<Descriptor>> boundMustWriteSet = new HashSet<NTuple<Descriptor>>();
2388 boundMustWriteSet.addAll(calleeIntersectBoundMustWriteSet);
2390 Set<NTuple<Descriptor>> boundMayWriteSet = new HashSet<NTuple<Descriptor>>();
2391 boundMayWriteSet.addAll(calleeUnionBoundMayWriteSet);
2393 mapFlatNodeToBoundReadSet.put(fn, boundReadSet);
2394 mapFlatNodeToBoundMustWriteSet.put(fn, boundMustWriteSet);
2395 mapFlatNodeToBoundMayWriteSet.put(fn, boundMayWriteSet);
2397 // add heap path, which is an element of READ_bound set and is not
2399 // element of WT set, to the caller's READ set
2400 for (Iterator iterator = calleeUnionBoundReadSet.iterator(); iterator.hasNext();) {
2401 NTuple<Descriptor> read = (NTuple<Descriptor>) iterator.next();
2402 if (!currMustWriteSet.contains(read)) {
2407 // add heap path, which is an element of OVERWRITE_bound set, to the
2409 for (Iterator iterator = calleeIntersectBoundMustWriteSet.iterator(); iterator.hasNext();) {
2410 NTuple<Descriptor> write = (NTuple<Descriptor>) iterator.next();
2411 currMustWriteSet.add(write);
2414 // add heap path, which is an element of WRITE_BOUND set, to the
2415 // caller's writeSet
2416 for (Iterator iterator = calleeUnionBoundMayWriteSet.iterator(); iterator.hasNext();) {
2417 NTuple<Descriptor> write = (NTuple<Descriptor>) iterator.next();
2418 mayWriteSet.add(write);
2424 case FKind.FlatExit: {
2425 // merge the current written set with OVERWRITE set
2426 merge(mustWriteSet, currMustWriteSet);
2434 static public FieldDescriptor getArrayField(TypeDescriptor td) {
2435 FieldDescriptor fd = mapTypeToArrayField.get(td);
2438 new FieldDescriptor(new Modifiers(Modifiers.PUBLIC), td, arrayElementFieldName, null,
2440 mapTypeToArrayField.put(td, fd);
2445 private void merge(Set<NTuple<Descriptor>> curr, Set<NTuple<Descriptor>> in) {
2446 if (curr.isEmpty()) {
2447 // set has a special initial value which covers all possible
2449 // For the first time of intersection, we can take all previous set
2452 // otherwise, current set is the intersection of the two sets
2458 // combine two heap path
2459 private NTuple<Descriptor> combine(NTuple<Descriptor> callerIn, NTuple<Descriptor> calleeIn) {
2460 NTuple<Descriptor> combined = new NTuple<Descriptor>();
2462 for (int i = 0; i < callerIn.size(); i++) {
2463 combined.add(callerIn.get(i));
2466 // the first element of callee's heap path represents parameter
2467 // so we skip the first one since it is already added from caller's heap
2469 for (int i = 1; i < calleeIn.size(); i++) {
2470 combined.add(calleeIn.get(i));
2476 private Set<NTuple<Descriptor>> bindSet(Set<NTuple<Descriptor>> calleeSet,
2477 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc,
2478 Hashtable<Integer, NTuple<Descriptor>> mapCallerArgIdx2HeapPath) {
2480 Set<NTuple<Descriptor>> boundedCalleeSet = new HashSet<NTuple<Descriptor>>();
2482 Set<Integer> keySet = mapCallerArgIdx2HeapPath.keySet();
2483 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2484 Integer idx = (Integer) iterator.next();
2486 NTuple<Descriptor> callerArgHeapPath = mapCallerArgIdx2HeapPath.get(idx);
2487 TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
2488 for (Iterator iterator2 = calleeSet.iterator(); iterator2.hasNext();) {
2489 NTuple<Descriptor> element = (NTuple<Descriptor>) iterator2.next();
2490 if (element.startsWith(calleeParam)) {
2491 NTuple<Descriptor> boundElement = combine(callerArgHeapPath, element);
2492 boundedCalleeSet.add(boundElement);
2498 return boundedCalleeSet;
2502 // Borrowed it from disjoint analysis
2503 private LinkedList<MethodDescriptor> topologicalSort(Set<MethodDescriptor> toSort) {
2505 Set<MethodDescriptor> discovered = new HashSet<MethodDescriptor>();
2507 LinkedList<MethodDescriptor> sorted = new LinkedList<MethodDescriptor>();
2509 Iterator<MethodDescriptor> itr = toSort.iterator();
2510 while (itr.hasNext()) {
2511 MethodDescriptor d = itr.next();
2513 if (!discovered.contains(d)) {
2514 dfsVisit(d, toSort, sorted, discovered);
2521 // While we're doing DFS on call graph, remember
2522 // dependencies for efficient queuing of methods
2523 // during interprocedural analysis:
2525 // a dependent of a method decriptor d for this analysis is:
2526 // 1) a method or task that invokes d
2527 // 2) in the descriptorsToAnalyze set
2528 private void dfsVisit(MethodDescriptor md, Set<MethodDescriptor> toSort,
2529 LinkedList<MethodDescriptor> sorted, Set<MethodDescriptor> discovered) {
2533 Iterator itr = callGraph.getCallerSet(md).iterator();
2534 while (itr.hasNext()) {
2535 MethodDescriptor dCaller = (MethodDescriptor) itr.next();
2536 // only consider callers in the original set to analyze
2537 if (!toSort.contains(dCaller)) {
2540 if (!discovered.contains(dCaller)) {
2541 addDependent(md, // callee
2545 dfsVisit(dCaller, toSort, sorted, discovered);
2549 // for leaf-nodes last now!
2553 // a dependent of a method decriptor d for this analysis is:
2554 // 1) a method or task that invokes d
2555 // 2) in the descriptorsToAnalyze set
2556 private void addDependent(MethodDescriptor callee, MethodDescriptor caller) {
2557 Set<MethodDescriptor> deps = mapDescriptorToSetDependents.get(callee);
2559 deps = new HashSet<MethodDescriptor>();
2562 mapDescriptorToSetDependents.put(callee, deps);
2565 private Set<MethodDescriptor> getDependents(MethodDescriptor callee) {
2566 Set<MethodDescriptor> deps = mapDescriptorToSetDependents.get(callee);
2568 deps = new HashSet<MethodDescriptor>();
2569 mapDescriptorToSetDependents.put(callee, deps);
2574 private NTuple<Descriptor> computePath(Descriptor td) {
2575 // generate proper path fot input td
2576 // if td is local variable, it just generate one element tuple path
2577 if (mapHeapPath.containsKey(td)) {
2578 NTuple<Descriptor> rtrHeapPath = new NTuple<Descriptor>();
2579 rtrHeapPath.addAll(mapHeapPath.get(td));
2582 NTuple<Descriptor> rtrHeapPath = new NTuple<Descriptor>();
2583 rtrHeapPath.add(td);
2588 private NTuple<Location> deriveThisLocationTuple(MethodDescriptor md) {
2589 String thisLocIdentifier = ssjava.getMethodLattice(md).getThisLoc();
2590 Location thisLoc = new Location(md, thisLocIdentifier);
2591 NTuple<Location> locTuple = new NTuple<Location>();
2592 locTuple.add(thisLoc);
2596 private NTuple<Location> deriveGlobalLocationTuple(MethodDescriptor md) {
2597 String globalLocIdentifier = ssjava.getMethodLattice(md).getGlobalLoc();
2598 Location globalLoc = new Location(md, globalLocIdentifier);
2599 NTuple<Location> locTuple = new NTuple<Location>();
2600 locTuple.add(globalLoc);
2604 private NTuple<Location> deriveLocationTuple(MethodDescriptor md, TempDescriptor td) {
2606 assert td.getType() != null;
2608 if (mapDescriptorToLocationPath.containsKey(td)) {
2609 NTuple<Location> locPath = mapDescriptorToLocationPath.get(td);
2610 NTuple<Location> rtrPath = new NTuple<Location>();
2611 rtrPath.addAll(locPath);
2614 if (td.getSymbol().startsWith("this")) {
2615 NTuple<Location> thisPath = deriveThisLocationTuple(md);
2616 NTuple<Location> rtrPath = new NTuple<Location>();
2617 rtrPath.addAll(thisPath);
2621 if (td.getType().getExtension() != null) {
2622 SSJavaType ssJavaType = (SSJavaType) td.getType().getExtension();
2623 if (ssJavaType.getCompLoc() != null) {
2624 NTuple<Location> rtrPath = new NTuple<Location>();
2625 rtrPath.addAll(ssJavaType.getCompLoc().getTuple());