On Tue, 6 May 2025 12:32:38 GMT, Per Minborg <pminb...@openjdk.org> wrote:

>> As we advance, converting older JDK code to use the relatively new FFM API 
>> requires system calls that can provide `errno` and the likes to explicitly 
>> allocate a MemorySegment to capture potential error states. This can lead to 
>> negative performance implications if not designed carefully and also 
>> introduces unnecessary code complexity.
>> 
>> Hence, this PR proposes adding a JDK internal method handle adapter that can 
>> be used to handle system calls with `errno`, `GetLastError`, and 
>> `WSAGetLastError`.
>> 
>> It relies on an efficient carrier-thread-local cache of memory regions to 
>> allide allocations.
>
> Per Minborg has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Address comments

src/java.base/share/classes/jdk/internal/foreign/CaptureStateUtil.java line 78:

> 76:                 inputs.add(new BasicKey(c, layout.name().orElseThrow()));
> 77:             }
> 78:         }

Suggestion:

        for (MemoryLayout layout : CAPTURE_LAYOUT.memberLayouts()) {
            String name = layout.name().orElseThrow();
            inputs.add(new BasicKey(int.class, name));
            inputs.add(new BasicKey(long.class, name));
        }

There are only two classes, int.class and long.class, so this might be simpler.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25043#discussion_r2076694737

Reply via email to