cleanup action captures original segment
    Maurizio Cimadamore 
    maurizio.cimadamore at oracle.com
       
    Mon Jan  6 11:08:32 UTC 2025
    
    
  
On 29/12/2024 10:50, Wojciech Lukowicz wrote:
> Turns out AbstractMemorySegmentImpl#reinterpretInternal creates a lambda
> wrapper around the cleanup action which captures the original segment
> and consequently its scope, doing here what the JavaDoc warns against:
This is correct, and subtle. What the code does is this:
```
Runnable action = cleanup != null ?
                 () -> 
cleanup.accept(SegmentFactories.makeNativeSegmentUnchecked(address(), 
newSize)) :
                 null;
```
The cleanup action is created against a _fresh_ memory segment that 
points at the same address as the old segment. The fresh segment points 
to the global arena, so it doesn't share anything with the old segment. 
BUT, the use of `address()` inside the cleanup action implicitly 
captures the old segment instance. This is a bug.
Filed:
https://bugs.openjdk.org/browse/JDK-8347047
Thanks
Maurizio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20250106/c0192cc2/attachment.htm>
    
    
More information about the panama-dev
mailing list