Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8148869

StringConcatFactory MH_INLINE_SIZED_EXACT strategy does not work with -XX:-CompactStrings

XMLWordPrintable

      The failure happens with MH_INLINE_SIZED_EXACT strategy and -XX:-CompactStrings, because this strategy builds the byte[] storage completely by itself.

      In doing that, it figures out the coder for the final String, but it starts with coder=0, which happens to be String.LATIN1. However, with -XX:-CompactStrings, every String should be String.UTF16. This is not a problem for most concats that capture Strings arguments, because that argument will promote the coder to UTF16. But, in our current scheme, we can request concat expression without Strings, e.g. two *characters*, which escapes the promotion. In the end, the strategy sometimes builds a broken byte[] array, and fails either with AIOOBE, or the garbled String.

      The fix is to start with the initial coder that depends on Strings.COMPACT_STRINGS field.

            shade Aleksey Shipilev
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: