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 16:55:29 UTC 2025
On Tue, 17 Jun 2025 12:52:08 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> 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.
>
> Sorry but I'm having trouble understanding how somehow could evaluate whether a dynamic initialization is okay based on the current statement.
Does the initialization modify some other global state? Or does it depend on
some other global state that might not be knowable yet? Avoid those.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25812#discussion_r2152737085
More information about the hotspot-dev
mailing list