]> source.dussan.org Git - aspectj.git/commit
Avoid ThreadLocal memory leak in JoinPointImpl
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Sat, 2 Mar 2024 10:52:31 +0000 (11:52 +0100)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Tue, 12 Mar 2024 07:21:38 +0000 (08:21 +0100)
commit43df701a10a80306dd98da8644a9bbfbf5d17089
tree8feb6335937a3a5d1e6170a7325c14dd4b4226b7
parent966397e3bfe0d38aeca28c6aec0f543d62a0e2ea
Avoid ThreadLocal memory leak in JoinPointImpl

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 <Alexander@Kriegisch.name>
runtime/src/main/java/org/aspectj/runtime/reflect/JoinPointImpl.java
tests/src/test/java/org/aspectj/systemtest/ajc199/Bugs199Tests.java
tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml