mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 06:14:49 +02:00
8347047: Cleanup action passed to MemorySegment::reinterpret keeps old segment alive
Reviewed-by: mcimadamore
This commit is contained in:
parent
bcefab5e55
commit
b0c935c03e
1 changed files with 8 additions and 3 deletions
|
@ -145,12 +145,17 @@ public abstract sealed class AbstractMemorySegmentImpl
|
|||
Reflection.ensureNativeAccess(callerClass, MemorySegment.class, "reinterpret", false);
|
||||
Utils.checkNonNegativeArgument(newSize, "newSize");
|
||||
if (!isNative()) throw new UnsupportedOperationException("Not a native segment");
|
||||
Runnable action = cleanup != null ?
|
||||
() -> cleanup.accept(SegmentFactories.makeNativeSegmentUnchecked(address(), newSize)) :
|
||||
null;
|
||||
Runnable action = cleanupAction(address(), newSize, cleanup);
|
||||
return SegmentFactories.makeNativeSegmentUnchecked(address(), newSize, scope, readOnly, action);
|
||||
}
|
||||
|
||||
// Using a static helper method ensures there is no unintended lambda capturing of `this`
|
||||
private static Runnable cleanupAction(long address, long newSize, Consumer<MemorySegment> cleanup) {
|
||||
return cleanup != null ?
|
||||
() -> cleanup.accept(SegmentFactories.makeNativeSegmentUnchecked(address, newSize)) :
|
||||
null;
|
||||
}
|
||||
|
||||
private AbstractMemorySegmentImpl asSliceNoCheck(long offset, long newSize) {
|
||||
return dup(offset, newSize, readOnly, scope);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue