[aspectc-user] Aspects advising aspects

Andreas Gal gal at uci.edu
Fri Jan 6 07:42:58 CET 2006

Hi Mike,

I am not sure I understand why the second problem (tracking the stats of a 
cache) is a cross-cutting concern that should be implemented as an aspect. 
Implementing caching as an aspect makes sense because it cross-cuts many
functions all over the program code. Its hard to modularize without an 

The stat counting, however, only affects an already modular piece of code: 
the caching aspect. Thus, simple inheritence should be sufficient to 
implement it in a modular fashion (by deriving a CountingCacheAspect from 
the original CacheAspect).

Maybe I am missing something.


(Note: I am not claiming there is no application for aspects advising 
aspect code. I just think this particular example does not require that.)

On Fri, 6 Jan 2006 mike-mortensen at comcast.net wrote:

> I'm exploring aspects that have multiple concerns in them...
> For example, Caching is a concern that can be implemented in an aspect.
> In addition, we could have a Caching aspect that not only uses around advice to 'intercept'
> calls and return precomputed values, but also keeps track of the number of 'hits' and 'misses' for
> each function that it is caching.  Each separate function of course has a separate cache
> (e.g. static map <key,value>) and separate hit/miss stats.  This can be useful, because
> caching a function that rarely recomputes the same value will not save run time...
> One could argue that tracking the stats of a cache is a separate concern of the cacher, in
> the same way that adding caching code directly to each method is adding an extra concern
> to the functions.
> I've created a Cache that tracks stats per join point, but one thing I am trying
> (not so successfully) is to use to two aspects -- one to implement Caching using
> around advice and a Cache class, and another to implement calls to the Cache class
> from the CachingAspect.
> So, in a nutshell, I want to create an aspect that captures calls from inside another aspect.
> This is kind of like AspectJ's adviceexecution, but I don't believe AspectC++ has that.
> What I have found from experimenting with a trivial case (not even caching) is that I
> can have:
>   AspectA, which calls a function HELLO
>  AspectB, which uses the execution pointcut of HELLO
> BUT, if AspectB tries to use   call("% HELLO(...)") instead of execution (so that it's
> weaving inide of AspectA) or if AspectB tries to use something like
>   JoinPoint::signature()
> even with the execution joinpoint, I get errors when the woven code is compiled.
> I'm guessing that trying to weave into another aspect's advice or access JoinPoint
> info there is not supported, but without doing this the second aspect doesn't have
> enough context to be able to do anything useful...
> Here's an example of the aspect file that works.  It has an Advisor
> aspect that calls HELLO, and a Monitor aspect that weaves against
> the execution of HELLO but doesn't use JoinPoint information
> (since the joinpoint would occur when Advisor's advice calls HELLO).
> #include <iostream>
> #include <map>
> #include <string>
> void HELLO() { std::cerr << " IN HELLO" << std::endl; }
> aspect Advisor {
>   pointcut CallCircleArea() = call("% CircleArea(...)");
>   advice CallCircleArea() : around()
>   {
>      HELLO();
>      tjp->proceed();
>      std::cerr << " In Advisor aspect..." << std::endl;
>   }
> };
> aspect Monitor {
>   pointcut Hello() = execution("% HELLO(...)");
>   advice Hello() : before() {
>      std::cerr << " In Monitor, about to call HELLO ............." << std::endl;
>   }
> };
> Is this aspects that weave into other aspects beyond the scope of what AspectC++ can currently do,
> or am I just missing something?
> Thanks!
> -Mike Mortensen

Andreas Gal, PhD Candidate                  Tel: (949) 350-7417
Computer Science Department                 Fax: (213) 232-0599
University of California, Irvine               Office: CS/E 105
Irvine, CA 92697-3430                        Email: gal at uci.edu

More information about the aspectc-user mailing list