-
Enhancement
-
Resolution: Won't Fix
-
P4
-
9, 10
If we compare two idiomatic constructions for CompareAndSet vs CompareAndExchange, then CAE would perform worse than CAS. Looking at -prof perfasm, it seems to happen because CAE loop omits reading the hot line back, *but* it also widens the window where the actual value may change. If we put the Unsafe.getIntVolatile in CAE loop, then a "fresher" value is available for mutation, and performance is similar to CAS. This has implications for performance testing, and maybe the codegen.
Benchmark:
http://cr.openjdk.java.net/~shade/8141640/CAEvsCAS.java
CAEvsCAS.exchange: 986.721 ± 11.816 ns/op
CAEvsCAS.exchange_withReread: 850.282 ± 11.068 ns/op
CAEvsCAS.swap: 854.341 ± 18.451 ns/op
Hot loops:
http://cr.openjdk.java.net/~shade/8141640/perf.txt
Benchmark:
http://cr.openjdk.java.net/~shade/8141640/CAEvsCAS.java
CAEvsCAS.exchange: 986.721 ± 11.816 ns/op
CAEvsCAS.exchange_withReread: 850.282 ± 11.068 ns/op
CAEvsCAS.swap: 854.341 ± 18.451 ns/op
Hot loops:
http://cr.openjdk.java.net/~shade/8141640/perf.txt