RFR: 8319242: HotSpot Style Guide should discourage non-local variables with non-trivial initialization or destruction [v2]
Kim Barrett
kbarrett at openjdk.org
Tue Jun 17 08:40:38 UTC 2025
On Tue, 17 Jun 2025 03:29:58 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> Kim Barrett has updated the pull request incrementally with one additional commit since the last revision:
>>
>> better terminology, merge separate sections
>
> doc/hotspot-style.md line 778:
>
>> 776: [C++14 3.6.2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf)).
>> 777: should be avoided, unless an implementation is permitted to perform the
>> 778: initialization as a static initialization. The order in which dynamic
>
> What does "an implementation" refer to here? The C++ compiler? If so how could we permit this unless all supported "implementations" are guaranteed to permit it?
Yes, "an implementation" is the C++ compiler.
The restrictions on static initialization are significantly more stringent
than we want to require. The restrictions on dynamic initialization => static
initialization seem like pretty much what we would want, e.g. (roughly)
doesn't affect other initializations by assignments to global variables, and
doesn't depend on other initializations that are not required to be ordered
before it. So even if the implementation doesn't perform the initialization
statically, things should be okay. I won't guarantee there's no possibility
for problems, as there may be edge cases or implementation bugs, but this
seems pretty safe to me. I think the most likely way to fail is for us to
not recognize an unordered dependency in our code. Keeping dynamic
initializations fairly simple is probably the best way to avoid that.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25812#discussion_r2151674391
More information about the hotspot-dev
mailing list