[BACKOUT] Move input validation checks to Java for java.lang.StringCoding intrinsics

XMLWordPrintable

    • master
    • x86_64
    • linux, windows

        Summary: Back out `java.lang.StringCoding` changes delivered in JDK-8361842, which causes regressions reported here.

        When `generate_string_range_check` calls in `LibraryCallKit::inline_string_copy` are migrated from C++ (`library_call.cpp`) to Java (`StringUTF16.java`), `TestStringConstruction` causes a C2 crash on Linux and Windows x64 debug builds:

        ```
        CompileCommand: inline java/lang/String.* bool inline = true
        CompileCommand: inline java/lang/StringUTF16.* bool inline = true
        CompileCommand: exclude java/lang/String.checkBoundsOffCount bool exclude = true
        Default case invoked for:
           opcode = 121, "Con"
          o1 Con === o0 [[ ]] #top

        --N: o1 Con === o0 [[ ]] #top

        #
        # A fatal error has been detected by the Java Runtime Environment:
        #
        # Internal Error (/home/vy/oracle/jdk~1/open/src/hotspot/share/opto/matcher.cpp:1640), pid=236333, tid=236359
        # assert(false) failed: bad AD file
        #
        # JRE version: Java(TM) SE Runtime Environment (27.0) (fastdebug build 27-internal-vy.open)
        # Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 27-internal-vy.open, mixed mode, sharing, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
        # Problematic frame:
        # V [libjvm.so+0x148e399] Matcher::Label_Root(Node const*, State*, Node*, Node*&)+0x5b3
        ```

        ### Reproduction

        Apply the following patch:

        ```
        diff --git a/src/hotspot/share/opto/library_call.cpp b/src/hotspot/share/opto/library_call.cpp
        index a057f66a989..f95bb27bc75 100644
        --- a/src/hotspot/share/opto/library_call.cpp
        +++ b/src/hotspot/share/opto/library_call.cpp
        @@ -1490,7 +1490,6 @@ bool LibraryCallKit::inline_string_copy(bool compress) {
           }
         
           // Range checks
        - generate_string_range_check(src, src_offset, length, convert_src);
           generate_string_range_check(dst, dst_offset, length, convert_dst);
           if (stopped()) {
             return true;
        diff --git a/src/java.base/share/classes/java/lang/StringUTF16.java b/src/java.base/share/classes/java/lang/StringUTF16.java
        index 75c9e8239ba..288495a5c11 100644
        --- a/src/java.base/share/classes/java/lang/StringUTF16.java
        +++ b/src/java.base/share/classes/java/lang/StringUTF16.java
        @@ -220,6 +220,7 @@ static byte coderFromArrayLen(byte[] value, int len) {
              */
             @ForceInline
             static byte[] compress(final char[] val, final int off, final int count) {
        + String.checkBoundsOffCount(off, count, val.length);
                 byte[] latin1 = new byte[count];
                 int ndx = compress(val, off, latin1, 0, count);
                 if (ndx != count) {
        ```

        Run `TestStringConstruction`:

        ```
        CONF=linux-x64-debug make clean run-test TEST=open/test/hotspot/jtreg/compiler/intrinsics/string/TestStringConstruction.java JTREG="JAVA_OPTIONS=-XX:CompileThreshold=100 -XX:+UnlockExperimentalVMOptions -XX:-TieredCompilation"
        ```

              Assignee:
              Volkan Yazici
              Reporter:
              Volkan Yazici
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: