Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.
/ jdk16 Public archive

Commit e66187d

Browse files
mcimadamoreUwe Schindler
and
Uwe Schindler
committed
8259032: MappedMemorySegmentImpl#makeMappedSegment() ignores Unmapper#pagePosition
Co-authored-by: Uwe Schindler <uschindler@openjdk.org> Reviewed-by: alanb
1 parent 80110da commit e66187d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ private Unmapper(long address, long size, long cap,
889889

890890
@Override
891891
public long address() {
892-
return address;
892+
return address + pagePosition;
893893
}
894894

895895
@Override

test/jdk/java/foreign/TestByteBuffer.java

+22
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,28 @@ public void testBadMapNegativeOffset() throws IOException {
464464
MemorySegment.mapFile(f.toPath(), -1, 1, FileChannel.MapMode.READ_WRITE);
465465
}
466466

467+
@Test
468+
public void testMapOffset() throws IOException {
469+
File f = new File("testMapOffset.out");
470+
f.createNewFile();
471+
f.deleteOnExit();
472+
473+
int SIZE = Byte.MAX_VALUE;
474+
475+
try (MemorySegment segment = MemorySegment.mapFile(f.toPath(), 0, SIZE, FileChannel.MapMode.READ_WRITE)) {
476+
for (byte offset = 0; offset < SIZE; offset++) {
477+
MemoryAccess.setByteAtOffset(segment, offset, offset);
478+
}
479+
MappedMemorySegments.force(segment);
480+
}
481+
482+
for (int offset = 0 ; offset < SIZE ; offset++) {
483+
try (MemorySegment segment = MemorySegment.mapFile(f.toPath(), offset, SIZE - offset, FileChannel.MapMode.READ_ONLY)) {
484+
assertEquals(MemoryAccess.getByte(segment), offset);
485+
}
486+
}
487+
}
488+
467489
@Test
468490
public void testMapZeroSize() throws IOException {
469491
File f = new File("testPos1.out");

0 commit comments

Comments
 (0)