On Tue, 15 Sep 2026 15:37:26 GMT, Viktor Klang <[email protected]> wrote:
> I've experimented with many different approaches to approximate the number of
> spins, both statically and dynamically, and going with ((1 << 13) | (1 <<
> 14)) or, in other words 24576, seems to have the best trade-off known by the
> author at this time.
>
> Including benchmark results for exchanges below.
>
>
> As compared to jdk21:
>
> Base
> Test
> Name Run target (exchanges) (virtual) Score Error
> Score Error Change Unit
> exchange Linux aarch64 1000 false 335791.046 ± 101.849
> 332159.281 ± 207.779 1.01x ns/op
> p0.00 321536.000
> 300032.000 1.02x ns/op
> p0.50 335360.000
> 343552.000 1.01x ns/op
> p0.90 336384.000
> 344064.000 1.01x ns/op
> p0.95 337920.000
> 345600.000 1.00x ns/op
> p0.99 356352.000
> 348160.000 1.04x? ns/op
> p0.999 413184.000
> 402944.000 1.05x? ns/op
> p0.9999 700636.160
> 706471.629 1.01x ns/op
> p1.00 1060864.000
> 1030144.000 1.01x ns/op
> exchange Linux x64 1000 false 184007.923 ± 151.093
> 177661.486 ± 37.691 1.04x? ns/op
> p0.00 54976.000
> 160768.000 0.93x ns/op
> p0.50 187392.000
> 178432.000 1.04x? ns/op
> p0.90 196352.000
> 182272.000 1.06x? ns/op
> p0.95 196608.000
> 183296.000 1.05x? ns/op
> p0.99 198912.000
> 185344.000 1.05x? ns/op
> p0.999 202240.000
> 190208.000 1.06x? ns/op
> p0.9999 226521.651
> 210782.899 1.15x ns/op
> p1.00 785408.000
> 483328.000 ...
Tagging @AlanBateman and @DougLea
src/java.base/share/classes/java/util/concurrent/Exchanger.java line 260:
> 258: * blocking or possibly shrinking arena.
> 259: */
> 260: private static final int SPINS = 24576;
Suggestion:
private static final int SPINS = 24576; // Determined by benchmark
-------------
PR Comment: https://git.openjdk.org/jdk/pull/32886#issuecomment-5683371834
PR Review Comment: https://git.openjdk.org/jdk/pull/32886#discussion_r4017469216