davidchang168 (8) [Avatar] Offline

Please forgive me if this is not a place to post questions NOT related to the book "AspectJ in Action" ... smilie

I tried to modify the log statement of our codes by adding line number to tell where the log come from and I found the usage of "thisJoinPoint.getSourceLocation().getLine()" expands every log statement with something like below:

String str1 = "Couldn't find a state machine for the subscribe response msg";
String str2 = "handleMessage(ICmpMessageHeader, MsgSubscribeResponse)";
String str3 = CLASSNAME;
Level localLevel = Level.WARNING;
Logger localLogger = this.m_logger;
Object[] arrayOfObject = new Object[4];
arrayOfObject[0] = localLevel;
arrayOfObject[1] = str3;
arrayOfObject[2] = str2;
arrayOfObject[3] = str1;
JoinPoint localJoinPoint = Factory.makeJP(ajc$tjp_23, this, localLogger, arrayOfObject);
logp_aroundBody47$advice(this, localLogger, localLevel, str3, str2, str1, localJoinPoint, LineNumberLogger.aspectOf(), localJoinPoint, localLevel, str3, str2, str1);

and also the Factory.makeJP(...) creates an instance of JoinPointImpl as below:

public static JoinPoint makeJP(JoinPoint.StaticPart staticPart, Object _this, Object target, Object[] args) {
return new JoinPointImpl(staticPart, _this, target, args);

so I was wondering if the call to getLine() will introduce too much overhead for each log statement or not ?

davidchang168 (8) [Avatar] Offline
Re: Overhead of the call to thisJoinPoint.getSourceLocation().getLine()

"The ajc compiler will use static typing information to only insert the advice and dynamic pointcut tests that are absolutely necessary. Unless you use 'thisJoinPoint' or 'if', the main dynamic checks will be 'instanceof' checks which are generally quite fast. These checks will only be inserted when they can not be inferred from the static type information..."