Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] expression based pointcuts

Hi,

> pointcut p2() : if(Simple.foo != null && Simple.foo.equals("foo")) &&> within(Simple);>> 1. Aspectj determines whether the result of the if statement is statically> determinable> 2. Aspectj determines the pointcuts which may match (in this example limit> to Simple class?)> 3. Injects portions to capture the appropriate execution

AspectJ optimizes the pointcut, ensuring the cheaper checks are done
first (like within).  A within can be used to eliminate entire classes
from matching very quickly. For every joinpoint it then determines if
the pointcut matches.  If it does fully statically match then the
advice call is injected directly into the bytecode.  If we don't know
because something cannot be statically determined then we have what is
called 'residue' left over, which is a runtime test that is inserted
into the code - if that test passes then the advice will be called.
It isn't just 'if()' that will generate residue, something like
'target(SomeInterface)' may generate residue (an instanceof test).

Very little work is done on the contents of if() clauses.  I think we
recognize if(true) and if(false) but beyond that no static analysis is
done, and so you find the 'residue' in this case is a call to the
method that captures the code in the if().

> This is just a wild guess please correct me.>> pointcut p3() : if(thisJoinPoint.getArgs()[0].equals("sss"));>> in this case the if can not be evaluated statically so EVERY exposed join> point in> the system must be injected to carry out the evaluation of the "if"?>

Yep. This is why we recommend a scoping component to all pointcuts, to
limit the matching, and usually a kind component that determines what
kinds of joinpoint you are interested in
(execution/call/handler/field-get/field-set/etc).

cheers,
Andy
On 29 December 2011 13:04, Dénes Németh <mr.nemeth.denes@xxxxxxxxx> wrote:
> Hi
>
> How does the expression-based pointcut work?
>
> public class Simple {
>   public static String foo = "foo";
>   public void foom(){
>
>   }
>   public static void main(String[] args) {
>     Simple s = new Simple();
>     s.foom();
>   }
> }
>
> pointcut p2() : if(Simple.foo != null && Simple.foo.equals("foo")) &&
> within(Simple);
>
> 1. Aspectj determines whether the result of the if statement is statically
> determinable
> 2. Aspectj determines the pointcuts which may match (in this example limit
> to Simple class?)
> 3. Injects portions to capture the appropriate execution
>
> This is just a wild guess please correct me.
>
> pointcut p3() : if(thisJoinPoint.getArgs()[0].equals("sss"));
>
> in this case the if can not be evaluated statically so EVERY exposed join
> point in
> the system must be injected to carry out the evaluation of the "if"?
>
> If someone knows any documentation regards if pointcut please share it...
>
> Thanks Denes
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top