RFR: 8315856: RISC-V: Use Zacas extension for cmpxchg

Fei Yang fyang at openjdk.org
Mon Dec 4 06:38:38 UTC 2023


On Thu, 30 Nov 2023 17:48:11 GMT, Ludovic Henry <luhenry at openjdk.org> wrote:

> 8315856: RISC-V: Use Zacas extension for cmpxchg

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp line 2630:

> 2628:     mv(tmp, oldv);
> 2629:     atomic_cas(tmp, newv, addr, Assembler::int64, Assembler::aq, Assembler::rl);
> 2630:     beq(tmp, oldv, succeed);

The Zacas spec says: `The memory operation performed by an AMOCAS.W/D/Q, when not successful, has acquire semantics if aq bit is 1 but does not have release semantics, regardless of rl.` So when the CAS fails, I think we are lacking the needed semantics which is enforced at L2645 for the else block. Seems that we should place a `membar(AnyAny);` after the `beq` instruction when  like our aarch64 counterpart [1].

[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp#L2758

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16910#discussion_r1413422831


More information about the hotspot-dev mailing list