Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] lazyTJP optimization for around advice

I'd probably recommend trying a code style aspect if you can, rather than annotation style - the woven code will be more optimal.  A code style aspect achieving most of what you want above will not cause creation of the bytecode for creating the joinpoint:

Object around(int i): execution(* Print.ech*(int)) && args(i) && if (Profiler.enabled(thisJoinPointStaticPart.getSignature().getDeclaringTypeName())) {

...

}

But the proceeding of the joinpoint will have to occur in the advice body rather than in the Profiler.profile code.


To answer the question. 311749 has not been implemented. If it had been then the makeJP call would be after the call to the condition check (pc()), which it isn't right now:

     8:   invokestatic    #32; //Method org/aspectj/runtime/internal/Conversions.intObject:(I)Ljava/lang/Object;

   11:  invokestatic    #38; //Method org/aspectj/runtime/reflect/Factory.makeJP:(Lorg/aspectj/lang/JoinPoint$StaticPart;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Lorg/aspectj/lang/JoinPoint;

   14:  astore  4

   16:  iload_3

   17:  getstatic   #26; //Field ajc$tjp_0:Lorg/aspectj/lang/JoinPoint$StaticPart;

   20:  invokestatic    #76; //Method Azpect.pc:(ILorg/aspectj/lang/JoinPoint$StaticPart;)Z


Code style doesn't need the join point to be passed in for proceeding, so the cost of building it is completely avoided.


cheers,

Andy




On 26 November 2012 16:30, Hmil P <amil@xxxxxx> wrote:
Hello,

I am using AspectJ to log performance of code and want to minimize the
impact on code when profiling is disabled. I have decompiled some
AspectJ-woven code:
public int echo(int num) {
        int i = num;
        org.aspectj.lang.JoinPoint localJoinPoint =
org.aspectj.runtime.reflect.Factory
                        .makeJP(ajc$tjp_0, this, this, Conversions.intObject(i));
        return Conversions.intValue(echo_aroundBody1$advice(this, i,
                        localJoinPoint, aj.ScrapAspect.aspectOf(),
                        (org.aspectj.lang.ProceedingJoinPoint) localJoinPoint, i));
}


Basically, I want to forego the JoinPoint instantiation in the case of
profiling being disabled for a method by adding an if pointcut calling the
static Profiler.enabled() function /dependent on the name of the method/.

@Pointcut("(execution(* Print.ech*(int))) && args(i) && if()")
public static boolean pc(int i, JoinPoint.StaticPart
thisJoinPointStaticPart) {
        return
Profiler.enabled(thisJoinPointStaticPart.getSignature().getDeclaringTypeName());
}
@Around("pc(i)")
public Object profileMethods(ProceedingJoinPoint thisJoinPoint, int i)
        throws Throwable {
        return Profiler.profile(thisJoinPoint, i);
}


I saw  the bug request
<https://bugs.eclipse.org/bugs/show_bug.cgi?id=311749>   and was wondering
if it has been implemented.
Also, does my conditional pointcut really stop the join point instantiation
(because it is only using the static part)?



--
View this message in context: http://aspectj.2085585.n4.nabble.com/lazyTJP-optimization-for-around-advice-tp4650646.html
Sent from the AspectJ - users mailing list archive at Nabble.com.
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top