RFR: 8363584: Sort share/utilities includes [v3]

Francesco Andreuzzi duke at openjdk.org
Thu Jul 24 08:52:38 UTC 2025


On Wed, 23 Jul 2025 08:25:02 GMT, Francesco Andreuzzi <duke at openjdk.org> wrote:

>> src/hotspot/share/utilities/globalDefinitions_visCPP.hpp line 43:
>> 
>>> 41: # include <io.h>    // for stream.cpp
>>> 42: # include <float.h> // for _isnan
>>> 43: # include <stdio.h> // for va_list
>> 
>> These aren't being flagged as out of order by the checker, because of the trailing comments.
>> And the comment for `<stdio.h>` is odd, since that's already being brought in by `<stdarg.h>`.
>
> @kimbarrett How should we tackle this problem? I tried the following:
> 
>  # include <stdlib.h>
>  # include <string.h>
> -# include <stddef.h>// for offsetof
> +// for offsetof
> +# include <stddef.h>
>  # include <sys/stat.h>
> -# include <io.h>    // for stream.cpp
> -# include <float.h> // for _isnan
> -# include <stdio.h> // for va_list
> +// for stream.cpp
> +# include <io.h>
> +// for _isnan
> +# include <float.h>
> +// for va_list
> +# include <stdio.h>
>  # include <fcntl.h>
>  # include <inttypes.h>
>  # include <limits.h>
> 
> 
> Then running `SortInclude` gives the following result:
> 
>  # include <float.h>
>  // for va_list
> -# include <stdio.h>
>  # include <fcntl.h>
>  # include <inttypes.h>
>  # include <limits.h>
> +# include <stdio.h>
>  # include <time.h>
> 
> 
> from which I infer that `SortInclude` disregards comments above the `include` statement, which of course is not what we want. 
> 
> Either we remove the comments, or `SortIncludes.java` should be improved somehow. For example, I see the following comment in `TestIncludesAreSorted`:
> 
> Note that non-space characters after the closing " or > of an include statement
> can be used to prevent re-ordering of the include.
> 
> Would it be acceptable to change this behavior to prevent only lines containing a particular combination from being reordered? (e.g. `// do not reorder`)

Fixed in 6c8507a09d1f2e9956ce18b14993382622e6741f, I manually removed the comment, ran the tool, and re-applied the comments. Should be good enough, but I wonder if such operation could be done by the tool automagically?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26428#discussion_r2227877312


More information about the hotspot-dev mailing list