RFR: 8287788: reuse intermediate segments allocated during FFM stub invocations [v8]
Jorn Vernee
jvernee at openjdk.org
Wed Jan 22 11:52:56 UTC 2025
On Wed, 22 Jan 2025 10:52:57 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java line 389:
>>
>>> 387: @Override
>>> 388: protected BufferStack initialValue() {
>>> 389: return new BufferStack(Arena.ofAuto().allocate(256));
>>
>> Could as well use keep using TerminatingThreadLocal+Unsafe here, I just like the fact to use as few non-public apis as possible.
>
> I'm told that TerminatingThreadLocal runs the "terminate" action for an object T from the same thread T refers to. So, in principle, using a TerminatingThreadLocal + confined arena should be ok.
>
> If that works, I'd suggest to consider maybe moving all this sharing logic inside BufferStack, so that users only need to do:
>
>
> static final BufferStack LINKER_BUFFER = new BufferStack(256);
>
> ...
>
> try (Arena arena = BufferStack.reserve(size)) {
> ...
> }
>
>
> Which seems a more re-usable API. After all, the fact that we decide to lock or not in certain cases is heavily influenced by the fact that we expect a BufferStack to be used with a carrier local, so we might just as well fold the caching in there.
Isn't the problem access? E.g. a virtual thread `A` running on our carrier thread might create the confined arena, binding it to _virtual_ thread `A`, and then another virtual thread `B` comes along one the same carrier thread, and wants to use the same `BufferStack`, but can't because it is confined to thread `A`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23142#discussion_r1925189099
More information about the core-libs-dev
mailing list