mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8309042: MemorySegment::reinterpret cleanup action is not called for all overloads
Reviewed-by: jvernee
This commit is contained in:
parent
78aac241b8
commit
2b186e246e
2 changed files with 16 additions and 1 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue