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

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Mar 2 14:52:55 UTC 2023


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.

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

Commit messages:
 - Initial push

Changes: https://git.openjdk.org/panama-foreign/pull/807/files
 Webrev: https://webrevs.openjdk.org/?repo=panama-foreign&pr=807&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8303519
  Stats: 227 lines in 6 files changed: 72 ins; 100 del; 55 mod
  Patch: https://git.openjdk.org/panama-foreign/pull/807.diff
  Fetch: git fetch https://git.openjdk.org/panama-foreign pull/807/head:pull/807

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


More information about the panama-dev mailing list