Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid synchronization in AbstractAspectJAdvice#calculateArgumentBindings #26377

Closed
hnxy opened this issue Jan 12, 2021 · 4 comments
Closed

Avoid synchronization in AbstractAspectJAdvice#calculateArgumentBindings #26377

hnxy opened this issue Jan 12, 2021 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@hnxy
Copy link

hnxy commented Jan 12, 2021

I see AbstractAspectJAdvice#calculateArgumentBindings is synchronized, but if first time the Advice method calculates the argument binding, the next time it can return directly without lock, I think it can prevent some lock competition.

such as:

public final void calculateArgumentBindings() {
    // The simple case... nothing to bind.
    if (this.argumentsIntrospected || this.parameterTypes.length == 0) {
	    return;
    }
    synchronized(this) {
      if (this.argumentsIntrospected || this.parameterTypes.length == 0) {
        return;
      }
      int numUnboundArgs = this.parameterTypes.length;
      Class<?>[] parameterTypes = this.aspectJAdviceMethod.getParameterTypes();
      if (maybeBindJoinPoint(parameterTypes[0]) || maybeBindProceedingJoinPoint(parameterTypes[0])) {
        numUnboundArgs--;
      }
      else if (maybeBindJoinPointStaticPart(parameterTypes[0])) {
        numUnboundArgs--;
      }
      
      if (numUnboundArgs > 0) {
      // need to bind arguments by name as returned from the pointcut match
        bindArgumentsByName(numUnboundArgs);
      }
  
       this.argumentsIntrospected = true;
    }		
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 12, 2021
@rstoyanchev rstoyanchev added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 10, 2021
@leexgone
Copy link

leexgone commented Jul 7, 2022

We had the same problem! This led to serious performance issues in our system.
I had to modify the source code locally to temporarily fix it.
We hope this problem can be fixed as soon as possible.

@sbrannen sbrannen added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 11, 2022
@sbrannen
Copy link
Member

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Jul 11, 2022
@jhoeller
Copy link
Contributor

Reopened for a simpler approach as discussed in my closing comment on #28783: We should be able to drop the synchronization completely since ReflectiveAspectJAdvisorFactory always performs an early call to calculateArgumentBindings anyway, covering our standard scenario. I'll resolve this in time for the 5.3.22 release.

@jhoeller jhoeller reopened this Jul 13, 2022
@jhoeller jhoeller self-assigned this Jul 13, 2022
@jhoeller jhoeller added type: enhancement A general enhancement and removed status: superseded An issue that has been superseded by another labels Jul 13, 2022
@jhoeller jhoeller added this to the 5.3.22 milestone Jul 13, 2022
@jhoeller jhoeller changed the title why AbstractAspectJAdvice#calculateArgumentBindings is synchronized? Avoid synchronization in AbstractAspectJAdvice#calculateArgumentBindings Jul 13, 2022
@leexgone
Copy link

Reopened for a simpler approach as discussed in my closing comment on #28783: We should be able to drop the synchronization completely since ReflectiveAspectJAdvisorFactory always performs an early call to calculateArgumentBindings anyway, covering our standard scenario. I'll resolve this in time for the 5.3.22 release.

That's a great idea! I'm look forward to the new version.

gleison pushed a commit to gleison/spring-framework that referenced this issue Dec 8, 2023
Aligned with the early calculateArgumentBindings call in ReflectiveAspectJAdvisorFactory.

Closes spring-projectsgh-26377
gleison pushed a commit to gleison/spring-framework that referenced this issue Dec 8, 2023
Aligned with the early calculateArgumentBindings call in ReflectiveAspectJAdvisorFactory.

Closes spring-projectsgh-26377
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

6 participants