Feature requests.
Paul Sandoz
paul.sandoz at oracle.com
Mon May 19 15:51:36 UTC 2025
Note that will not guarantee stable alignment. The GC can move the allocated array.
I don’t know if we will ever get to supporting hyper-aligned heap objects, it's likely complex for GCs to support and to surface that up to developers. There are more important things to work on.
Paul.
On May 19, 2025, at 6:18 AM, Per-Ake Minborg <per-ake.minborg at oracle.com> wrote:
Hi again Lee!
1.
The VM/GC has its own rules for how arrays are allocated, and so, there is no way (at least not now) to control primitive array alignment except for the way you mentioned — a primitive array is always aligned to its component's natural alignment. A very simple way to allocate and align heap arrays could be to implement a method similar to this one:
static MemorySegment heapSegment(MemoryLayout layout) {
byte[] arr = new byte[(int) layout.byteSize() * (int)layout.byteAlignment() - 1];
SegmentAllocator allocator = SegmentAllocator.slicingAllocator(MemorySegment.ofArray(arr));
return allocator.allocate(layout);
}
If memory efficiency is a concern, a more complex solution can be written that leverages the implicit alignment of arrays of int and long.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20250519/d2ee8567/attachment.htm>
More information about the panama-dev
mailing list