Re: [abc-users] polyglot compiler exception while using abc to instrument aspect code

From: Luca Cavallaro <cavallaro_at_elet.polimi.it>
Date: Wed, 15 Oct 2008 19:23:27 +0200

Dear Eric, thanks for your reply.
I tried the same abc without the modification and it works on the code.
The code i am using as a target is composed of three java classes and an
aspect. It does nothing specifical, it is just a small example. I am
pasting my code in the following of this email.

public aspect BoundPoint {

/* ’this’ is a reference to a Point object */
PropertyChangeSupport classes.Point.support = new
PropertyChangeSupport(this);

public void
classes.Point.addPropertyChangeListener(PropertyChangeListener l){
support.addPropertyChangeListener(l);

}

void firePropertyChange(Point p, String property,double oldval, double
newval) {
p.support.firePropertyChange(property,
new Double(oldval),new Double(newval));
}

// ====== pointcuts =======
pointcut setterX(Point p): call(public void Point.setX(*)) && target(p);

pointcut setterXonly(Point p): setterX(p) &&
!cflow(execution(public void Point.setRectangular(int,int)));
// ====== advices ======
before(Point p, int x) throws InvalidException:
setterX(p) && args(x) { // before1
if (x < 0) throw new InvalidException("bad");
}
void around(Point p): setterX(p) { // around1
int oldX = p.getX(); proceed(p);
firePropertyChange(p,"setX",oldX,p.getX());
}
void around(Point p): setterXonly(p) { // around2
int oldX = p.getX(); proceed(p);
firePropertyChange(p,"onlysetX",oldX,p.getX());
}
before (Point p): setterX(p){ // before2
System.out.println("start setting p.x");
}
after(Point p) throwing (Exception ex):
setterX(p) { // afterThrowing1
System.out.println(ex);
}
after(Point p): setterX(p){ // after1
System.out.println("done setting p.x");
}

}

public class Demo implements PropertyChangeListener {

//@Override
public void propertyChange(PropertyChangeEvent arg0) {
// TODO Auto-generated method stub

}

public static void main(String[] a) throws Exception {
Point p1 = new Point();
p1.addPropertyChangeListener(new Demo());
p1.setRectangular(5,2);
System.out.println("p1 = " + p1);
p1.setX(6);
p1.setY(3);
System.out.println("p1 = " + p1);
PointExt p2 = new PointExt();
p2.addPropertyChangeListener(new Demo());
p2.setRectangular(5,2);
System.out.println("p2 = " + p2);
p2.setX(5);
}
}

public class Point {

int x = 0, y = 0;

public int getX() {
return x;
}

public int getY() {
return y;
}

public void setRectangular(int newX, int newY) throws Exception {
setX(newX);
setY(newY);
}

public void setX(int newX) throws Exception {
x = newX;
}

public void setY(int newY) throws Exception {
y = newY;
}

public String toString() {
return("X="+x+",Y="+y);
}

}

public class PointExt extends Point {

public void setRectangular(int newX, int newY) throws Exception {
setX(newX+ 1);
setY(newY + 1);
}

public void setX(int newX) throws Exception {
x = (int)newX /2;
}

}

Best regards
Luca

