static_cast<void>(0) vs do while
Kim Barrett
kim.barrett at oracle.com
Fri Jan 12 06:50:01 UTC 2024
> On Jan 12, 2024, at 12:24 AM, Julian Waters <tanksherman27 at gmail.com> wrote:
>
> Hi all,
>
> In my personal fork of HotSpot I have the following commit
> https://github.com/TheShermanTanker/jdk/commit/54131b70d40a88ab4176d23821f4c32044c0043d
> which replaces some occurrences of do while with a discarding
> static_cast (static_cast<void>(0) is a nop), to avoid inefficiencies
> in the compiled code for debug mode, when optimizations are turned off
> (Namely a compare and jump back to the start of the loop on a
> condition that is always false). Is this minor optimization worth
> committing upstream to HotSpot? It should also mean that the compiled
> code is clearer when the methods containing asserts are disassembled.
No, I don't think we should do this. `do { ... } while (false)` is a
well-known idiom. Uglifying things this way does not seem helpful. The
proposed change would also make assert and friends expand to multiple
statements instead of one. I've no idea what the impact of that might be, but
suspect there are cases where it could change the meaning of code (possibly
into a compile-time error, or worse, perhaps even silently). At the very
least it would violate expectations.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <https://mail.openjdk.org/pipermail/hotspot-dev/attachments/20240112/654c71cb/signature.asc>
More information about the hotspot-dev
mailing list