Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
AW: [aspectj-users] [newbie] General help needed here.....

Hello,

I am also a little bit confused about this statement:

> By the way, this(Type) && execution(...) has *no* dynamic test

Take these test classes:

public interface FooIF {
	public void foo();
}

pubic class Simple {
	public void anotherFoo() {
		System.err.println("Another Foo");
	}
}

public class Derived extends Simple implements FooIF {
	public void foo() {
		System.err.println("Foo");
	}
}

public aspect ExecutionAspect {

	pointcut test(): execution(* *(..)) && this(FooIF);

	before (): test() {
		System.err.println("Before");
	}
}

This advises Simple.anotherFoo with runtime test (according to Outline view 
in eclipse). So there is a runtime test with this(Type) && execution(...).
So what do you mean with this statement? When Simple also implements FooIF
there are no longer advices that need runtime tests. So the compiler makes 
some optimizations (as described in the paper you provided).

In my opinion the documentation lacks some good examples regarding this 
topic. Take these two misunderstandings.

- It is allowed to use a + in this(Type+) which makes no difference. But
  one could think this(Type) could mean exactly this type and this(Type+)
  instanceof this Type.
- Take execution(* Type.*(..)) For me it was a surprise that derived 
  classes from type that override methods from Type get advices too.

A little test which picks up the usual misunderstandings at the end
of the programming guide would be great.

Vincenz

-----Ursprüngliche Nachricht-----
Von: aspectj-users-admin@xxxxxxxxxxx
[mailto:aspectj-users-admin@xxxxxxxxxxx] Im Auftrag von Ron Bodkin
Gesendet: Montag, 19. Juli 2004 08:36
An: aspectj-users@xxxxxxxxxxx
Betreff: RE: [aspectj-users] [newbie] General help needed here.....

Hi Otavio,

That's right, if you need to bind to the currently executing object it does
have a performance impact. But if you are using execution(* method(..)) &&
this(Type) only to filter the objects matching, it does not have a
performance impact when compared to using execution(* Type.method(..))

Ron

