Skip to content

Commit d85f651

Browse files
zifeihanHamlin Li
authored andcommitted
8349428: RISC-V: "bad alignment" with -XX:-AvoidUnalignedAccesses after JDK-8347489
Reviewed-by: fyang, mli
1 parent 7e30791 commit d85f651

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,12 +1461,14 @@ void C2_MacroAssembler::string_compare(Register str1, Register str2,
14611461
{
14621462
if (str1_isL == str2_isL) { // LL or UU
14631463
#ifdef ASSERT
1464-
Label align_ok;
1465-
orr(t0, str1, str2);
1466-
andi(t0, t0, 0x7);
1467-
beqz(t0, align_ok);
1468-
stop("bad alignment");
1469-
bind(align_ok);
1464+
if (AvoidUnalignedAccesses) {
1465+
Label align_ok;
1466+
orr(t0, str1, str2);
1467+
andi(t0, t0, 0x7);
1468+
beqz(t0, align_ok);
1469+
stop("bad alignment");
1470+
bind(align_ok);
1471+
}
14701472
#endif
14711473
// load 8 bytes once to compare
14721474
ld(tmp1, Address(str1));
@@ -1518,7 +1520,7 @@ void C2_MacroAssembler::string_compare(Register str1, Register str2,
15181520
// main loop
15191521
bind(NEXT_WORD);
15201522
if (str1_isL == str2_isL) { // LL or UU
1521-
// both of the two loads are 8-byte aligned
1523+
// 8-byte aligned loads when AvoidUnalignedAccesses is enabled
15221524
add(t0, str1, cnt2);
15231525
ld(tmp1, Address(t0));
15241526
add(t0, str2, cnt2);
@@ -1713,12 +1715,14 @@ void C2_MacroAssembler::arrays_equals(Register a1, Register a2,
17131715
bltz(cnt1, SHORT);
17141716

17151717
#ifdef ASSERT
1716-
Label align_ok;
1717-
orr(t0, a1, a2);
1718-
andi(t0, t0, 0x7);
1719-
beqz(t0, align_ok);
1720-
stop("bad alignment");
1721-
bind(align_ok);
1718+
if (AvoidUnalignedAccesses) {
1719+
Label align_ok;
1720+
orr(t0, a1, a2);
1721+
andi(t0, t0, 0x7);
1722+
beqz(t0, align_ok);
1723+
stop("bad alignment");
1724+
bind(align_ok);
1725+
}
17221726
#endif
17231727

17241728
// Main 8 byte comparison loop.
@@ -1817,12 +1821,14 @@ void C2_MacroAssembler::string_equals(Register a1, Register a2,
18171821
bltz(cnt1, SHORT);
18181822

18191823
#ifdef ASSERT
1820-
Label align_ok;
1821-
orr(t0, a1, a2);
1822-
andi(t0, t0, 0x7);
1823-
beqz(t0, align_ok);
1824-
stop("bad alignment");
1825-
bind(align_ok);
1824+
if (AvoidUnalignedAccesses) {
1825+
Label align_ok;
1826+
orr(t0, a1, a2);
1827+
andi(t0, t0, 0x7);
1828+
beqz(t0, align_ok);
1829+
stop("bad alignment");
1830+
bind(align_ok);
1831+
}
18261832
#endif
18271833

18281834
// Main 8 byte comparison loop.

src/hotspot/cpu/riscv/stubGenerator_riscv.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,7 +2458,15 @@ class StubGenerator: public StubCodeGenerator {
24582458
assert((base_offset % (UseCompactObjectHeaders ? 4 :
24592459
(UseCompressedClassPointers ? 8 : 4))) == 0, "Must be");
24602460

2461-
// strL is 8-byte aligned
2461+
#ifdef ASSERT
2462+
if (AvoidUnalignedAccesses) {
2463+
Label align_ok;
2464+
__ andi(t0, strL, 0x7);
2465+
__ beqz(t0, align_ok);
2466+
__ stop("bad alignment");
2467+
__ bind(align_ok);
2468+
}
2469+
#endif
24622470
__ ld(tmpLval, Address(strL));
24632471
__ addi(strL, strL, wordSize);
24642472

@@ -2542,7 +2550,7 @@ class StubGenerator: public StubCodeGenerator {
25422550
__ subi(cnt2, cnt2, wordSize / 2);
25432551
}
25442552

2545-
// we are now 8-bytes aligned on strL
2553+
// we are now 8-bytes aligned on strL when AvoidUnalignedAccesses is true
25462554
__ subi(cnt2, cnt2, wordSize * 2);
25472555
__ bltz(cnt2, TAIL);
25482556
__ bind(SMALL_LOOP); // smaller loop

0 commit comments

Comments
 (0)