Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execution Vs. call Join point

Tags:

I have two different aspect classes to count the number of non-static method calls for an execution of a test program. The first aspect counts methods on "call" join points:

pointcut methodCalls() : call (!static * test..*(..)); before(): methodCalls() {         counter.methodCallCounter(); } 

while the second aspect counts methods on "execution" join points:

pointcut methodCalls() : execution (!static * test..*(..)); before(): methodCalls() {         counter.methodCallCounter(); } 

methodCallCounter() is a static method in counter class.

The number of method calls for small test program is the same. But when I change the test program with a larger program the number of method calls in the second aspect class (with execution pointcut) is more than the number of method calls in the aspect class with call pointcut. This is reasonable since the call join point does not pick out the calls made with super and therefore does not count them.

However, I encountered a case where for the specific execution of program the number non-static method calls in the aspect class with "call pointcut" was higher than the number of method calls in the aspect class with "execution pointcut". I can not find any interpretation why this is happening. Any thought about the reason of second situation is appreciated.

like image 949
user1843337 Avatar asked Aug 08 '13 17:08

user1843337


People also ask

What is the distinction between a join point and a pointcut?

A Joinpoint is a point in the control flow of a program where the control flow can arrive via two different paths(IMO : that's why call joint). A Pointcut is a matching Pattern of Joinpoint i.e. set of join points.

What is pointcut execution?

Pointcut is a set of one or more JoinPoint where an advice should be executed. You can specify Pointcuts using expressions or patterns as we will see in our AOP examples. In Spring, Pointcut helps to use specific JoinPoints to apply the advice.

What events are part of the join point model in AspectJ?

Join points consist of things like method calls, method executions, object instantiations, constructor executions, field references and handler executions. (See the AspectJ Quick Reference for a complete listing.)

Which method is executed first in AOP?

Executing method on the target class Thus, Spring AOP injects a proxy instead of an actual instance of the target class. When we start the Spring or Spring Boot application, we see Spring executes the advice before the actual method.


2 Answers

Acutally the explanation is quite simple if you understand the basic difference between call() and execution() pointcuts: While the former intercepts all callers (i.e. the sources of method calls), the latter intercepts the calls themselves no matter where they originate from.

So how can the number of interceptions triggered by both pointcuts differ?

  • If you call JRE/JDK methods from your own code, AspectJ can weave into your calls, but not into the execution joinpoints within the JDK (unless you have created a woven JDK as a preparatory step). Thus, the number of calls will be higher than the number of executions.
  • Similarly, if you call methods in third party libraries which you have not woven with AspectJ because they were not on the in-path during LTW or CTW, again the executions will not be captured.
  • Last, but not least, it can happen the other way around if your own woven code is called by third party libs or by JRE/JDK classes. In this case the counted number of executions will be higher than the number of calls because they originate from places outside the control of your AspectJ code.

Generally, in all cases the reason is the difference between overall used code and the subset of woven code. In other words: the difference between code under and beyond your (or the aspects') control.

like image 61
kriegaex Avatar answered Nov 03 '22 12:11

kriegaex


hy, this image might help you visualize the difference between execution and call: enter image description here

like image 43
fatemeakbari Avatar answered Nov 03 '22 14:11

fatemeakbari