RFR: 8255082: HotSpot Style Guide should permit noexcept [v3]

Vladimir Kozlov kvn at openjdk.org
Fri Jun 20 14:15:30 UTC 2025


On Tue, 3 Jun 2025 11:01:06 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> Please review this change to permit the use of `noexcept` under certain
>> circumstances in HotSpot code.
>> 
>> http://wg21.link/n3050
>> 
>> Testing:
>> 
>> JDK-8316930 (HotSpot should use noexcept instead of throw()) showed what the
>> conversion would look like. It will need to be brought up to current mainline,
>> possibly with modifications.
>> 
>> This is a modification of the Style Guide, so rough consensus among the
>> HotSpot Group members is required to make this change. Only Group members
>> should vote for approval (via the github PR), though reasoned objections or
>> comments from anyone will be considered. A decision on this proposal will not
>> be made before Friday 16-June-2025 at 12h00 UTC.
>> 
>> Since we're piggybacking on github PRs here, please use the PR review process
>> to approve (click on Review Changes > Approve), rather than sending a "vote:
>> yes" email reply that would be normal for a CFV.
>
> Kim Barrett has updated the pull request incrementally with one additional commit since the last revision:
> 
>   more dholmes

Hi @kimbarrett 
Could you please answer my questions? Some statements are confusing for me.

Do we need to update `Guide` about `throw()`? Its usage seems confusing based on bugs you pointed.

doc/hotspot-style.md line 1118:

> 1116: failure must be declared `noexcept`.
> 1117: * All other uses of `noexcept` exception specifications are forbidden.
> 1118: * `noexcept` expressions are forbidden.

"argument-less form of `noexcept` are permitted" vs "`noexcept` expressions are forbidden". So what we should use? `noexcept()`? The example would be nice.

doc/hotspot-style.md line 1140:

> 1138: result. If an allocation function is not declared `noexcept` then the compiler
> 1139: may elide that checking and handling for a `new` expression calling that
> 1140: function.

This implies that compiler may generate a `nullptr` check if `noexcept` is specified.  Is it true?  Is it static (during compilation) check or it can generate runtime check?

We usually have explicit checks in such places to catch allocation failure. We are missing check in some places which may lead to crashes (reference through `nullptr`). Can compiler helps here?

doc/hotspot-style.md line 1153:

> 1151: HotSpot code can assume no exceptions will ever be thrown, even from functions
> 1152: not declared `noexcept`. So HotSpot code doesn't ever need to check, either
> 1153: with conditional exception specifications or with `noexcept` expressions.

"doesn't ever need to check" - what check? We still need to have nullptr checks. Right?

-------------

PR Review: https://git.openjdk.org/jdk/pull/25574#pullrequestreview-2946301888
PR Comment: https://git.openjdk.org/jdk/pull/25574#issuecomment-2991789891
PR Review Comment: https://git.openjdk.org/jdk/pull/25574#discussion_r2159073407
PR Review Comment: https://git.openjdk.org/jdk/pull/25574#discussion_r2159079821
PR Review Comment: https://git.openjdk.org/jdk/pull/25574#discussion_r2159083710


More information about the hotspot-dev mailing list