8309042: MemorySegment::reinterpret cleanup action is not called for all overloads
Reviewed-by: jvernee
This commit is contained in:
parent
78aac241b8
commit
2b186e246e
src/java.base/share/classes/jdk/internal/foreign
test/jdk/java/foreign
@ -125,7 +125,7 @@ public abstract sealed class AbstractMemorySegmentImpl
|
||||
public final MemorySegment reinterpret(long newSize, Arena arena, Consumer<MemorySegment> cleanup) {
|
||||
Objects.requireNonNull(arena);
|
||||
return reinterpretInternal(Reflection.getCallerClass(), newSize,
|
||||
MemorySessionImpl.toMemorySession(arena), null);
|
||||
MemorySessionImpl.toMemorySession(arena), cleanup);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,6 +36,7 @@ import org.testng.annotations.Test;
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.Supplier;
|
||||
@ -352,6 +353,20 @@ public class TestSegments {
|
||||
assertEquals(end.address(), segment.byteSize()); // end address should be equal to segment byte size
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReinterpret() {
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
try (Arena arena = Arena.ofConfined()){
|
||||
// check size
|
||||
assertEquals(MemorySegment.ofAddress(42).reinterpret(100).byteSize(), 100);
|
||||
assertEquals(MemorySegment.ofAddress(42).reinterpret(100, Arena.ofAuto(), null).byteSize(), 100);
|
||||
// check scope and cleanup
|
||||
assertEquals(MemorySegment.ofAddress(42).reinterpret(100, arena, s -> counter.incrementAndGet()).scope(), arena.scope());
|
||||
assertEquals(MemorySegment.ofAddress(42).reinterpret(arena, s -> counter.incrementAndGet()).scope(), arena.scope());
|
||||
}
|
||||
assertEquals(counter.get(), 2);
|
||||
}
|
||||
|
||||
@DataProvider(name = "badSizeAndAlignments")
|
||||
public Object[][] sizesAndAlignments() {
|
||||
return new Object[][] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user