JDK-6500646 : Use Escape Analysis to optimize StringBuffer.toString()
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2006-12-05
  • Updated: 2010-05-10
  • Resolved: 2008-02-26
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 7
7Resolved
Related Reports
Duplicate :  
Description
A common use of StringBuffer in Java programs is that a local StringBuffer
object is used to build a character sequences which is then converted to a
String.  This conversion involves allocating a new char array and copying
the StringBuffer's char array.

If both the StringBuffer and String do not escape, this operation can be
optimized:  the char array from the StringBuffer can be used directly for
the String in some cases.  This is possible if the compiler can determine
that the char array is never modified after the String creation.

Comments
EVALUATION This optimization could be done by treating as an intrinsic, the String constructor used by StringBuffer.toString(): public String(char value[], int offset, int count) It will require further investigation to determine whether the situation where this optimization could be done occurs often enough to make it workthwhile. Because of the way the compiler represents the control structure of a Java program it may be difficult to verify that there are no modifications to the char array following the String creation unless all uses of the String and StringBuffer are fairly localized.
05-12-2006