The test stnippet IndexOfTest listed below fails the StringBuilder.indexOf after some time on AArch64 JDK12.
Expected value is -1 but after some time it returns 256.
Excluding java.lang.String.indexOf from compilation makes the test successful.
This error is observed on JDK12 revision: 6e8c8d16ecb4 and AdoptOpenJDK version 11.0.1+13
Commandline error case:
[sanzinger@... compiler]$ ~/jdk/jdk12-6e8c8d16ecb4/build/linux-aarch64-server-release/jdk/bin/java -XX:-Inline -Xcomp -cp . IndexOfTest
ERROR: Expected offset -1, got 256
Commandline success case (exclude String.indexOf from compilation):
[sanzinger@... compiler]$ ~/jdk/jdk12-6e8c8d16ecb4/build/linux-aarch64-server-release/jdk/bin/java -XX:-Inline -XX:CompileCommand=exclude,java.lang.String::indexOf -Xcomp -cp . IndexOfTest
CompileCommand: exclude java/lang/String.indexOf
Test was successful
public class IndexOfTest {
public static final String sourceString = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata ";
public static final String constantString = sourceString.substring(50, 50 + 64);
public static final StringBuilder sb;
static {
sb = new StringBuilder(sourceString);
sb.append(constantString);
sb.setLength(sourceString.length());
}
public static void main(String[] argv) {
for(int i = 0; i < 2000; i++) {
testStringBuilderIndexOfConstantOffset();
}
System.out.println("Test was successful");
}
public static void testStringBuilderIndexOfConstantOffset() {
int off = testStringBuilderIndexOfOffset(sb, constantString, Math.max(0, sourceString.length() - constantString.length()));
if(off != -1) {
System.out.println("ERROR: Expected offset -1, got " + off);
System.exit(1);
}
}
public static int testStringBuilderIndexOfOffset(StringBuilder a, String b, int fromIndex) {
return a.indexOf(b, fromIndex);
}
}