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

(str) Need String alternative with shared storage



    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:


      Prior to the fix for JDK-6924259 (in JDK 8 and JDK 7u6) the String was allowed to share its storage with its substrings.
      That approach, in particular, could lead to memory leaks, and had some other disadvantages.

      However, it also had its advantages, e.g. ability to search within a limited range of a String: str.substring(n, m).indexOf(xxx).

      We need to investigate, if it is worthwhile to introduce another CharSequence implementation, which would behave analogously to the old implementation of String, i.e. will have a link to the potentially shared buffer, plus offset within this buffer and length.
      This new class can be named in such a way that it would remind about its shared buffer, so that the user will have to take responsibility to avoid memory leaks. One possible name is SharedString.

      The String class will have a methods to create SharedStrings referencing the entire string or it's substrings without expensive copying.

      SharedString will have search/match methods, analogous to the ones of String.

      Primary use case of the new class would be to create local temporary variables for cheap substrings for quick access to sub-ranges.
      This may be useful for applications with extensive text processing, like parsers.

      Need to create a draft implementation and see how using such an alternative to String affects performance of JDK tools: javac, javadoc, etc.


          Issue Links



              igerasim Ivan Gerasimov
              igerasim Ivan Gerasimov
              0 Vote for this issue
              1 Start watching this issue