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

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Mar 4 14:03:04 UTC 2025


On Tue, 4 Mar 2025 12:37:18 GMT, Adam Sotona <asotona at openjdk.org> wrote:

>> Holding `Arena` instances in `OnnxRuntime` and `Session` still cause memory leaks.
>> This patch allows to pass explicit arena for `Tensor` construction, `Session` construction and  each `Session` run.
>> Improved handling of `Session` life cycle allows to cache live `Session` instead of its protobuf model.
>
> Adam Sotona has updated the pull request incrementally with one additional commit since the last revision:
> 
>   using Arena.ofConfined() instance for each individual test in CNNTest

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.

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

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


More information about the babylon-dev mailing list