On Sep 3, 2008, at 10:11 PM, Andy Clement wrote: In the first case, the generated compare method is a generics bridge method - which merely acts as a bridge from the (Object,Object) variant to your (String,String). If you look at the bytecode for it, you will see it calls the other compare method.
AspectJ does not advise bridge methods, because they just delegate to the 'real' method. If we did then in this case your advice would run twice if you called the Object,Object version.
In your second case you provided your own compare(Object,Object) method and so it was advised.
Thanks Andy for the rapid answer. If I understood well, AspectJ does not advise bridge method as optimization... The problem is that we need to advice all methods (from third party compiled code)... which is important for context sensitive applications. Currently we have 'lost slots' because of the non advised bridge methods, which are very hard to debug :-(
I'm not sure if enabling advise of bridge methods could benefit other users.... but it would be helpful to have such a feature.
Cheers,
Alex
cheers, Andy. 2008/9/3 Alex Villazon <alex.villazon@xxxxxxxxxxx> Dear all, I have a problem with the following aspect which can advice methods, depending on how it's compiled... public class A implements java.util.Comparator <String> { public int compare(String a, String b) { return 0; } } javac generated a compare(Object, Object) method corresponding to public int compare(Object a, Object b) { return compare((String)a, (String)b); } When weaving A.java with the following aspect, only the compare(String, String) method is adviced... public aspect Foo { before() : execution(* *(..)) && !within(Foo) {} } javac A.java jar cvf a.jar A.class ajc -showWeaveInfo -inpath a.jar -outjar woven.jar Foo.aj Join point 'method-execution(int A.compare(java.lang.String, java.lang.String))' in Type 'A' (A.java:3) advised by before advice from 'Foo' (Foo.aj:2) Now, if I add the compare(Object, Object) manually, the Foo aspect advice both compare(String, String) and compare(Object, Object) methods!!!! public class A implements java.util.Comparator /*<String> */ { public int compare(String a, String b) { return 0; } public int compare(Object a, Object b) { return compare((String)a, (String)b); } } javac A.java jar cvf a.jar A.class ajc -showWeaveInfo -inpath a.jar -outjar woven.jar Foo.aj Join point 'method-execution(int A.compare(java.lang.String, java.lang.String))' in Type 'A' (A.java:3) advised by before advice from 'Foo' (Foo.aj:2) Join point 'method-execution(int A.compare(java.lang.Object, java.lang.Object))' in Type 'A' (A.java:6) advised by before advice from 'Foo' (Foo.aj:2) Curiously, the bytecode for compare(Object, Object) is strictly the same.. in both cases.. public int compare(java.lang.Object, java.lang.Object); Signature: (Ljava/lang/Object;Ljava/lang/Object;)I Code: Stack=3, Locals=3, Args_size=3 0: aload_0 1: aload_1 2: checkcast #2; //class java/lang/String 5: aload_2 6: checkcast #2; //class java/lang/String 9: invokevirtual #3; //Method compare:(Ljava/lang/String;Ljava/lang/String;)I 12: ireturn LineNumberTable: line 1: 0 Is this a bug of ajc? I tested it with 1.6.1 and 1.6.2 (development version) Thanks a lot, Alex _______________________________________________ aspectj-users mailing list aspectj-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/aspectj-users <ATT00001.txt>
|