Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private static long allocateNativeInternal(long byteSize, long byteAlignment, Me
allocationBase = allocateMemoryWrapper(allocationSize);
result = Utils.alignUp(allocationBase, byteAlignment);
} else {
allocationSize = alignedSize;
allocationSize = Math.max(alignedSize, byteAlignment);
if (shouldReserve) {
AbstractMemorySegmentImpl.NIO_ACCESS.reserveMemory(allocationSize, byteSize);
}
Expand Down
8 changes: 7 additions & 1 deletion test/jdk/java/foreign/TestMemoryAlignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ public void testAlignedAccess(long align) {
assertEquals(aligned.byteAlignment(), align); //unreasonable alignment here, to make sure access throws
VarHandle vh = aligned.varHandle();
try (Arena arena = Arena.ofConfined()) {
MemorySegment segment = arena.allocate(aligned);;
MemorySegment segment = arena.allocate(aligned);
vh.set(segment, 0L, -42);

// Allocate another segment and fill it with data to
// check that the first segment is not overwritten
MemorySegment nextSegment = arena.allocate(aligned);
vh.set(nextSegment, 0L, 0xffffff);

int val = (int)vh.get(segment, 0L);
assertEquals(val, -42);
}
Expand Down