On Wed, 30 Apr 2025 15:33:52 GMT, Per Minborg <pminb...@openjdk.org> wrote:
>> This PR is based on the work of @mernst-github and aims to implement an >> _internal_ thread-local 'stack' allocator, which works like a dynamically >> sized arena, but with reset functionality to reset the allocated size back >> to a certain level. The underlying memory could stay around between calls, >> which could improve performance. >> >> Re-allocated segments are not zeroed between allocations. > > Per Minborg has updated the pull request incrementally with one additional > commit since the last revision: > > Improve on comments src/java.base/share/classes/jdk/internal/foreign/BufferStack.java line 163: > 161: lock.unlock(); > 162: } > 163: Reference.reachabilityFence(arena); I'm not sure this is enough to keep the automatic arena alive. If the client lets the Frame arena go out of scope w/o calling close, then `arena` will become unreachable, but some segments created by the Frame arena might still be reachable. To be more correct, I think `Frame` should add a "close action" to its confined arena which keeps the outer automatic arena alive. This can be done, for instance, by passing a close action to the `reinterpret` call: frame = new SlicingAllocator(frameSegment.reinterpret(confinedArena, () -> Reference.reachabilityFence(arena))); The close action is installed in the `MemorySession` object of `confinedArena` -- which is then attached to all segments returned by `Frame` -- thus keeping the automatic arena alive. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/24829#discussion_r2070063828