Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/hotspot/share/ci/ciUtilities.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define SHARE_CI_CIUTILITIES_INLINE_HPP

#include "ci/ciUtilities.hpp"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line not removed?

#include "runtime/interfaceSupport.inline.hpp"


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line inserted?

Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/compiler/compilerDefinitions.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#ifndef SHARE_COMPILER_COMPILERDEFINITIONS_INLINE_HPP
#define SHARE_COMPILER_COMPILERDEFINITIONS_INLINE_HPP

#include "compiler/compiler_globals.hpp"
#include "compiler/compilerDefinitions.hpp"

#include "compiler/compiler_globals.hpp"
#include "runtime/arguments.hpp"

inline bool CompilerConfig::is_interpreter_only() {
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/compiler/oopMap.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define SHARE_VM_COMPILER_OOPMAP_INLINE_HPP

#include "compiler/oopMap.hpp"

#include "oops/compressedOops.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/globals.hpp"
Expand Down
54 changes: 43 additions & 11 deletions test/hotspot/jtreg/sources/SortIncludes.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,65 @@ private static Comparator<String> sortKeyForInclude(char delim) {
return Comparator.comparing(s -> s.toLowerCase().substring(s.indexOf(delim)));
}

/// Gets the first substring in `s` enclosed by `start` and `end`.
private static String extract(String s, char start, char end) {
int startIndex = s.indexOf(start);
int endIndex = s.indexOf(end, startIndex + 1);
if (startIndex == -1 || endIndex == -1) {
throw new IllegalArgumentException(s);
}
return s.substring(startIndex + 1, endIndex);
}

/// Sorts the include statements in `block`.
///
/// @param path path of source file containing `block`
/// @param block source code chunk containing 1 or more include statements
/// @return `block` with the include statements sorted and a blank line between user and
/// sys includes
private static String sortedIncludes(String block) {
private static String sortedIncludes(Path path, String block) {
String[] lines = block.split("\\n");
SortedSet<String> userIncludes = new TreeSet<>(sortKeyForInclude('"'));
SortedSet<String> sysIncludes = new TreeSet<>(sortKeyForInclude('<'));
List<String> blankLines = new ArrayList<>();

// Partition lines into user include, sys includes and blank lines
// From the style guide:
//
// All .inline.hpp files should include their corresponding .hpp file
// as the first include line with a blank line separating it from the
// rest of the include lines. Declarations needed by other files should
// be put in the .hpp file, and not in the .inline.hpp file. This rule
// exists to resolve problems with circular dependencies between
// .inline.hpp files.
String pathString = path.toString();
boolean isInlineHpp = pathString.endsWith(".inline.hpp");
String nonInlineHpp = pathString.replace(".inline.hpp", ".hpp");

List<String> result = new ArrayList<>(lines.length);

// Partition lines into user include and sys includes and discard blank lines
for (String line : lines) {
int doubleQuote = line.indexOf('"');
if (line.contains("\"")) {
userIncludes.add(line);
if (isInlineHpp && nonInlineHpp.endsWith(extract(line, '"', '"'))) {
result.add(line);
} else {
userIncludes.add(line);
}
} else if (line.contains("<")) {
sysIncludes.add(line);
} else if (line.isEmpty()) {
blankLines.add(line);
}
}

List<String> result = new ArrayList<>(userIncludes);
if (!userIncludes.isEmpty() && !sysIncludes.isEmpty() && blankLines.isEmpty()) {
blankLines = List.of("");
if (!result.isEmpty() && (!userIncludes.isEmpty() || !sysIncludes.isEmpty())) {
// Insert blank line between include of .hpp from .inline.hpp
// and the rest of the includes
result.add("");
}
result.addAll(userIncludes);
if (!userIncludes.isEmpty() && !sysIncludes.isEmpty()) {
// Insert blank line between user and sys includes
result.add("");
}
result.addAll(blankLines);
result.addAll(sysIncludes);

return String.join("\n", result) + "\n";
Expand All @@ -95,7 +127,7 @@ public static boolean sortIncludes(Path path, boolean update) throws IOException
if (matcher.start() != end) {
buf.append(source, end, matcher.start());
}
buf.append(sortedIncludes(matcher.group()));
buf.append(sortedIncludes(path, matcher.group()));
end = matcher.end();
}

Expand Down