RFR: JDK-8273914: Indy string concat changes order of operations

Liam Miller-Cushon cushon at openjdk.java.net
Wed Oct 6 22:24:05 UTC 2021

On Wed, 6 Oct 2021 21:36:30 GMT, Rémi Forax <forax at openjdk.org> wrote:

>> This change makes string concatenation call `toString` on the arguments eagerly, to preserve the correct evaluation order of the arguments and the calls to `toString`.
> src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/StringConcat.java line 313:
>> 311:          * possible side-effects.
>> 312:          */
>> 313:         protected boolean shouldConvertToStringEagerly(Type argType) {
> For me the implementation should be neither a primitive type nor a final class of java.lang. I think that at least the wrappers should not be converted eagerly

@forax can you expand on the suggestion here?

The current implementation is not eagerly converting boxes for primitives types, which wrappers should not be converted eagerly?

Also note that one of the motivating examples was `StringBuilder`, which is a `final` class in `java.lang`. It's not just about `toString()` not having side-effects, it's also about insulting the operands from each others's side effects (e.g. `myStringBuilder.append("foo") + myStringBuilder.append("bar")`)


PR: https://git.openjdk.java.net/jdk/pull/5844

More information about the hotspot-runtime-dev mailing list