mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-27 07:10:45 +00:00
8367463: Improved Arena allocations
Reviewed-by: rhalade, rriggs, jvernee
This commit is contained in:
parent
3f242123e0
commit
152a497007
@ -190,15 +190,16 @@ public class SegmentFactories {
|
||||
if (VM.isDirectMemoryPageAligned()) {
|
||||
byteAlignment = Math.max(byteAlignment, AbstractMemorySegmentImpl.NIO_ACCESS.pageSize());
|
||||
}
|
||||
// Always allocate at least some memory so that zero-length segments have distinct
|
||||
// non-zero addresses.
|
||||
byteSize = Math.max(1, byteSize);
|
||||
|
||||
// Align the allocation size up to a multiple of 8 so we can init the memory with longs
|
||||
long alignedSize = init ? Utils.alignUp(byteSize, Long.BYTES) : byteSize;
|
||||
// Check for wrap around
|
||||
if (alignedSize < 0) {
|
||||
throw new OutOfMemoryError();
|
||||
}
|
||||
// Always allocate at least some memory so that zero-length segments have distinct
|
||||
// non-zero addresses.
|
||||
alignedSize = Math.max(1, alignedSize);
|
||||
|
||||
long allocationSize;
|
||||
long allocationBase;
|
||||
@ -226,12 +227,13 @@ public class SegmentFactories {
|
||||
if (init) {
|
||||
initNativeMemory(result, alignedSize);
|
||||
}
|
||||
final long cleanupByteSize = byteSize;
|
||||
sessionImpl.addOrCleanupIfFail(new MemorySessionImpl.ResourceList.ResourceCleanup() {
|
||||
@Override
|
||||
public void cleanup() {
|
||||
UNSAFE.freeMemory(allocationBase);
|
||||
if (shouldReserve) {
|
||||
AbstractMemorySegmentImpl.NIO_ACCESS.unreserveMemory(allocationSize, byteSize);
|
||||
AbstractMemorySegmentImpl.NIO_ACCESS.unreserveMemory(allocationSize, cleanupByteSize);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user