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

Improve String concatenation optimization

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: hs24, 9, 10
    • Fix Version/s: tbd
    • Component/s: hotspot
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      There are cases where String concatenation optimization bailout and which could be easily fixed. For example:

      public class MultipleUse {
        public static String foo() {
          String s = "testing";
          s = new StringBuilder(s).append(s).toString().toString();
          s = new StringBuilder(s).append(s).toString();
          return s;
        }

        public static void main(String[] args) throws Exception {
          final String s = "testing";
          for (int i = 0; i < 20000; i++) {
            if (!(s + s + s + s).equals(foo())) {
              System.out.println("bad string concat");
            }
          }
          System.out.println("done");
          System.in.read();
        }
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              kvn Vladimir Kozlov
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: