8288850: SegmentAllocator:allocate() can return null some cases

Reviewed-by: psandoz
This commit is contained in:
Maurizio Cimadamore 2022-07-12 14:14:46 +00:00
parent 3164c98f4c
commit 2baf526fce
2 changed files with 9 additions and 1 deletions

View File

@ -78,7 +78,9 @@ public final class ArenaAllocator implements SegmentAllocator {
return slice;
} else {
long maxPossibleAllocationSize = bytesSize + bytesAlignment - 1;
if (maxPossibleAllocationSize > blockSize) {
if (maxPossibleAllocationSize < 0) {
throw new OutOfMemoryError();
} else if (maxPossibleAllocationSize > blockSize) {
// too big
return newSegment(bytesSize, bytesAlignment);
} else {

View File

@ -160,6 +160,12 @@ public class TestSegmentAllocators {
allocator.allocate(1, 3);
}
@Test(expectedExceptions = OutOfMemoryError.class)
public void testBadArenaNullReturn() {
SegmentAllocator segmentAllocator = SegmentAllocator.newNativeArena(MemorySession.openImplicit());
segmentAllocator.allocate(Long.MAX_VALUE, 2);
}
@Test
public void testArrayAllocateDelegation() {
AtomicInteger calls = new AtomicInteger();