On AArch64, the String.indexOf() may produce incorrect results for empty
strings due to absence of the argument length check in
MacroAssembler::string_indexof_char().
Following test demonstrates the problem:
public class Test1 {
public static void main(String ... str) {
System.out.println("Begin");
for (int i = 0 ; i < 100000; i ++) {
String emptyString = "";
for(int c=0; c<0xFFFF; c++) {
int dot = emptyString.indexOf((char)c, -1);
if (dot != -1) {
System.out.println("indexOf returned index " + dot);
}
}
}
System.out.println("End");
}
}
Run:
java -XX:-CompactStrings Test1
Suggested fix:
diff --git a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
--- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
+++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
@@ -4860,6 +4860,8 @@
Register ch1 = rscratch1;
Register result_tmp = rscratch2;
+ cbz(cnt1, NOMATCH);
+
cmp(cnt1, (u1)4);
br(LT, DO1_SHORT);