1 package Analysis.Disjoint;
3 import Analysis.CallGraph.*;
4 import Analysis.Liveness;
5 import Analysis.ArrayReferencees;
6 import Analysis.OoOJava.RBlockRelationAnalysis;
7 import Analysis.OoOJava.RBlockStatusAnalysis;
10 import IR.Tree.Modifiers;
15 public class DisjointAnalysis {
17 ///////////////////////////////////////////
19 // Public interface to discover possible
20 // sharing in the program under analysis
22 ///////////////////////////////////////////
24 // if an object allocated at the target site may be
25 // reachable from both an object from root1 and an
26 // object allocated at root2, return TRUE
27 public boolean mayBothReachTarget( FlatMethod fm,
32 AllocSite asr1 = getAllocationSiteFromFlatNew( fnRoot1 );
33 AllocSite asr2 = getAllocationSiteFromFlatNew( fnRoot2 );
34 assert asr1.isFlagged();
35 assert asr2.isFlagged();
37 AllocSite ast = getAllocationSiteFromFlatNew( fnTarget );
38 ReachGraph rg = getPartial( fm.getMethod() );
40 return rg.mayBothReachTarget( asr1, asr2, ast );
43 // similar to the method above, return TRUE if ever
44 // more than one object from the root allocation site
45 // may reach an object from the target site
46 public boolean mayManyReachTarget( FlatMethod fm,
50 AllocSite asr = getAllocationSiteFromFlatNew( fnRoot );
51 assert asr.isFlagged();
53 AllocSite ast = getAllocationSiteFromFlatNew( fnTarget );
54 ReachGraph rg = getPartial( fm.getMethod() );
56 return rg.mayManyReachTarget( asr, ast );
62 public HashSet<AllocSite>
63 getFlaggedAllocationSitesReachableFromTask(TaskDescriptor td) {
64 checkAnalysisComplete();
65 return getFlaggedAllocationSitesReachableFromTaskPRIVATE(td);
68 public AllocSite getAllocationSiteFromFlatNew(FlatNew fn) {
69 checkAnalysisComplete();
70 return getAllocSiteFromFlatNewPRIVATE(fn);
73 public AllocSite getAllocationSiteFromHeapRegionNodeID(Integer id) {
74 checkAnalysisComplete();
75 return mapHrnIdToAllocSite.get(id);
78 public Set<HeapRegionNode> hasPotentialSharing(Descriptor taskOrMethod,
81 checkAnalysisComplete();
82 ReachGraph rg=mapDescriptorToCompleteReachGraph.get(taskOrMethod);
83 FlatMethod fm=state.getMethodFlat(taskOrMethod);
85 return rg.mayReachSharedObjects(fm, paramIndex1, paramIndex2);
88 public Set<HeapRegionNode> hasPotentialSharing(Descriptor taskOrMethod,
89 int paramIndex, AllocSite alloc) {
90 checkAnalysisComplete();
91 ReachGraph rg = mapDescriptorToCompleteReachGraph.get(taskOrMethod);
92 FlatMethod fm=state.getMethodFlat(taskOrMethod);
94 return rg.mayReachSharedObjects(fm, paramIndex, alloc);
97 public Set<HeapRegionNode> hasPotentialSharing(Descriptor taskOrMethod,
98 AllocSite alloc, int paramIndex) {
99 checkAnalysisComplete();
100 ReachGraph rg = mapDescriptorToCompleteReachGraph.get(taskOrMethod);
101 FlatMethod fm=state.getMethodFlat(taskOrMethod);
103 return rg.mayReachSharedObjects(fm, paramIndex, alloc);
106 public Set<HeapRegionNode> hasPotentialSharing(Descriptor taskOrMethod,
107 AllocSite alloc1, AllocSite alloc2) {
108 checkAnalysisComplete();
109 ReachGraph rg = mapDescriptorToCompleteReachGraph.get(taskOrMethod);
111 return rg.mayReachSharedObjects(alloc1, alloc2);
114 public String prettyPrintNodeSet(Set<HeapRegionNode> s) {
115 checkAnalysisComplete();
119 Iterator<HeapRegionNode> i = s.iterator();
120 while (i.hasNext()) {
121 HeapRegionNode n = i.next();
123 AllocSite as = n.getAllocSite();
125 out += " " + n.toString() + ",\n";
127 out += " " + n.toString() + ": " + as.toStringVerbose()
136 // use the methods given above to check every possible sharing class
137 // between task parameters and flagged allocation sites reachable
139 public void writeAllSharing(String outputFile,
142 boolean tabularOutput,
145 throws java.io.IOException {
146 checkAnalysisComplete();
148 BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile));
150 if (!tabularOutput) {
151 bw.write("Conducting ownership analysis with allocation depth = "
152 + allocationDepth + "\n");
153 bw.write(timeReport + "\n");
158 // look through every task for potential sharing
159 Iterator taskItr = state.getTaskSymbolTable().getDescriptorsIterator();
160 while (taskItr.hasNext()) {
161 TaskDescriptor td = (TaskDescriptor) taskItr.next();
163 if (!tabularOutput) {
164 bw.write("\n---------" + td + "--------\n");
167 HashSet<AllocSite> allocSites = getFlaggedAllocationSitesReachableFromTask(td);
169 Set<HeapRegionNode> common;
171 // for each task parameter, check for sharing classes with
172 // other task parameters and every allocation site
173 // reachable from this task
174 boolean foundSomeSharing = false;
176 FlatMethod fm = state.getMethodFlat(td);
177 for (int i = 0; i < fm.numParameters(); ++i) {
179 // skip parameters with types that cannot reference
181 if( !shouldAnalysisTrack( fm.getParameter( i ).getType() ) ) {
185 // for the ith parameter check for sharing classes to all
186 // higher numbered parameters
187 for (int j = i + 1; j < fm.numParameters(); ++j) {
189 // skip parameters with types that cannot reference
191 if( !shouldAnalysisTrack( fm.getParameter( j ).getType() ) ) {
196 common = hasPotentialSharing(td, i, j);
197 if (!common.isEmpty()) {
198 foundSomeSharing = true;
200 if (!tabularOutput) {
201 bw.write("Potential sharing between parameters " + i
202 + " and " + j + ".\n");
203 bw.write(prettyPrintNodeSet(common) + "\n");
208 // for the ith parameter, check for sharing classes against
209 // the set of allocation sites reachable from this
211 Iterator allocItr = allocSites.iterator();
212 while (allocItr.hasNext()) {
213 AllocSite as = (AllocSite) allocItr.next();
214 common = hasPotentialSharing(td, i, as);
215 if (!common.isEmpty()) {
216 foundSomeSharing = true;
218 if (!tabularOutput) {
219 bw.write("Potential sharing between parameter " + i
220 + " and " + as.getFlatNew() + ".\n");
221 bw.write(prettyPrintNodeSet(common) + "\n");
227 // for each allocation site check for sharing classes with
228 // other allocation sites in the context of execution
230 HashSet<AllocSite> outerChecked = new HashSet<AllocSite>();
231 Iterator allocItr1 = allocSites.iterator();
232 while (allocItr1.hasNext()) {
233 AllocSite as1 = (AllocSite) allocItr1.next();
235 Iterator allocItr2 = allocSites.iterator();
236 while (allocItr2.hasNext()) {
237 AllocSite as2 = (AllocSite) allocItr2.next();
239 if (!outerChecked.contains(as2)) {
240 common = hasPotentialSharing(td, as1, as2);
242 if (!common.isEmpty()) {
243 foundSomeSharing = true;
245 if (!tabularOutput) {
246 bw.write("Potential sharing between "
247 + as1.getFlatNew() + " and "
248 + as2.getFlatNew() + ".\n");
249 bw.write(prettyPrintNodeSet(common) + "\n");
255 outerChecked.add(as1);
258 if (!foundSomeSharing) {
259 if (!tabularOutput) {
260 bw.write("No sharing between flagged objects in Task " + td
268 bw.write(" & " + numSharing + " & " + justTime + " & " + numLines
269 + " & " + numMethodsAnalyzed() + " \\\\\n");
271 bw.write("\nNumber sharing classes: "+numSharing);
277 // this version of writeAllSharing is for Java programs that have no tasks
278 public void writeAllSharingJava(String outputFile,
281 boolean tabularOutput,
284 throws java.io.IOException {
285 checkAnalysisComplete();
291 BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile));
293 bw.write("Conducting disjoint reachability analysis with allocation depth = "
294 + allocationDepth + "\n");
295 bw.write(timeReport + "\n\n");
297 boolean foundSomeSharing = false;
299 Descriptor d = typeUtil.getMain();
300 HashSet<AllocSite> allocSites = getFlaggedAllocationSites(d);
302 // for each allocation site check for sharing classes with
303 // other allocation sites in the context of execution
305 HashSet<AllocSite> outerChecked = new HashSet<AllocSite>();
306 Iterator allocItr1 = allocSites.iterator();
307 while (allocItr1.hasNext()) {
308 AllocSite as1 = (AllocSite) allocItr1.next();
310 Iterator allocItr2 = allocSites.iterator();
311 while (allocItr2.hasNext()) {
312 AllocSite as2 = (AllocSite) allocItr2.next();
314 if (!outerChecked.contains(as2)) {
315 Set<HeapRegionNode> common = hasPotentialSharing(d,
318 if (!common.isEmpty()) {
319 foundSomeSharing = true;
320 bw.write("Potential sharing between "
321 + as1.getDisjointAnalysisId() + " and "
322 + as2.getDisjointAnalysisId() + ".\n");
323 bw.write(prettyPrintNodeSet(common) + "\n");
329 outerChecked.add(as1);
332 if (!foundSomeSharing) {
333 bw.write("No sharing classes between flagged objects found.\n");
335 bw.write("\nNumber sharing classes: "+numSharing);
338 bw.write("Number of methods analyzed: "+numMethodsAnalyzed()+"\n");
343 ///////////////////////////////////////////
345 // end public interface
347 ///////////////////////////////////////////
351 protected void checkAnalysisComplete() {
352 if( !analysisComplete ) {
353 throw new Error("Warning: public interface method called while analysis is running.");
362 // run in faster mode, only when bugs wrung out!
363 public static boolean releaseMode;
365 // use command line option to set this, analysis
366 // should attempt to be deterministic
367 public static boolean determinismDesired;
369 // when we want to enforce determinism in the
370 // analysis we need to sort descriptors rather
371 // than toss them in efficient sets, use this
372 public static DescriptorComparator dComp =
373 new DescriptorComparator();
376 // data from the compiler
378 public CallGraph callGraph;
379 public Liveness liveness;
380 public ArrayReferencees arrayReferencees;
381 public RBlockRelationAnalysis rblockRel;
382 public RBlockStatusAnalysis rblockStatus;
383 public TypeUtil typeUtil;
384 public int allocationDepth;
386 protected boolean doEffectsAnalysis = false;
387 protected EffectsAnalysis effectsAnalysis;
389 // data structure for public interface
390 private Hashtable< Descriptor, HashSet<AllocSite> >
391 mapDescriptorToAllocSiteSet;
394 // for public interface methods to warn that they
395 // are grabbing results during analysis
396 private boolean analysisComplete;
399 // used to identify HeapRegionNode objects
400 // A unique ID equates an object in one
401 // ownership graph with an object in another
402 // graph that logically represents the same
404 // start at 10 and increment to reserve some
405 // IDs for special purposes
406 static protected int uniqueIDcount = 10;
409 // An out-of-scope method created by the
410 // analysis that has no parameters, and
411 // appears to allocate the command line
412 // arguments, then invoke the source code's
413 // main method. The purpose of this is to
414 // provide the analysis with an explicit
415 // top-level context with no parameters
416 protected MethodDescriptor mdAnalysisEntry;
417 protected FlatMethod fmAnalysisEntry;
419 // main method defined by source program
420 protected MethodDescriptor mdSourceEntry;
422 // the set of task and/or method descriptors
423 // reachable in call graph
424 protected Set<Descriptor>
425 descriptorsToAnalyze;
427 // current descriptors to visit in fixed-point
428 // interprocedural analysis, prioritized by
429 // dependency in the call graph
430 protected Stack<Descriptor>
431 descriptorsToVisitStack;
432 protected PriorityQueue<DescriptorQWrapper>
435 // a duplication of the above structure, but
436 // for efficient testing of inclusion
437 protected HashSet<Descriptor>
438 descriptorsToVisitSet;
440 // storage for priorities (doesn't make sense)
441 // to add it to the Descriptor class, just in
443 protected Hashtable<Descriptor, Integer>
444 mapDescriptorToPriority;
446 // when analyzing a method and scheduling more:
447 // remember set of callee's enqueued for analysis
448 // so they can be put on top of the callers in
449 // the stack-visit mode
450 protected Set<Descriptor>
453 // maps a descriptor to its current partial result
454 // from the intraprocedural fixed-point analysis--
455 // then the interprocedural analysis settles, this
456 // mapping will have the final results for each
458 protected Hashtable<Descriptor, ReachGraph>
459 mapDescriptorToCompleteReachGraph;
461 // maps a descriptor to its known dependents: namely
462 // methods or tasks that call the descriptor's method
463 // AND are part of this analysis (reachable from main)
464 protected Hashtable< Descriptor, Set<Descriptor> >
465 mapDescriptorToSetDependents;
467 // if the analysis client wants to flag allocation sites
468 // programmatically, it should provide a set of FlatNew
469 // statements--this may be null if unneeded
470 protected Set<FlatNew> sitesToFlag;
472 // maps each flat new to one analysis abstraction
473 // allocate site object, these exist outside reach graphs
474 protected Hashtable<FlatNew, AllocSite>
475 mapFlatNewToAllocSite;
477 // maps intergraph heap region IDs to intergraph
478 // allocation sites that created them, a redundant
479 // structure for efficiency in some operations
480 protected Hashtable<Integer, AllocSite>
483 // maps a method to its initial heap model (IHM) that
484 // is the set of reachability graphs from every caller
485 // site, all merged together. The reason that we keep
486 // them separate is that any one call site's contribution
487 // to the IHM may changed along the path to the fixed point
488 protected Hashtable< Descriptor, Hashtable< FlatCall, ReachGraph > >
489 mapDescriptorToIHMcontributions;
491 // additionally, keep a mapping from descriptors to the
492 // merged in-coming initial context, because we want this
493 // initial context to be STRICTLY MONOTONIC
494 protected Hashtable<Descriptor, ReachGraph>
495 mapDescriptorToInitialContext;
497 // make the result for back edges analysis-wide STRICTLY
498 // MONOTONIC as well, but notice we use FlatNode as the
499 // key for this map: in case we want to consider other
500 // nodes as back edge's in future implementations
501 protected Hashtable<FlatNode, ReachGraph>
502 mapBackEdgeToMonotone;
505 public static final String arrayElementFieldName = "___element_";
506 static protected Hashtable<TypeDescriptor, FieldDescriptor>
509 // for controlling DOT file output
510 protected boolean writeFinalDOTs;
511 protected boolean writeAllIncrementalDOTs;
513 // supporting DOT output--when we want to write every
514 // partial method result, keep a tally for generating
516 protected Hashtable<Descriptor, Integer>
517 mapDescriptorToNumUpdates;
519 //map task descriptor to initial task parameter
520 protected Hashtable<Descriptor, ReachGraph>
521 mapDescriptorToReachGraph;
523 protected PointerMethod pm;
525 static protected Hashtable<FlatNode, ReachGraph> fn2rg =
526 new Hashtable<FlatNode, ReachGraph>();
528 private Hashtable<FlatCall, Descriptor> fc2enclosing;
531 // allocate various structures that are not local
532 // to a single class method--should be done once
533 protected void allocateStructures() {
535 if( determinismDesired ) {
536 // use an ordered set
537 descriptorsToAnalyze = new TreeSet<Descriptor>( dComp );
539 // otherwise use a speedy hashset
540 descriptorsToAnalyze = new HashSet<Descriptor>();
543 mapDescriptorToCompleteReachGraph =
544 new Hashtable<Descriptor, ReachGraph>();
546 mapDescriptorToNumUpdates =
547 new Hashtable<Descriptor, Integer>();
549 mapDescriptorToSetDependents =
550 new Hashtable< Descriptor, Set<Descriptor> >();
552 mapFlatNewToAllocSite =
553 new Hashtable<FlatNew, AllocSite>();
555 mapDescriptorToIHMcontributions =
556 new Hashtable< Descriptor, Hashtable< FlatCall, ReachGraph > >();
558 mapDescriptorToInitialContext =
559 new Hashtable<Descriptor, ReachGraph>();
561 mapBackEdgeToMonotone =
562 new Hashtable<FlatNode, ReachGraph>();
564 mapHrnIdToAllocSite =
565 new Hashtable<Integer, AllocSite>();
567 mapTypeToArrayField =
568 new Hashtable <TypeDescriptor, FieldDescriptor>();
570 if( state.DISJOINTDVISITSTACK ||
571 state.DISJOINTDVISITSTACKEESONTOP
573 descriptorsToVisitStack =
574 new Stack<Descriptor>();
577 if( state.DISJOINTDVISITPQUE ) {
578 descriptorsToVisitQ =
579 new PriorityQueue<DescriptorQWrapper>();
582 descriptorsToVisitSet =
583 new HashSet<Descriptor>();
585 mapDescriptorToPriority =
586 new Hashtable<Descriptor, Integer>();
589 new HashSet<Descriptor>();
591 mapDescriptorToAllocSiteSet =
592 new Hashtable<Descriptor, HashSet<AllocSite> >();
594 mapDescriptorToReachGraph =
595 new Hashtable<Descriptor, ReachGraph>();
597 pm = new PointerMethod();
599 fc2enclosing = new Hashtable<FlatCall, Descriptor>();
604 // this analysis generates a disjoint reachability
605 // graph for every reachable method in the program
606 public DisjointAnalysis( State s,
611 Set<FlatNew> sitesToFlag,
612 RBlockRelationAnalysis rra,
613 RBlockStatusAnalysis rsa
615 init( s, tu, cg, l, ar, sitesToFlag, rra, rsa );
618 protected void init( State state,
622 ArrayReferencees arrayReferencees,
623 Set<FlatNew> sitesToFlag,
624 RBlockRelationAnalysis rra,
625 RBlockStatusAnalysis rsa
628 analysisComplete = false;
631 this.typeUtil = typeUtil;
632 this.callGraph = callGraph;
633 this.liveness = liveness;
634 this.arrayReferencees = arrayReferencees;
635 this.sitesToFlag = sitesToFlag;
636 this.rblockRel = rra;
637 this.rblockStatus = rsa;
639 if( rblockRel != null ) {
640 doEffectsAnalysis = true;
641 effectsAnalysis = new EffectsAnalysis();
644 this.allocationDepth = state.DISJOINTALLOCDEPTH;
645 this.releaseMode = state.DISJOINTRELEASEMODE;
646 this.determinismDesired = state.DISJOINTDETERMINISM;
648 this.writeFinalDOTs = state.DISJOINTWRITEDOTS && !state.DISJOINTWRITEALL;
649 this.writeAllIncrementalDOTs = state.DISJOINTWRITEDOTS && state.DISJOINTWRITEALL;
651 this.takeDebugSnapshots = state.DISJOINTSNAPSYMBOL != null;
652 this.descSymbolDebug = state.DISJOINTSNAPSYMBOL;
653 this.visitStartCapture = state.DISJOINTSNAPVISITTOSTART;
654 this.numVisitsToCapture = state.DISJOINTSNAPNUMVISITS;
655 this.stopAfterCapture = state.DISJOINTSNAPSTOPAFTER;
656 this.snapVisitCounter = 1; // count visits from 1 (user will write 1, means 1st visit)
657 this.snapNodeCounter = 0; // count nodes from 0
660 state.DISJOINTDVISITSTACK ||
661 state.DISJOINTDVISITPQUE ||
662 state.DISJOINTDVISITSTACKEESONTOP;
663 assert !(state.DISJOINTDVISITSTACK && state.DISJOINTDVISITPQUE);
664 assert !(state.DISJOINTDVISITSTACK && state.DISJOINTDVISITSTACKEESONTOP);
665 assert !(state.DISJOINTDVISITPQUE && state.DISJOINTDVISITSTACKEESONTOP);
667 // set some static configuration for ReachGraphs
668 ReachGraph.allocationDepth = allocationDepth;
669 ReachGraph.typeUtil = typeUtil;
671 ReachGraph.debugCallSiteVisitStartCapture
672 = state.DISJOINTDEBUGCALLVISITTOSTART;
674 ReachGraph.debugCallSiteNumVisitsToCapture
675 = state.DISJOINTDEBUGCALLNUMVISITS;
677 ReachGraph.debugCallSiteStopAfter
678 = state.DISJOINTDEBUGCALLSTOPAFTER;
680 ReachGraph.debugCallSiteVisitCounter
681 = 0; // count visits from 1, is incremented before first visit
685 allocateStructures();
687 double timeStartAnalysis = (double) System.nanoTime();
689 // start interprocedural fixed-point computation
692 } catch( IOException e ) {
693 throw new Error( "IO Exception while writing disjointness analysis output." );
696 analysisComplete=true;
698 double timeEndAnalysis = (double) System.nanoTime();
699 double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) );
700 String treport = String.format( "The reachability analysis took %.3f sec.", dt );
701 String justtime = String.format( "%.2f", dt );
702 System.out.println( treport );
705 if( writeFinalDOTs && !writeAllIncrementalDOTs ) {
709 if( state.DISJOINTWRITEIHMS ) {
713 if( state.DISJOINTWRITEINITCONTEXTS ) {
714 writeInitialContexts();
717 if( state.DISJOINTALIASFILE != null ) {
719 writeAllSharing(state.DISJOINTALIASFILE, treport, justtime, state.DISJOINTALIASTAB, state.lines);
721 writeAllSharingJava(state.DISJOINTALIASFILE,
724 state.DISJOINTALIASTAB,
729 } catch( IOException e ) {
730 throw new Error( "IO Exception while writing disjointness analysis output." );
736 protected boolean moreDescriptorsToVisit() {
737 if( state.DISJOINTDVISITSTACK ||
738 state.DISJOINTDVISITSTACKEESONTOP
740 return !descriptorsToVisitStack.isEmpty();
742 } else if( state.DISJOINTDVISITPQUE ) {
743 return !descriptorsToVisitQ.isEmpty();
746 throw new Error( "Neither descriptor visiting mode set" );
750 // fixed-point computation over the call graph--when a
751 // method's callees are updated, it must be reanalyzed
752 protected void analyzeMethods() throws java.io.IOException {
754 // task or non-task (java) mode determines what the roots
755 // of the call chain are, and establishes the set of methods
756 // reachable from the roots that will be analyzed
759 System.out.println( "Bamboo mode..." );
761 Iterator taskItr = state.getTaskSymbolTable().getDescriptorsIterator();
762 while( taskItr.hasNext() ) {
763 TaskDescriptor td = (TaskDescriptor) taskItr.next();
764 if( !descriptorsToAnalyze.contains( td ) ) {
765 // add all methods transitively reachable from the
767 descriptorsToAnalyze.add( td );
768 descriptorsToAnalyze.addAll( callGraph.getAllMethods( td ) );
773 System.out.println( "Java mode..." );
775 // add all methods transitively reachable from the
776 // source's main to set for analysis
777 mdSourceEntry = typeUtil.getMain();
778 descriptorsToAnalyze.add( mdSourceEntry );
779 descriptorsToAnalyze.addAll( callGraph.getAllMethods( mdSourceEntry ) );
781 // fabricate an empty calling context that will call
782 // the source's main, but call graph doesn't know
783 // about it, so explicitly add it
784 makeAnalysisEntryMethod( mdSourceEntry );
785 descriptorsToAnalyze.add( mdAnalysisEntry );
789 // now, depending on the interprocedural mode for visiting
790 // methods, set up the needed data structures
792 if( state.DISJOINTDVISITPQUE ) {
794 // topologically sort according to the call graph so
795 // leaf calls are last, helps build contexts up first
796 LinkedList<Descriptor> sortedDescriptors =
797 topologicalSort( descriptorsToAnalyze );
799 // add sorted descriptors to priority queue, and duplicate
800 // the queue as a set for efficiently testing whether some
801 // method is marked for analysis
803 Iterator<Descriptor> dItr;
805 // for the priority queue, give items at the head
806 // of the sorted list a low number (highest priority)
807 while( !sortedDescriptors.isEmpty() ) {
808 Descriptor d = sortedDescriptors.removeFirst();
809 mapDescriptorToPriority.put( d, new Integer( p ) );
810 descriptorsToVisitQ.add( new DescriptorQWrapper( p, d ) );
811 descriptorsToVisitSet.add( d );
815 } else if( state.DISJOINTDVISITSTACK ||
816 state.DISJOINTDVISITSTACKEESONTOP
818 // if we're doing the stack scheme, just throw the root
819 // method or tasks on the stack
821 Iterator taskItr = state.getTaskSymbolTable().getDescriptorsIterator();
822 while( taskItr.hasNext() ) {
823 TaskDescriptor td = (TaskDescriptor) taskItr.next();
824 descriptorsToVisitStack.add( td );
825 descriptorsToVisitSet.add( td );
829 descriptorsToVisitStack.add( mdAnalysisEntry );
830 descriptorsToVisitSet.add( mdAnalysisEntry );
834 throw new Error( "Unknown method scheduling mode" );
838 // analyze scheduled methods until there are no more to visit
839 while( moreDescriptorsToVisit() ) {
842 if( state.DISJOINTDVISITSTACK ||
843 state.DISJOINTDVISITSTACKEESONTOP
845 d = descriptorsToVisitStack.pop();
847 } else if( state.DISJOINTDVISITPQUE ) {
848 d = descriptorsToVisitQ.poll().getDescriptor();
851 assert descriptorsToVisitSet.contains( d );
852 descriptorsToVisitSet.remove( d );
854 // because the task or method descriptor just extracted
855 // was in the "to visit" set it either hasn't been analyzed
856 // yet, or some method that it depends on has been
857 // updated. Recompute a complete reachability graph for
858 // this task/method and compare it to any previous result.
859 // If there is a change detected, add any methods/tasks
860 // that depend on this one to the "to visit" set.
862 System.out.println( "Analyzing " + d );
864 if( state.DISJOINTDVISITSTACKEESONTOP ) {
865 assert calleesToEnqueue.isEmpty();
868 ReachGraph rg = analyzeMethod( d );
869 ReachGraph rgPrev = getPartial( d );
871 if( !rg.equals( rgPrev ) ) {
874 if( state.DISJOINTDEBUGSCHEDULING ) {
875 System.out.println( " complete graph changed, scheduling callers for analysis:" );
878 // results for d changed, so enqueue dependents
879 // of d for further analysis
880 Iterator<Descriptor> depsItr = getDependents( d ).iterator();
881 while( depsItr.hasNext() ) {
882 Descriptor dNext = depsItr.next();
885 if( state.DISJOINTDEBUGSCHEDULING ) {
886 System.out.println( " "+dNext );
891 // whether or not the method under analysis changed,
892 // we may have some callees that are scheduled for
893 // more analysis, and they should go on the top of
894 // the stack now (in other method-visiting modes they
895 // are already enqueued at this point
896 if( state.DISJOINTDVISITSTACKEESONTOP ) {
897 Iterator<Descriptor> depsItr = calleesToEnqueue.iterator();
898 while( depsItr.hasNext() ) {
899 Descriptor dNext = depsItr.next();
902 calleesToEnqueue.clear();
908 protected ReachGraph analyzeMethod( Descriptor d )
909 throws java.io.IOException {
911 // get the flat code for this descriptor
913 if( d == mdAnalysisEntry ) {
914 fm = fmAnalysisEntry;
916 fm = state.getMethodFlat( d );
918 pm.analyzeMethod( fm );
920 // intraprocedural work set
921 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
922 flatNodesToVisit.add( fm );
924 // if determinism is desired by client, shadow the
925 // set with a queue to make visit order deterministic
926 Queue<FlatNode> flatNodesToVisitQ = null;
927 if( determinismDesired ) {
928 flatNodesToVisitQ = new LinkedList<FlatNode>();
929 flatNodesToVisitQ.add( fm );
932 // mapping of current partial results
933 Hashtable<FlatNode, ReachGraph> mapFlatNodeToReachGraph =
934 new Hashtable<FlatNode, ReachGraph>();
936 // the set of return nodes partial results that will be combined as
937 // the final, conservative approximation of the entire method
938 HashSet<FlatReturnNode> setReturns = new HashSet<FlatReturnNode>();
940 while( !flatNodesToVisit.isEmpty() ) {
943 if( determinismDesired ) {
944 assert !flatNodesToVisitQ.isEmpty();
945 fn = flatNodesToVisitQ.remove();
947 fn = flatNodesToVisit.iterator().next();
949 flatNodesToVisit.remove( fn );
951 // effect transfer function defined by this node,
952 // then compare it to the old graph at this node
953 // to see if anything was updated.
955 ReachGraph rg = new ReachGraph();
956 TaskDescriptor taskDesc;
957 if(fn instanceof FlatMethod && (taskDesc=((FlatMethod)fn).getTask())!=null){
958 if(mapDescriptorToReachGraph.containsKey(taskDesc)){
959 // retrieve existing reach graph if it is not first time
960 rg=mapDescriptorToReachGraph.get(taskDesc);
962 // create initial reach graph for a task
963 rg=createInitialTaskReachGraph((FlatMethod)fn);
965 mapDescriptorToReachGraph.put(taskDesc, rg);
969 // start by merging all node's parents' graphs
970 for( int i = 0; i < pm.numPrev(fn); ++i ) {
971 FlatNode pn = pm.getPrev(fn,i);
972 if( mapFlatNodeToReachGraph.containsKey( pn ) ) {
973 ReachGraph rgParent = mapFlatNodeToReachGraph.get( pn );
974 rg.merge( rgParent );
979 if( takeDebugSnapshots &&
980 d.getSymbol().equals( descSymbolDebug )
982 debugSnapshot( rg, fn, true );
986 // modify rg with appropriate transfer function
987 rg = analyzeFlatNode( d, fm, fn, setReturns, rg );
990 if( takeDebugSnapshots &&
991 d.getSymbol().equals( descSymbolDebug )
993 debugSnapshot( rg, fn, false );
998 // if the results of the new graph are different from
999 // the current graph at this node, replace the graph
1000 // with the update and enqueue the children
1001 ReachGraph rgPrev = mapFlatNodeToReachGraph.get( fn );
1002 if( !rg.equals( rgPrev ) ) {
1003 mapFlatNodeToReachGraph.put( fn, rg );
1005 for( int i = 0; i < pm.numNext( fn ); i++ ) {
1006 FlatNode nn = pm.getNext( fn, i );
1008 flatNodesToVisit.add( nn );
1009 if( determinismDesired ) {
1010 flatNodesToVisitQ.add( nn );
1017 // end by merging all return nodes into a complete
1018 // reach graph that represents all possible heap
1019 // states after the flat method returns
1020 ReachGraph completeGraph = new ReachGraph();
1022 assert !setReturns.isEmpty();
1023 Iterator retItr = setReturns.iterator();
1024 while( retItr.hasNext() ) {
1025 FlatReturnNode frn = (FlatReturnNode) retItr.next();
1027 assert mapFlatNodeToReachGraph.containsKey( frn );
1028 ReachGraph rgRet = mapFlatNodeToReachGraph.get( frn );
1030 completeGraph.merge( rgRet );
1034 if( takeDebugSnapshots &&
1035 d.getSymbol().equals( descSymbolDebug )
1037 // increment that we've visited the debug snap
1038 // method, and reset the node counter
1039 System.out.println( " @@@ debug snap at visit "+snapVisitCounter );
1041 snapNodeCounter = 0;
1043 if( snapVisitCounter == visitStartCapture + numVisitsToCapture &&
1046 System.out.println( "!!! Stopping analysis after debug snap captures. !!!" );
1052 return completeGraph;
1056 protected ReachGraph
1057 analyzeFlatNode( Descriptor d,
1058 FlatMethod fmContaining,
1060 HashSet<FlatReturnNode> setRetNodes,
1062 ) throws java.io.IOException {
1065 // any variables that are no longer live should be
1066 // nullified in the graph to reduce edges
1067 //rg.nullifyDeadVars( liveness.getLiveInTemps( fmContaining, fn ) );
1071 FieldDescriptor fld;
1072 TypeDescriptor tdElement;
1073 FieldDescriptor fdElement;
1074 FlatSESEEnterNode sese;
1075 FlatSESEExitNode fsexn;
1077 // use node type to decide what transfer function
1078 // to apply to the reachability graph
1079 switch( fn.kind() ) {
1081 case FKind.FlatMethod: {
1082 // construct this method's initial heap model (IHM)
1083 // since we're working on the FlatMethod, we know
1084 // the incoming ReachGraph 'rg' is empty
1086 Hashtable<FlatCall, ReachGraph> heapsFromCallers =
1087 getIHMcontributions( d );
1089 Set entrySet = heapsFromCallers.entrySet();
1090 Iterator itr = entrySet.iterator();
1091 while( itr.hasNext() ) {
1092 Map.Entry me = (Map.Entry) itr.next();
1093 FlatCall fc = (FlatCall) me.getKey();
1094 ReachGraph rgContrib = (ReachGraph) me.getValue();
1096 assert fc.getMethod().equals( d );
1098 rg.merge( rgContrib );
1101 // additionally, we are enforcing STRICT MONOTONICITY for the
1102 // method's initial context, so grow the context by whatever
1103 // the previously computed context was, and put the most
1104 // up-to-date context back in the map
1105 ReachGraph rgPrevContext = mapDescriptorToInitialContext.get( d );
1106 rg.merge( rgPrevContext );
1107 mapDescriptorToInitialContext.put( d, rg );
1111 case FKind.FlatOpNode:
1112 FlatOpNode fon = (FlatOpNode) fn;
1113 if( fon.getOp().getOp() == Operation.ASSIGN ) {
1114 lhs = fon.getDest();
1115 rhs = fon.getLeft();
1117 // before transfer, do effects analysis support
1118 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1119 if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
1120 // x gets status of y
1121 if(!rg.isAccessible(rhs)){
1122 rg.makeInaccessible(lhs);
1128 rg.assignTempXEqualToTempY( lhs, rhs );
1132 case FKind.FlatCastNode:
1133 FlatCastNode fcn = (FlatCastNode) fn;
1137 TypeDescriptor td = fcn.getType();
1140 // before transfer, do effects analysis support
1141 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1142 if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
1143 // x gets status of y
1144 if(!rg.isAccessible(rhs)){
1145 rg.makeInaccessible(lhs);
1151 rg.assignTempXEqualToCastedTempY( lhs, rhs, td );
1154 case FKind.FlatFieldNode:
1155 FlatFieldNode ffn = (FlatFieldNode) fn;
1159 fld = ffn.getField();
1161 // before graph transform, possible inject
1162 // a stall-site taint
1163 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1165 if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
1166 // x=y.f, stall y if not accessible
1167 // contributes read effects on stall site of y
1168 if(!rg.isAccessible(rhs)) {
1169 rg.taintStallSite(fn, rhs);
1172 // after this, x and y are accessbile.
1173 rg.makeAccessible(lhs);
1174 rg.makeAccessible(rhs);
1178 if( shouldAnalysisTrack( fld.getType() ) ) {
1180 rg.assignTempXEqualToTempYFieldF( lhs, rhs, fld );
1183 // after transfer, use updated graph to
1184 // do effects analysis
1185 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1186 effectsAnalysis.analyzeFlatFieldNode( rg, rhs, fld );
1190 case FKind.FlatSetFieldNode:
1191 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
1193 lhs = fsfn.getDst();
1194 fld = fsfn.getField();
1195 rhs = fsfn.getSrc();
1197 boolean strongUpdate = false;
1199 // before transfer func, possibly inject
1200 // stall-site taints
1201 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1203 if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
1204 // x.y=f , stall x and y if they are not accessible
1205 // also contribute write effects on stall site of x
1206 if(!rg.isAccessible(lhs)) {
1207 rg.taintStallSite(fn, lhs);
1210 if(!rg.isAccessible(rhs)) {
1211 rg.taintStallSite(fn, rhs);
1214 // accessible status update
1215 rg.makeAccessible(lhs);
1216 rg.makeAccessible(rhs);
1220 if( shouldAnalysisTrack( fld.getType() ) ) {
1222 strongUpdate = rg.assignTempXFieldFEqualToTempY( lhs, fld, rhs );
1225 // use transformed graph to do effects analysis
1226 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1227 effectsAnalysis.analyzeFlatSetFieldNode( rg, lhs, fld, strongUpdate );
1231 case FKind.FlatElementNode:
1232 FlatElementNode fen = (FlatElementNode) fn;
1237 assert rhs.getType() != null;
1238 assert rhs.getType().isArray();
1240 tdElement = rhs.getType().dereference();
1241 fdElement = getArrayField( tdElement );
1243 // before transfer func, possibly inject
1245 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1247 if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
1248 // x=y.f, stall y if not accessible
1249 // contributes read effects on stall site of y
1250 // after this, x and y are accessbile.
1251 if(!rg.isAccessible(rhs)) {
1252 rg.taintStallSite(fn, rhs);
1255 rg.makeAccessible(lhs);
1256 rg.makeAccessible(rhs);
1260 if( shouldAnalysisTrack( lhs.getType() ) ) {
1262 rg.assignTempXEqualToTempYFieldF( lhs, rhs, fdElement );
1265 // use transformed graph to do effects analysis
1266 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1267 effectsAnalysis.analyzeFlatFieldNode( rg, rhs, fdElement );
1271 case FKind.FlatSetElementNode:
1272 FlatSetElementNode fsen = (FlatSetElementNode) fn;
1274 lhs = fsen.getDst();
1275 rhs = fsen.getSrc();
1277 assert lhs.getType() != null;
1278 assert lhs.getType().isArray();
1280 tdElement = lhs.getType().dereference();
1281 fdElement = getArrayField( tdElement );
1283 // before transfer func, possibly inject
1284 // stall-site taints
1285 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1287 if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
1288 // x.y=f , stall x and y if they are not accessible
1289 // also contribute write effects on stall site of x
1290 if(!rg.isAccessible(lhs)) {
1291 rg.taintStallSite(fn, lhs);
1294 if(!rg.isAccessible(rhs)) {
1295 rg.taintStallSite(fn, rhs);
1298 // accessible status update
1299 rg.makeAccessible(lhs);
1300 rg.makeAccessible(rhs);
1304 if( shouldAnalysisTrack( rhs.getType() ) ) {
1305 // transfer func, BUT
1306 // skip this node if it cannot create new reachability paths
1307 if( !arrayReferencees.doesNotCreateNewReaching( fsen ) ) {
1308 rg.assignTempXFieldFEqualToTempY( lhs, fdElement, rhs );
1312 // use transformed graph to do effects analysis
1313 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1314 effectsAnalysis.analyzeFlatSetFieldNode( rg, lhs, fdElement,
1320 FlatNew fnn = (FlatNew) fn;
1322 if( shouldAnalysisTrack( lhs.getType() ) ) {
1323 AllocSite as = getAllocSiteFromFlatNewPRIVATE( fnn );
1325 // before transform, support effects analysis
1326 if (doEffectsAnalysis && fmContaining != fmAnalysisEntry) {
1327 if (rblockStatus.isInCriticalRegion(fmContaining, fn)) {
1328 // after creating new object, lhs is accessible
1329 rg.makeAccessible(lhs);
1334 rg.assignTempEqualToNewAlloc( lhs, as );
1338 case FKind.FlatSESEEnterNode:
1339 sese = (FlatSESEEnterNode) fn;
1341 if( sese.getIsCallerSESEplaceholder() ) {
1342 // ignore these dummy rblocks!
1346 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1348 // always remove ALL stall site taints at enter
1349 rg.removeAllStallSiteTaints();
1351 // inject taints for in-set vars
1352 rg.taintInSetVars( sese );
1357 case FKind.FlatSESEExitNode:
1358 fsexn = (FlatSESEExitNode) fn;
1359 sese = fsexn.getFlatEnter();
1361 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1363 // @ sese exit make all live variables
1364 // inaccessible to later parent statements
1365 rg.makeInaccessible( liveness.getLiveInTemps( fmContaining, fn ) );
1367 // always remove ALL stall site taints at exit
1368 rg.removeAllStallSiteTaints();
1370 // remove in-set var taints for the exiting rblock
1371 rg.removeInContextTaints( sese );
1376 case FKind.FlatCall: {
1377 Descriptor mdCaller;
1378 if( fmContaining.getMethod() != null ){
1379 mdCaller = fmContaining.getMethod();
1381 mdCaller = fmContaining.getTask();
1383 FlatCall fc = (FlatCall) fn;
1384 MethodDescriptor mdCallee = fc.getMethod();
1385 FlatMethod fmCallee = state.getMethodFlat( mdCallee );
1387 boolean debugCallSite =
1388 mdCaller.getSymbol().equals( state.DISJOINTDEBUGCALLER ) &&
1389 mdCallee.getSymbol().equals( state.DISJOINTDEBUGCALLEE );
1391 boolean writeDebugDOTs = false;
1392 boolean stopAfter = false;
1393 if( debugCallSite ) {
1394 ++ReachGraph.debugCallSiteVisitCounter;
1395 System.out.println( " $$$ Debug call site visit "+
1396 ReachGraph.debugCallSiteVisitCounter+
1400 (ReachGraph.debugCallSiteVisitCounter >=
1401 ReachGraph.debugCallSiteVisitStartCapture) &&
1403 (ReachGraph.debugCallSiteVisitCounter <
1404 ReachGraph.debugCallSiteVisitStartCapture +
1405 ReachGraph.debugCallSiteNumVisitsToCapture)
1407 writeDebugDOTs = true;
1408 System.out.println( " $$$ Capturing this call site visit $$$" );
1409 if( ReachGraph.debugCallSiteStopAfter &&
1410 (ReachGraph.debugCallSiteVisitCounter ==
1411 ReachGraph.debugCallSiteVisitStartCapture +
1412 ReachGraph.debugCallSiteNumVisitsToCapture - 1)
1420 // calculate the heap this call site can reach--note this is
1421 // not used for the current call site transform, we are
1422 // grabbing this heap model for future analysis of the callees,
1423 // so if different results emerge we will return to this site
1424 ReachGraph heapForThisCall_old =
1425 getIHMcontribution( mdCallee, fc );
1427 // the computation of the callee-reachable heap
1428 // is useful for making the callee starting point
1429 // and for applying the call site transfer function
1430 Set<Integer> callerNodeIDsCopiedToCallee =
1431 new HashSet<Integer>();
1433 ReachGraph heapForThisCall_cur =
1434 rg.makeCalleeView( fc,
1436 callerNodeIDsCopiedToCallee,
1440 if( !heapForThisCall_cur.equals( heapForThisCall_old ) ) {
1441 // if heap at call site changed, update the contribution,
1442 // and reschedule the callee for analysis
1443 addIHMcontribution( mdCallee, fc, heapForThisCall_cur );
1445 // map a FlatCall to its enclosing method/task descriptor
1446 // so we can write that info out later
1447 fc2enclosing.put( fc, mdCaller );
1449 if( state.DISJOINTDEBUGSCHEDULING ) {
1450 System.out.println( " context changed, scheduling callee: "+mdCallee );
1453 if( state.DISJOINTDVISITSTACKEESONTOP ) {
1454 calleesToEnqueue.add( mdCallee );
1456 enqueue( mdCallee );
1461 // the transformation for a call site should update the
1462 // current heap abstraction with any effects from the callee,
1463 // or if the method is virtual, the effects from any possible
1464 // callees, so find the set of callees...
1465 Set<MethodDescriptor> setPossibleCallees;
1466 if( determinismDesired ) {
1467 // use an ordered set
1468 setPossibleCallees = new TreeSet<MethodDescriptor>( dComp );
1470 // otherwise use a speedy hashset
1471 setPossibleCallees = new HashSet<MethodDescriptor>();
1474 if( mdCallee.isStatic() ) {
1475 setPossibleCallees.add( mdCallee );
1477 TypeDescriptor typeDesc = fc.getThis().getType();
1478 setPossibleCallees.addAll( callGraph.getMethods( mdCallee,
1483 ReachGraph rgMergeOfPossibleCallers = new ReachGraph();
1485 Iterator<MethodDescriptor> mdItr = setPossibleCallees.iterator();
1486 while( mdItr.hasNext() ) {
1487 MethodDescriptor mdPossible = mdItr.next();
1488 FlatMethod fmPossible = state.getMethodFlat( mdPossible );
1490 addDependent( mdPossible, // callee
1493 // don't alter the working graph (rg) until we compute a
1494 // result for every possible callee, merge them all together,
1495 // then set rg to that
1496 ReachGraph rgPossibleCaller = new ReachGraph();
1497 rgPossibleCaller.merge( rg );
1499 ReachGraph rgPossibleCallee = getPartial( mdPossible );
1501 if( rgPossibleCallee == null ) {
1502 // if this method has never been analyzed just schedule it
1503 // for analysis and skip over this call site for now
1504 if( state.DISJOINTDVISITSTACKEESONTOP ) {
1505 calleesToEnqueue.add( mdPossible );
1507 enqueue( mdPossible );
1510 if( state.DISJOINTDEBUGSCHEDULING ) {
1511 System.out.println( " callee hasn't been analyzed, scheduling: "+mdPossible );
1516 // calculate the method call transform
1517 rgPossibleCaller.resolveMethodCall( fc,
1520 callerNodeIDsCopiedToCallee,
1524 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1525 if( !rgPossibleCallee.isAccessible( ReachGraph.tdReturn ) ) {
1526 rgPossibleCaller.makeInaccessible( fc.getReturnTemp() );
1532 rgMergeOfPossibleCallers.merge( rgPossibleCaller );
1537 System.out.println( "$$$ Exiting after requested captures of call site. $$$" );
1542 // now that we've taken care of building heap models for
1543 // callee analysis, finish this transformation
1544 rg = rgMergeOfPossibleCallers;
1548 case FKind.FlatReturnNode:
1549 FlatReturnNode frn = (FlatReturnNode) fn;
1550 rhs = frn.getReturnTemp();
1552 // before transfer, do effects analysis support
1553 if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
1554 if(!rg.isAccessible(rhs)){
1555 rg.makeInaccessible(ReachGraph.tdReturn);
1559 if( rhs != null && shouldAnalysisTrack( rhs.getType() ) ) {
1560 rg.assignReturnEqualToTemp( rhs );
1563 setRetNodes.add( frn );
1569 // dead variables were removed before the above transfer function
1570 // was applied, so eliminate heap regions and edges that are no
1571 // longer part of the abstractly-live heap graph, and sweep up
1572 // and reachability effects that are altered by the reduction
1573 //rg.abstractGarbageCollect();
1577 // back edges are strictly monotonic
1578 if( pm.isBackEdge( fn ) ) {
1579 ReachGraph rgPrevResult = mapBackEdgeToMonotone.get( fn );
1580 rg.merge( rgPrevResult );
1581 mapBackEdgeToMonotone.put( fn, rg );
1584 // at this point rg should be the correct update
1585 // by an above transfer function, or untouched if
1586 // the flat node type doesn't affect the heap
1592 // this method should generate integers strictly greater than zero!
1593 // special "shadow" regions are made from a heap region by negating
1595 static public Integer generateUniqueHeapRegionNodeID() {
1597 return new Integer( uniqueIDcount );
1602 static public FieldDescriptor getArrayField( TypeDescriptor tdElement ) {
1603 FieldDescriptor fdElement = mapTypeToArrayField.get( tdElement );
1604 if( fdElement == null ) {
1605 fdElement = new FieldDescriptor( new Modifiers( Modifiers.PUBLIC ),
1607 arrayElementFieldName,
1610 mapTypeToArrayField.put( tdElement, fdElement );
1617 private void writeFinalGraphs() {
1618 Set entrySet = mapDescriptorToCompleteReachGraph.entrySet();
1619 Iterator itr = entrySet.iterator();
1620 while( itr.hasNext() ) {
1621 Map.Entry me = (Map.Entry) itr.next();
1622 Descriptor d = (Descriptor) me.getKey();
1623 ReachGraph rg = (ReachGraph) me.getValue();
1625 rg.writeGraph( "COMPLETE"+d,
1626 true, // write labels (variables)
1627 true, // selectively hide intermediate temp vars
1628 true, // prune unreachable heap regions
1629 false, // hide reachability altogether
1630 true, // hide subset reachability states
1631 true, // hide predicates
1632 false ); // hide edge taints
1636 private void writeFinalIHMs() {
1637 Iterator d2IHMsItr = mapDescriptorToIHMcontributions.entrySet().iterator();
1638 while( d2IHMsItr.hasNext() ) {
1639 Map.Entry me1 = (Map.Entry) d2IHMsItr.next();
1640 Descriptor d = (Descriptor) me1.getKey();
1641 Hashtable<FlatCall, ReachGraph> IHMs = (Hashtable<FlatCall, ReachGraph>) me1.getValue();
1643 Iterator fc2rgItr = IHMs.entrySet().iterator();
1644 while( fc2rgItr.hasNext() ) {
1645 Map.Entry me2 = (Map.Entry) fc2rgItr.next();
1646 FlatCall fc = (FlatCall) me2.getKey();
1647 ReachGraph rg = (ReachGraph) me2.getValue();
1649 rg.writeGraph( "IHMPARTFOR"+d+"FROM"+fc2enclosing.get( fc )+fc,
1650 true, // write labels (variables)
1651 true, // selectively hide intermediate temp vars
1652 true, // hide reachability altogether
1653 true, // prune unreachable heap regions
1654 true, // hide subset reachability states
1655 false, // hide predicates
1656 true ); // hide edge taints
1661 private void writeInitialContexts() {
1662 Set entrySet = mapDescriptorToInitialContext.entrySet();
1663 Iterator itr = entrySet.iterator();
1664 while( itr.hasNext() ) {
1665 Map.Entry me = (Map.Entry) itr.next();
1666 Descriptor d = (Descriptor) me.getKey();
1667 ReachGraph rg = (ReachGraph) me.getValue();
1669 rg.writeGraph( "INITIAL"+d,
1670 true, // write labels (variables)
1671 true, // selectively hide intermediate temp vars
1672 true, // prune unreachable heap regions
1673 false, // hide all reachability
1674 true, // hide subset reachability states
1675 true, // hide predicates
1676 false );// hide edge taints
1681 protected ReachGraph getPartial( Descriptor d ) {
1682 return mapDescriptorToCompleteReachGraph.get( d );
1685 protected void setPartial( Descriptor d, ReachGraph rg ) {
1686 mapDescriptorToCompleteReachGraph.put( d, rg );
1688 // when the flag for writing out every partial
1689 // result is set, we should spit out the graph,
1690 // but in order to give it a unique name we need
1691 // to track how many partial results for this
1692 // descriptor we've already written out
1693 if( writeAllIncrementalDOTs ) {
1694 if( !mapDescriptorToNumUpdates.containsKey( d ) ) {
1695 mapDescriptorToNumUpdates.put( d, new Integer( 0 ) );
1697 Integer n = mapDescriptorToNumUpdates.get( d );
1699 rg.writeGraph( d+"COMPLETE"+String.format( "%05d", n ),
1700 true, // write labels (variables)
1701 true, // selectively hide intermediate temp vars
1702 true, // prune unreachable heap regions
1703 false, // hide all reachability
1704 true, // hide subset reachability states
1705 false, // hide predicates
1706 false); // hide edge taints
1708 mapDescriptorToNumUpdates.put( d, n + 1 );
1714 // return just the allocation site associated with one FlatNew node
1715 protected AllocSite getAllocSiteFromFlatNewPRIVATE( FlatNew fnew ) {
1717 boolean flagProgrammatically = false;
1718 if( sitesToFlag != null && sitesToFlag.contains( fnew ) ) {
1719 flagProgrammatically = true;
1722 if( !mapFlatNewToAllocSite.containsKey( fnew ) ) {
1723 AllocSite as = AllocSite.factory( allocationDepth,
1725 fnew.getDisjointId(),
1726 flagProgrammatically
1729 // the newest nodes are single objects
1730 for( int i = 0; i < allocationDepth; ++i ) {
1731 Integer id = generateUniqueHeapRegionNodeID();
1732 as.setIthOldest( i, id );
1733 mapHrnIdToAllocSite.put( id, as );
1736 // the oldest node is a summary node
1737 as.setSummary( generateUniqueHeapRegionNodeID() );
1739 mapFlatNewToAllocSite.put( fnew, as );
1742 return mapFlatNewToAllocSite.get( fnew );
1746 public static boolean shouldAnalysisTrack( TypeDescriptor type ) {
1747 // don't track primitive types, but an array
1748 // of primitives is heap memory
1749 if( type.isImmutable() ) {
1750 return type.isArray();
1753 // everything else is an object
1757 protected int numMethodsAnalyzed() {
1758 return descriptorsToAnalyze.size();
1765 // Take in source entry which is the program's compiled entry and
1766 // create a new analysis entry, a method that takes no parameters
1767 // and appears to allocate the command line arguments and call the
1768 // source entry with them. The purpose of this analysis entry is
1769 // to provide a top-level method context with no parameters left.
1770 protected void makeAnalysisEntryMethod( MethodDescriptor mdSourceEntry ) {
1772 Modifiers mods = new Modifiers();
1773 mods.addModifier( Modifiers.PUBLIC );
1774 mods.addModifier( Modifiers.STATIC );
1776 TypeDescriptor returnType =
1777 new TypeDescriptor( TypeDescriptor.VOID );
1779 this.mdAnalysisEntry =
1780 new MethodDescriptor( mods,
1782 "analysisEntryMethod"
1785 TempDescriptor cmdLineArgs =
1786 new TempDescriptor( "args",
1787 mdSourceEntry.getParamType( 0 )
1791 new FlatNew( mdSourceEntry.getParamType( 0 ),
1796 TempDescriptor[] sourceEntryArgs = new TempDescriptor[1];
1797 sourceEntryArgs[0] = cmdLineArgs;
1800 new FlatCall( mdSourceEntry,
1806 FlatReturnNode frn = new FlatReturnNode( null );
1808 FlatExit fe = new FlatExit();
1810 this.fmAnalysisEntry =
1811 new FlatMethod( mdAnalysisEntry,
1815 this.fmAnalysisEntry.addNext( fn );
1822 protected LinkedList<Descriptor> topologicalSort( Set<Descriptor> toSort ) {
1824 Set<Descriptor> discovered;
1826 if( determinismDesired ) {
1827 // use an ordered set
1828 discovered = new TreeSet<Descriptor>( dComp );
1830 // otherwise use a speedy hashset
1831 discovered = new HashSet<Descriptor>();
1834 LinkedList<Descriptor> sorted = new LinkedList<Descriptor>();
1836 Iterator<Descriptor> itr = toSort.iterator();
1837 while( itr.hasNext() ) {
1838 Descriptor d = itr.next();
1840 if( !discovered.contains( d ) ) {
1841 dfsVisit( d, toSort, sorted, discovered );
1848 // While we're doing DFS on call graph, remember
1849 // dependencies for efficient queuing of methods
1850 // during interprocedural analysis:
1852 // a dependent of a method decriptor d for this analysis is:
1853 // 1) a method or task that invokes d
1854 // 2) in the descriptorsToAnalyze set
1855 protected void dfsVisit( Descriptor d,
1856 Set <Descriptor> toSort,
1857 LinkedList<Descriptor> sorted,
1858 Set <Descriptor> discovered ) {
1859 discovered.add( d );
1861 // only methods have callers, tasks never do
1862 if( d instanceof MethodDescriptor ) {
1864 MethodDescriptor md = (MethodDescriptor) d;
1866 // the call graph is not aware that we have a fabricated
1867 // analysis entry that calls the program source's entry
1868 if( md == mdSourceEntry ) {
1869 if( !discovered.contains( mdAnalysisEntry ) ) {
1870 addDependent( mdSourceEntry, // callee
1871 mdAnalysisEntry // caller
1873 dfsVisit( mdAnalysisEntry, toSort, sorted, discovered );
1877 // otherwise call graph guides DFS
1878 Iterator itr = callGraph.getCallerSet( md ).iterator();
1879 while( itr.hasNext() ) {
1880 Descriptor dCaller = (Descriptor) itr.next();
1882 // only consider callers in the original set to analyze
1883 if( !toSort.contains( dCaller ) ) {
1887 if( !discovered.contains( dCaller ) ) {
1888 addDependent( md, // callee
1892 dfsVisit( dCaller, toSort, sorted, discovered );
1897 // for leaf-nodes last now!
1898 sorted.addLast( d );
1902 protected void enqueue( Descriptor d ) {
1904 if( !descriptorsToVisitSet.contains( d ) ) {
1906 if( state.DISJOINTDVISITSTACK ||
1907 state.DISJOINTDVISITSTACKEESONTOP
1909 descriptorsToVisitStack.add( d );
1911 } else if( state.DISJOINTDVISITPQUE ) {
1912 Integer priority = mapDescriptorToPriority.get( d );
1913 descriptorsToVisitQ.add( new DescriptorQWrapper( priority,
1918 descriptorsToVisitSet.add( d );
1923 // a dependent of a method decriptor d for this analysis is:
1924 // 1) a method or task that invokes d
1925 // 2) in the descriptorsToAnalyze set
1926 protected void addDependent( Descriptor callee, Descriptor caller ) {
1927 Set<Descriptor> deps = mapDescriptorToSetDependents.get( callee );
1928 if( deps == null ) {
1929 deps = new HashSet<Descriptor>();
1932 mapDescriptorToSetDependents.put( callee, deps );
1935 protected Set<Descriptor> getDependents( Descriptor callee ) {
1936 Set<Descriptor> deps = mapDescriptorToSetDependents.get( callee );
1937 if( deps == null ) {
1938 deps = new HashSet<Descriptor>();
1939 mapDescriptorToSetDependents.put( callee, deps );
1945 public Hashtable<FlatCall, ReachGraph> getIHMcontributions( Descriptor d ) {
1947 Hashtable<FlatCall, ReachGraph> heapsFromCallers =
1948 mapDescriptorToIHMcontributions.get( d );
1950 if( heapsFromCallers == null ) {
1951 heapsFromCallers = new Hashtable<FlatCall, ReachGraph>();
1952 mapDescriptorToIHMcontributions.put( d, heapsFromCallers );
1955 return heapsFromCallers;
1958 public ReachGraph getIHMcontribution( Descriptor d,
1961 Hashtable<FlatCall, ReachGraph> heapsFromCallers =
1962 getIHMcontributions( d );
1964 if( !heapsFromCallers.containsKey( fc ) ) {
1968 return heapsFromCallers.get( fc );
1972 public void addIHMcontribution( Descriptor d,
1976 Hashtable<FlatCall, ReachGraph> heapsFromCallers =
1977 getIHMcontributions( d );
1979 heapsFromCallers.put( fc, rg );
1983 private AllocSite createParameterAllocSite( ReachGraph rg,
1984 TempDescriptor tempDesc,
1990 flatNew = new FlatNew( tempDesc.getType(), // type
1991 tempDesc, // param temp
1992 false, // global alloc?
1993 "param"+tempDesc // disjoint site ID string
1996 flatNew = new FlatNew( tempDesc.getType(), // type
1997 tempDesc, // param temp
1998 false, // global alloc?
1999 null // disjoint site ID string
2003 // create allocation site
2004 AllocSite as = AllocSite.factory( allocationDepth,
2006 flatNew.getDisjointId(),
2009 for (int i = 0; i < allocationDepth; ++i) {
2010 Integer id = generateUniqueHeapRegionNodeID();
2011 as.setIthOldest(i, id);
2012 mapHrnIdToAllocSite.put(id, as);
2014 // the oldest node is a summary node
2015 as.setSummary( generateUniqueHeapRegionNodeID() );
2023 private Set<FieldDescriptor> getFieldSetTobeAnalyzed(TypeDescriptor typeDesc){
2025 Set<FieldDescriptor> fieldSet=new HashSet<FieldDescriptor>();
2026 if(!typeDesc.isImmutable()){
2027 ClassDescriptor classDesc = typeDesc.getClassDesc();
2028 for (Iterator it = classDesc.getFields(); it.hasNext();) {
2029 FieldDescriptor field = (FieldDescriptor) it.next();
2030 TypeDescriptor fieldType = field.getType();
2031 if (shouldAnalysisTrack( fieldType )) {
2032 fieldSet.add(field);
2040 private HeapRegionNode createMultiDeimensionalArrayHRN(ReachGraph rg, AllocSite alloc, HeapRegionNode srcHRN, FieldDescriptor fd, Hashtable<HeapRegionNode, HeapRegionNode> map, Hashtable<TypeDescriptor, HeapRegionNode> mapToExistingNode, ReachSet alpha ){
2042 int dimCount=fd.getType().getArrayCount();
2043 HeapRegionNode prevNode=null;
2044 HeapRegionNode arrayEntryNode=null;
2045 for(int i=dimCount;i>0;i--){
2046 TypeDescriptor typeDesc=fd.getType().dereference();//hack to get instance of type desc
2047 typeDesc.setArrayCount(i);
2048 TempDescriptor tempDesc=new TempDescriptor(typeDesc.getSymbol(),typeDesc);
2049 HeapRegionNode hrnSummary ;
2050 if(!mapToExistingNode.containsKey(typeDesc)){
2055 as = createParameterAllocSite(rg, tempDesc, false);
2057 // make a new reference to allocated node
2059 rg.createNewHeapRegionNode(as.getSummary(), // id or null to generate a new one
2060 false, // single object?
2062 false, // out-of-context?
2063 as.getType(), // type
2064 as, // allocation site
2065 alpha, // inherent reach
2066 alpha, // current reach
2067 ExistPredSet.factory(rg.predTrue), // predicates
2068 tempDesc.toString() // description
2070 rg.id2hrn.put(as.getSummary(),hrnSummary);
2072 mapToExistingNode.put(typeDesc, hrnSummary);
2074 hrnSummary=mapToExistingNode.get(typeDesc);
2078 // make a new reference between new summary node and source
2079 RefEdge edgeToSummary = new RefEdge(srcHRN, // source
2082 fd.getSymbol(), // field name
2084 ExistPredSet.factory(rg.predTrue), // predicates
2088 rg.addRefEdge(srcHRN, hrnSummary, edgeToSummary);
2089 prevNode=hrnSummary;
2090 arrayEntryNode=hrnSummary;
2092 // make a new reference between summary nodes of array
2093 RefEdge edgeToSummary = new RefEdge(prevNode, // source
2096 arrayElementFieldName, // field name
2098 ExistPredSet.factory(rg.predTrue), // predicates
2102 rg.addRefEdge(prevNode, hrnSummary, edgeToSummary);
2103 prevNode=hrnSummary;
2108 // create a new obj node if obj has at least one non-primitive field
2109 TypeDescriptor type=fd.getType();
2110 if(getFieldSetTobeAnalyzed(type).size()>0){
2111 TypeDescriptor typeDesc=type.dereference();
2112 typeDesc.setArrayCount(0);
2113 if(!mapToExistingNode.containsKey(typeDesc)){
2114 TempDescriptor tempDesc=new TempDescriptor(type.getSymbol(),typeDesc);
2115 AllocSite as = createParameterAllocSite(rg, tempDesc, false);
2116 // make a new reference to allocated node
2117 HeapRegionNode hrnSummary =
2118 rg.createNewHeapRegionNode(as.getSummary(), // id or null to generate a new one
2119 false, // single object?
2121 false, // out-of-context?
2123 as, // allocation site
2124 alpha, // inherent reach
2125 alpha, // current reach
2126 ExistPredSet.factory(rg.predTrue), // predicates
2127 tempDesc.toString() // description
2129 rg.id2hrn.put(as.getSummary(),hrnSummary);
2130 mapToExistingNode.put(typeDesc, hrnSummary);
2131 RefEdge edgeToSummary = new RefEdge(prevNode, // source
2134 arrayElementFieldName, // field name
2136 ExistPredSet.factory(rg.predTrue), // predicates
2139 rg.addRefEdge(prevNode, hrnSummary, edgeToSummary);
2140 prevNode=hrnSummary;
2142 HeapRegionNode hrnSummary=mapToExistingNode.get(typeDesc);
2143 if(prevNode.getReferenceTo(hrnSummary, typeDesc, arrayElementFieldName)==null){
2144 RefEdge edgeToSummary = new RefEdge(prevNode, // source
2147 arrayElementFieldName, // field name
2149 ExistPredSet.factory(rg.predTrue), // predicates
2152 rg.addRefEdge(prevNode, hrnSummary, edgeToSummary);
2154 prevNode=hrnSummary;
2158 map.put(arrayEntryNode, prevNode);
2159 return arrayEntryNode;
2162 private ReachGraph createInitialTaskReachGraph(FlatMethod fm) {
2163 ReachGraph rg = new ReachGraph();
2164 TaskDescriptor taskDesc = fm.getTask();
2166 for (int idx = 0; idx < taskDesc.numParameters(); idx++) {
2167 Descriptor paramDesc = taskDesc.getParameter(idx);
2168 TypeDescriptor paramTypeDesc = taskDesc.getParamType(idx);
2170 // setup data structure
2171 Set<HashMap<HeapRegionNode, FieldDescriptor>> workSet =
2172 new HashSet<HashMap<HeapRegionNode, FieldDescriptor>>();
2173 Hashtable<TypeDescriptor, HeapRegionNode> mapTypeToExistingSummaryNode =
2174 new Hashtable<TypeDescriptor, HeapRegionNode>();
2175 Hashtable<HeapRegionNode, HeapRegionNode> mapToFirstDimensionArrayNode =
2176 new Hashtable<HeapRegionNode, HeapRegionNode>();
2177 Set<String> doneSet = new HashSet<String>();
2179 TempDescriptor tempDesc = fm.getParameter(idx);
2181 AllocSite as = createParameterAllocSite(rg, tempDesc, true);
2182 VariableNode lnX = rg.getVariableNodeFromTemp(tempDesc);
2183 Integer idNewest = as.getIthOldest(0);
2184 HeapRegionNode hrnNewest = rg.id2hrn.get(idNewest);
2186 // make a new reference to allocated node
2187 RefEdge edgeNew = new RefEdge(lnX, // source
2189 taskDesc.getParamType(idx), // type
2191 hrnNewest.getAlpha(), // beta
2192 ExistPredSet.factory(rg.predTrue), // predicates
2195 rg.addRefEdge(lnX, hrnNewest, edgeNew);
2197 // set-up a work set for class field
2198 ClassDescriptor classDesc = paramTypeDesc.getClassDesc();
2199 for (Iterator it = classDesc.getFields(); it.hasNext();) {
2200 FieldDescriptor fd = (FieldDescriptor) it.next();
2201 TypeDescriptor fieldType = fd.getType();
2202 if (shouldAnalysisTrack( fieldType )) {
2203 HashMap<HeapRegionNode, FieldDescriptor> newMap = new HashMap<HeapRegionNode, FieldDescriptor>();
2204 newMap.put(hrnNewest, fd);
2205 workSet.add(newMap);
2209 int uniqueIdentifier = 0;
2210 while (!workSet.isEmpty()) {
2211 HashMap<HeapRegionNode, FieldDescriptor> map = workSet
2213 workSet.remove(map);
2215 Set<HeapRegionNode> key = map.keySet();
2216 HeapRegionNode srcHRN = key.iterator().next();
2217 FieldDescriptor fd = map.get(srcHRN);
2218 TypeDescriptor type = fd.getType();
2219 String doneSetIdentifier = srcHRN.getIDString() + "_" + fd;
2221 if (!doneSet.contains(doneSetIdentifier)) {
2222 doneSet.add(doneSetIdentifier);
2223 if (!mapTypeToExistingSummaryNode.containsKey(type)) {
2224 // create new summary Node
2225 TempDescriptor td = new TempDescriptor("temp"
2226 + uniqueIdentifier, type);
2228 AllocSite allocSite;
2229 if(type.equals(paramTypeDesc)){
2230 //corresponding allocsite has already been created for a parameter variable.
2233 allocSite = createParameterAllocSite(rg, td, false);
2235 String strDesc = allocSite.toStringForDOT()
2237 TypeDescriptor allocType=allocSite.getType();
2239 HeapRegionNode hrnSummary;
2240 if(allocType.isArray() && allocType.getArrayCount()>0){
2241 hrnSummary=createMultiDeimensionalArrayHRN(rg,allocSite,srcHRN,fd,mapToFirstDimensionArrayNode,mapTypeToExistingSummaryNode,hrnNewest.getAlpha());
2244 rg.createNewHeapRegionNode(allocSite.getSummary(), // id or null to generate a new one
2245 false, // single object?
2247 false, // out-of-context?
2248 allocSite.getType(), // type
2249 allocSite, // allocation site
2250 hrnNewest.getAlpha(), // inherent reach
2251 hrnNewest.getAlpha(), // current reach
2252 ExistPredSet.factory(rg.predTrue), // predicates
2253 strDesc // description
2255 rg.id2hrn.put(allocSite.getSummary(),hrnSummary);
2257 // make a new reference to summary node
2258 RefEdge edgeToSummary = new RefEdge(srcHRN, // source
2261 fd.getSymbol(), // field name
2262 hrnNewest.getAlpha(), // beta
2263 ExistPredSet.factory(rg.predTrue), // predicates
2267 rg.addRefEdge(srcHRN, hrnSummary, edgeToSummary);
2271 mapTypeToExistingSummaryNode.put(type, hrnSummary);
2273 // set-up a work set for fields of the class
2274 Set<FieldDescriptor> fieldTobeAnalyzed=getFieldSetTobeAnalyzed(type);
2275 for (Iterator iterator = fieldTobeAnalyzed.iterator(); iterator
2277 FieldDescriptor fieldDescriptor = (FieldDescriptor) iterator
2279 HeapRegionNode newDstHRN;
2280 if(mapToFirstDimensionArrayNode.containsKey(hrnSummary)){
2281 //related heap region node is already exsited.
2282 newDstHRN=mapToFirstDimensionArrayNode.get(hrnSummary);
2284 newDstHRN=hrnSummary;
2286 doneSetIdentifier = newDstHRN.getIDString() + "_" + fieldDescriptor;
2287 if(!doneSet.contains(doneSetIdentifier)){
2288 // add new work item
2289 HashMap<HeapRegionNode, FieldDescriptor> newMap =
2290 new HashMap<HeapRegionNode, FieldDescriptor>();
2291 newMap.put(newDstHRN, fieldDescriptor);
2292 workSet.add(newMap);
2297 // if there exists corresponding summary node
2298 HeapRegionNode hrnDst=mapTypeToExistingSummaryNode.get(type);
2300 RefEdge edgeToSummary = new RefEdge(srcHRN, // source
2302 fd.getType(), // type
2303 fd.getSymbol(), // field name
2304 srcHRN.getAlpha(), // beta
2305 ExistPredSet.factory(rg.predTrue), // predicates
2308 rg.addRefEdge(srcHRN, hrnDst, edgeToSummary);
2314 // debugSnapshot(rg, fm, true);
2318 // return all allocation sites in the method (there is one allocation
2319 // site per FlatNew node in a method)
2320 private HashSet<AllocSite> getAllocationSiteSet(Descriptor d) {
2321 if( !mapDescriptorToAllocSiteSet.containsKey(d) ) {
2322 buildAllocationSiteSet(d);
2325 return mapDescriptorToAllocSiteSet.get(d);
2329 private void buildAllocationSiteSet(Descriptor d) {
2330 HashSet<AllocSite> s = new HashSet<AllocSite>();
2333 if( d instanceof MethodDescriptor ) {
2334 fm = state.getMethodFlat( (MethodDescriptor) d);
2336 assert d instanceof TaskDescriptor;
2337 fm = state.getMethodFlat( (TaskDescriptor) d);
2339 pm.analyzeMethod(fm);
2341 // visit every node in this FlatMethod's IR graph
2342 // and make a set of the allocation sites from the
2343 // FlatNew node's visited
2344 HashSet<FlatNode> visited = new HashSet<FlatNode>();
2345 HashSet<FlatNode> toVisit = new HashSet<FlatNode>();
2348 while( !toVisit.isEmpty() ) {
2349 FlatNode n = toVisit.iterator().next();
2351 if( n instanceof FlatNew ) {
2352 s.add(getAllocSiteFromFlatNewPRIVATE( (FlatNew) n) );
2358 for( int i = 0; i < pm.numNext(n); ++i ) {
2359 FlatNode child = pm.getNext(n, i);
2360 if( !visited.contains(child) ) {
2366 mapDescriptorToAllocSiteSet.put(d, s);
2369 private HashSet<AllocSite> getFlaggedAllocationSites(Descriptor dIn) {
2371 HashSet<AllocSite> out = new HashSet<AllocSite>();
2372 HashSet<Descriptor> toVisit = new HashSet<Descriptor>();
2373 HashSet<Descriptor> visited = new HashSet<Descriptor>();
2377 while (!toVisit.isEmpty()) {
2378 Descriptor d = toVisit.iterator().next();
2382 HashSet<AllocSite> asSet = getAllocationSiteSet(d);
2383 Iterator asItr = asSet.iterator();
2384 while (asItr.hasNext()) {
2385 AllocSite as = (AllocSite) asItr.next();
2386 if (as.getDisjointAnalysisId() != null) {
2391 // enqueue callees of this method to be searched for
2392 // allocation sites also
2393 Set callees = callGraph.getCalleeSet(d);
2394 if (callees != null) {
2395 Iterator methItr = callees.iterator();
2396 while (methItr.hasNext()) {
2397 MethodDescriptor md = (MethodDescriptor) methItr.next();
2399 if (!visited.contains(md)) {
2410 private HashSet<AllocSite>
2411 getFlaggedAllocationSitesReachableFromTaskPRIVATE(TaskDescriptor td) {
2413 HashSet<AllocSite> asSetTotal = new HashSet<AllocSite>();
2414 HashSet<Descriptor> toVisit = new HashSet<Descriptor>();
2415 HashSet<Descriptor> visited = new HashSet<Descriptor>();
2419 // traverse this task and all methods reachable from this task
2420 while( !toVisit.isEmpty() ) {
2421 Descriptor d = toVisit.iterator().next();
2425 HashSet<AllocSite> asSet = getAllocationSiteSet(d);
2426 Iterator asItr = asSet.iterator();
2427 while( asItr.hasNext() ) {
2428 AllocSite as = (AllocSite) asItr.next();
2429 TypeDescriptor typed = as.getType();
2430 if( typed != null ) {
2431 ClassDescriptor cd = typed.getClassDesc();
2432 if( cd != null && cd.hasFlags() ) {
2438 // enqueue callees of this method to be searched for
2439 // allocation sites also
2440 Set callees = callGraph.getCalleeSet(d);
2441 if( callees != null ) {
2442 Iterator methItr = callees.iterator();
2443 while( methItr.hasNext() ) {
2444 MethodDescriptor md = (MethodDescriptor) methItr.next();
2446 if( !visited.contains(md) ) {
2456 public Set<Descriptor> getDescriptorsToAnalyze() {
2457 return descriptorsToAnalyze;
2460 public EffectsAnalysis getEffectsAnalysis(){
2461 return effectsAnalysis;
2465 // get successive captures of the analysis state, use compiler
2467 boolean takeDebugSnapshots = false;
2468 String descSymbolDebug = null;
2469 boolean stopAfterCapture = false;
2470 int snapVisitCounter = 0;
2471 int snapNodeCounter = 0;
2472 int visitStartCapture = 0;
2473 int numVisitsToCapture = 0;
2476 void debugSnapshot( ReachGraph rg, FlatNode fn, boolean in ) {
2477 if( snapVisitCounter > visitStartCapture + numVisitsToCapture ) {
2485 if( snapVisitCounter >= visitStartCapture ) {
2486 System.out.println( " @@@ snapping visit="+snapVisitCounter+
2487 ", node="+snapNodeCounter+
2491 graphName = String.format( "snap%03d_%04din",
2495 graphName = String.format( "snap%03d_%04dout",
2500 graphName = graphName + fn;
2502 rg.writeGraph( graphName,
2503 true, // write labels (variables)
2504 true, // selectively hide intermediate temp vars
2505 true, // prune unreachable heap regions
2506 false, // hide reachability
2507 true, // hide subset reachability states
2508 true, // hide predicates
2509 false );// hide edge taints