-
Bug
-
Resolution: Fixed
-
P3
-
11, 14, 15
-
b13
-
aarch64
-
linux
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8240810 | 14.0.2 | Andrew Brygin | P3 | Resolved | Fixed | b01 |
JDK-8241284 | 13.0.3 | Andrew Brygin | P3 | Resolved | Fixed | b01 |
JDK-8248711 | 11.0.9-oracle | Andrew Brygin | P3 | Resolved | Fixed | b01 |
JDK-8241197 | 11.0.8 | Andrew Brygin | P3 | Resolved | Fixed | b01 |
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);
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);
- backported by
-
JDK-8240810 AArch64: String.indexOf may incorrectly handle empty strings.
- Resolved
-
JDK-8241197 AArch64: String.indexOf may incorrectly handle empty strings.
- Resolved
-
JDK-8241284 AArch64: String.indexOf may incorrectly handle empty strings.
- Resolved
-
JDK-8248711 AArch64: String.indexOf may incorrectly handle empty strings.
- Resolved
- relates to
-
JDK-8157708 aarch64: StrIndexOfChar intrinsic is not implemented
- Resolved