[code-reflection] RFR: Explicit Arena passing to Tensor construction and Session execution [v2]

Adam Sotona asotona at openjdk.org
Tue Mar 4 14:09:10 UTC 2025


On Tue, 4 Mar 2025 14:04:52 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> cr-examples/onnx/src/main/java/oracle/code/onnx/OnnxRuntime.java line 315:
>> 
>>> 313:         private final MemorySegment sessionAddress;
>>> 314: 
>>> 315:         private Session(Arena arena, MemorySegment sessionAddress) {
>> 
>> I don't think this is an improvement? The idea behind the current code is that  a session has a lifetime (managed by an arena) -- and all the resources allocated during `run` are associated to that same lifetime.
>> 
>> In the current code, `arena` is passed as parameter to both the constructor and `run` -- which means you could pass two different arenas, and that would result in subtle use-after-free issues.
>
> (I see that this is done to cache the session --- but IMHO this feels like the caching tail is wagging the API dog a bit).

That is the intention. If we want to cache sessions and allow multiple executions, they must be constructed with a different arena than each of the execution. Execution has different lifecycle than the session.

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

PR Review Comment: https://git.openjdk.org/babylon/pull/337#discussion_r1979526913


More information about the babylon-dev mailing list