Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] can the around advice be (partially) inlined when it applies to itself?

Hi all,
 
The ajc compiler inlines the around advice in most of the cases, except for some, which include cases where the advice applies to a shadow within its own body. Consider the following example,
 
public aspect MyAspect {
 
        Object around() : call(* println(..)) && !cflow(within(MyAspect)) {
                System.out.println("around advice");
                return proceed();
        }
}
 
public class Test {
        public static void main(String[] args) {
                System.out.println("main");
        }
}
 
Ajc resorts to closure object creation for the above example. While closure creation cannot be avoided in the above case, it can be limited to only the shadow in the around advice, and the around advice can be inlined for the shadow in the main method.
 
To make the point concrete,
 
public static void main(String[] args) {
        if(cflow-condition-is-met) {
                AjcClosure1 ac1 = new AjClosure1();
                ...
                ajc$around(ac1);
        }
        else
                System.out.println("around advice");
        System.out.println("main");
}
 
While the above code deviates a bit from how ajc would inline the advice, I hope it does make the point clear. Instead of having to make an either-or decision between inlining or closure creation, the above strategy uses a hybrid approach, resorting to closure creation only if the advice actually applies to the shadow in the around adevice at runtime (and we know that this won't happen because of the !cflow(..)).
 
Now for the question.  
 
Is the hybrid approach workable, or am I missing something? If it is workable, then how much of an implementation effort would it take to modify the ajc source code to follow this strategy?  
 
Thanks,
Immad

Back to the top