Skip to content

8355638: Allow -Xlog:aot to be used as an alias for -Xlog:cds #24895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 31 additions & 1 deletion src/hotspot/share/logging/logSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ bool LogSelection::superset_of(const LogSelection& other) const {
return true;
}

// quick-and-dirty -- to be refactored properly.
int _cds_tag_specified = 0;

static LogSelection parse_internal(char *str, outputStream* errstream) {
// Parse the level, if specified
LogLevelType level = LogLevel::Unspecified;
Expand Down Expand Up @@ -166,7 +169,34 @@ static LogSelection parse_internal(char *str, outputStream* errstream) {
}
}

return LogSelection(tags, wildcard, level);
LogSelection ls = LogSelection(tags, wildcard, level);
if (ls.tag_sets_selected() == 0) {
// Make "aot" an alias for "cds. E.g.,
// -Xlog:aot -> -Xlog:cds
// -Xlog:aot+class -> -Xlog:cds+class
if (tags[0] == LogTag::_aot) {
LogTagType aliased_tags[LogTag::MaxTags];
memcpy(aliased_tags, tags, sizeof(tags));
aliased_tags[0] = LogTag::_cds;
LogSelection aliased_ls = LogSelection(aliased_tags, wildcard, level);
if (aliased_ls.tag_sets_selected() > 0) {
return aliased_ls;
}
}
} else {
if (tags[0] == LogTag::_cds) {
// If the user has specified ONLY -Xlog:aot, then all "cds" logs will be printed with an "aot" decoration.
//
// [0.022s][info][aot] full module graph: enabled
// [2.335s][debug][aot,class] klasses[ 1587] = ...
//
// For backwards compatibility (until we convert all "cds" logs to "aot" logs, if
// the user has specifed at least one log of the "cds" type, then we will
// revert to the "cds" decoration.
_cds_tag_specified ++;
}
}
return ls;
}

LogSelection LogSelection::parse(const char* str, outputStream* error_stream) {
Expand Down
29 changes: 28 additions & 1 deletion src/hotspot/share/logging/logSelectionList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

static const char* DefaultExpressionString = "all";

extern int _cds_tag_specified;

bool LogSelectionList::verify_selections(outputStream* out) const {
bool valid = true;

Expand Down Expand Up @@ -67,6 +69,8 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) {
str = DefaultExpressionString;
}
char* copy = os::strdup_check_oom(str, mtLogging);
char* injected_copy = nullptr;

// Split string on commas
for (char *comma_pos = copy, *cur = copy; success; cur = comma_pos + 1) {
if (_nselections == MaxSelections) {
Expand All @@ -83,6 +87,22 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) {
*comma_pos = '\0';
}

if (strncmp(cur, "aot*", 4) == 0 && injected_copy == nullptr) {
// Special case: because -Xlog:aot* matches with (unaliased) aot logs, we
// need to inject an "cds*" tag as well.
//
// This is not necessary for -Xlog:aot+mirror*, because this will not
// match any aot logs, and the aliasing will be done inside LogSelection::parse().

size_t len = strlen(cur);
injected_copy = (char*)os::malloc(len+10, mtLogging);
strcpy(injected_copy + 1, cur);
injected_copy[0] = ','; // will be skipped
injected_copy[1] = 'c';
injected_copy[2] = 'd';
injected_copy[3] = 's';
_cds_tag_specified --;
}
LogSelection selection = LogSelection::parse(cur, errstream);
if (selection == LogSelection::Invalid) {
success = false;
Expand All @@ -91,7 +111,14 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) {
_selections[_nselections++] = selection;

if (comma_pos == nullptr) {
break;
if (injected_copy != nullptr) {
os::free(copy);
copy = injected_copy;
comma_pos = copy;
injected_copy = nullptr;
} else {
break;
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/hotspot/share/logging/logTagSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ void LogTagSet::log(const LogMessageBuffer& msg) {
}
}

extern int _cds_tag_specified;

void LogTagSet::label(outputStream* st, const char* separator) const {
for (size_t i = 0; i < _ntags; i++) {
size_t i = 0;
if (_ntags > 0 && _tag[0] == LogTag::_cds && _cds_tag_specified == 0) {
st->print("%s", "aot");
i++;
}

for (; i < _ntags; i++) {
st->print("%s%s", (i == 0 ? "" : separator), LogTag::name(_tag[i]));
}
}
Expand Down