Can we have some heap segment allocation API in the future?
刘希晨
benrush0705 at gmail.com
Wed Mar 27 16:47:13 UTC 2024
Hi there, I am really happy that Panama-FFI finally
released, congratulation!
I have been using Panama's features since JDK19, and when I am migrating to
JDK22, I found that Heap segment could be passed to native functions if the
call is really short, which is really helpful in lots of ways.
However, allocating heap segments are not so convenient as allocating
native segments, it seems that we could only use MemorySegment.ofArray() to
transform an array into a memorysegment.
Hence I got several question:
1. Could there be a HeapArena, which targets at allocating heap segments
with given byteSize and byteAlignment, just like native segments? That
would be pretty helpful in a lot of scenarios.
2. Could there be an API, for developers, to allocate a heap segment, with
no zero-bytes filled, so that heap allocation would be much faster?
3. I noticed that, when calling MemorySegment.get() or MemorySegment.set()
methods, it will use the underlying Varhandle to do the job, I read about
Varhandle in
https://jornvernee.github.io/methodhandles/2024/01/19/methodhandle-primer.html,
and when I run the following code:
System.out.println(ValueLayout.JAVA_INT.varHandle().hasInvokeExactBehavior());
the result is false, so there is no InvokeExactBehaviour, which is not
recommended. I thought this could be a mistake, or it's intended to handle
the auto-boxing conversion, please take a look at this.
Best regards!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20240328/ab57d5fc/attachment-0001.htm>
More information about the panama-dev
mailing list