8289188: SegmentAllocator:allocateArray(*) default behavior mismatch to spec

Reviewed-by: alanb
This commit is contained in:
Maurizio Cimadamore 2022-06-27 15:37:08 +00:00
parent 699ad45b43
commit 2c8ada689f
3 changed files with 48 additions and 6 deletions

View file

@ -282,12 +282,13 @@ public interface SegmentAllocator {
private <Z> MemorySegment copyArrayWithSwapIfNeeded(Z array, ValueLayout elementLayout,
Function<Z, MemorySegment> heapSegmentFactory) {
Objects.requireNonNull(array);
Objects.requireNonNull(elementLayout);
int size = Array.getLength(array);
MemorySegment addr = allocate(MemoryLayout.sequenceLayout(size, elementLayout));
MemorySegment.copy(heapSegmentFactory.apply(array), elementLayout, 0,
addr, elementLayout.withOrder(ByteOrder.nativeOrder()), 0, size);
int size = array == null ? 0 : Array.getLength(array);
MemorySegment addr = allocateArray(elementLayout, size);
if (size > 0) {
MemorySegment.copy(heapSegmentFactory.apply(array), elementLayout, 0,
addr, elementLayout.withOrder(ByteOrder.nativeOrder()), 0, size);
}
return addr;
}