JDK-8215792 : AArch64: String.indexOf generates incorrect result
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11,12
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: aarch64
  • Submitted: 2018-12-21
  • Updated: 2020-11-19
  • Resolved: 2019-05-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 13
11.0.11-oracleFixed 13 b22Fixed
Related Reports
Relates :  
Description
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);
    }
}

Comments
Fix Request for jdk11u What: Original patch applies as is to jdk11u Why: fix incorrect behaviour of important function Testing: tier1 tests passed. New test covering this problem also passed. Risk: low and restricted only to AArch64 builds
14-08-2019

~dpochepk Priority was changed to P2.
22-01-2019

~dpochepk (Dmitrij Pochepko) has proposed a single line fix http://cr.openjdk.java.net/~dpochepk/8215792/webrev.01/
22-01-2019

This is a bug in stub code of AArch64 string intrinscis and can be reproduced by below simpler case and JVM options. public class Test { public static void main(String[] args) { StringBuilder str = new StringBuilder("ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890123456789"); str.setLength(str.length() - 10); System.out.println(str.indexOf("01234567890123456789")); } } $ java Test -1 $ java -Xcomp -XX:-Inline Test 26
02-01-2019