1 package Analysis.SSJava;
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
6 import java.util.LinkedList;
8 import java.util.Stack;
10 import Analysis.CallGraph.CallGraph;
12 import IR.FieldDescriptor;
13 import IR.MethodDescriptor;
16 import IR.TypeDescriptor;
18 import IR.Flat.FlatCall;
19 import IR.Flat.FlatFieldNode;
20 import IR.Flat.FlatLiteralNode;
21 import IR.Flat.FlatMethod;
22 import IR.Flat.FlatNode;
23 import IR.Flat.FlatOpNode;
24 import IR.Flat.FlatSetFieldNode;
25 import IR.Flat.TempDescriptor;
27 public class DefinitelyWrittenCheck {
29 SSJavaAnalysis ssjava;
33 // maps a descriptor to its known dependents: namely
34 // methods or tasks that call the descriptor's method
35 // AND are part of this analysis (reachable from main)
36 private Hashtable<Descriptor, Set<MethodDescriptor>> mapDescriptorToSetDependents;
38 // maps a flat node to its WrittenSet: this keeps all heap path overwritten
40 private Hashtable<FlatNode, Set<NTuple<Descriptor>>> mapFlatNodeToWrittenSet;
42 // maps a temp descriptor to its heap path
43 // each temp descriptor has a unique heap path since we do not allow any
45 private Hashtable<Descriptor, NTuple<Descriptor>> mapHeapPath;
47 // maps a flat method to the READ that is the set of heap path that is
48 // expected to be written before method invocation
49 private Hashtable<FlatMethod, Set<NTuple<Descriptor>>> mapFlatMethodToRead;
51 // maps a flat method to the OVERWRITE that is the set of heap path that is
52 // overwritten on every possible path during method invocation
53 private Hashtable<FlatMethod, Set<NTuple<Descriptor>>> mapFlatMethodToOverWrite;
55 // points to method containing SSJAVA Loop
56 private MethodDescriptor methodContainingSSJavaLoop;
58 // maps a flatnode to definitely written analysis mapping M
59 private Hashtable<FlatNode, Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>>> definitelyWrittenResults;
61 private Set<NTuple<Descriptor>> calleeUnionBoundReadSet;
62 private Set<NTuple<Descriptor>> calleeIntersectBoundOverWriteSet;
64 public DefinitelyWrittenCheck(SSJavaAnalysis ssjava, State state) {
67 this.callGraph = ssjava.getCallGraph();
68 this.mapFlatNodeToWrittenSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
69 this.mapDescriptorToSetDependents = new Hashtable<Descriptor, Set<MethodDescriptor>>();
70 this.mapHeapPath = new Hashtable<Descriptor, NTuple<Descriptor>>();
71 this.mapFlatMethodToRead = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
72 this.mapFlatMethodToOverWrite = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
73 this.definitelyWrittenResults =
74 new Hashtable<FlatNode, Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>>>();
75 this.calleeUnionBoundReadSet = new HashSet<NTuple<Descriptor>>();
76 this.calleeIntersectBoundOverWriteSet = new HashSet<NTuple<Descriptor>>();
79 public void definitelyWrittenCheck() {
80 if (!ssjava.getAnnotationRequireSet().isEmpty()) {
81 methodReadOverWriteAnalysis();
86 private void writtenAnalyis() {
87 // perform second stage analysis: intraprocedural analysis ensure that
89 // variables are definitely written in-between the same read
91 // First, identify ssjava loop entrace
92 FlatMethod fm = state.getMethodFlat(methodContainingSSJavaLoop);
93 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
94 flatNodesToVisit.add(fm);
96 FlatNode entrance = null;
98 while (!flatNodesToVisit.isEmpty()) {
99 FlatNode fn = flatNodesToVisit.iterator().next();
100 flatNodesToVisit.remove(fn);
102 String label = (String) state.fn2labelMap.get(fn);
105 if (label.equals(ssjava.SSJAVA)) {
111 for (int i = 0; i < fn.numNext(); i++) {
112 FlatNode nn = fn.getNext(i);
113 flatNodesToVisit.add(nn);
117 assert entrance != null;
119 writtenAnalysis_analyzeLoop(entrance);
123 private void writtenAnalysis_analyzeLoop(FlatNode entrance) {
125 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
126 flatNodesToVisit.add(entrance);
128 while (!flatNodesToVisit.isEmpty()) {
129 FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
130 flatNodesToVisit.remove(fn);
132 Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>> prev =
133 definitelyWrittenResults.get(fn);
135 Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>> curr =
136 new Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>>();
137 for (int i = 0; i < fn.numPrev(); i++) {
138 FlatNode nn = fn.getPrev(i);
139 Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>> dwIn =
140 definitelyWrittenResults.get(nn);
146 writtenAnalysis_nodeAction(fn, curr, entrance);
148 // if a new result, schedule forward nodes for analysis
149 if (!curr.equals(prev)) {
150 definitelyWrittenResults.put(fn, curr);
152 for (int i = 0; i < fn.numNext(); i++) {
153 FlatNode nn = fn.getNext(i);
154 flatNodesToVisit.add(nn);
160 private void writtenAnalysis_nodeAction(FlatNode fn,
161 Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>> curr, FlatNode loopEntrance) {
162 if (fn.equals(loopEntrance)) {
163 // it reaches loop entrance: changes all flag to true
164 Set<NTuple<Descriptor>> keySet = curr.keySet();
165 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
166 NTuple<Descriptor> key = (NTuple<Descriptor>) iterator.next();
167 Hashtable<FlatNode, Boolean> pair = curr.get(key);
169 Set<FlatNode> pairKeySet = pair.keySet();
170 for (Iterator iterator2 = pairKeySet.iterator(); iterator2.hasNext();) {
171 FlatNode pairKey = (FlatNode) iterator2.next();
172 pair.put(pairKey, Boolean.TRUE);
182 case FKind.FlatOpNode: {
183 FlatOpNode fon = (FlatOpNode) fn;
187 NTuple<Descriptor> rhsHeapPath = computePath(rhs);
188 if (!rhs.getType().isImmutable()) {
189 mapHeapPath.put(lhs, rhsHeapPath);
191 if (fon.getOp().getOp() == Operation.ASSIGN) {
193 readValue(fn, rhsHeapPath, curr);
196 NTuple<Descriptor> lhsHeapPath = computePath(lhs);
197 removeHeapPath(curr, lhsHeapPath);
202 case FKind.FlatLiteralNode: {
203 FlatLiteralNode fln = (FlatLiteralNode) fn;
207 NTuple<Descriptor> lhsHeapPath = computePath(lhs);
208 removeHeapPath(curr, lhsHeapPath);
213 case FKind.FlatFieldNode:
214 case FKind.FlatElementNode: {
216 FlatFieldNode ffn = (FlatFieldNode) fn;
219 fld = ffn.getField();
222 NTuple<Descriptor> srcHeapPath = mapHeapPath.get(rhs);
223 NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
224 fldHeapPath.add(fld);
226 if (fld.getType().isImmutable()) {
227 readValue(fn, fldHeapPath, curr);
230 // propagate rhs's heap path to the lhs
231 mapHeapPath.put(lhs, fldHeapPath);
236 case FKind.FlatSetFieldNode:
237 case FKind.FlatSetElementNode: {
239 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
241 fld = fsfn.getField();
244 NTuple<Descriptor> lhsHeapPath = computePath(lhs);
245 NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
246 fldHeapPath.add(fld);
247 removeHeapPath(curr, fldHeapPath);
252 case FKind.FlatCall: {
254 FlatCall fc = (FlatCall) fn;
255 bindHeapPathCallerArgWithCaleeParam(fc);
257 // add <hp,statement,false> in which hp is an element of
259 // of callee: callee has 'read' requirement!
260 for (Iterator iterator = calleeUnionBoundReadSet.iterator(); iterator.hasNext();) {
261 NTuple<Descriptor> read = (NTuple<Descriptor>) iterator.next();
263 Hashtable<FlatNode, Boolean> gen = curr.get(read);
265 gen = new Hashtable<FlatNode, Boolean>();
268 Boolean currentStatus = gen.get(fn);
269 if (currentStatus == null) {
270 gen.put(fn, Boolean.FALSE);
272 checkFlag(currentStatus.booleanValue(), fn);
276 // removes <hp,statement,flag> if hp is an element of
278 // set of callee. it means that callee will overwrite it
279 for (Iterator iterator = calleeIntersectBoundOverWriteSet.iterator(); iterator.hasNext();) {
280 NTuple<Descriptor> write = (NTuple<Descriptor>) iterator.next();
281 removeHeapPath(curr, write);
291 private void readValue(FlatNode fn, NTuple<Descriptor> hp,
292 Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>> curr) {
293 Hashtable<FlatNode, Boolean> gen = curr.get(hp);
295 gen = new Hashtable<FlatNode, Boolean>();
298 Boolean currentStatus = gen.get(fn);
299 if (currentStatus == null) {
300 gen.put(fn, Boolean.FALSE);
302 checkFlag(currentStatus.booleanValue(), fn);
307 private void removeHeapPath(Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>> curr,
308 NTuple<Descriptor> hp) {
310 // removes all of heap path that starts with prefix 'hp'
311 // since any reference overwrite along heap path gives overwriting side
312 // effects on the value
314 Set<NTuple<Descriptor>> keySet = curr.keySet();
315 for (Iterator<NTuple<Descriptor>> iter = keySet.iterator(); iter.hasNext();) {
316 NTuple<Descriptor> key = iter.next();
317 if (key.startsWith(hp)) {
318 curr.put(key, new Hashtable<FlatNode, Boolean>());
324 private void bindHeapPathCallerArgWithCaleeParam(FlatCall fc) {
325 // compute all possible callee set
326 // transform all READ/OVERWRITE set from the any possible
330 calleeUnionBoundReadSet.clear();
331 calleeIntersectBoundOverWriteSet.clear();
333 MethodDescriptor mdCallee = fc.getMethod();
334 FlatMethod fmCallee = state.getMethodFlat(mdCallee);
335 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
336 TypeDescriptor typeDesc = fc.getThis().getType();
337 setPossibleCallees.addAll(callGraph.getMethods(mdCallee, typeDesc));
339 // create mapping from arg idx to its heap paths
340 Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
341 new Hashtable<Integer, NTuple<Descriptor>>();
343 // arg idx is starting from 'this' arg
344 NTuple<Descriptor> thisHeapPath = new NTuple<Descriptor>();
345 thisHeapPath.add(fc.getThis());
346 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
348 for (int i = 0; i < fc.numArgs(); i++) {
349 TempDescriptor arg = fc.getArg(i);
350 NTuple<Descriptor> argHeapPath = computePath(arg);
351 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
354 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
355 MethodDescriptor callee = (MethodDescriptor) iterator.next();
356 FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
358 // binding caller's args and callee's params
360 Set<NTuple<Descriptor>> calleeReadSet = mapFlatMethodToRead.get(calleeFlatMethod);
361 if (calleeReadSet == null) {
362 calleeReadSet = new HashSet<NTuple<Descriptor>>();
363 mapFlatMethodToRead.put(calleeFlatMethod, calleeReadSet);
365 Set<NTuple<Descriptor>> calleeOverWriteSet = mapFlatMethodToOverWrite.get(calleeFlatMethod);
366 if (calleeOverWriteSet == null) {
367 calleeOverWriteSet = new HashSet<NTuple<Descriptor>>();
368 mapFlatMethodToOverWrite.put(calleeFlatMethod, calleeOverWriteSet);
371 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
372 new Hashtable<Integer, TempDescriptor>();
373 for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
374 TempDescriptor param = calleeFlatMethod.getParameter(i);
375 mapParamIdx2ParamTempDesc.put(Integer.valueOf(i), param);
378 Set<NTuple<Descriptor>> calleeBoundReadSet =
379 bindSet(calleeReadSet, mapParamIdx2ParamTempDesc, mapArgIdx2CallerArgHeapPath);
380 // union of the current read set and the current callee's
382 calleeUnionBoundReadSet.addAll(calleeBoundReadSet);
383 Set<NTuple<Descriptor>> calleeBoundWriteSet =
384 bindSet(calleeOverWriteSet, mapParamIdx2ParamTempDesc, mapArgIdx2CallerArgHeapPath);
385 // intersection of the current overwrite set and the current
388 merge(calleeIntersectBoundOverWriteSet, calleeBoundWriteSet);
393 private void checkFlag(boolean booleanValue, FlatNode fn) {
396 "There is a variable who comes back to the same read statement without being overwritten at the out-most iteration at "
397 + methodContainingSSJavaLoop.getClassDesc().getSourceFileName()
403 private void merge(Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>> curr,
404 Hashtable<NTuple<Descriptor>, Hashtable<FlatNode, Boolean>> in) {
406 Set<NTuple<Descriptor>> inKeySet = in.keySet();
407 for (Iterator iterator = inKeySet.iterator(); iterator.hasNext();) {
408 NTuple<Descriptor> inKey = (NTuple<Descriptor>) iterator.next();
409 Hashtable<FlatNode, Boolean> inPair = in.get(inKey);
411 Set<FlatNode> pairKeySet = inPair.keySet();
412 for (Iterator iterator2 = pairKeySet.iterator(); iterator2.hasNext();) {
413 FlatNode pairKey = (FlatNode) iterator2.next();
414 Boolean inFlag = inPair.get(pairKey);
416 Hashtable<FlatNode, Boolean> currPair = curr.get(inKey);
417 if (currPair == null) {
418 currPair = new Hashtable<FlatNode, Boolean>();
419 curr.put(inKey, currPair);
422 Boolean currFlag = currPair.get(pairKey);
423 // by default, flag is set by false
424 if (currFlag == null) {
425 currFlag = Boolean.FALSE;
427 currFlag = Boolean.valueOf(inFlag.booleanValue() | currFlag.booleanValue());
428 currPair.put(pairKey, currFlag);
435 private void methodReadOverWriteAnalysis() {
436 // perform method READ/OVERWRITE analysis
437 Set<MethodDescriptor> methodDescriptorsToAnalyze = new HashSet<MethodDescriptor>();
438 methodDescriptorsToAnalyze.addAll(ssjava.getAnnotationRequireSet());
440 LinkedList<MethodDescriptor> sortedDescriptors = topologicalSort(methodDescriptorsToAnalyze);
442 // no need to analyze method having ssjava loop
443 methodContainingSSJavaLoop = sortedDescriptors.removeFirst();
445 // current descriptors to visit in fixed-point interprocedural analysis,
447 // dependency in the call graph
448 Stack<MethodDescriptor> methodDescriptorsToVisitStack = new Stack<MethodDescriptor>();
450 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
451 methodDescriptorToVistSet.addAll(sortedDescriptors);
453 while (!sortedDescriptors.isEmpty()) {
454 MethodDescriptor md = sortedDescriptors.removeFirst();
455 methodDescriptorsToVisitStack.add(md);
458 // analyze scheduled methods until there are no more to visit
459 while (!methodDescriptorsToVisitStack.isEmpty()) {
460 // start to analyze leaf node
461 MethodDescriptor md = methodDescriptorsToVisitStack.pop();
462 FlatMethod fm = state.getMethodFlat(md);
464 Set<NTuple<Descriptor>> readSet = new HashSet<NTuple<Descriptor>>();
465 Set<NTuple<Descriptor>> overWriteSet = new HashSet<NTuple<Descriptor>>();
467 methodReadOverWrite_analyzeMethod(fm, readSet, overWriteSet);
469 Set<NTuple<Descriptor>> prevRead = mapFlatMethodToRead.get(fm);
470 Set<NTuple<Descriptor>> prevOverWrite = mapFlatMethodToOverWrite.get(fm);
472 if (!(readSet.equals(prevRead) && overWriteSet.equals(prevOverWrite))) {
473 mapFlatMethodToRead.put(fm, readSet);
474 mapFlatMethodToOverWrite.put(fm, overWriteSet);
476 // results for callee changed, so enqueue dependents caller for
479 Iterator<MethodDescriptor> depsItr = getDependents(md).iterator();
480 while (depsItr.hasNext()) {
481 MethodDescriptor methodNext = depsItr.next();
482 if (!methodDescriptorsToVisitStack.contains(methodNext)
483 && methodDescriptorToVistSet.contains(methodNext)) {
484 methodDescriptorsToVisitStack.add(methodNext);
495 private void methodReadOverWrite_analyzeMethod(FlatMethod fm, Set<NTuple<Descriptor>> readSet,
496 Set<NTuple<Descriptor>> overWriteSet) {
497 if (state.SSJAVADEBUG) {
498 System.out.println("Definitely written Analyzing: " + fm);
501 // intraprocedural analysis
502 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
503 Set<FlatNode> visited = new HashSet<FlatNode>();
504 flatNodesToVisit.add(fm);
506 while (!flatNodesToVisit.isEmpty()) {
507 FlatNode fn = flatNodesToVisit.iterator().next();
508 flatNodesToVisit.remove(fn);
511 Set<NTuple<Descriptor>> curr = new HashSet<NTuple<Descriptor>>();
513 for (int i = 0; i < fn.numPrev(); i++) {
514 FlatNode prevFn = fn.getPrev(i);
515 Set<NTuple<Descriptor>> in = mapFlatNodeToWrittenSet.get(prevFn);
521 methodReadOverWrite_nodeActions(fn, curr, readSet, overWriteSet);
523 mapFlatNodeToWrittenSet.put(fn, curr);
525 for (int i = 0; i < fn.numNext(); i++) {
526 FlatNode nn = fn.getNext(i);
527 if (!visited.contains(nn)) {
528 flatNodesToVisit.add(nn);
536 private void methodReadOverWrite_nodeActions(FlatNode fn, Set<NTuple<Descriptor>> writtenSet,
537 Set<NTuple<Descriptor>> readSet, Set<NTuple<Descriptor>> overWriteSet) {
543 case FKind.FlatMethod: {
545 // set up initial heap paths for method parameters
546 FlatMethod fm = (FlatMethod) fn;
547 for (int i = 0; i < fm.numParameters(); i++) {
548 TempDescriptor param = fm.getParameter(i);
549 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
551 mapHeapPath.put(param, heapPath);
556 case FKind.FlatOpNode: {
557 FlatOpNode fon = (FlatOpNode) fn;
558 // for a normal assign node, need to propagate lhs's heap path to
560 if (fon.getOp().getOp() == Operation.ASSIGN) {
564 NTuple<Descriptor> rhsHeapPath = mapHeapPath.get(rhs);
565 if (rhsHeapPath != null) {
566 mapHeapPath.put(lhs, mapHeapPath.get(rhs));
573 case FKind.FlatFieldNode:
574 case FKind.FlatElementNode: {
578 FlatFieldNode ffn = (FlatFieldNode) fn;
581 fld = ffn.getField();
584 NTuple<Descriptor> srcHeapPath = mapHeapPath.get(rhs);
585 NTuple<Descriptor> readingHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
586 readingHeapPath.add(fld);
587 mapHeapPath.put(lhs, readingHeapPath);
590 if (fld.getType().isImmutable()) {
591 // if WT doesnot have hp(x.f), add hp(x.f) to READ
592 if (!writtenSet.contains(readingHeapPath)) {
593 readSet.add(readingHeapPath);
597 // need to kill hp(x.f) from WT
598 writtenSet.remove(readingHeapPath);
603 case FKind.FlatSetFieldNode:
604 case FKind.FlatSetElementNode: {
607 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
609 fld = fsfn.getField();
613 NTuple<Descriptor> lhsHeapPath = mapHeapPath.get(lhs);
614 NTuple<Descriptor> newHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
615 newHeapPath.add(fld);
616 mapHeapPath.put(fld, newHeapPath);
619 // need to add hp(y) to WT
620 writtenSet.add(newHeapPath);
625 case FKind.FlatCall: {
627 FlatCall fc = (FlatCall) fn;
629 bindHeapPathCallerArgWithCaleeParam(fc);
631 // add heap path, which is an element of READ_bound set and is not
633 // element of WT set, to the caller's READ set
634 for (Iterator iterator = calleeUnionBoundReadSet.iterator(); iterator.hasNext();) {
635 NTuple<Descriptor> read = (NTuple<Descriptor>) iterator.next();
636 if (!writtenSet.contains(read)) {
640 writtenSet.removeAll(calleeUnionBoundReadSet);
642 // add heap path, which is an element of OVERWRITE_bound set, to the
644 for (Iterator iterator = calleeIntersectBoundOverWriteSet.iterator(); iterator.hasNext();) {
645 NTuple<Descriptor> write = (NTuple<Descriptor>) iterator.next();
646 writtenSet.add(write);
652 case FKind.FlatExit: {
653 // merge the current written set with OVERWRITE set
654 merge(overWriteSet, writtenSet);
662 private void merge(Set<NTuple<Descriptor>> curr, Set<NTuple<Descriptor>> in) {
663 if (curr.isEmpty()) {
664 // WrittenSet has a special initial value which covers all possible
666 // For the first time of intersection, we can take all previous set
669 // otherwise, current set is the intersection of the two sets
675 // combine two heap path
676 private NTuple<Descriptor> combine(NTuple<Descriptor> callerIn, NTuple<Descriptor> calleeIn) {
677 NTuple<Descriptor> combined = new NTuple<Descriptor>();
679 for (int i = 0; i < callerIn.size(); i++) {
680 combined.add(callerIn.get(i));
683 // the first element of callee's heap path represents parameter
684 // so we skip the first one since it is already added from caller's heap
686 for (int i = 1; i < calleeIn.size(); i++) {
687 combined.add(calleeIn.get(i));
693 private Set<NTuple<Descriptor>> bindSet(Set<NTuple<Descriptor>> calleeSet,
694 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc,
695 Hashtable<Integer, NTuple<Descriptor>> mapCallerArgIdx2HeapPath) {
697 Set<NTuple<Descriptor>> boundedCalleeSet = new HashSet<NTuple<Descriptor>>();
699 Set<Integer> keySet = mapCallerArgIdx2HeapPath.keySet();
700 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
701 Integer idx = (Integer) iterator.next();
703 NTuple<Descriptor> callerArgHeapPath = mapCallerArgIdx2HeapPath.get(idx);
704 TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
706 for (Iterator iterator2 = calleeSet.iterator(); iterator2.hasNext();) {
707 NTuple<Descriptor> element = (NTuple<Descriptor>) iterator2.next();
708 if (element.startsWith(calleeParam)) {
709 NTuple<Descriptor> boundElement = combine(callerArgHeapPath, element);
710 boundedCalleeSet.add(boundElement);
716 return boundedCalleeSet;
720 // Borrowed it from disjoint analysis
721 private LinkedList<MethodDescriptor> topologicalSort(Set<MethodDescriptor> toSort) {
723 Set<MethodDescriptor> discovered = new HashSet<MethodDescriptor>();
725 LinkedList<MethodDescriptor> sorted = new LinkedList<MethodDescriptor>();
727 Iterator<MethodDescriptor> itr = toSort.iterator();
728 while (itr.hasNext()) {
729 MethodDescriptor d = itr.next();
731 if (!discovered.contains(d)) {
732 dfsVisit(d, toSort, sorted, discovered);
739 // While we're doing DFS on call graph, remember
740 // dependencies for efficient queuing of methods
741 // during interprocedural analysis:
743 // a dependent of a method decriptor d for this analysis is:
744 // 1) a method or task that invokes d
745 // 2) in the descriptorsToAnalyze set
746 private void dfsVisit(MethodDescriptor md, Set<MethodDescriptor> toSort,
747 LinkedList<MethodDescriptor> sorted, Set<MethodDescriptor> discovered) {
751 // otherwise call graph guides DFS
752 Iterator itr = callGraph.getCallerSet(md).iterator();
753 while (itr.hasNext()) {
754 MethodDescriptor dCaller = (MethodDescriptor) itr.next();
756 // only consider callers in the original set to analyze
757 if (!toSort.contains(dCaller)) {
761 if (!discovered.contains(dCaller)) {
762 addDependent(md, // callee
766 dfsVisit(dCaller, toSort, sorted, discovered);
770 // for leaf-nodes last now!
774 // a dependent of a method decriptor d for this analysis is:
775 // 1) a method or task that invokes d
776 // 2) in the descriptorsToAnalyze set
777 private void addDependent(MethodDescriptor callee, MethodDescriptor caller) {
778 Set<MethodDescriptor> deps = mapDescriptorToSetDependents.get(callee);
780 deps = new HashSet<MethodDescriptor>();
783 mapDescriptorToSetDependents.put(callee, deps);
786 private Set<MethodDescriptor> getDependents(MethodDescriptor callee) {
787 Set<MethodDescriptor> deps = mapDescriptorToSetDependents.get(callee);
789 deps = new HashSet<MethodDescriptor>();
790 mapDescriptorToSetDependents.put(callee, deps);
795 private NTuple<Descriptor> computePath(TempDescriptor td) {
796 // generate proper path fot input td
797 // if td is local variable, it just generate one element tuple path
798 if (mapHeapPath.containsKey(td)) {
799 return mapHeapPath.get(td);
801 NTuple<Descriptor> path = new NTuple<Descriptor>();