Skip to content

Commit

Permalink
JoinPointImpl: Remove thread-locals after usage, where possible
Browse files Browse the repository at this point in the history
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 eclipse-aspectj#302.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Signed-off-by: KimmingLau <294001791@qq.com>
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
  • Loading branch information
KimmingLau and kriegaex committed Apr 7, 2024
1 parent 0f020e0 commit ab63bdf
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ public final String toLongString() {
arcs = new ArrayList<>();
}
if (arc == null) {
arcIndex.set(arcIndex.get() - 1);
int newIndex = arcIndex.get() - 1;
arcIndex.set(newIndex);
if (newIndex == -1) {
arcIndex.remove();
}
}
else {
this.arcs.add(arc);
Expand Down

0 comments on commit ab63bdf

Please sign in to comment.