Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8259032: MappedMemorySegmentImpl#makeMappedSegment() ignores Unmapper…
…#pagePosition

Co-authored-by: Uwe Schindler <uschindler@openjdk.org>
Reviewed-by: alanb
  • Loading branch information
mcimadamore and Uwe Schindler committed Jan 6, 2021
1 parent 80110da commit e66187d885b6b6b29a812007d6b6283313954591
Showing with 23 additions and 1 deletion.
  1. +1 −1 src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java
  2. +22 −0 test/jdk/java/foreign/TestByteBuffer.java
@@ -889,7 +889,7 @@ private Unmapper(long address, long size, long cap,

@Override
public long address() {
return address;
return address + pagePosition;
}

@Override
@@ -464,6 +464,28 @@ public void testBadMapNegativeOffset() throws IOException {
MemorySegment.mapFile(f.toPath(), -1, 1, FileChannel.MapMode.READ_WRITE);
}

@Test
public void testMapOffset() throws IOException {
File f = new File("testMapOffset.out");
f.createNewFile();
f.deleteOnExit();

int SIZE = Byte.MAX_VALUE;

try (MemorySegment segment = MemorySegment.mapFile(f.toPath(), 0, SIZE, FileChannel.MapMode.READ_WRITE)) {
for (byte offset = 0; offset < SIZE; offset++) {
MemoryAccess.setByteAtOffset(segment, offset, offset);
}
MappedMemorySegments.force(segment);
}

for (int offset = 0 ; offset < SIZE ; offset++) {
try (MemorySegment segment = MemorySegment.mapFile(f.toPath(), offset, SIZE - offset, FileChannel.MapMode.READ_ONLY)) {
assertEquals(MemoryAccess.getByte(segment), offset);
}
}
}

@Test
public void testMapZeroSize() throws IOException {
File f = new File("testPos1.out");

1 comment on commit e66187d

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on e66187d Jan 6, 2021

Please sign in to comment.