[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
|
- From: Andy Clement <andrew.clement@xxxxxxxxx>
- Date: Thu, 6 Aug 2009 12:09:12 -0700
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=/z7zFeUc5YDVVs6LhStMLAwdsaHZ4dCaQ/ghKgN5Quo=; b=OPPis6Qce0U18M8fBTQ2pJBcjX52EBYts85eqNy3F0IIUKDSjyQMEJhlE+i3WgBeux iUC4wXVbvKEHgdJkdB+nGMUCURgo00Y/yEyWppPhHVYri42pV8E3uSUk3NPYQPXcAXP4 UNp4ane+RPtFnSlDitWFcDpcfTXe+aaJ/kUco=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=iJtyikMWc0n6aEHJCXiGLnRuuDwggrTuArwhCkbSIhbYLeghcNAoc/aKaJ83XtuXz9 5ihd+1shRk+A2jyLnVj8TrCS30mzn/8tZSvAZaAkPaPkNz+rR6LrmbFiZ5p21kYSHTzl FKndcncRhY/taZdoz5k6NIsno2i3yLjkz0b1I=
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