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 ThreadLocal memory leak in JoinPointImpl #291

Merged
merged 3 commits into from
Mar 12, 2024
Merged

Avoid ThreadLocal memory leak in JoinPointImpl #291

merged 3 commits into from
Mar 12, 2024

Conversation

kriegaex
Copy link
Contributor

@kriegaex kriegaex commented Mar 2, 2024

according to RSPEC-5164.

  • Add test reproducing the problem
  • Fix issue

Fixes #288, #141.

@kriegaex kriegaex added the bug Something isn't working label Mar 2, 2024
@kriegaex kriegaex self-assigned this Mar 2, 2024
@kriegaex kriegaex force-pushed the gh-288 branch 3 times, most recently from eb4d567 to c3c2907 Compare March 6, 2024 09:13
kriegaex added 3 commits March 6, 2024 17:13
- Recognise more "fork-worthy" JVM parameters
- Pass on program arguments to program in forked JVM

Signed-off-by: Alexander Kriegisch <[email protected]>
Leak was introduced in commit 3c80a36, fixing #128, but introducing
#288 instead, which was the lesser of two evils, but still bad for some
users unwilling to use native AspectJ syntax for their aspects, avoiding
the problem.

Relates to #288.

Signed-off-by: Alexander Kriegisch <[email protected]>
according to https://rules.sonarsource.com/java/tag/leak/RSPEC-5164/.
Now, there no longer is a thread-local stack of AroundClosure instances,
but rather a list of them, which can only grow but never shrink.
Instead, we now have a thread-local (integer) list index, for every
thread being initialised with pointing to the last element. I.e., every
thread can unwind by decrementing the index while proceeding,
independently of other threads.

A positive side effect is that this approach also works for long-lived
threads from thread pools, used by executor services. Hence, test
Bugs199Tests.testAsyncProceedNestedAroundAdviceThreadPool_gh128, which
was previously commented out, has been activated and passes, see #141.

I am not sure if this brings @AspectJ style, non-inlined, nested around
advice execution functionally on par with native ones, but at least for
current scenarios it seems to work.

Fixes #288, #141.

Signed-off-by: Alexander Kriegisch <[email protected]>
@kriegaex kriegaex requested a review from aclement March 6, 2024 16:48
@kriegaex kriegaex added this to the 1.9.21.2 milestone Mar 6, 2024
@kriegaex kriegaex added the enhancement New feature or request label Mar 6, 2024
@kriegaex
Copy link
Contributor Author

kriegaex commented Mar 6, 2024

@aclement, knowing your time constraints, I would merge without your review, too, but I want to invite you to take a look, because you also participated in the discussion about #128, in which I introduced the imperfect inheritable thread-local solution which fixed #128, but left #141 open and, as we now know, caused the memory leak in #288.

This PR fixes both problems in one change and also adds regression tests, i.e. it is a fix and a feature enhancement at the same time. Because JoinPointImpl is such a central place in the runtime API, I would appreciate your feedback.

@kriegaex kriegaex merged commit 43df701 into master Mar 12, 2024
3 checks passed
@kriegaex kriegaex deleted the gh-288 branch March 12, 2024 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
2 participants