diff --git a/src/hotspot/share/logging/logSelection.cpp b/src/hotspot/share/logging/logSelection.cpp index 476fdebc9c540..ef863c292f23b 100644 --- a/src/hotspot/share/logging/logSelection.cpp +++ b/src/hotspot/share/logging/logSelection.cpp @@ -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; @@ -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) { diff --git a/src/hotspot/share/logging/logSelectionList.cpp b/src/hotspot/share/logging/logSelectionList.cpp index f8c2d9e7cfb69..695f254cfc1b7 100644 --- a/src/hotspot/share/logging/logSelectionList.cpp +++ b/src/hotspot/share/logging/logSelectionList.cpp @@ -28,6 +28,8 @@ static const char* DefaultExpressionString = "all"; +extern int _cds_tag_specified; + bool LogSelectionList::verify_selections(outputStream* out) const { bool valid = true; @@ -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) { @@ -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; @@ -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; + } } } diff --git a/src/hotspot/share/logging/logTagSet.cpp b/src/hotspot/share/logging/logTagSet.cpp index f7b0e01331c91..d12d382123f13 100644 --- a/src/hotspot/share/logging/logTagSet.cpp +++ b/src/hotspot/share/logging/logTagSet.cpp @@ -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])); } }