RFR: 8215371: Better nodes for concatenated string literals

Liam Miller-Cushon cushon at google.com
Fri Dec 14 17:31:52 UTC 2018


Hi,

I've been thinking a bit about the discussion of string literals
in JDK-8182769, and I started a separate bug for that part:
https://bugs.openjdk.java.net/browse/JDK-8215371

The issue is that long string concatenation chains are represented as
unbalanced binary expression trees, and it's easy to run out of stack when
processing those trees recursively. As a work-around, javac currently
supports folding concatenated string literals during parsing, but that
work-around reduces the fidelity of the AST and is problematic for IDE-like
tooling.

A possible fix is to remove the early constant folding, and instead balance
the binary trees for concatentation:
http://cr.openjdk.java.net/~cushon/8215371/webrev.00/

There's some discussion of the tradeoffs in the comments on JDK-8182769.
Other ideas include:

* Refactoring code processing string literals to avoid recursion. This
removes the constraint on the shape on the AST, but might reduce
readability. The problem also affects non-javac users of the com.sun.source
APIs which we don't have the option of refactoring.

* Introducing a new AST node to represent concatenated string literals as a
flat list. This would require more refactoring to javac, and an addition to
the com.sun.source APIs.

What do you think? My prototype fix is kind of a work-around, but I think
it's a modest improvement over the status quo. If there are ideas of a more
principled solution I'm happy to investigate alternatives.

Thanks,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20181214/6d3706b8/attachment.html>


More information about the compiler-dev mailing list