mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8224042: Add private alignDown method to MappedByteBuffer
Use alignDown method to round addresses down to page boundary Reviewed-by: stuefe, mikael, alanb
This commit is contained in:
parent
244bdce994
commit
772ad03cb5
1 changed files with 7 additions and 1 deletions
|
@ -106,7 +106,7 @@ public abstract class MappedByteBuffer
|
|||
private long mappingOffset(int index) {
|
||||
int ps = Bits.pageSize();
|
||||
long indexAddress = address + index;
|
||||
long baseAddress = (indexAddress & ~(ps-1));
|
||||
long baseAddress = alignDown(indexAddress, ps);
|
||||
return indexAddress - baseAddress;
|
||||
}
|
||||
|
||||
|
@ -140,6 +140,12 @@ public abstract class MappedByteBuffer
|
|||
return length + mappingOffset;
|
||||
}
|
||||
|
||||
// align address down to page size
|
||||
private static long alignDown(long address, int pageSize) {
|
||||
// pageSize must be a power of 2
|
||||
return address & ~(pageSize - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not this buffer's content is resident in physical
|
||||
* memory.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue