[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: adding methods to InvokeGraphs



The InvokeGraph is (supposed to be) just a container for call graph
information, with no code for actually building the call graph. The code
for building the call graph is in other classes, such as
ClassHierarchyAnalysis, VariableTypeAnalysis, and so on.

Assuming you want to resolve calls using CHA, you can add the targets
of call sites in a method m using (roughly) the following chunk of code
snipped out of ClassHierarchyAnalysis.java:

	Body b = m.retrieveActiveBody();

	Iterator unitsIt = b.getUnits().iterator();
	while (unitsIt.hasNext()) {
	  Stmt s = (Stmt)unitsIt.next();
	  if (s.containsInvokeExpr()) {
	    InvokeExpr ie = (InvokeExpr)s.getInvokeExpr();
	    if (ie instanceof VirtualInvokeExpr ||
		ie instanceof InterfaceInvokeExpr) {
	      Type receiverType = ((InstanceInvokeExpr)ie).getBase().getType();

	      g.addSite(s, m);
                            
	      if(receiverType instanceof RefType) {   
		// since Type might be Null
		Iterator targetsIt = 
		  fh.resolveAbstractDispatch(((RefType)receiverType).getSootClass(), 
					    ie.getMethod()).iterator();
                            
		while (targetsIt.hasNext())
		  g.addTarget(s, (SootMethod)targetsIt.next());
	      }
	    } else if (ie instanceof StaticInvokeExpr) {
	      g.addSite(s, m);
	      g.addTarget(s, ie.getMethod());
	    } else if (ie instanceof SpecialInvokeExpr) {
	      g.addSite(s, m);
	      g.addTarget(s, fh.resolveSpecialDispatch((SpecialInvokeExpr)ie, m));
	    }
	  }
        }

Ondrej

On Tue, Feb 25, 2003 at 09:43:13AM -0500, Ankush Varma wrote:
> 
> Given an InvokeGraph, is there a way to add another method to it as a node, and
> find out the targets/sites needed to add this method. More formally:
> 
> If I have an InvokeGraph i and a method m not contained in i, is there a way to
> add m without completely rebuilding i?
> 
> I suppose this can be done using addSite and addTarget. But how do I find the
> sites/targets of m?
> 
> Ankush
> 
> 
> On Wed, 19 Feb 2003, Ondrej LHOTAK wrote:
> 
> > On Wed, Feb 19, 2003 at 12:54:40PM -0500, Ankush Varma wrote:
> > > Is there a way to perform VTA/RTA etc. on only a subset of classes, instead of
> > > an entire Scene. Right now it requires all classes in the Scene to be
> > > application classes.
> >
> > VTA and RTA are, by definition, whole-program analyses. They require all
> > the code for all the classes to be available. The classes do not have
> > to all be application classes; they have to be either library or
> > application classes. The -a switch turns the required classes from
> > context classes into library classes. Basically, the categories of
> > classes are as follows:
> >
> > Application classes are both read and written by Soot.
> >
> > Library classes may be read but not written by Soot.
> >
> > Context classes may be inspected to see what methods and fields they
> > have, but the code of the methods may not be read.
> >
> > Phantom classes are invented by Soot and do not correspond to any real
> > classes.
> >
> > > Also, is there a fast way to find the targets(not transitive targets) of a given
> > > method.
> >
> > InvokeGraph has but getTargetsOf(SootMethod m) and
> > getTransitiveTargetsOf(SootMethod m).
> >
> > >
> > > Ankush
> > >
> > > "No trees were killed in the creation of this email :
> > > however, a vast number of electrons were incredibly inconvenienced."
> > >
> > > -------------------------------------------------
> > > Ankush Varma
> > > Ph.D. Student / Graduate Research Assistant
> > > DSP-CAD Research Group
> > > Department of Electrical and Computer Engineering
> > > University of Maryland, College Park.
> > >
> > > email:
> > > ankush@eng.umd.edu
> > > not_ankush@yahoo.com
> > >
> > > Home: 301-439-0438           Office: 301-405-3089
> > > --------------------------------------------------
> > >
> >
> 
> 
> "No trees were killed in the creation of this email :
> however, a vast number of electrons were incredibly inconvenienced."
> 
> -------------------------------------------------
> Ankush Varma
> Ph.D. Student / Graduate Research Assistant
> DSP-CAD Research Group
> Department of Electrical and Computer Engineering
> University of Maryland, College Park.
> 
> email:
> ankush@eng.umd.edu
> not_ankush@yahoo.com
> 
> Home: 301-439-0438           Office: 301-405-3089
> --------------------------------------------------
>