[code-reflection] RFR: Use memory segment

Adam Sotona asotona at openjdk.org
Wed Feb 26 13:45:02 UTC 2025


On Wed, 26 Feb 2025 12:50:50 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>>> No - `allocateFrom` creates a new off-heap segment when invoked on an `Arena`. `Arena` is a segment allocator that always allocates off-heap. The `allocateFrom` functions are explicitly designed for use cases when you want to allocate and copy existing data on top of the new allocated segment -- in which case the FFM knows that zeroing the allocated segment is redundant. I think that should be used here.
>> 
>> Note: what I'm pointing out is that, performance-wise, `allocateFrom` is not the same as `allocate` + `copyFrom`. Internally, `allocateFrom` will still create a temporary on-heap view of the byte array (w/o allocating a new heap array though) -- but that will be passed to an allocation routine that does allocation + copy w/o zeroring. If you call `allocate` zeroing will happen no matter what.
>
> And... final note -- ByteBuffer doesn't have an `allocateFrom` variant, so zeroing is unavoidable there -- but with segments we can do better.

Oh, I mixed it with MemorySegment::ofArray

-------------

PR Review Comment: https://git.openjdk.org/babylon/pull/328#discussion_r1971610700


More information about the babylon-dev mailing list