Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] If pointcut and side effects

Take a look at the implementation of PointcutEvaluationExpenseComparator, which determines the ordering of terms within an conjunction or disjunction. The more complex part of the equation is implemented in PointcutRewriter  which does all the DNF translations and optimisations etc. first.

The implementation speeds up the matching process, and allows for maximum disambiguation of argument binding. We always also generate the smallest possible runtime tests (which an 'if' pointcut represents).

Regards, Adrian.

On 31/05/06, Jon S. Baekken <jbaekken@xxxxxxxxxxxx> wrote:
Why was this decision made? For better/faster implementation? From a usability point of view, one would certainly like to have control over the evaluation order (especially since AspectJ is an augmentation of Java where boolean expressions have a defined order).

Are there any simple rules that can be stated about evaluation order given the current (eclipse) implementation of AspectJ? (I know I shouldn't rely on them but I'm curious)

Jon

On May 31, 2006, at 12:51 AM, Adrian Colyer wrote:

As Wes indicates, an if pointcut _expression_ may be evaluated zero, one, or even many times :- the AspectJ language does not define an order for the evaluation of pointcut expressions.

Our implementation of the language rewrites pointcuts to DNF to disambiguate binding references, optimizes the pointcut _expression_ (reducing terms such as (A and !A) ), and then orders terms for fastest possible matching based on heuristics.

Writing if pointcut expressions with side-effects is certainly not something to be relied on!

On 31/05/06, Wes < wes@xxxxxxxxxxxxxx> wrote:
> Is p1 and p2 evaluated independently? Which is evaluated
> first? Why doesn't the assignment in p1 affect p2?

>From the programming guide, semantics appendix discussion of
the if pointcut:

  Note that the order of evaluation for pointcut _expression_
  components at a join point is undefined. Writing if pointcuts
  that have side-effects is considered bad style and may also
  lead to potentially confusing or even changing behavior with
  regard to when or if the test code will run.

It can be confusing because programmers come to rely on the
order of evaluation for boolean expressions in Java, but
these aren't that.

Wes

> ------------Original Message------------
> From: "Jon S. Baekken" < jbaekken@xxxxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Tue, May-30-2006 2:08 PM
> Subject: [aspectj-users] If pointcut and side effects
>
> Hi all,
>
> I ran into an issues regarding combining several if pointcuts in one
> and wondered if somebody could explain what seems to me like strange
> behavior (the example is artificial but illustrates the point):
>
> Say I have the following aspect:
>
> aspect A {
>     pointcut p1() : call(* m(..)) && if((x=2) == 2); // last one
> always true of course
>     before() : p1() && if(x==0) {...}
>     static int x = 0;
> }
>
> And a class with two methods:
>
> void main() {
>     m();
> }
>
> void m() {
>     ...
> }
>
> As expected, the advice is not executed at a call to m(), I guess
> because x cannot be both 0 and 2 at the same time.
>
> However, if I move the if(x==0) from the advice spec to a named
> pointcut p2:
>
> pointcut p2() : if(x==0);
>
> and change the advice to:
>
> before() : p1() && p2();
>
> the advice executed!
>
> I guess this is related to the side effect the if pointcut has in
> changing the state value of x, but why different results in the two
> cases? Is p1 and p2 evaluated independently? Which is evaluated
> first? Why doesn't the assignment in p1 affect p2?
>
> Thanks,
> Jon
>
>
> _______________________________________________
> 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



--
-- Adrian
adrian.colyer@xxxxxxxxx
_______________________________________________


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users





--
-- Adrian
adrian.colyer@xxxxxxxxx

Back to the top