1 package Analysis.SSJava;
3 import java.io.BufferedWriter;
4 import java.io.FileWriter;
5 import java.io.IOException;
6 import java.util.ArrayList;
7 import java.util.Collections;
8 import java.util.Comparator;
9 import java.util.HashMap;
10 import java.util.HashSet;
11 import java.util.Hashtable;
12 import java.util.Iterator;
13 import java.util.LinkedList;
14 import java.util.List;
17 import java.util.StringTokenizer;
18 import java.util.Vector;
20 import Analysis.CallGraph.CallGraph;
21 import Analysis.Loops.GlobalFieldType;
22 import Analysis.Loops.LoopOptimize;
23 import Analysis.Loops.LoopTerminate;
24 import IR.AnnotationDescriptor;
25 import IR.ClassDescriptor;
27 import IR.FieldDescriptor;
28 import IR.MethodDescriptor;
30 import IR.SymbolTable;
32 import IR.Flat.BuildFlat;
33 import IR.Flat.FlatMethod;
34 import IR.Flat.FlatNode;
37 public class SSJavaAnalysis {
39 public static final String SSJAVA = "SSJAVA";
40 public static final String LATTICE = "LATTICE";
41 public static final String METHODDEFAULT = "METHODDEFAULT";
42 public static final String THISLOC = "THISLOC";
43 public static final String GLOBALLOC = "GLOBALLOC";
44 public static final String RETURNLOC = "RETURNLOC";
45 public static final String PCLOC = "PCLOC";
46 public static final String LOC = "LOC";
47 public static final String DELTA = "DELTA";
48 public static final String TERMINATE = "TERMINATE";
49 public static final String DELEGATE = "DELEGATE";
50 public static final String DELEGATETHIS = "DELEGATETHIS";
51 public static final String TRUST = "TRUST";
53 public static final String TOP = "_top_";
54 public static final String BOTTOM = "_bottom_";
58 FlowDownCheck flowDownChecker;
59 MethodAnnotationCheck methodAnnotationChecker;
62 // set containing method requires to be annoated
63 Set<MethodDescriptor> annotationRequireSet;
65 // class -> field lattice
66 Hashtable<ClassDescriptor, SSJavaLattice<String>> cd2lattice;
68 // class -> default local variable lattice
69 Hashtable<ClassDescriptor, MethodLattice<String>> cd2methodDefault;
71 // method -> local variable lattice
72 Hashtable<MethodDescriptor, MethodLattice<String>> md2lattice;
74 // method set that does not want to have loop termination analysis
75 Hashtable<MethodDescriptor, Integer> skipLoopTerminate;
77 // map shared location to its descriptors
78 Hashtable<Location, Set<Descriptor>> mapSharedLocation2DescriptorSet;
80 // set containing a class that has at least one annoated method
81 Set<ClassDescriptor> annotationRequireClassSet;
83 // the set of method descriptor required to check the linear type property
84 Set<MethodDescriptor> linearTypeCheckMethodSet;
86 // the set of method descriptors annotated as "TRUST"
87 Set<MethodDescriptor> trustWorthyMDSet;
89 // method -> the initial program counter location
90 Map<MethodDescriptor, CompositeLocation> md2pcLoc;
92 // points to method containing SSJAVA Loop
93 private MethodDescriptor methodContainingSSJavaLoop;
95 private FlatNode ssjavaLoopEntrance;
97 // keep the field ownership from the linear type checking
98 Hashtable<MethodDescriptor, Set<FieldDescriptor>> mapMethodToOwnedFieldSet;
100 Set<FlatNode> sameHeightWriteFlatNodeSet;
104 LinearTypeCheck checker;
106 // maps a descriptor to its known dependents: namely
107 // methods or tasks that call the descriptor's method
108 // AND are part of this analysis (reachable from main)
109 private Hashtable<Descriptor, Set<MethodDescriptor>> mapDescriptorToSetDependents;
111 private LinkedList<MethodDescriptor> sortedDescriptors;
113 private Map<Location, Set<Descriptor>> mapSharedLocToDescSet;
115 public SSJavaAnalysis(State state, TypeUtil tu, BuildFlat bf, CallGraph callgraph) {
118 this.callgraph = callgraph;
119 this.cd2lattice = new Hashtable<ClassDescriptor, SSJavaLattice<String>>();
120 this.cd2methodDefault = new Hashtable<ClassDescriptor, MethodLattice<String>>();
121 this.md2lattice = new Hashtable<MethodDescriptor, MethodLattice<String>>();
122 this.annotationRequireSet = new HashSet<MethodDescriptor>();
123 this.annotationRequireClassSet = new HashSet<ClassDescriptor>();
124 this.skipLoopTerminate = new Hashtable<MethodDescriptor, Integer>();
125 this.mapSharedLocation2DescriptorSet = new Hashtable<Location, Set<Descriptor>>();
126 this.linearTypeCheckMethodSet = new HashSet<MethodDescriptor>();
128 this.trustWorthyMDSet = new HashSet<MethodDescriptor>();
129 this.mapMethodToOwnedFieldSet = new Hashtable<MethodDescriptor, Set<FieldDescriptor>>();
130 this.sameHeightWriteFlatNodeSet = new HashSet<FlatNode>();
131 this.mapDescriptorToSetDependents = new Hashtable<Descriptor, Set<MethodDescriptor>>();
132 this.sortedDescriptors = new LinkedList<MethodDescriptor>();
133 this.md2pcLoc = new HashMap<MethodDescriptor, CompositeLocation>();
134 this.mapSharedLocToDescSet = new HashMap<Location, Set<Descriptor>>();
137 public void doCheck() {
138 doMethodAnnotationCheck();
140 if (state.SSJAVA && !state.SSJAVAINFER) {
141 computeLinearTypeCheckMethodSet();
146 if (state.SSJAVADEBUG) {
147 // debug_printAnnotationRequiredSet();
149 if (state.SSJAVAINFER) {
153 parseLocationAnnotation();
155 doDefinitelyWrittenCheck();
161 // perform topological sort over the set of methods accessed by the main
163 Set<MethodDescriptor> methodDescriptorsToAnalyze = new HashSet<MethodDescriptor>();
164 methodDescriptorsToAnalyze.addAll(getAnnotationRequireSet());
165 sortedDescriptors = topologicalSort(methodDescriptorsToAnalyze);
168 public LinkedList<MethodDescriptor> getSortedDescriptors() {
169 return (LinkedList<MethodDescriptor>) sortedDescriptors.clone();
172 public void addSharedDesc(Location loc, Descriptor fd) {
173 if (!mapSharedLocToDescSet.containsKey(loc)) {
174 mapSharedLocToDescSet.put(loc, new HashSet<Descriptor>());
176 mapSharedLocToDescSet.get(loc).add(fd);
179 public Set<Descriptor> getSharedDescSet(Location loc) {
180 return mapSharedLocToDescSet.get(loc);
183 private void inference() {
184 LocationInference inferEngine = new LocationInference(this, state);
185 inferEngine.inference();
188 private void doLoopCheck() {
189 GlobalFieldType gft = new GlobalFieldType(callgraph, state, tu.getMain());
190 LoopOptimize lo = new LoopOptimize(gft, tu);
192 SymbolTable classtable = state.getClassSymbolTable();
194 List<ClassDescriptor> toanalyzeList = new ArrayList<ClassDescriptor>();
195 List<MethodDescriptor> toanalyzeMethodList = new ArrayList<MethodDescriptor>();
197 toanalyzeList.addAll(classtable.getValueSet());
198 Collections.sort(toanalyzeList, new Comparator<ClassDescriptor>() {
199 public int compare(ClassDescriptor o1, ClassDescriptor o2) {
200 return o1.getClassName().compareTo(o2.getClassName());
204 for (int i = 0; i < toanalyzeList.size(); i++) {
205 ClassDescriptor cd = toanalyzeList.get(i);
207 SymbolTable methodtable = cd.getMethodTable();
208 toanalyzeMethodList.clear();
209 toanalyzeMethodList.addAll(methodtable.getValueSet());
210 Collections.sort(toanalyzeMethodList, new Comparator<MethodDescriptor>() {
211 public int compare(MethodDescriptor o1, MethodDescriptor o2) {
212 return o1.getSymbol().compareTo(o2.getSymbol());
216 for (int mdIdx = 0; mdIdx < toanalyzeMethodList.size(); mdIdx++) {
217 MethodDescriptor md = toanalyzeMethodList.get(mdIdx);
218 if (needTobeAnnotated(md)) {
219 lo.analyze(state.getMethodFlat(md));
220 doLoopTerminationCheck(lo, state.getMethodFlat(md));
228 public void addTrustMethod(MethodDescriptor md) {
229 trustWorthyMDSet.add(md);
232 public boolean isTrustMethod(MethodDescriptor md) {
233 return trustWorthyMDSet.contains(md);
236 private void computeLinearTypeCheckMethodSet() {
238 Set<MethodDescriptor> allCalledSet = callgraph.getMethodCalls(tu.getMain());
239 linearTypeCheckMethodSet.addAll(allCalledSet);
241 Set<MethodDescriptor> trustedSet = new HashSet<MethodDescriptor>();
243 for (Iterator iterator = trustWorthyMDSet.iterator(); iterator.hasNext();) {
244 MethodDescriptor trustMethod = (MethodDescriptor) iterator.next();
245 Set<MethodDescriptor> calledFromTrustMethodSet = callgraph.getMethodCalls(trustMethod);
246 trustedSet.add(trustMethod);
247 trustedSet.addAll(calledFromTrustMethodSet);
250 linearTypeCheckMethodSet.removeAll(trustedSet);
252 // if a method is called only by trusted method, no need to check linear
253 // type & flow down rule
254 for (Iterator iterator = trustedSet.iterator(); iterator.hasNext();) {
255 MethodDescriptor md = (MethodDescriptor) iterator.next();
256 Set<MethodDescriptor> callerSet = callgraph.getCallerSet(md);
257 if (!trustedSet.containsAll(callerSet) && !trustWorthyMDSet.contains(md)) {
258 linearTypeCheckMethodSet.add(md);
264 private void doLinearTypeCheck() {
265 LinearTypeCheck checker = new LinearTypeCheck(this, state);
266 checker.linearTypeCheck();
269 public void debug_printAnnotationRequiredSet() {
270 System.out.println("SSJAVA: SSJava is checking the following methods:");
271 for (Iterator<MethodDescriptor> iterator = annotationRequireSet.iterator(); iterator.hasNext();) {
272 MethodDescriptor md = iterator.next();
273 System.out.println(md);
275 System.out.println();
278 private void doMethodAnnotationCheck() {
279 methodAnnotationChecker = new MethodAnnotationCheck(this, state, tu);
280 methodAnnotationChecker.methodAnnoatationCheck();
281 methodAnnotationChecker.methodAnnoataionInheritanceCheck();
282 if (state.SSJAVAINFER) {
283 annotationRequireClassSet.add(methodContainingSSJavaLoop.getClassDesc());
284 annotationRequireSet.add(methodContainingSSJavaLoop);
286 state.setAnnotationRequireSet(annotationRequireSet);
289 public void doFlowDownCheck() {
290 flowDownChecker = new FlowDownCheck(this, state);
291 flowDownChecker.flowDownCheck();
294 public void doDefinitelyWrittenCheck() {
295 DefinitelyWrittenCheck checker = new DefinitelyWrittenCheck(this, state);
296 checker.definitelyWrittenCheck();
299 private void parseLocationAnnotation() {
300 Iterator it = state.getClassSymbolTable().getDescriptorsIterator();
301 while (it.hasNext()) {
302 ClassDescriptor cd = (ClassDescriptor) it.next();
303 // parsing location hierarchy declaration for the class
304 Vector<AnnotationDescriptor> classAnnotations = cd.getModifier().getAnnotations();
305 for (int i = 0; i < classAnnotations.size(); i++) {
306 AnnotationDescriptor an = classAnnotations.elementAt(i);
307 String marker = an.getMarker();
308 if (marker.equals(LATTICE)) {
309 SSJavaLattice<String> locOrder =
310 new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM);
311 cd2lattice.put(cd, locOrder);
312 parseClassLatticeDefinition(cd, an.getValue(), locOrder);
314 if (state.SSJAVADEBUG) {
315 // generate lattice dot file
316 writeLatticeDotFile(cd, null, locOrder);
319 } else if (marker.equals(METHODDEFAULT)) {
320 MethodLattice<String> locOrder =
321 new MethodLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM);
322 cd2methodDefault.put(cd, locOrder);
323 parseMethodDefaultLatticeDefinition(cd, an.getValue(), locOrder);
327 for (Iterator method_it = cd.getMethods(); method_it.hasNext();) {
328 MethodDescriptor md = (MethodDescriptor) method_it.next();
329 // parsing location hierarchy declaration for the method
331 if (needTobeAnnotated(md)) {
332 Vector<AnnotationDescriptor> methodAnnotations = md.getModifiers().getAnnotations();
333 if (methodAnnotations != null) {
334 for (int i = 0; i < methodAnnotations.size(); i++) {
335 AnnotationDescriptor an = methodAnnotations.elementAt(i);
336 if (an.getMarker().equals(LATTICE)) {
337 // developer explicitly defines method lattice
338 MethodLattice<String> locOrder =
339 new MethodLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM);
340 md2lattice.put(md, locOrder);
341 parseMethodDefaultLatticeDefinition(cd, an.getValue(), locOrder);
342 } else if (an.getMarker().equals(TERMINATE)) {
343 // developer explicitly wants to skip loop termination analysis
344 String value = an.getValue();
345 int maxIteration = 0;
347 maxIteration = Integer.parseInt(value);
349 skipLoopTerminate.put(md, new Integer(maxIteration));
360 public <T> void writeLatticeDotFile(ClassDescriptor cd, MethodDescriptor md,
361 SSJavaLattice<T> locOrder) {
362 writeLatticeDotFile(cd, md, locOrder, "");
366 public <T> void writeLatticeDotFile(ClassDescriptor cd, MethodDescriptor md,
367 SSJavaLattice<T> locOrder, String nameSuffix) {
369 String fileName = "lattice_";
372 cd.getSymbol().replaceAll("[\\W_]", "") + "_" + md.toString().replaceAll("[\\W_]", "");
374 fileName += cd.getSymbol().replaceAll("[\\W_]", "");
377 fileName += nameSuffix;
379 Set<Pair<T, T>> pairSet = locOrder.getOrderingPairSet();
381 if (pairSet.size() > 0) {
383 BufferedWriter bw = new BufferedWriter(new FileWriter(fileName + ".dot"));
385 bw.write("digraph " + fileName + " {\n");
387 for (Iterator iterator = pairSet.iterator(); iterator.hasNext();) {
388 // pair is in the form of <higher, lower>
389 Pair<T, T> pair = (Pair<T, T>) iterator.next();
391 T highLocId = pair.getFirst();
392 String highLocStr, lowLocStr;
393 if (locOrder.isSharedLoc(highLocId)) {
394 highLocStr = "\"" + highLocId + "*\"";
396 highLocStr = highLocId.toString();
398 T lowLocId = pair.getSecond();
399 if (locOrder.isSharedLoc(lowLocId)) {
400 lowLocStr = "\"" + lowLocId + "*\"";
402 lowLocStr = lowLocId.toString();
404 bw.write(highLocStr + " -> " + lowLocStr + ";\n");
409 } catch (IOException e) {
417 private void parseMethodDefaultLatticeDefinition(ClassDescriptor cd, String value,
418 MethodLattice<String> locOrder) {
420 value = value.replaceAll(" ", ""); // remove all blank spaces
422 StringTokenizer tokenizer = new StringTokenizer(value, ",");
424 while (tokenizer.hasMoreTokens()) {
425 String orderElement = tokenizer.nextToken();
426 int idx = orderElement.indexOf("<");
427 if (idx > 0) {// relative order element
428 String lowerLoc = orderElement.substring(0, idx);
429 String higherLoc = orderElement.substring(idx + 1);
430 locOrder.put(higherLoc, lowerLoc);
431 if (locOrder.isIntroducingCycle(higherLoc)) {
432 throw new Error("Error: the order relation " + lowerLoc + " < " + higherLoc
433 + " introduces a cycle.");
435 } else if (orderElement.startsWith(THISLOC + "=")) {
436 String thisLoc = orderElement.substring(8);
437 locOrder.setThisLoc(thisLoc);
438 } else if (orderElement.startsWith(GLOBALLOC + "=")) {
439 String globalLoc = orderElement.substring(10);
440 locOrder.setGlobalLoc(globalLoc);
441 } else if (orderElement.startsWith(RETURNLOC + "=")) {
442 String returnLoc = orderElement.substring(10);
443 locOrder.setReturnLoc(returnLoc);
444 } else if (orderElement.endsWith("*")) {
445 // spin loc definition
446 locOrder.addSharedLoc(orderElement.substring(0, orderElement.length() - 1));
449 locOrder.put(orderElement);
454 if (locOrder.getThisLoc() != null && !locOrder.containsKey(locOrder.getThisLoc())) {
455 throw new Error("Variable 'this' location '" + locOrder.getThisLoc()
456 + "' is not defined in the local variable lattice at " + cd.getSourceFileName());
459 if (locOrder.getGlobalLoc() != null && !locOrder.containsKey(locOrder.getGlobalLoc())) {
460 throw new Error("Variable global location '" + locOrder.getGlobalLoc()
461 + "' is not defined in the local variable lattice at " + cd.getSourceFileName());
465 private void parseClassLatticeDefinition(ClassDescriptor cd, String value,
466 SSJavaLattice<String> locOrder) {
468 value = value.replaceAll(" ", ""); // remove all blank spaces
470 StringTokenizer tokenizer = new StringTokenizer(value, ",");
472 while (tokenizer.hasMoreTokens()) {
473 String orderElement = tokenizer.nextToken();
474 int idx = orderElement.indexOf("<");
476 if (idx > 0) {// relative order element
477 String lowerLoc = orderElement.substring(0, idx);
478 String higherLoc = orderElement.substring(idx + 1);
479 locOrder.put(higherLoc, lowerLoc);
480 if (locOrder.isIntroducingCycle(higherLoc)) {
481 throw new Error("Error: the order relation " + lowerLoc + " < " + higherLoc
482 + " introduces a cycle in the class lattice " + cd);
484 } else if (orderElement.contains("*")) {
485 // spin loc definition
486 locOrder.addSharedLoc(orderElement.substring(0, orderElement.length() - 1));
489 locOrder.put(orderElement);
494 Set<String> spinLocSet = locOrder.getSharedLocSet();
495 for (Iterator iterator = spinLocSet.iterator(); iterator.hasNext();) {
496 String spinLoc = (String) iterator.next();
497 if (!locOrder.containsKey(spinLoc)) {
498 throw new Error("Spin location '" + spinLoc
499 + "' is not defined in the default local variable lattice at " + cd.getSourceFileName());
504 public Hashtable<ClassDescriptor, SSJavaLattice<String>> getCd2lattice() {
508 public Hashtable<ClassDescriptor, MethodLattice<String>> getCd2methodDefault() {
509 return cd2methodDefault;
512 public Hashtable<MethodDescriptor, MethodLattice<String>> getMd2lattice() {
516 public SSJavaLattice<String> getClassLattice(ClassDescriptor cd) {
517 return cd2lattice.get(cd);
520 public MethodLattice<String> getMethodDefaultLattice(ClassDescriptor cd) {
521 return cd2methodDefault.get(cd);
524 public MethodLattice<String> getMethodLattice(MethodDescriptor md) {
525 if (md2lattice.containsKey(md)) {
526 return md2lattice.get(md);
529 if (cd2methodDefault.containsKey(md.getClassDesc())) {
530 return cd2methodDefault.get(md.getClassDesc());
532 throw new Error("Method Lattice of " + md + " is not defined.");
538 public CompositeLocation getPCLocation(MethodDescriptor md) {
539 if (!md2pcLoc.containsKey(md)) {
540 // by default, the initial pc location is TOP
541 CompositeLocation pcLoc = new CompositeLocation(new Location(md, Location.TOP));
542 md2pcLoc.put(md, pcLoc);
544 return md2pcLoc.get(md);
547 public void setPCLocation(MethodDescriptor md, CompositeLocation pcLoc) {
548 md2pcLoc.put(md, pcLoc);
551 public boolean needToCheckLinearType(MethodDescriptor md) {
552 return linearTypeCheckMethodSet.contains(md);
555 public boolean needTobeAnnotated(MethodDescriptor md) {
556 return annotationRequireSet.contains(md);
559 public boolean needToBeAnnoated(ClassDescriptor cd) {
560 return annotationRequireClassSet.contains(cd);
563 public void addAnnotationRequire(ClassDescriptor cd) {
564 annotationRequireClassSet.add(cd);
567 public void addAnnotationRequire(MethodDescriptor md) {
569 ClassDescriptor cd = md.getClassDesc();
570 // if a method requires to be annotated, class containg that method also
571 // requires to be annotated
572 if (!isSSJavaUtil(cd)) {
573 annotationRequireClassSet.add(cd);
574 annotationRequireSet.add(md);
578 public Set<MethodDescriptor> getAnnotationRequireSet() {
579 return annotationRequireSet;
582 public void doLoopTerminationCheck(LoopOptimize lo, FlatMethod fm) {
583 LoopTerminate lt = new LoopTerminate(this, state);
584 if (needTobeAnnotated(fm.getMethod())) {
585 lt.terminateAnalysis(fm, lo.getLoopInvariant(fm));
589 public CallGraph getCallGraph() {
593 public SSJavaLattice<String> getLattice(Descriptor d) {
595 if (d instanceof MethodDescriptor) {
596 return getMethodLattice((MethodDescriptor) d);
598 return getClassLattice((ClassDescriptor) d);
603 public boolean isSharedLocation(Location loc) {
604 SSJavaLattice<String> lattice = getLattice(loc.getDescriptor());
605 return lattice.getSharedLocSet().contains(loc.getLocIdentifier());
608 public void mapSharedLocation2Descriptor(Location loc, Descriptor d) {
609 Set<Descriptor> set = mapSharedLocation2DescriptorSet.get(loc);
611 set = new HashSet<Descriptor>();
612 mapSharedLocation2DescriptorSet.put(loc, set);
617 public BuildFlat getBuildFlat() {
621 public MethodDescriptor getMethodContainingSSJavaLoop() {
622 return methodContainingSSJavaLoop;
625 public void setMethodContainingSSJavaLoop(MethodDescriptor methodContainingSSJavaLoop) {
626 this.methodContainingSSJavaLoop = methodContainingSSJavaLoop;
629 public boolean isSSJavaUtil(ClassDescriptor cd) {
630 if (cd.getSymbol().equals("SSJAVA")) {
636 public void setFieldOnwership(MethodDescriptor md, FieldDescriptor field) {
638 Set<FieldDescriptor> fieldSet = mapMethodToOwnedFieldSet.get(md);
639 if (fieldSet == null) {
640 fieldSet = new HashSet<FieldDescriptor>();
641 mapMethodToOwnedFieldSet.put(md, fieldSet);
646 public boolean isOwnedByMethod(MethodDescriptor md, FieldDescriptor field) {
647 Set<FieldDescriptor> fieldSet = mapMethodToOwnedFieldSet.get(md);
648 if (fieldSet != null) {
649 return fieldSet.contains(field);
654 public FlatNode getSSJavaLoopEntrance() {
655 return ssjavaLoopEntrance;
658 public void setSSJavaLoopEntrance(FlatNode ssjavaLoopEntrance) {
659 this.ssjavaLoopEntrance = ssjavaLoopEntrance;
662 public void addSameHeightWriteFlatNode(FlatNode fn) {
663 this.sameHeightWriteFlatNodeSet.add(fn);
666 public boolean isSameHeightWrite(FlatNode fn) {
667 return this.sameHeightWriteFlatNodeSet.contains(fn);
670 public LinkedList<MethodDescriptor> topologicalSort(Set<MethodDescriptor> toSort) {
672 Set<MethodDescriptor> discovered = new HashSet<MethodDescriptor>();
674 LinkedList<MethodDescriptor> sorted = new LinkedList<MethodDescriptor>();
676 Iterator<MethodDescriptor> itr = toSort.iterator();
677 while (itr.hasNext()) {
678 MethodDescriptor d = itr.next();
680 if (!discovered.contains(d)) {
681 dfsVisit(d, toSort, sorted, discovered);
688 // While we're doing DFS on call graph, remember
689 // dependencies for efficient queuing of methods
690 // during interprocedural analysis:
692 // a dependent of a method decriptor d for this analysis is:
693 // 1) a method or task that invokes d
694 // 2) in the descriptorsToAnalyze set
695 private void dfsVisit(MethodDescriptor md, Set<MethodDescriptor> toSort,
696 LinkedList<MethodDescriptor> sorted, Set<MethodDescriptor> discovered) {
700 Iterator itr2 = callgraph.getCalleeSet(md).iterator();
701 while (itr2.hasNext()) {
702 MethodDescriptor dCallee = (MethodDescriptor) itr2.next();
703 addDependent(dCallee, md);
706 Iterator itr = callgraph.getCallerSet(md).iterator();
707 while (itr.hasNext()) {
708 MethodDescriptor dCaller = (MethodDescriptor) itr.next();
709 // only consider callers in the original set to analyze
710 if (!toSort.contains(dCaller)) {
713 if (!discovered.contains(dCaller)) {
714 addDependent(md, // callee
718 dfsVisit(dCaller, toSort, sorted, discovered);
722 // for leaf-nodes last now!
726 public void addDependent(MethodDescriptor callee, MethodDescriptor caller) {
727 Set<MethodDescriptor> deps = mapDescriptorToSetDependents.get(callee);
729 deps = new HashSet<MethodDescriptor>();
732 mapDescriptorToSetDependents.put(callee, deps);
735 public Set<MethodDescriptor> getDependents(MethodDescriptor callee) {
736 Set<MethodDescriptor> deps = mapDescriptorToSetDependents.get(callee);
738 deps = new HashSet<MethodDescriptor>();
739 mapDescriptorToSetDependents.put(callee, deps);