can anyone in the know summarize to me how exactly does -XX:+OptimizeStringConcat work? Googling didn't turn up anything useful…
Thanks, and apologies for slightly off-topic, but this group seems to be the focal point of knowledgable JVM people nowadays.
It recognizes pattern like new StringBuilder().append(...).toString()
with ... being a String, a char or an int (it doesn't seem to recognize
if it's an Object)
and tries to create the corresponding String once.
Recursive patterns like new StringBuilder().append(new
are also recognized and then collapsed,
append(Integer.toString(number)) is transformed to append(number),
and there is a special handling if the string may be null (equivalent of
The generated code sums the size of each char, integer or string to be
then the char buffer of the string is allocated (without zeroig it!) and
by copying the chars from the values to be appended.
Then the String is created.
(there is a code to reuse an existing String object but the part that
which String object to reuse is guarded by a #if 0)
The result is that the String is allocated once and no StringBuilder are
allocated at all.
You received this message because you are subscribed to the Google Groups "JVM Languages" group.
To post to this group, send email to jvm-...@googlegroups.com.
To unsubscribe from this group, send email to jvm-languages+unsu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en.