Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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 e66187d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Expand Up @@ -889,7 +889,7 @@ private Unmapper(long address, long size, long cap,

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

@Override
Expand Down
22 changes: 22 additions & 0 deletions test/jdk/java/foreign/TestByteBuffer.java
Expand Up @@ -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");
Expand Down

1 comment on commit e66187d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.