Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Reducing code overhead

Hi,
We decided to use AspectJ in our product TICL. I wrote an aspect and
everything is working, but there's a
quite big overhead and the resulting jar has grow with around 400K. So I'd
like to ask for some advices how
to cut down this overhead. Let me fisrt descrive what is our aspect supposed
to do. We have a bunch of
classes (around 90) representing custom JSP tags, which should be modified
in a way to provide EL support.
We have written such classes too, but because  the code is very similar, we
decided to use an aspect to get
rid of those EL classes. So what is our aspect supposed to do: it should
intercept all doStartTag(), doEndTag()
methods, and all setters. The string setters should be handled differently
that all other setters. I've applided every
possible restriction taht i'm aware of, but I'm not an AspectJ expert, so
i'd like to ask you for some help.
The code is given below:

aspect ElAspect perthis(tags())
{
    pointcut tags(): (this(TICLTagSupport+) || this(TICLBodyTagSupport+))
     && within(com.kobrix.ticl.tags.*) &&
!within(com.kobrix.ticl.tags.el.*);

    //calls that must pass without our modifications
    pointcut spec(): withincode(void ElAspect.restoreAttributes(Object)) ||
    withincode(void ElAspect.saveAndEvaluateAttributes(Object));

    pointcut setters(): execution(public void TICLTagSupport+.set*(String))
&& target(TICLTagSupport+)&& !cflow(spec());
    pointcut setters1(): execution(public void
TICLBodyTagSupport+.set*(String)) && target(TICLBodyTagSupport+) &&
!cflow(spec());

    void around() : setters() || setters1()
    {
        Object arg = thisJoinPoint.getArgs()[0];
        if(arg != null)
          savedAttributes_.put(thisJoinPoint.getSignature().getName(), arg);
        proceed();
    }

    pointcut special_setters():  call(public void TICLTagSupport+.set*(*))
    && !call(public void TICLTagSupport+.set*(String)) &&
target(TICLTagSupport+);
    pointcut special_setters1():  call(public void TICLTagSupport+.set*(*))
    && !call(public void TICLBodyTagSupport+.set*(String)) &&
target(TICLBodyTagSupport+);


    void around() : special_setters() || special_setters1()
    {
        Object arg = thisJoinPoint.getArgs()[0];
        if(arg != null)
           savedAttributes_.remove(thisJoinPoint.getSignature().getName());
        proceed();
    }

    pointcut doStartTag(Object tag): execution(public int
TICLTagSupport+.doStartTag())
    && target(tag) && !cflowbelow(execution(public int
TICLTagSupport+.doStartTag()));
    pointcut doStartTag1(Object tag):  execution(public int
TICLBodyTagSupport+.doStartTag()) &&
    target(tag) && !cflowbelow(execution(public int
TICLBodyTagSupport+.doStartTag()));

    before(Object tag) : doStartTag(tag) || doStartTag1(tag)
    {
        saveAndEvaluateAttributes(tag);
    }

    pointcut doEndTag(TICLTagSupport tag):  execution(public int
TICLTagSupport+.doEndTag())
    && this(tag) && !cflowbelow(execution(public int
TICLTagSupport+.doEndTag()));
    pointcut doEndTag1(TICLBodyTagSupport tag):  execution(public int
TICLBodyTagSupport+.doEndTag())
    && this(tag) && !cflowbelow(execution(public int
TICLBodyTagSupport+.doEndTag()));

    after(Object tag) : doEndTag(tag) || doEndTag1(tag)
    {
        restoreAttributes(tag);
    }

    //setXXX/value
    private final Map savedAttributes_ = new HashMap();

    private void saveAndEvaluateAttributes(Object tag)
    {
        //some code here
    }

    private void restoreAttributes(Object tag)
    {
       //some code here
    }
}

All the tags are subclasses of TICLBodyTagSupport or TICLTagSupport.

Thanks in advance, Konstantin


Back to the top