RFR (L): 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder

Kim Barrett kim.barrett at oracle.com
Thu Aug 2 23:38:29 UTC 2018


> On Aug 2, 2018, at 6:45 PM, David Holmes <david.holmes at oracle.com> wrote:
> 
> Hi Thomas,
> 
> On 2/08/2018 10:51 PM, Thomas Schatzl wrote:
>> Hi,
>> On Thu, 2018-08-02 at 22:34 +1000, David Holmes wrote:
>>> Hi Thomas,
>>> 
>>> On 2/08/2018 7:09 PM, Thomas Schatzl wrote:
>>>> Hi all,
>>>> 
>>>>    there have been several suggestions to try to fix the Hotspot
>>>> code to
>>>> allow us to enable -Wreorder in the Hotspot sources.
>>> 
>>> Can you enlighten us on what -Wreorder is/does and so what changes
>>> you are making please.
>>   oh, sorry, my fault. -Wreorder is a compiler switch that checks that
>> the order of declaration of members in the initializer lists of
>> constructors match the order of declaration in the class.
>> C++ always initializes members in the initializer list in the order of
>> the declaration in the class, it does not matter whether you specify it
>> differently in the initializer list or not.
> 
> Wow! is that considered a "feature"??? I can't think why the compiler would not simply execute the code in the order you write it. :( If it's going to do that then the language should have made it an error to write the initializer list any other way. No wonder people just use constructor bodies in preference to initializer lists.

There needs to be a well-defined order for initialization of members
(and base classes) that aren't mentioned in the initializer list.

Declaration order is a reasonable choice for those not mentioned in
the initializer list.

Also, the destruction order is in reverse declaration order, as
there's nothing corresponding to the initializer list in a
destructor, and some order needs to be chosen.

This goes all the way back to the very beginnings of C++.  For
example, C++ ARM p292 says about the initialization order "The
declaration order is used to ensure that sub-objects and members are
destroyed in reverse order of initialization."

Using order in the initialization list rather than declaration order
would likely require some complicated rules and complex implementation
for things like an exception being thrown during the execution of one
of the initializers.

I'm inclined to agree it should have been an error to have
out-of-order initializers; I have no idea why that wasn't
done. -Wreorder + -Wfatal makes it an error for us.  But we first need
to fix lots of code that has out-of-order initializers.

And there are lots of reasons to still prefer initializer lists to in-body
assignment.

[Thomas - This isn't a review.  If I have time I’ll look at some of these
changes, but don’t wait for me if you have other reviewers.  And thank
you for doing this; I’ve been wanting to get this done for a while.]




More information about the hotspot-dev mailing list