JDK-8067471 : Use private static final char[0] for empty Strings
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2013-05-31
  • Updated: 2015-09-29
  • Resolved: 2015-01-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Fixed 9 b47Fixed
Related Reports
Relates :  
Description
In an average heap dump, 292 kB is wasted from empty Strings having their own char[] of length 0.  Instead, the String class should declare a zero-length char[] and use that for empty Strings.  The constructor should detect that an empty String is being created and use the common char[].
Comments
Microbenchmark runs: http://cr.openjdk.java.net/~shade/8067471/performance.txt
19-12-2014

http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-December/030402.html
17-12-2014

Originally, it was rejected by suggestion On 05/26/2012 12:09 AM, Mike Duigou wrote: > On May 25 2012, at 06:57 , R��mi Forax wrote: > >> Hi Mike, Hi Alan, Hi all, >> in my opinion, EMPTY_STRING_VALUE is a premature optimization, >> the idea is, I think, to avoid to create an empty char but if you want to do that, >> it's better to do that in StringBuilder.toString() to avoid to create the String at all. > I have removed most of the use of EMPTY_STRING_VALUE. It remains for the empty constructor only. I may be wrong but this constructor is used rarely so for me it's like you add one static field that will be never used. in http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-May/010300.html and pushed as http://hg.openjdk.java.net/jdk9/dev/jdk/rev/2c773daa825d Currently in jdk9 it's used in: jdk.httpserver/share/classes/sun/net/httpserver/Request.java:200: v = new String(); java.base/share/classes/sun/net/www/MessageHeader.java:508: v = new String(); java.base/share/classes/java/lang/invoke/MethodHandles.java:829:MethodType MT_newString = methodType(void.class); //()V for new String() jdk.runtime/share/classes/sun/security/tools/policytool/PolicyTool.java:947: String stringEntry = new String(); [~nreynold], Could you please provide particular examples of "average heap dump" where this enhancement may help?
17-12-2014

Previous discussion on this topic here: http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-May/010257.html
16-12-2014