Skip to content

Commit c3e0439

Browse files
committed
8354121: Use a record class rather than a lambda in AbstractMemorySegmentImpl::cleanupAction
Reviewed-by: liach
1 parent 9d8b93b commit c3e0439

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,19 @@ private NativeMemorySegmentImpl reinterpretInternal(Class<?> callerClass, long n
162162

163163
// Using a static helper method ensures there is no unintended lambda capturing of `this`
164164
private static Runnable cleanupAction(long address, long newSize, Consumer<MemorySegment> cleanup) {
165-
return cleanup != null ?
166-
() -> cleanup.accept(SegmentFactories.makeNativeSegmentUnchecked(address, newSize)) :
167-
null;
165+
166+
record CleanupAction(long address, long newSize, Consumer<MemorySegment> cleanup) implements Runnable {
167+
@Override
168+
public void run() {
169+
cleanup().accept(SegmentFactories.makeNativeSegmentUnchecked(address(), newSize()));
170+
}
171+
}
172+
173+
return cleanup != null
174+
// Use a record (which is always static) instead of a lambda to avoid
175+
// capturing and to enable early use in the init sequence.
176+
? new CleanupAction(address, newSize, cleanup)
177+
: null;
168178
}
169179

170180
private AbstractMemorySegmentImpl asSliceNoCheck(long offset, long newSize) {

0 commit comments

Comments
 (0)