[code-reflection] Integrated: Make downcall method handles for ORT API functions static

Adam Sotona asotona at openjdk.org
Tue Feb 18 19:28:20 UTC 2025


On Tue, 18 Feb 2025 15:15:26 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This PR tweaks the method handles in `OnnxRuntime` to be static and final.
> The trick is to use a so called "virtual" downcall handle -- a downcall handle that takes its input address as an extra parameter.
> Then, we can just adapt such a method handle to fetch the target function address from the incoming `runtimeAddress` parameter.
> This way, all the method handles modelling functions in the ORT API can be made static, which unlocks better C2 optimizations.
> 
> Clients of such method handles have to be tweaked to pass in the additional leading `runtimeAddress` parameter.

It looks good to me.

I'm wondering if there are any guides what patterns can be better optimized.
OnnxRuntime is a singleton, so the optimization-wise differences between static final and singleton instance final are not clear to me.

Thanks!

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

Marked as reviewed by asotona (Reviewer).

PR Review: https://git.openjdk.org/babylon/pull/322#pullrequestreview-2624082892


More information about the babylon-dev mailing list