[Soot-list] Two interesting questions of Soot

Chris Pickett chris.pickett at mail.mcgill.ca
Sun Feb 27 00:46:51 EST 2005


Ye Henry Tian wrote:
> SootMethod toCall = Scene.v().getMethod("<java.lang.StringBuffer: void
> <init>(java.lang.String)>");
> arglist.add(IntType.v());
> toCall.setParameterTypes(arglist);
> 
> SootMethod toCall = Scene.v().getMethod("<java.lang.StringBuffer: void
> <init>(java.lang.String)>");
> 
> In run time it will raise exception says that the method is nonexistence.
> I don't understand the reason. Is it because I change its argument type?
> but I thought, I just copy the method in to a SootMethod variable and
> modify it, how come it effect the Scene? Can someone explain this question
> for me!?? Thanks a lot! I want to know how the method
> Scene.v().getMethod() works.

Hi Henry,

Yes, Scene.v().getMethod() returns an object reference to a globally 
visible SootMethod (this is like getting a pointer in C).  You are not 
getting a cloned instance of the SootMethod.  This is like if you put 
objects in a HashMap, and then get one out and modify it: if you get it 
out again, you will get the modified one, not the original (this should 
be very easy for you to try).  So, you are modifying what all of Soot 
thinks is the set of methods and classes that represent your application 
when you call toCall.setParameterTypes().

> if you look at the Jimple code in a Jimple file, it may
> look something like this:
> 
> $r2 = new java.lang.StringBuffer;
> $r3 = staticinvoke <java.lang.String: java.lang.String
> valueOf(java.lang.Object)>(r1);
> specialinvoke $r2.<java.lang.StringBuffer: void
> <init>(java.lang.String)>($r3);
> 
> but if you use a bodytransformer to iterate the body, you got something
> like this:
> 
> $r2 = new java.lang.StringBuffer;
> specialinvoke $r2.<java.lang.StringBuffer: void <init>()>();
> $r3 = virtualinvoke $r2.<java.lang.StringBuffer: java.lang.StringBuffer
> append(java.lang.String)>(r1);
> 
> Can anyone explain the reason for this!? Thanks a lot!

My guess is that optimization passes are happening in the second case. 
Somebody else can probably clarify better what's going on, but in the 
meantime you can try specifying the same set of optimization passes from 
the command line in each case and see if it makes a difference.

Cheers,
Chris


More information about the Soot-list mailing list