[Soot-list] identify calls on local objects with Jimple?

Chris Pickett chris.pickett at mail.mcgill.ca
Fri Aug 12 10:59:50 EDT 2005


Christian Lindig wrote:
> 
> We like to classify method calls into calls on local objects versus 
> calls on non-local objects. A local object is created inside a method 
> and is not a parameter or held in a static variable. Is there a good way 
> to do this in Jimple, at least approximately?
> 
> Just because an object is held in a local register (like r7) this does 
> not guarantee that the object was created locally. It seems, that all 
> objects are loaded into a local register before a method call and thus 
> this is too simple.

By default locals are unique, that is they are assigned to only once. 
So I think the following should work inside a 
BodyTransformer.internalTransform():

HashSet LocallyCreatedObjects = new HashSet();
Iterator stmtIt = body.getUnits().snapshotIterator();
while (stmtIt.hasNext())
{
     Stmt s = (Stmt) stmtIt.next();
     if (s instanceof AssignStmt)
     {
         AssignStmt a = (AssignStmt) s;
         if (a.getRightOp() instanceof AnyNewExpr &&
             a.getLeftOp() instanceof Local)
         {
             LocallyCreatedObjects.add(a.getLeftOp());
         }
     }
}

and then another pass to find the method calls.  If you don't want 
arrays, s/AnyNewExpr/NewExpr/.  You could also use a ForwardFlowAnalysis 
to get a different set of Locals for each program point, but I don't 
think it will affect the binary question, "Is this a call on a local 
object?"

Cheers,
Chris



More information about the Soot-list mailing list