8259032: MappedMemorySegmentImpl#makeMappedSegment() ignores Unmapper#pagePosition

Co-authored-by: Uwe Schindler <uschindler@openjdk.org>
Reviewed-by: alanb
This commit is contained in:
Maurizio Cimadamore 2021-01-06 12:18:43 +00:00
parent 80110dac91
commit e66187d885
2 changed files with 23 additions and 1 deletions

View File

@ -889,7 +889,7 @@ public class FileChannelImpl
@Override
public long address() {
return address;
return address + pagePosition;
}
@Override

View File

@ -464,6 +464,28 @@ public class TestByteBuffer {
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");