Eric Bodden wrote:
> Hi Luca.
>
> At a first glance I cannot see anything wrong with your code. Are you
> sure that the un-modified abc does not also fail on the same input
> program? What is you input program anyway? What aspects do you have
> and what are you weaving them into?
>
> Eric
>
> 2008/10/15 Luca Cavallaro <cavallaro_at_elet.polimi.it>:
>
>> Dear all,
>> I found out the following problem using abc:
>> I am trying to instrument the compiled code in order to deduce basic blocks
>> coverage. To do this I read the soot tutorial to instrument class files and
>> I produced the following code:
>> I modified abc.main.AbcExtension adding to the method addJimplePacks()these
>> four code lines:
>>
>> //added by me
>> Scene.v().addBasicClass("abc.aspectj.instrumentation.BlockTagger",SootClass.SIGNATURES);
>> //added by me
>> Scene.v().addBasicClass("java.io.PrintStream",SootClass.SIGNATURES);
>> //added by me
>> Scene.v().addBasicClass("java.lang.System",SootClass.SIGNATURES);
>> PackManager.v().getPack("jtp").add(new Transform("jtp.uce",
>> UnreachableCodeEliminator.v()));
>> //added by me
>> PackManager.v().getPack("jtp").add(new Transform("jtp.blockInstrumentation",
>> new BlockInstrumenter()));
>>
>> I built a BlockInstrumenter class which extends BodyTransformer and I
>> redefined internaltransform method:
>>
>> protected void internalTransform(Body b, String arg1, Map arg2) {
>> SootClass sc =
>> Scene.v().getSootClass("abc.aspectj.instrumentation.BlockTagger");
>> SootMethod instrumenter = sc.getMethodByName("tagFirstUnitInBlock");
>> BlockGraph bg = new CompleteBlockGraph(b);
>> List<Block> blocksInGraph = bg.getBlocks();
>> Chain units = b.getUnits();
>> for(Block bl: blocksInGraph){
>> Unit head = bl.getHead();
>> InvokeExpr incExpr=
>> Jimple.v().newStaticInvokeExpr(instrumenter.makeRef());
>> Stmt incStmt = Jimple.v().newInvokeStmt(incExpr);
>> units.insertAfter(incStmt,head);
>> }
>>
>> Here is the code of the class I am trying to use for instrumentation. This
>> class has a static method that I would like to add a call to when a basic
>> block is entered.
>>
>> public class BlockTagger {
>> public static void tagFirstUnitInBlock(Unit u){
>> ExecutedBlockTag t = new ExecutedBlockTag();
>> ExecutedBlockTagAggregator ta = new ExecutedBlockTagAggregator();
>> ta.considerTag(t, u);
>> }
>>
>> }
>>
>> ExecutedBlockTag() implements Tag and contains a boolean field.
>> ExecutedBlockTagAggregator() has an overridden method:
>> public void considerTag(Tag t, Unit u) {
>> units.add(u);
>> tags.add(t);
>> }
>>
>> When I run abc on my target program the compilation fails reporting the
>> following exception:
>>
>> polyglot.util.InternalCompilerError: BoundPoint.aj:29,1-32:2: Error during
>> matching
>> at
>> abc.weaving.matching.AdviceApplication.doShadows(AdviceApplication.java:208)
>> at abc.main.AbcExtension.findMethodShadows(AbcExtension.java:508)
>> at
>> abc.weaving.matching.AdviceApplication.doMethod(AdviceApplication.java:275)
>> at
>> abc.weaving.matching.AdviceApplication.computeAdviceLists(AdviceApplication.java:312)
>> at
>> abc.weaving.aspectinfo.GlobalAspectInfo.computeAdviceLists(GlobalAspectInfo.java:463)
>> at analysis.aspectj.Main.preprocess(Main.java:381)
>> at analysis.aspectj.Main.main(Main.java:91)
>> Caused by: java.lang.NullPointerException
>> at abc.weaving.residues.CheckType.construct(CheckType.java:62)
>> at abc.weaving.residues.Bind.construct(Bind.java:89)
>> at abc.weaving.aspectinfo.ArgVar.matchesAt(ArgVar.java:53)
>> at abc.weaving.aspectinfo.Args.matchesAt(Args.java:134)
>> at abc.weaving.aspectinfo.AndPointcut.matchesAt(AndPointcut.java:68)
>> at
>> abc.weaving.matching.AdviceApplication$2.run(AdviceApplication.java:114)
>> at
>> abc.weaving.matching.AdviceApplication.doShadows(AdviceApplication.java:191)
>> ... 6 more
>> polyglot.util.InternalCompilerError: BoundPoint.aj:29,1-32:2: Error during
>> matching
>> at
>> abc.weaving.matching.AdviceApplication.doShadows(AdviceApplication.java:208)
>> at abc.main.AbcExtension.findMethodShadows(AbcExtension.java:508)
>> at
>> abc.weaving.matching.AdviceApplication.doMethod(AdviceApplication.java:275)
>> at
>> abc.weaving.matching.AdviceApplication.computeAdviceLists(AdviceApplication.java:312)
>> at
>> abc.weaving.aspectinfo.GlobalAspectInfo.computeAdviceLists(GlobalAspectInfo.java:463)
>> at analysis.aspectj.Main.preprocess(Main.java:381)
>> at analysis.aspectj.Main.main(Main.java:91)
>> Caused by: java.lang.NullPointerException
>> at abc.weaving.residues.CheckType.construct(CheckType.java:62)
>> at abc.weaving.residues.Bind.construct(Bind.java:89)
>> at abc.weaving.aspectinfo.ArgVar.matchesAt(ArgVar.java:53)
>> at abc.weaving.aspectinfo.Args.matchesAt(Args.java:134)
>> at abc.weaving.aspectinfo.AndPointcut.matchesAt(AndPointcut.java:68)
>> at
>> abc.weaving.matching.AdviceApplication$2.run(AdviceApplication.java:114)
>> at
>> abc.weaving.matching.AdviceApplication.doShadows(AdviceApplication.java:191)
>> ... 6 more
>>
>> does anyone have any suggestion that can help me?
>> thanks in advance
>> Luca
>>
>> --
>> Luca Cavallaro
>> Ph.D. student
>> DEI, Politecnico di Milano,
>> Via Golgi 40
>> 200133 Milan,
>> Italy
>> /------------------------------------------------------------/
>> Aphasia is the loss of speech in computer scientists when asked:
>> "But of what use is your research?"
>>
>>
>>
>>
>>
>
>
>
>

-- 
Luca Cavallaro
Ph.D. student
DEI, Politecnico di Milano,
Via Golgi 40
200133 Milan,
Italy
/------------------------------------------------------------/
Aphasia is the loss of speech in computer scientists when asked:
   "But of what use is your research?"
Received on Wed Oct 15 2008 - 18:23:36 BST

This archive was generated by hypermail 2.2.0 : Wed Oct 15 2008 - 22:30:12 BST