Integrated: 8343541: C1: Plain memory accesses are emitted with membars with +AlwaysAtomicAccesses

Xiaolong Peng xpeng at openjdk.org
Wed Nov 20 10:37:35 UTC 2024


On Mon, 18 Nov 2024 07:27:03 GMT, Xiaolong Peng <xpeng at openjdk.org> wrote:

> C1 and C2 has different implementations for `+AlwaysAtomicAccesses`, [C2 impl](https://github.com/openjdk/jdk/blob/4a7ce1d7c1bd4b751063b98cf8bedcd27055760b/src/hotspot/share/gc/shared/c2/barrierSetC2.cpp#L410) only guarantees atomicity hence no membars  are emitted for plain memory access, but C1 treats it same as volatile access hence it emits membars.  The change removes the unnecessary membars in C1 for `+AlwaysAtomicAccesses`. 
> 
> The test have been verified by very simple JMH benchmarks to measure the latency of reading/writing long/volatile long variable 10000 times, and run with VM option `-XX:TieredStopAtLevel=3 -XX:+UnlockExperimentalVMOptions -XX:+AlwaysAtomicAccesses`: 
> 
> Before the fix:
> 
> Benchmark                                   Mode  Cnt       Score      Error  Units
> AlwaysAtomicAccesses.testReadLong           avgt    5   58711.131 ±  716.940  ns/op
> AlwaysAtomicAccesses.testReadVolatileLong   avgt    5   59014.735 ±  675.354  ns/op
> AlwaysAtomicAccesses.testWriteLong          avgt    5  115817.978 ±  302.089  ns/op
> AlwaysAtomicAccesses.testWriteVolatileLong  avgt    5  116317.835 ± 1451.365  ns/op
> 
> 
> After the fix:
> 
> Benchmark                                   Mode  Cnt       Score      Error  Units
> AlwaysAtomicAccesses.testReadLong           avgt    5   49651.527 ±  159.948  ns/op
> AlwaysAtomicAccesses.testReadVolatileLong   avgt    5   58668.844 ±  316.029  ns/op
> AlwaysAtomicAccesses.testWriteLong          avgt    5   23008.361 ±   10.947  ns/op
> AlwaysAtomicAccesses.testWriteVolatileLong  avgt    5  116440.017 ± 1240.832  ns/op

This pull request has now been integrated.

Changeset: afee7405
Author:    Xiaolong Peng <xpeng at openjdk.org>
Committer: Aleksey Shipilev <shade at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/afee7405bd13cbe1cb829dd150a9de7e6faf49ae
Stats:     6 lines in 1 file changed: 2 ins; 0 del; 4 mod

8343541: C1: Plain memory accesses are emitted with membars with +AlwaysAtomicAccesses

Reviewed-by: shade, vlivanov

-------------

PR: https://git.openjdk.org/jdk/pull/22191


More information about the hotspot-dev mailing list