[foreign-memaccess+abi] Integrated: 8303519: Replace Binding.Context with an arena
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Mar 2 15:55:31 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.
This pull request has now been integrated.
Changeset: a7df48c8
Author: Maurizio Cimadamore <mcimadamore at openjdk.org>
URL: https://git.openjdk.org/panama-foreign/commit/a7df48c8b0eed89dbb8c6a0ff441e483b3385ddb
Stats: 227 lines in 6 files changed: 72 ins; 100 del; 55 mod
8303519: Replace Binding.Context with an arena
Reviewed-by: jvernee
-------------
PR: https://git.openjdk.org/panama-foreign/pull/807
More information about the panama-dev
mailing list