On Fri, 28 Aug 2026 08:40:49 GMT, ExE Boss <[email protected]> wrote: >> src/java.base/share/classes/jdk/internal/foreign/ConfinedSegmentPool.java >> line 130: >> >>> 128: static long acquire(Thread thread) { >>> 129: assert thread == Thread.currentThread(); >>> 130: return POOLING_DISABLED ? 0 : >>> acquireFromCache(cacheOwner(thread)); >> >> It would be safer to pin a virtual thread to its carrier here (same thing in >> release) to ensure there isn't preemption (it's hard to spot the places >> where preemption may happen). >> >> if (Thread.currentThread().isVirtual() && ContinuationSupport.isSupported()) >> { >> Continuation.pin(); >> try { >> return acquireFromCache(JLA.currentCarrierThread()); >> } finally { >> Continuation.unpin(); >> } >> } > > The call in the `finally` clause needs to be `Continuation.unpin()`.
Adding pinning would have a relatively large performance impact: No pinning: Benchmark (size) Mode Cnt Score Error Units AllocTest.OfVirtual.alloc_confined 5 avgt 30 1.401 ± 0.016 ns/op AllocTest.OfVirtual.alloc_confined_no_pool 5 avgt 30 15.382 ± 0.106 ns/op AllocTest.alloc_confined 5 avgt 30 1.060 ± 0.026 ns/op AllocTest.alloc_confined_no_pool 5 avgt 30 15.335 ± 0.140 ns/op Pinning Benchmark (size) Mode Cnt Score Error Units AllocTest.OfVirtual.alloc_confined 5 avgt 30 3.258 ± 0.312 ns/op AllocTest.OfVirtual.alloc_confined_no_pool 5 avgt 30 15.607 ± 0.189 ns/op AllocTest.alloc_confined 5 avgt 30 1.076 ± 0.028 ns/op AllocTest.alloc_confined_no_pool 5 avgt 30 15.552 ± 0.097 ns/op ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/31365#discussion_r3894884723
