[Soot-list] need help with method references
Kevin Dean
kdean1 at gmu.edu
Fri Apr 28 20:33:58 EDT 2006
Hi,
I am working on a project for my compiler class which involves
capturing the "hot path" in a program execution (a trace of basic
blocks that were called most frequently). My approach so far has been
to create a bodyTransformer which is part of the "jtp" pack. In the
bodyTransformer I am getting access to the blocks for that method.
What I am trying to do is create an external class which accepts
blocks and adds them to a vector (there is an algorithm here). I want
to instrument the code so that for every statement that is the head
of a block, there should be a method reference to my external
class... and to pass that method the current block. I have seen the
example on how to do this for a type such as int in the example:
// 1. first, make a new invoke expression
InvokeExpr incExpr= Jimple.v().newStaticInvokeExpr
(increaseCounter.makeRef(),IntConstant.v(1));
// 2. then, make a invoke statement
Stmt incStmt = Jimple.v().newInvokeStmt(incExpr);
// 3. insert new statement into the chain
// (we are mutating the unit chain).
units.insertBefore(incStmt, stmt);
However, I am trying to do something like:
//this is the class that will maintain the basic blocks
counterClass = Scene.v().loadClassAndSupport("MyCounter");
//this is the method that will accept the basic block
testBlock = counterClass.getMethod("void setBlock
(soot.toolkits.graph.Block)");
//a class which extends BriefUnitGraph and just passes super(body)
SubPathUG sug = new SubPathUG(method.getActiveBody());
//this class extends BlockGraph and allows access to the basic blocks
SubPathBlock sub = new SubPathBlock(sug);
blck=sub.getBlocks();
it = blck.listIterator();
while(it.hasNext()){
Block b = (Block)it.next();
v.add(b);
InvokeExpr incExpr= Jimple.v().newStaticInvokeExpr
(testBlock.makeRef(),v);
Stmt incStmt = Jimple.v().newInvokeStmt(incExpr);
}
I know its failing because v is not a "Value" but a block.... but
maybe I am not using the right class here? Is InvokeExpr the right
way to do this? I would appreciate any guidance or sugestions on
this. Soot seems so overwhelming with all its functionality, I am not
sure if this is the best way to accomplish what I am trying.
sincerely,
Kevin
More information about the Soot-list
mailing list