[foreign-memaccess+abi] RFR: 8303519: Replace Binding.Context with an arena

Jorn Vernee jvernee at openjdk.org
Thu Mar 2 15:47:24 UTC 2023


On Thu, 2 Mar 2023 14:46:03 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This patch contains a cleanup I wanted to do for some time. Basically, the linker uses an internal class (`Binding.Context`) to perform allocation needed during a native call/upcall. This context class used to provide both a scope (e.g. `ResourceScope`) and an allocator (`SegmentAllocator`).
> 
> Given that in recent iteratons of the API, `Arena` *is* an allocator, we can tweak bindings to accept a segment allocator parameter (instead of a context object). For bindings that only need to allocate, they can just call one of the `SegmentAllocator::allocate`) overloads. This simplifies the case where we need to use an external allocation for structs returned by value - as we can now just pass the external allocator - no need to wrap it in a "context".
> 
> If, on the other hand, the binding needs access to the scope, we can still implement that, by downcasting the segment allocator to `Arena` and then get the scope from there. This is always sound, because this arena is always internally created by the linker.
> 
> I moved some helper methods/fields to provide ready-made arena flavors in `SharedUtils`, so as to keep `Bindings.java` all about bindings. I think the result is rather nice, and in principle it should perform a little better, given that we don't need to wrap everything into a separate context object.

Nice cleanup!

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

Marked as reviewed by jvernee (Committer).

PR: https://git.openjdk.org/panama-foreign/pull/807


More information about the panama-dev mailing list