8349428: RISC-V: "bad alignment" with -XX:-AvoidUnalignedAccesses after JDK-8347489

Reviewed-by: fyang, mli
This commit is contained in:
Gui Cao 2025-02-06 09:31:54 +00:00 committed by Hamlin Li
parent 7e307916ec
commit d85f65147a
2 changed files with 35 additions and 21 deletions

View File

@ -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.

View File

@ -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