AspectJ – execute call join point

I have two different aspect classes to calculate the number of non - static method calls that execute the test program The first aspect is the method of calculating the "call" connection point:

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

The second aspect is the method of calculating the "execution" connection point:

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

Methodcallcounter () is a static method in the counter class

The number of method calls of the applet is the same However, when I change the test program with a larger program, the method calls in the second aspect class (with execution pointcut) are more than those in the aspect class using the call pointcut This is reasonable because the call join point does not select calls made with super, so it is not counted

However, I have encountered a situation that for the specific execution of the program, the number of non static method calls in the aspect class with "call pointcut" is higher than that in the aspect class with "execution pointcut" I can't find any explanation for why this happened Any idea of the reason for the second situation is appreciated

Solution

If you understand the basic difference between call () and execution () pointcuts, the explanation is simple: the former intercepts all callers (i.e. the source of the method call), and the latter intercepts the call itself, no matter where they are

So how are the interception times triggered by the two pointcuts different?

>If you call the JRE / JDK method from your own code, AspectJ can program your call, but not the execution connection point in the JDK (unless you have created a weaving JDK as a preparatory step) Therefore, the number of calls will be higher than the number of executions. > Similarly, if you invoke the method in the third party library, because they are not on the path during LTW or CTW, so you can not use AspectJ to weave, then the execution will not be captured again. Last but not least, this can happen if your own code is called by a third-party library or JRE / JDK class In this case, the number of executions will be higher than the number of calls because they originate outside the control of AspectJ code

Usually, in all cases, the reason is the difference between the overall use code and the woven code subset In other words: the difference between the control of the code outside of you

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>