[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Using cflowbelow to detect cycles in the call graph - Not working
|
Hi, thanks for your swift reply. That's roughly how I "solved" it but I was hoping I could elegantly represent it as a simple PCD instead of handling the control flow manually. It's a bit odd why the original PCD doesn't match the cyclic function calls. Apparently what's happining is that it was only matching a single level of cflowbelow, not taking into consideration the if(), it somehow wasn't able to backtrack and find a true match to the original PCD.
On Thu, Aug 6, 2009 at 9:09 PM, Andy Clement
<andrew.clement@xxxxxxxxx> wrote:
I modified the aspect and it does what I think you want, but requires that you handle the control flow yourself. I think that is necessary because the method you are advising is 'equals()' which is likely to be used internally to the cflow implementation (although I haven't checked).
aspect A {
pointcut inTest1(Test1 i): within(Test1) && execution(boolean Test1.equals(Object)) && target(i);
Stack<Test1> t1Stack = new Stack<Test1>();
boolean around(Test1 t): inTest1(t) {
for (int i=0;i<t1Stack.size();i++) {
if (t1Stack.get(i)==t) {
return true;
}
}
t1Stack.push(t);
boolean b = proceed(t);
t1Stack.pop();
return b;
}
pointcut inTest2(Test2 i): within(Test2) && execution(boolean Test2.equals(Object)) && target(i);
Stack<Test2> t2Stack = new Stack<Test2>();
boolean around(Test2 t): inTest2(t) {
for (int i=0;i<t2Stack.size();i++) {
if (t2Stack.get(i)==t) {
return true;
}
}
t2Stack.push(t);
boolean b = proceed(t);
t2Stack.pop();
return b;
}
}
run:
3
4
1
2
4
1
2
3
haha, no more cycles!
2009/8/6 Neville Grech
<nevillegrech@xxxxxxxxx>
Hi, I'm trying out the following simple example whereby I have two classes, which contain an object of the other class's type in each. I then proceed to construct four objects in such a way that a cycle is created. When I call the equals method, I should get an infinite cycle. I tried to create a pointcut descriptor that detects this. Unfortunately, this only works when the nesting level in the call stack is less than 4. I need to create a PCD which detects cycles when the same equals method in the same object is called in the same call stack. Here is the code (which doesn't work as it should):
import java.util.*;
class Launcher {
public static void main(String[] args) {
Test1 t1=new Test1(1);
Test2 t2=new Test2(2);
Test1 t3=new Test1(3);
Test2 t4=new Test2(4);
t1.myObject=t2;
t2.myObject=t3;
t3.myObject=t4;
t4.myObject=t1;
assert t3.equals(t1);
System.out.println("haha, no more cycles!");
}
}
class Test1 {
public Test1(int c) { i=c; }
int i;
Test2 myObject;
public boolean equals(Object o) {
System.out.println(i);
return myObject.equals(((Test1)o).myObject);
}
}
class Test2 {
public Test2(int c) { i=c; }
int i;
Test1 myObject;
public boolean equals(Object o) {
System.out.println(i);
return myObject.equals(((Test2)o).myObject);
}
}
aspect A {
pointcut inTest1(Test1 i): call(boolean Test1.equals(Object)) && target(i);
pointcut inTest2(Test2 i): call(boolean Test2.equals(Object)) && target(i);
boolean around(Test1 up, Test1 now):
inTest1(now) && cflowbelow(inTest1(up)) && if(up==now){
return true;
}
boolean around(Test2 up, Test2 now):
if(up==now) && cflowbelow(inTest2(up)) && inTest2(now) {
return true;
}
}
--
Regards,
Neville Grech
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
--
Regards,
Neville Grech