RFR: 8363584: Sort share/utilities includes

Francesco Andreuzzi duke at openjdk.org
Wed Jul 23 08:27:54 UTC 2025


On Tue, 22 Jul 2025 19:16:48 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> This PR sorts the includes in hotspot/share/utilities using test/hotspot/jtreg/sources/SortIncludes.java. I'm also adding the directory to TestIncludesAreSorted.java.
>> 
>> Passes tier1 tests and GHA.
>
> 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`)

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

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


More information about the hotspot-dev mailing list