This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
My interpretation of the original code was that it was meant to prevent the possibility that a small substring of a large StringBuffer would prevent the large array being gc'd.
The patch you checked in breaks this. Consider:
String Foo() { StringBuffer b = new StringBuffer(); ... put a megabyte of stuff into b ... String ignored = b.toString(); // sets b.shared return b.substring (0, 1); }
The 1 character String returned from Foo now has it's contents stored in
a megabyte char[], and that array has no other references.
Passing ((len << 2) >= value.length) rather than StringBuffer.shared to the String constructor prevented this.
Attachment:
StringBuffer2.patch.txt
Description: Text document
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |