String concatenation tweaks

Florian Weimer fweimer at redhat.com
Fri Mar 20 10:52:34 UTC 2015


On 03/13/2015 12:28 AM, Alex Buckley wrote:
> More abstract presentation. Given the expression:
> 
>   "foo" + m() + n()
> 
> you must not evaluate n() if evaluation of "foo" + m() completes
> abruptly. The proposed implementation evaluates n() regardless.
> 
> All is not lost. In the proposed implementation, the abrupt completion
> of "foo" + m() could occur because an append call fails or (thanks to
> Jon for pointing this out) the StringBuilder ctor fails. The
> quality-of-implementation issue is thus: if the proposed implementation
> is of sufficiently high quality to guarantee that the ctor and the first
> append both succeed, then the evaluation of "foo" + m() will always
> complete normally, and it would be an unobservable (thus acceptable)
> implementation detail to evaluate n() early.

The current implementation can still call m() and n() and fail with OOME
in something somewhat related to the concatenation, with a sufficiently
unfortunate garbage collection.  (That's why OOME is a
VirtualMachineError and not a RuntimeException.)  I don't think
preserving the OOME behavior is worth the effort.

-- 
Florian Weimer / Red Hat Product Security


More information about the compiler-dev mailing list