From d85f65147aeb4009742bfe401c6070d920b71b3e Mon Sep 17 00:00:00 2001 From: Gui Cao Date: Thu, 6 Feb 2025 09:31:54 +0000 Subject: [PATCH] 8349428: RISC-V: "bad alignment" with -XX:-AvoidUnalignedAccesses after JDK-8347489 Reviewed-by: fyang, mli --- .../cpu/riscv/c2_MacroAssembler_riscv.cpp | 44 +++++++++++-------- src/hotspot/cpu/riscv/stubGenerator_riscv.cpp | 12 ++++- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp b/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp index c3296aeb76b..f52d5d7d12c 100644 --- a/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp +++ b/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp @@ -1461,12 +1461,14 @@ void C2_MacroAssembler::string_compare(Register str1, Register str2, { if (str1_isL == str2_isL) { // LL or UU #ifdef ASSERT - Label align_ok; - orr(t0, str1, str2); - andi(t0, t0, 0x7); - beqz(t0, align_ok); - stop("bad alignment"); - bind(align_ok); + if (AvoidUnalignedAccesses) { + Label align_ok; + orr(t0, str1, str2); + andi(t0, t0, 0x7); + beqz(t0, align_ok); + stop("bad alignment"); + bind(align_ok); + } #endif // load 8 bytes once to compare ld(tmp1, Address(str1)); @@ -1518,7 +1520,7 @@ void C2_MacroAssembler::string_compare(Register str1, Register str2, // main loop bind(NEXT_WORD); if (str1_isL == str2_isL) { // LL or UU - // both of the two loads are 8-byte aligned + // 8-byte aligned loads when AvoidUnalignedAccesses is enabled add(t0, str1, cnt2); ld(tmp1, Address(t0)); add(t0, str2, cnt2); @@ -1713,12 +1715,14 @@ void C2_MacroAssembler::arrays_equals(Register a1, Register a2, bltz(cnt1, SHORT); #ifdef ASSERT - Label align_ok; - orr(t0, a1, a2); - andi(t0, t0, 0x7); - beqz(t0, align_ok); - stop("bad alignment"); - bind(align_ok); + if (AvoidUnalignedAccesses) { + Label align_ok; + orr(t0, a1, a2); + andi(t0, t0, 0x7); + beqz(t0, align_ok); + stop("bad alignment"); + bind(align_ok); + } #endif // Main 8 byte comparison loop. @@ -1817,12 +1821,14 @@ void C2_MacroAssembler::string_equals(Register a1, Register a2, bltz(cnt1, SHORT); #ifdef ASSERT - Label align_ok; - orr(t0, a1, a2); - andi(t0, t0, 0x7); - beqz(t0, align_ok); - stop("bad alignment"); - bind(align_ok); + if (AvoidUnalignedAccesses) { + Label align_ok; + orr(t0, a1, a2); + andi(t0, t0, 0x7); + beqz(t0, align_ok); + stop("bad alignment"); + bind(align_ok); + } #endif // Main 8 byte comparison loop. diff --git a/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp b/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp index bb536c3e111..bef5638ed07 100644 --- a/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp +++ b/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp @@ -2458,7 +2458,15 @@ class StubGenerator: public StubCodeGenerator { assert((base_offset % (UseCompactObjectHeaders ? 4 : (UseCompressedClassPointers ? 8 : 4))) == 0, "Must be"); - // strL is 8-byte aligned +#ifdef ASSERT + if (AvoidUnalignedAccesses) { + Label align_ok; + __ andi(t0, strL, 0x7); + __ beqz(t0, align_ok); + __ stop("bad alignment"); + __ bind(align_ok); + } +#endif __ ld(tmpLval, Address(strL)); __ addi(strL, strL, wordSize); @@ -2542,7 +2550,7 @@ class StubGenerator: public StubCodeGenerator { __ subi(cnt2, cnt2, wordSize / 2); } - // we are now 8-bytes aligned on strL + // we are now 8-bytes aligned on strL when AvoidUnalignedAccesses is true __ subi(cnt2, cnt2, wordSize * 2); __ bltz(cnt2, TAIL); __ bind(SMALL_LOOP); // smaller loop