[code-reflection] RFR: Use memory segment

Adam Sotona asotona at openjdk.org
Wed Feb 26 12:34:47 UTC 2025


On Wed, 26 Feb 2025 10:15:00 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Replace many uses of `ByteBuffer` use with idiomatic `MemorySegment` use. This also tends to make clearer the life cycle of segments. Generally in any ONNX APIs we design i think we should avoid exposing `*Buffer`. The "escape hatch" for accessing the data of a `Tensor` should be `MemorySegment`.
>
> cr-examples/onnx/src/main/java/oracle/code/onnx/OnnxProtoBuilder.java line 320:
> 
>> 318:                 .buf.toByteArray();
>> 319: //        OnnxProtoPrinter.printModel(ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN));
>> 320:         return Arena.ofAuto().allocate(bytes.length).copyFrom(MemorySegment.ofArray(bytes)).asReadOnly();
> 
> I suggest using `allocateFrom(JAVA_BYTE, bytes)` to avoid the zeroing

allocateFrom creates on-heap memory segment

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

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


More information about the babylon-dev mailing list