diff options
author | KimmingLau <294001791@qq.com> | 2024-04-04 04:20:18 +0800 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2024-04-10 11:23:00 +0200 |
commit | 70a454761097fc22918861c53db1f09445b685bb (patch) | |
tree | 300c5f5d2c7825d7d51f25096b60e335e44dbc10 | |
parent | 856db5d97f329041751418b2cc43d7574e26144d (diff) | |
download | aspectj-70a454761097fc22918861c53db1f09445b685bb.tar.gz aspectj-70a454761097fc22918861c53db1f09445b685bb.zip |
JoinPointImpl: Remove thread-locals after usage, where possible
Avoid potential ThreadLocalMap.Entry accumulation. Entry is a
WeakReference. When JoinPointImpl objects are collected by GC, Entry
instances are still be referenced by ThreadLocalMap, which leads to
memory pressure and potentially more full GCs. So, we proactively remove
ThreadLocal<Integer> arcIndex instances when arcIndex has been
decremented back to -1 per thread. This is not perfect, because not each
thread can be expected to proceed, but it should ameliorate the
situation to some degree.
Fixes #302.
Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Signed-off-by: KimmingLau <294001791@qq.com>
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
-rw-r--r-- | runtime/src/main/java/org/aspectj/runtime/reflect/JoinPointImpl.java | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/JoinPointImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/JoinPointImpl.java index 8db5e0730..01def8451 100644 --- a/runtime/src/main/java/org/aspectj/runtime/reflect/JoinPointImpl.java +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/JoinPointImpl.java @@ -154,7 +154,11 @@ class JoinPointImpl implements ProceedingJoinPoint { arcs = new ArrayList<>(); } if (arc == null) { - arcIndex.set(arcIndex.get() - 1); + int newIndex = arcIndex.get() - 1; + if (newIndex > -1) + arcIndex.set(newIndex); + else + arcIndex.remove(); } else { this.arcs.add(arc); |