On Mon, 5 May 2025 16:53:58 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. The current benchmarks (M1 macOS): ~/Applications/brr --build --build-microbenchmarks -w CaptureStateUtilBench Benchmark Mode Cnt Score Error Units CaptureStateUtilBench.OfVirtual.adaptedSysCallFail avgt 30 34.372 ± 0.221 ns/op CaptureStateUtilBench.OfVirtual.adaptedSysCallSuccess avgt 30 12.694 ± 0.251 ns/op CaptureStateUtilBench.OfVirtual.explicitAllocationFail avgt 30 40.470 ± 0.529 ns/op CaptureStateUtilBench.OfVirtual.explicitAllocationSuccess avgt 30 21.680 ± 0.339 ns/op CaptureStateUtilBench.adaptedSysCallFail avgt 30 31.054 ± 0.575 ns/op CaptureStateUtilBench.adaptedSysCallSuccess avgt 30 5.029 ± 0.088 ns/op CaptureStateUtilBench.explicitAllocationFail avgt 30 40.338 ± 0.586 ns/op CaptureStateUtilBench.explicitAllocationSuccess avgt 30 21.769 ± 0.552 ns/op Passes `tier1` on multiple platforms. ------------- PR Comment: https://git.openjdk.org/jdk/pull/25043#issuecomment-2851658924