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

The compiler doesn't do integer -> string constant folding in some cases.

    Details

    • Type: Bug
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 11
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Linux amd64 OpenJDK 11.0.4

      A DESCRIPTION OF THE PROBLEM :
      Consider this class:

      public class Class1
      {
        private static final int CONST = 3000;

        protected String extra()
        { return "other "; }

        public String toFoldedString()
        { return "string " + CONST; }

        public String toUnfoldedString()
        { return "with " + extra() + CONST + " here"; }
      }

      The compiler (targeting 1.8, btw) will simplify toFoldedString() to simply return a constant string. In this case CONST is converted to a string at compile time. However, toUnfoldedString() internally is using a StringBuilder. However it no longer folds CONST + <string constant> as in the toFoldedString() case. Instead it calls append(int) and then append(String). It seems like it may be more optimal to fold constants as much as possible here.

      I seem to vaguely recall this working in a past release but can't confirm.


        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: