Skip to content

Commit

Permalink
Add UseZtso to optimize memory fences on TSO-enabled platforms (openj…
Browse files Browse the repository at this point in the history
  • Loading branch information
luhenry authored Oct 21, 2022
1 parent ba90b88 commit 54f5aa1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/hotspot/cpu/riscv/globals_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ define_pd_global(intx, InlineSmallCode, 1000);
product(bool, UseZicbom, false, EXPERIMENTAL, "Use Zicbom instructions") \
product(bool, UseZicbop, false, EXPERIMENTAL, "Use Zicbop instructions") \
product(bool, UseZicboz, false, EXPERIMENTAL, "Use Zicboz instructions") \
product(bool, UseZtso, false, EXPERIMENTAL, "Assume Ztso memory model") \
product(bool, UseRVVForBigIntegerShiftIntrinsics, true, \
"Use RVV instructions for left/right shift of BigInteger")

Expand Down
27 changes: 18 additions & 9 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,21 +347,30 @@ class MacroAssembler: public Assembler {
static void membar_mask_to_pred_succ(uint32_t order_constraint, uint32_t& predecessor, uint32_t& successor) {
predecessor = (order_constraint >> 2) & 0x3;
successor = order_constraint & 0x3;

// extend rw -> iorw:
// 01(w) -> 0101(ow)
// 10(r) -> 1010(ir)
// 11(rw)-> 1111(iorw)
if (UseConservativeFence) {
predecessor |= predecessor << 2;
successor |= successor << 2;
}
}

static int pred_succ_to_membar_mask(uint32_t predecessor, uint32_t successor) {
return ((predecessor & 0x3) << 2) | (successor & 0x3);
}

void fence(uint32_t predecessor, uint32_t successor) {
if (UseZtso) {
// do not emit fence if it's not at least a StoreLoad fence
if (!((predecessor & w) && (successor & r))) {
return;
}
}
if (UseConservativeFence) {
// extend rw -> iorw:
// 01(w) -> 0101(ow)
// 10(r) -> 1010(ir)
// 11(rw)-> 1111(iorw)
predecessor |= (predecessor & 0b11) << 2;
successor |= (successor & 0b11) << 2;
}
Assembler::fence(predecessor, successor);
}

// prints msg, dumps registers and stops execution
void stop(const char* msg);

Expand Down

0 comments on commit 54f5aa1

Please sign in to comment.