> Going forward, 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 to add a _JDK internal_ method handle adapter that > can be used to handle system calls with `errno`, `GetLastError`, and > `WSAGetLastError`. > > It currently relies on a thread-local cache of MemorySegments to allide > allocations. If, in the future, a more efficient thread-associated allocation > scheme becomes available, we could easily migrate to that one. > > Here are some benchmarks: > > > Benchmark Mode Cnt Score Error Units > CaptureStateUtilBench.explicitFail avgt 30 42.184 ? 0.998 ns/op > CaptureStateUtilBench.explicitSuccess avgt 30 42.278 ? 1.490 ns/op > CaptureStateUtilBench.tlFail avgt 30 23.594 ? 0.774 ns/op > CaptureStateUtilBench.tlSuccess avgt 30 12.135 ? 0.107 ns/op > > > Explicit allocation: > > try (var arena = Arena.ofConfined()) { > return (int) HANDLE.invoke(arena.allocate(4), 0, 0); > } > > > Thread Local (tl): > > return (int) ADAPTED_HANDLE.invoke(arena.allocate(4), 0, 0); > > > Tested and passed tiers 1-3.
Per Minborg has updated the pull request incrementally with two additional commits since the last revision: - Clean up benchmark - Fix allocation problem in benchmark ------------- Changes: - all: https://git.openjdk.org/jdk/pull/22391/files - new: https://git.openjdk.org/jdk/pull/22391/files/4821c2f2..f128c912 Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk&pr=22391&range=05 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=22391&range=04-05 Stats: 11 lines in 1 file changed: 2 ins; 7 del; 2 mod Patch: https://git.openjdk.org/jdk/pull/22391.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/22391/head:pull/22391 PR: https://git.openjdk.org/jdk/pull/22391