> ------------Original Message------------
> From: Otávio Augusto Lazzarini Lemos <oall@xxxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Sat, Jul-17-2004 9:51 AM
> Subject: RE: [aspectj-users] [newbie] General help needed here.....
> 
>   About the last example you gave, you are not actually using the join 
> point´s
> currently executing object (this(ExecBytecode)) in your advice. Try to 
> use it
> in the before advice and you will have some differences at the bytecode 
> level.
> I guess that at least the object will be pushed on to the stack to be 
> used by
> the before advice. I don´t know the performance implications of that, 
> but the
> bytecode will not be the same.
> 
> Otávio
> 
>  .---------------------- --  --- ----  -----
> |Otávio Augusto Lazzarini Lemos
> |M. Sc. candidate
> |Labes - Software Engineering Laboratory
> |USP - University of São Paulo
> |São Carlos, SP - Brasil
> |oall@xxxxxxxxxxx - otaviolemos@xxxxxxxxxx
>  -------------------------------------------- --- -  -
> 
> Citando Ron Bodkin <rbodkin@xxxxxxxxxxxxxx>:
> 
> > Yes Wes, it is true that using the declaring type in the signature is 
> useful
> > and can be appropriate for those who have some experience with 
> AspectJ.
> > However, for new users it's helpful to get in the mindset of using 
> this to
> > specify types instead of doing it in the method signature, instead of 
> trying
> > to remember that using declaring types with call is problematic and 
> using
> > them with execution is ok (remember that Jerry started off using call 
> with a
> > static type in the signature!) And it is also a good rule because 
> it's
> > binding the currently executing object in your pointcut is commonly 
> done.
> > 
> > By the way, this(Type) && execution(...) has *no* dynamic test (+), 
> and with
> > the AspectJ 1.2 compiler optimizations should be compiled about 
> equally
> > quickly (e.g., slide 96 from Andy Clement's data at
> > 
> http://newaspects.com/presentations/Enterprise%20AOP%20AOSD%202004.ppt
which
> > shows some related improvements, although not the performance of 
> this(..) &&
> > execution(..)). 
> > 
> > It is true that it's not statically resolvable for declare 
> warning/error
> > (although I'd like to see the compiler restriction eased to allow use
> > pointcuts for any special cases where no dynamic test would be 
> required to
> > resolve a pointcut; maybe some day). And it also isn't useful for 
> statics
> > (clearly). But these are specialized scenarios, not the general rule.
> > 
> > Re: configuring AspectJ with Struts, the aTrack project is a working 
> example
> > that uses Struts with AspectJ.
> > 
> > Ron
> > 
> > (+) See section 4.1.2 in "Advice Weaving in AspectJ"
> > http://www.hugunin.net/papers/aosd-2004-cameraReady.pdf. Also I 
> compiled two
> > versions of an aspect with AspectJ 1.2 and found identical bytecode:
> > 
> > public aspect ExecBytecode {
> >     void foo() {}
> >     before() : this(ExecBytecode) && execution(* foo()) {}
> > }
> > 
> > Then from "javap -c ExecBytecode"
> > 
> > foo();
> >   Code:
> >    0:	invokestatic	#49; //Method aspectOf:()LExecBytecode;
> >    3:	invokevirtual	#51; //Method 
> ajc$before$ExecBytecode$1$eb4dac00:()V
> >    6:	return
> > 
> > public void ajc$before$ExecBytecode$1$eb4dac00();
> >   Code:
> >    0:	return
> > 
> > public aspect ExecBytecode {
> >     void foo() {}
> >     before() : execution(* ExecBytecode.foo()) {}
> > }
> > 
> > Produces:
> > void foo();
> >   Code:
> >    0:	invokestatic	#49; //Method aspectOf:()LExecBytecode;
> >    3:	invokevirtual	#51; //Method 
> ajc$before$ExecBytecode$1$b5db75e4:()V
> >    6:	return
> > 
> > public void ajc$before$ExecBytecode$1$b5db75e4();
> >   Code:
> >    0:	return
> > 
> > Ron Bodkin
> > Chief Technology Officer
> > New Aspects of Software
> > o: (415) 824-4690
> > m: (415) 509-2895
> > 
> > > ------------Original Message------------
> > > From: "Wes Isberg" <wes@xxxxxxxxxxxxxx>
> > > To: aspectj-users@xxxxxxxxxxx
> > > Date: Fri, Jul-16-2004 11:06 PM
> > > Subject: RE: [aspectj-users] [newbie] General help needed here.....
> > > 
> > > Hi Ron (, Jerry) -
> > > 
> > > re:
> > > > As a general rule, you probably don't want to use the form of 
> > > signature 
> > > > you have in that pointcut (which matches based on static types 
> > > instead 
> > > > of runtime instances). 
> > > 
> > > I've never heard this rule and I believe it is not correct;
> > > The original form
> > > 
> > >     execution(ReturnType DeclaringType.methodName(..))
> > > 
> > > is better than
> > > 
> > >     execution(ReturnType methodName(..)) && this(DeclaringType)
> > > 
> > > *because* it can be resolved staticly and requires no dynamic test
> > > (faster compile, faster implementation, and better IDE support).
> > > 
> > > You might be confusing this situation with the suggestion for
> > > the call pointcut not to use the declaring type in the call.  
> > > This suggestion is because the signature of a call join point
> > > refers to the type of the reference (at the call site), not the 
> > > type of the referent class (at run time).  So when people
> > > write
> > > 
> > >    call(ReturnType DeclaringType.methodName(..))
> > > 
> > > they usually mean
> > > 
> > >    call(ReturnType methodName(..)) && target(DeclaringType)
> > > 
> > > (hence the suggestion).
> > > 
> > > Wes
> > > 
> > > P.S. - If someone does figure out how to configure AspectJ
> > > with Struts, etc, it would be great to contribute back a
> > > description to the mailing list or a bug, for inclusion in
> > > the sample code repository...
> > > 
> > > 
> > > > ------------Original Message------------
> > > > From: "Ron Bodkin" <rbodkin@xxxxxxxxxxxxxx>
> > > > To: aspectj-users@xxxxxxxxxxx
> > > > Date: Fri, Jul-16-2004 4:09 PM
> > > > Subject: RE: [aspectj-users] [newbie] General help needed 
> here.....
> > > >
> > > > Jerry,
> > > > 
> > > > A couple of things to try:
> > > > 1) Make sure that you are opening the affected file with the 
> AspectJ 
> > > > editor and not the Java editor. You should go into window | 
> > > preferences | 
> > > > file associations and make sure that AspectJ is set the the 
> default 
> > > for 
> > > > .java files
> > > > 2) Try adding this line, to see if the pointcut is matching:
> > > > 
> > > > declare warning: actionCall() : "in action execution";
> > > > 
> > > > As a general rule, you probably don't want to use the form of 
> > > signature 
> > > > you have in that pointcut (which matches based on static types 
> > > instead 
> > > > of runtime instances). It should work for executions, but a 
> better 
> > > > version is:
> > > > 
> > > > pointcut actionExecute() : execution(public ActionForward 
> > > > execute(ActionMapping, ActionForm, 
> > > > HttpServletRequest, HttpServletResponse))) && this(Logon_Action);
> > > > 
> > > > Ron
> > > > 
> > > > p.s. there's an already defined, debugged version of a pointcut 
> for 
> > > > struts action execution in the aTrack project: see 
> > > > ajee.component.StrutsPointcuts. aTrack is at 
> > > https://atrack.dev.java.net/ 
> > > > 
> > > >     public pointcut actionExecute(Action action, ActionMapping 
> > > mapping, 
> > > > ActionForm form, 
> > > >         HttpServletRequest request, HttpServletResponse response) 
> :
> > > >         execution(ActionForward Action.execute(ActionMapping, 
> > > > ActionForm, 
> > > >             HttpServletRequest, HttpServletResponse)) && 
> this(action) 
> > > 
> > > > && 
> > > >         args(mapping, form, request, response);
> > > > 
> > > > 
> > > > Ron Bodkin
> > > > Chief Technology Officer
> > > > New Aspects of Software
> > > > o: (415) 824-4690
> > > > m: (415) 509-2895
> > > > 
> > > > > ------------Original Message------------
> > > > > From: "Jerry Jalenak" <Jerry.Jalenak@xxxxxxxxxx>
> > > > > To: "'aspectj-users@xxxxxxxxxxx'" <aspectj-users@xxxxxxxxxxx>
> > > > > Date: Fri, Jul-16-2004 1:07 PM
> > > > > Subject: RE: [aspectj-users] [newbie] General help needed 
> here.....
> > > > > 
> > > > > Another possibility that just occurred to me....
> > > > > 
> > > > > Since Logon_Action extends Action, do I need to 'expose' the
> > > > > org.apache.struts.action.Action class to the aspect?
> > > > > 
> > > > > Jerry Jalenak
> > > > > Development Manager, Web Publishing
> > > > > LabOne, Inc.
> > > > > 10101 Renner Blvd.
> > > > > Lenexa, KS  66219
> > > > > (913) 577-1496
> > > > > 
> > > > > jerry.jalenak@xxxxxxxxxx
> > > > > 
> > > > > 
> > > > > > -----Original Message-----
> > > > > > From: Ramnivas Laddad [mailto:ramnivas@xxxxxxxxxxxxxxx]
> > > > > > Sent: Friday, July 16, 2004 2:29 PM
> > > > > > To: aspectj-users@xxxxxxxxxxx
> > > > > > Subject: Re: [aspectj-users] [newbie] General help needed 
> > > here.....
> > > > > > 
> > > > > > 
> > > > > > Hi Jerry,
> > > > > > 
> > > > > > Otávio's suggestion of using execution() PCD is the right 
> one.
> > > > > > 
> > > > > > It is okay to use any number of aspects crosscutting a class. 
> 
> > > > > > Just a guess: Do you have every referred type in the pointcut 
> 
> > > > > > definition (in your case ActionMapping, ActionForm, 
> > > > > > HttpServletRequest, HttpServletResponse) appropriately 
> imported.
> > > > > > 
> > > > > > -Ramnivas
> > > > > > 
> > > > > > ===
> > > > > > 
> > > > > > Ramnivas Laddad,
> > > > > > Author, AspectJ in Action
> > > > > > http://ramnivas.com
> > > > > > 
> > > > > > Jerry Jalenak wrote:
> > > > > > 
> > > > > > >Otavio,
> > > > > > >
> > > > > > >Thanks for the reply.  Change the PCD from call to execution 
> 
> > > > > > didn't seem to
> > > > > > >change anything.  However, I starting to think I have 
> > > > > > something else wrong.
> > > > > > >In the AspectJ Visualizer perspective, I am only seeing 
> > > > > > where one aspect has
> > > > > > >been applied (I have two).  Is it not possible to have more 
> > > > > > than one aspect
> > > > > > >class?
> > > > > > >
> > > > > > >Thanks....
> > > > > > >
> > > > > > >Jerry Jalenak
> > > > > > >Development Manager, Web Publishing
> > > > > > >LabOne, Inc.
> > > > > > >10101 Renner Blvd.
> > > > > > >Lenexa, KS  66219
> > > > > > >(913) 577-1496
> > > > > > >
> > > > > > >jerry.jalenak@xxxxxxxxxx
> > > > > > >
> > > > > > >
> > > > > > >  
> > > > > > >
> > > > > > >>-----Original Message-----
> > > > > > >>From: Otávio Augusto Lazzarini Lemos 
> [mailto:oall@xxxxxxxxxxx]
> > > > > > >>Sent: Friday, July 16, 2004 1:31 PM
> > > > > > >>To: aspectj-users@xxxxxxxxxxx
> > > > > > >>Subject: Re: [aspectj-users] [newbie] General help needed 
> > > > here.....
> > > > > > >>
> > > > > > >>
> > > > > > >>You should use an execution PCD. In your example the calls 
> to
> > > > > > >>Logon_action.execute(ActionMapping, ActionForm, 
> > > > HttpServletRequest,
> > > > > > >>    
> > > > > > >>
> > > > > > >>>HttpServletResponse) are the intercepted join points, and 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>not the actual
> > > > > > >>execution of the method (try to look at the places where 
> you 
> > > > > > >>call the method).
> > > > > > >>Tell me if it works with the execution instead of the call 
> PCD.
> > > > > > >>
> > > > > > >>Otávio
> > > > > > >>
> > > > > > >>Citando Jerry Jalenak <Jerry.Jalenak@xxxxxxxxxx>:
> > > > > > >>
> > > > > > >>    
> > > > > > >>
> > > > > > >>>First, thanks to Rod, Adrian, and Ramnivas for their help 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>the other day.  I
> > > > > > >>    
> > > > > > >>
> > > > > > >>>think I'm starting to get the hang of this....
> > > > > > >>>
> > > > > > >>>That being said, I'm stuck as to why the following doesn't 
> 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>work.  I've just
> > > > > > >>    
> > > > > > >>
> > > > > > >>>upgraded to the AJDT 1.1.11 plug-in, if it matters.
> > > > > > >>>
> > > > > > >>>Here's the aspect :
> > > > > > >>>
> > > > > > >>>	public aspect MemberSolutions_BaseActionAspect
> > > > > > >>>	{
> > > > > > >>>	    // ~ Pointcut definitions
> > > > > > >>>	    
> > > > > > >>>	    pointcut actionCall() : 
> > > > > > >>>	        (call(public ActionForward
> > > > > > >>>Logon_Action.execute(ActionMapping, ActionForm, 
> > > > > HttpServletRequest,
> > > > > > >>>HttpServletResponse)));
> > > > > > >>>	    
> > > > > > >>>	    // ~ Advice definitions
> > > > > > >>>    
> > > > > > >>>	    before() : actionCall()
> > > > > > >>>	    {
> > > > > > >>>	        System.out.println("here i am");
> > > > > > >>>	    }
> > > > > > >>>	}
> > > > > > >>>
> > > > > > >>>and the class I'm trying to weave it into :
> > > > > > >>>
> > > > > > >>>	public class Logon_Action extends Action
> > > > > > >>>	{
> > > > > > >>>	    public ActionForward execute(ActionMapping 
> > > _actionMapping,
> > > > > > >>>	            ActionForm _actionForm, HttpServletRequest 
> > > > _request,
> > > > > > >>>	            HttpServletResponse _response)
> > > > > > >>>	    {
> > > > > > >>>	        Logon_ActionForm form = (Logon_ActionForm) 
> > > _actionForm;
> > > > > > >>>	        return null;
> > > > > > >>>	    }
> > > > > > >>>	}
> > > > > > >>>
> > > > > > >>>Everything compiles OK (no errors, anyway), but when I 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>check the class I
> > > > > > >>    
> > > > > > >>
> > > > > > >>>don't see any indication that the aspect is being applied. 
>  
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>I expect to see
> > > > > > >>    
> > > > > > >>
> > > > > > >>>an indicator on the first statement of the class....
> > > > > > >>>
> > > > > > >>>I'm probably being dense on this, and it's something 
> really 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>stupid, but I
> > > > > > >>    
> > > > > > >>
> > > > > > >>>can't seem to figure it out.  Any help?
> > > > > > >>>
> > > > > > >>>Thanks guys!
> > > > > > >>>
> > > > > > >>>Jerry Jalenak
> > > > > > >>>Development Manager, Web Publishing
> > > > > > >>>LabOne, Inc.
> > > > > > >>>10101 Renner Blvd.
> > > > > > >>>Lenexa, KS  66219
> > > > > > >>>(913) 577-1496
> > > > > > >>>
> > > > > > >>>jerry.jalenak@xxxxxxxxxx
> > > > > > >>>
> > > > > > >>>
> > > > > > >>>This transmission (and any information attached to it) may 
> 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>be confidential
> > > > > > >>    
> > > > > > >>
> > > > > > >>>and
> > > > > > >>>is intended solely for the use of the individual or entity 
> 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>to which it is
> > > > > > >>    
> > > > > > >>
> > > > > > >>>addressed. If you are not the intended recipient or the 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>person responsible
> > > > > > >>    
> > > > > > >>
> > > > > > >>>for
> > > > > > >>>delivering the transmission to the intended recipient, be 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>advised that you
> > > > > > >>    
> > > > > > >>
> > > > > > >>>have received this transmission in error and that any use, 
> 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>dissemination,
> > > > > > >>    
> > > > > > >>
> > > > > > >>>forwarding, printing, or copying of this information is 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>strictly prohibited.
> > > > > > >>    
> > > > > > >>
> > > > > > >>>If you have received this transmission in error, please 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>immediately notify
> > > > > > >>    
> > > > > > >>
> > > > > > >>>LabOne at the following email address: 
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>securityincidentreporting@xxxxxxxxxx
> > > > > > >>    
> > > > > > >>
> > > > > > >>>_______________________________________________
> > > > > > >>>aspectj-users mailing list
> > > > > > >>>aspectj-users@xxxxxxxxxxx
> > > > > > >>>http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > > > > >>>
> > > > > > >>>      
> > > > > > >>>
> > > > > > >>_______________________________________________
> > > > > > >>aspectj-users mailing list
> > > > > > >>aspectj-users@xxxxxxxxxxx
> > > > > > >>http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > > > > >>
> > > > > > >>    
> > > > > > >>
> > > > > > >
> > > > > > >This transmission (and any information attached to it) may 
> > > > > > be confidential and is intended solely for the use of the 
> > > > > > individual or entity to which it is addressed. If you are not 
> 
> > > > > > the intended recipient or the person responsible for 
> > > > > > delivering the transmission to the intended recipient, be 
> > > > > > advised that you have received this transmission in error and 
> 
> > > > > > that any use, dissemination, forwarding, printing, or copying 
> 
> > > > > > of this information is strictly prohibited. If you have 
> > > > > > received this transmission in error, please immediately 
> > > > > > notify LabOne at the following email address: 
> > > > > > securityincidentreporting@xxxxxxxxxx
> > > > > > >
> > > > > > >_______________________________________________
> > > > > > >aspectj-users mailing list
> > > > > > >aspectj-users@xxxxxxxxxxx
> > > > > > >http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > > > > >
> > > > > > >  
> > > > > > >
> > > > > > 
> > > > > > _______________________________________________
> > > > > > aspectj-users mailing list
> > > > > > aspectj-users@xxxxxxxxxxx
> > > > > > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > > > > 
> > > > > 
> > > > > This transmission (and any information attached to it) may be 
> > > > > confidential and is intended solely for the use of the 
> individual 
> > > or 
> > > > entity to 
> > > > > which it is addressed. If you are not the intended recipient or 
> the 
> > > 
> > > > > person responsible for delivering the transmission to the 
> intended 
> > > > > recipient, be advised that you have received this transmission 
> in 
> > > > error and 
> > > > > that any use, dissemination, forwarding, printing, or copying 
> of 
> > > this 
> > > > 
> > > > > information is strictly prohibited. If you have received this 
> > > > transmission 
> > > > > in error, please immediately notify LabOne at the following 
> email 
> > > > > address: securityincidentreporting@xxxxxxxxxx
> > > > > 
> > > > > _______________________________________________
> > > > > aspectj-users mailing list
> > > > > aspectj-users@xxxxxxxxxxx
> > > > > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > > > 
> > > > > 
> > > > 
> > > > _______________________________________________
> > > > aspectj-users mailing list
> > > > aspectj-users@xxxxxxxxxxx
> > > > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > > 
> > > 
> > > 
> > > _______________________________________________
> > > aspectj-users mailing list
> > > aspectj-users@xxxxxxxxxxx
> > > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > 
> > > 
> > 
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > 
> 
> 
> -- 
> -----------------------------------------------------------.__
>   Otávio Augusto Lazzarini Lemos                              |
>   oall@xxxxxxxxxxx - otaviolemos@xxxxxxxxxx                   |
> ------------------------------------------------------------- |
>   Insituto de Ciências Matemáticas e de Computação - ICMC/USP |
> --------------------------------------------- -------- ---- == 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> 

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




Back to the top