From 8ed2bf5076deb7b33bbee04e6490429249a002f5 Mon Sep 17 00:00:00 2001 From: iklam Date: Fri, 25 Apr 2025 22:56:15 -0700 Subject: [PATCH 01/15] 8355638: Allow -Xlog:aot to be used as an alias for -Xlog:cds --- src/hotspot/share/logging/logSelection.cpp | 32 ++++++++++++++++++- .../share/logging/logSelectionList.cpp | 23 ++++++++++++- src/hotspot/share/logging/logTagSet.cpp | 10 +++++- 3 files changed, 62 insertions(+), 3 deletions(-) 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..331be3e440522 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* extra_copy = nullptr; + // Split string on commas for (char *comma_pos = copy, *cur = copy; success; cur = comma_pos + 1) { if (_nselections == MaxSelections) { @@ -83,6 +87,16 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { *comma_pos = '\0'; } + if (strncmp(cur, "aot*", 4) == 0 && extra_copy == nullptr) { + size_t len = strlen(cur); + extra_copy = (char*)os::malloc(len+10, mtLogging); + strcpy(extra_copy + 1, cur); + extra_copy[0] = ','; + extra_copy[1] = 'c'; + extra_copy[2] = 'd'; + extra_copy[3] = 's'; + _cds_tag_specified --; + } LogSelection selection = LogSelection::parse(cur, errstream); if (selection == LogSelection::Invalid) { success = false; @@ -91,7 +105,14 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { _selections[_nselections++] = selection; if (comma_pos == nullptr) { - break; + if (extra_copy != nullptr) { + os::free(copy); + copy = extra_copy; + comma_pos = copy; + extra_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])); } } From cedc5dbf333e11818af79b9dedc35b2c156ebed4 Mon Sep 17 00:00:00 2001 From: iklam Date: Fri, 25 Apr 2025 23:00:38 -0700 Subject: [PATCH 02/15] update --- .../share/logging/logSelectionList.cpp | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/hotspot/share/logging/logSelectionList.cpp b/src/hotspot/share/logging/logSelectionList.cpp index 331be3e440522..695f254cfc1b7 100644 --- a/src/hotspot/share/logging/logSelectionList.cpp +++ b/src/hotspot/share/logging/logSelectionList.cpp @@ -69,7 +69,7 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { str = DefaultExpressionString; } char* copy = os::strdup_check_oom(str, mtLogging); - char* extra_copy = nullptr; + char* injected_copy = nullptr; // Split string on commas for (char *comma_pos = copy, *cur = copy; success; cur = comma_pos + 1) { @@ -87,14 +87,20 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { *comma_pos = '\0'; } - if (strncmp(cur, "aot*", 4) == 0 && extra_copy == nullptr) { + 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); - extra_copy = (char*)os::malloc(len+10, mtLogging); - strcpy(extra_copy + 1, cur); - extra_copy[0] = ','; - extra_copy[1] = 'c'; - extra_copy[2] = 'd'; - extra_copy[3] = 's'; + 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); @@ -105,11 +111,11 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { _selections[_nselections++] = selection; if (comma_pos == nullptr) { - if (extra_copy != nullptr) { + if (injected_copy != nullptr) { os::free(copy); - copy = extra_copy; + copy = injected_copy; comma_pos = copy; - extra_copy = nullptr; + injected_copy = nullptr; } else { break; } From 30f2ce6801dc020b026793f7da28c971088653a3 Mon Sep 17 00:00:00 2001 From: iklam Date: Tue, 6 May 2025 10:34:01 -0700 Subject: [PATCH 03/15] Simplified design/implementation: aliasing will always happen with new workflow; added PrintCDSLogsAsAOTLogs diagnostic flag --- src/hotspot/share/cds/cdsConfig.cpp | 7 +++- src/hotspot/share/cds/cds_globals.hpp | 3 ++ src/hotspot/share/logging/logSelection.cpp | 39 +++++++++---------- src/hotspot/share/logging/logSelection.hpp | 4 +- .../share/logging/logSelectionList.cpp | 16 +++++--- src/hotspot/share/logging/logTagSet.cpp | 8 ++-- 6 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/hotspot/share/cds/cdsConfig.cpp b/src/hotspot/share/cds/cdsConfig.cpp index 64ad07b0cf816..5ecbcd683169d 100644 --- a/src/hotspot/share/cds/cdsConfig.cpp +++ b/src/hotspot/share/cds/cdsConfig.cpp @@ -403,7 +403,12 @@ void CDSConfig::check_aot_flags() { CHECK_SINGLE_PATH(AOTConfiguration); if (FLAG_IS_DEFAULT(AOTCache) && FLAG_IS_DEFAULT(AOTConfiguration) && FLAG_IS_DEFAULT(AOTMode)) { - // AOTCache/AOTConfiguration/AOTMode not used. + // AOTCache/AOTConfiguration/AOTMode not used -> using the "classic CDS" workflow. + + // The old "cds" log tags are deprecated, but we keep printing them for now as [cds] + // for the classic workflow to be backwards compatible with older script. This will be + // removed as part of JDK-XXXXXXX. + PrintCDSLogsAsAOTLogs = false; return; } else { _new_aot_flags_used = true; diff --git a/src/hotspot/share/cds/cds_globals.hpp b/src/hotspot/share/cds/cds_globals.hpp index 2dae9b452212e..ecda3d32d28d0 100644 --- a/src/hotspot/share/cds/cds_globals.hpp +++ b/src/hotspot/share/cds/cds_globals.hpp @@ -99,6 +99,9 @@ "do not map the archive") \ range(0, 2) \ \ + product(bool, PrintCDSLogsAsAOTLogs, true, DIAGNOSTIC, \ + "Print [cds] logs as [aot] logs when AOT cache is used") \ + \ /*========== New "AOT" flags =========================================*/ \ /* The following 3 flags are aliases of -Xshare:dump, */ \ /* -XX:SharedArchiveFile=..., etc. See CDSConfig::check_flag_aliases()*/ \ diff --git a/src/hotspot/share/logging/logSelection.cpp b/src/hotspot/share/logging/logSelection.cpp index ef863c292f23b..a4a31435c271d 100644 --- a/src/hotspot/share/logging/logSelection.cpp +++ b/src/hotspot/share/logging/logSelection.cpp @@ -21,6 +21,8 @@ * questions. * */ + +#include "cds/cds_globals.hpp" #include "jvm_io.h" #include "logging/log.hpp" #include "logging/logSelection.hpp" @@ -85,9 +87,6 @@ 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; @@ -169,39 +168,37 @@ static LogSelection parse_internal(char *str, outputStream* errstream) { } } - LogSelection ls = LogSelection(tags, wildcard, level); - if (ls.tag_sets_selected() == 0) { + return LogSelection(tags, wildcard, level); +} + +#if INCLUDE_CDS +LogSelection LogSelection::translate_aot_tag_aliases() const { + if (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) { + if (_tags[0] == LogTag::_aot) { LogTagType aliased_tags[LogTag::MaxTags]; - memcpy(aliased_tags, tags, sizeof(tags)); + memcpy(aliased_tags, _tags, sizeof(_tags)); aliased_tags[0] = LogTag::_cds; - LogSelection aliased_ls = LogSelection(aliased_tags, wildcard, level); + 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; + return *this; } +#endif LogSelection LogSelection::parse(const char* str, outputStream* error_stream) { char* copy = os::strdup_check_oom(str, mtLogging); LogSelection s = parse_internal(copy, error_stream); +#if INCLUDE_CDS + if (PrintCDSLogsAsAOTLogs) { + s = s.translate_aot_tag_aliases(); + } +#endif os::free(copy); return s; } diff --git a/src/hotspot/share/logging/logSelection.hpp b/src/hotspot/share/logging/logSelection.hpp index 4555590295a5d..988868712a23c 100644 --- a/src/hotspot/share/logging/logSelection.hpp +++ b/src/hotspot/share/logging/logSelection.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,6 +44,8 @@ class LogSelection : public StackObj { LogSelection(); + LogSelection translate_aot_tag_aliases() const; + public: static const LogSelection Invalid; diff --git a/src/hotspot/share/logging/logSelectionList.cpp b/src/hotspot/share/logging/logSelectionList.cpp index 695f254cfc1b7..20f01e68d48a9 100644 --- a/src/hotspot/share/logging/logSelectionList.cpp +++ b/src/hotspot/share/logging/logSelectionList.cpp @@ -22,14 +22,13 @@ * */ +#include "cds/cds_globals.hpp" #include "logging/logSelectionList.hpp" #include "logging/logTagSet.hpp" #include "runtime/os.hpp" static const char* DefaultExpressionString = "all"; -extern int _cds_tag_specified; - bool LogSelectionList::verify_selections(outputStream* out) const { bool valid = true; @@ -69,7 +68,7 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { str = DefaultExpressionString; } char* copy = os::strdup_check_oom(str, mtLogging); - char* injected_copy = nullptr; + CDS_ONLY(char* injected_copy = nullptr); // Split string on commas for (char *comma_pos = copy, *cur = copy; success; cur = comma_pos + 1) { @@ -87,7 +86,8 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { *comma_pos = '\0'; } - if (strncmp(cur, "aot*", 4) == 0 && injected_copy == nullptr) { +#if INCLUDE_CDS + if (PrintCDSLogsAsAOTLogs && 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. // @@ -101,8 +101,9 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { injected_copy[1] = 'c'; injected_copy[2] = 'd'; injected_copy[3] = 's'; - _cds_tag_specified --; } +#endif + LogSelection selection = LogSelection::parse(cur, errstream); if (selection == LogSelection::Invalid) { success = false; @@ -111,12 +112,15 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { _selections[_nselections++] = selection; if (comma_pos == nullptr) { +#if INCLUDE_CDS if (injected_copy != nullptr) { os::free(copy); copy = injected_copy; comma_pos = copy; injected_copy = nullptr; - } else { + } else +#endif + { break; } } diff --git a/src/hotspot/share/logging/logTagSet.cpp b/src/hotspot/share/logging/logTagSet.cpp index d12d382123f13..e0b45523c62a4 100644 --- a/src/hotspot/share/logging/logTagSet.cpp +++ b/src/hotspot/share/logging/logTagSet.cpp @@ -21,6 +21,8 @@ * questions. * */ + +#include "cds/cds_globals.hpp" #include "jvm.h" #include "logging/logAsyncWriter.hpp" #include "logging/logDecorations.hpp" @@ -93,14 +95,14 @@ void LogTagSet::log(const LogMessageBuffer& msg) { } } -extern int _cds_tag_specified; - void LogTagSet::label(outputStream* st, const char* separator) const { size_t i = 0; - if (_ntags > 0 && _tag[0] == LogTag::_cds && _cds_tag_specified == 0) { +#if INCLUDE_CDS + if (PrintCDSLogsAsAOTLogs && _ntags > 0 && _tag[0] == LogTag::_cds) { st->print("%s", "aot"); i++; } +#endif for (; i < _ntags; i++) { st->print("%s%s", (i == 0 ? "" : separator), LogTag::name(_tag[i])); From 267fdc80c88c6fb611b9a42d8593da6f0c64c5f7 Mon Sep 17 00:00:00 2001 From: iklam Date: Tue, 6 May 2025 12:07:31 -0700 Subject: [PATCH 04/15] Added LogTagSet::verify_for_aot_aliases() --- .../share/logging/logConfiguration.cpp | 2 + src/hotspot/share/logging/logSelection.cpp | 26 +++++----- src/hotspot/share/logging/logTagSet.cpp | 48 +++++++++++++++++++ src/hotspot/share/logging/logTagSet.hpp | 4 +- 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/hotspot/share/logging/logConfiguration.cpp b/src/hotspot/share/logging/logConfiguration.cpp index 662c1f1c2bb79..a9a34297fed07 100644 --- a/src/hotspot/share/logging/logConfiguration.cpp +++ b/src/hotspot/share/logging/logConfiguration.cpp @@ -101,6 +101,8 @@ void LogConfiguration::post_initialize() { ConfigurationLock cl; describe_current_configuration(&info_stream); } + + LogTagSet::verify_for_aot_aliases(); } void LogConfiguration::initialize(jlong vm_start_time) { diff --git a/src/hotspot/share/logging/logSelection.cpp b/src/hotspot/share/logging/logSelection.cpp index a4a31435c271d..6029dc7cca771 100644 --- a/src/hotspot/share/logging/logSelection.cpp +++ b/src/hotspot/share/logging/logSelection.cpp @@ -173,18 +173,20 @@ static LogSelection parse_internal(char *str, outputStream* errstream) { #if INCLUDE_CDS LogSelection LogSelection::translate_aot_tag_aliases() const { - if (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; - } + if (tag_sets_selected() == 0 && _tags[0] == LogTag::_aot) { + // LogTagSet::verify_for_aot_aliases() has already verified that there are no overlaps + // in the aot vs cds LogSets: + // if (cds) exists, then (aot) must not exist. + // if (cds,foo) exists, then (aot,foo) must not exist. + // + // We come here if the user is asking -Xlog:aot or -Xlog:aot+foo. Let's see if we can + // translate to -Xlog:cds or -Xlog:cds+foo + 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; } } return *this; diff --git a/src/hotspot/share/logging/logTagSet.cpp b/src/hotspot/share/logging/logTagSet.cpp index e0b45523c62a4..97fd99381cc5b 100644 --- a/src/hotspot/share/logging/logTagSet.cpp +++ b/src/hotspot/share/logging/logTagSet.cpp @@ -34,6 +34,7 @@ #include "logging/logTagSet.hpp" #include "logging/logTagSetDescriptions.hpp" #include "memory/allocation.inline.hpp" +#include "memory/resourceArea.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/ostream.hpp" @@ -226,3 +227,50 @@ void LogTagSet::list_all_tagsets(outputStream* out) { out->cr(); FREE_C_HEAP_ARRAY(char*, tagset_labels); } + +void LogTagSet::verify_for_aot_aliases() { +#if !defined(PRODUCT) && INCLUDE_CDS + // If we had both log_info(cds, abc) and log_info(aot, abc) in the C++ code, it would make + // LogSelection::translate_aot_tag_aliases() more complicated. We scan all the LogTagSets + // that are used in the C++ code to make sure we don't have such combinations. + + // Rule: if we have a LogTagSet that starts with cds, then we cannot have another LogTagSet + // that starts with aot, where the rest of the tags of the two LogTagSets are the same. + // + // Uncomment one or more of the following lines to test the verification code. All cases are + // forbidden. + // + // log_info(aot, heap)("bad"); + // log_info(aot)("bad"); + + for (LogTagSet* x = first(); x != nullptr; x = x->next()) { + if (x->tag(0) == LogTag::_cds) { + for (LogTagSet* y = first(); y != nullptr; y = y->next()) { + if (y->tag(0) == LogTag::_aot && x->ntags() == y->ntags()) { + bool same = true; + for (size_t i = 1; i < x->ntags(); i++) { + if (x->tag(i) != y->tag(i)) { + same = false; + break; + } + } + if (same) { + ResourceMark rm; + PrintCDSLogsAsAOTLogs = false; + stringStream ss; + ss.print("Limitation: in C++ logging code, you cannot use both of these two log sets: "); + ss.print("("); + x->label(&ss); + ss.print("), and ("); + y->label(&ss); + ss.print("). They must all start with 'cds', or all start with 'aot'"); + fatal("%s", ss.freeze()); + } + } + } + } + } +#endif +} + + diff --git a/src/hotspot/share/logging/logTagSet.hpp b/src/hotspot/share/logging/logTagSet.hpp index f8b37e1a777c3..bfeca62600a20 100644 --- a/src/hotspot/share/logging/logTagSet.hpp +++ b/src/hotspot/share/logging/logTagSet.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,6 +30,7 @@ #include "logging/logPrefix.hpp" #include "logging/logTag.hpp" #include "utilities/globalDefinitions.hpp" +#include "utilities/macros.hpp" class LogMessageBuffer; @@ -66,6 +67,7 @@ class LogTagSet { public: static void describe_tagsets(outputStream* out); static void list_all_tagsets(outputStream* out); + static void verify_for_aot_aliases() PRODUCT_RETURN; void wait_until_no_readers() const { _output_list.wait_until_no_readers(); From ad6abfc5679be09fd6aa7e6fe62a6d0bb0a492ea Mon Sep 17 00:00:00 2001 From: iklam Date: Tue, 6 May 2025 12:43:37 -0700 Subject: [PATCH 05/15] More tightening .... but this may be the wrong approach --- .../share/logging/logSelectionList.cpp | 53 +++++++++---------- src/hotspot/share/logging/logTagSet.cpp | 21 ++++---- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/hotspot/share/logging/logSelectionList.cpp b/src/hotspot/share/logging/logSelectionList.cpp index 20f01e68d48a9..f5023be359cec 100644 --- a/src/hotspot/share/logging/logSelectionList.cpp +++ b/src/hotspot/share/logging/logSelectionList.cpp @@ -68,8 +68,6 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { str = DefaultExpressionString; } char* copy = os::strdup_check_oom(str, mtLogging); - CDS_ONLY(char* injected_copy = nullptr); - // Split string on commas for (char *comma_pos = copy, *cur = copy; success; cur = comma_pos + 1) { if (_nselections == MaxSelections) { @@ -86,43 +84,42 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { *comma_pos = '\0'; } + LogSelection selection = LogSelection::parse(cur, errstream); + if (selection == LogSelection::Invalid) { + success = false; + break; + } + _selections[_nselections++] = selection; + #if INCLUDE_CDS - if (PrintCDSLogsAsAOTLogs && strncmp(cur, "aot*", 4) == 0 && injected_copy == nullptr) { + if (PrintCDSLogsAsAOTLogs && strncmp(cur, "aot*", 4) == 0) { // 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(). + // match any aot logs (guarateed by LogTagSet::verify_for_aot_aliases()). + // The alias matching 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'; - } -#endif + char* alias = (char*)os::malloc(len + 1, mtLogging); + strcpy(alias, cur); + alias[0] = 'c'; + alias[1] = 'd'; + alias[2] = 's'; - LogSelection selection = LogSelection::parse(cur, errstream); - if (selection == LogSelection::Invalid) { - success = false; - break; - } - _selections[_nselections++] = selection; + selection = LogSelection::parse(alias, errstream); + os::free(alias); - if (comma_pos == nullptr) { -#if INCLUDE_CDS - if (injected_copy != nullptr) { - os::free(copy); - copy = injected_copy; - comma_pos = copy; - injected_copy = nullptr; - } else -#endif - { + if (selection == LogSelection::Invalid) { + success = false; break; } + _selections[_nselections++] = selection; + } +#endif + + if (comma_pos == nullptr) { + break; } } diff --git a/src/hotspot/share/logging/logTagSet.cpp b/src/hotspot/share/logging/logTagSet.cpp index 97fd99381cc5b..fe4eccb98c5e8 100644 --- a/src/hotspot/share/logging/logTagSet.cpp +++ b/src/hotspot/share/logging/logTagSet.cpp @@ -234,8 +234,10 @@ void LogTagSet::verify_for_aot_aliases() { // LogSelection::translate_aot_tag_aliases() more complicated. We scan all the LogTagSets // that are used in the C++ code to make sure we don't have such combinations. - // Rule: if we have a LogTagSet that starts with cds, then we cannot have another LogTagSet - // that starts with aot, where the rest of the tags of the two LogTagSets are the same. + // Rules: + // [1] The stand-alone Tagset (aot) must not be used. + // [2] If we have a LogTagSet that starts with cds, then we cannot have another LogTagSet + // that starts with aot, where the second tag of both LogTagSets are the same. // // Uncomment one or more of the following lines to test the verification code. All cases are // forbidden. @@ -246,15 +248,14 @@ void LogTagSet::verify_for_aot_aliases() { for (LogTagSet* x = first(); x != nullptr; x = x->next()) { if (x->tag(0) == LogTag::_cds) { for (LogTagSet* y = first(); y != nullptr; y = y->next()) { - if (y->tag(0) == LogTag::_aot && x->ntags() == y->ntags()) { - bool same = true; - for (size_t i = 1; i < x->ntags(); i++) { - if (x->tag(i) != y->tag(i)) { - same = false; - break; - } + if (y->tag(0) == LogTag::_aot) { + bool bad = 0; + if (x->ntags() == 1 && y->ntags() == 1) { + bad = true; + } else if (x->ntags() > 1 && y->ntags() > 1 && x->tag(1) == y->tag(1)) { + bad = true; } - if (same) { + if (bad) { ResourceMark rm; PrintCDSLogsAsAOTLogs = false; stringStream ss; From 4a520a578695d6d37275fa4f254c78d93175a735 Mon Sep 17 00:00:00 2001 From: iklam Date: Tue, 6 May 2025 12:55:30 -0700 Subject: [PATCH 06/15] Much simplified --- .../share/logging/logConfiguration.cpp | 2 - src/hotspot/share/logging/logSelection.cpp | 29 ----------- src/hotspot/share/logging/logSelection.hpp | 4 +- .../share/logging/logSelectionList.cpp | 23 +++++---- src/hotspot/share/logging/logTagSet.cpp | 48 ------------------- src/hotspot/share/logging/logTagSet.hpp | 4 +- 6 files changed, 15 insertions(+), 95 deletions(-) diff --git a/src/hotspot/share/logging/logConfiguration.cpp b/src/hotspot/share/logging/logConfiguration.cpp index a9a34297fed07..662c1f1c2bb79 100644 --- a/src/hotspot/share/logging/logConfiguration.cpp +++ b/src/hotspot/share/logging/logConfiguration.cpp @@ -101,8 +101,6 @@ void LogConfiguration::post_initialize() { ConfigurationLock cl; describe_current_configuration(&info_stream); } - - LogTagSet::verify_for_aot_aliases(); } void LogConfiguration::initialize(jlong vm_start_time) { diff --git a/src/hotspot/share/logging/logSelection.cpp b/src/hotspot/share/logging/logSelection.cpp index 6029dc7cca771..476fdebc9c540 100644 --- a/src/hotspot/share/logging/logSelection.cpp +++ b/src/hotspot/share/logging/logSelection.cpp @@ -21,8 +21,6 @@ * questions. * */ - -#include "cds/cds_globals.hpp" #include "jvm_io.h" #include "logging/log.hpp" #include "logging/logSelection.hpp" @@ -171,36 +169,9 @@ static LogSelection parse_internal(char *str, outputStream* errstream) { return LogSelection(tags, wildcard, level); } -#if INCLUDE_CDS -LogSelection LogSelection::translate_aot_tag_aliases() const { - if (tag_sets_selected() == 0 && _tags[0] == LogTag::_aot) { - // LogTagSet::verify_for_aot_aliases() has already verified that there are no overlaps - // in the aot vs cds LogSets: - // if (cds) exists, then (aot) must not exist. - // if (cds,foo) exists, then (aot,foo) must not exist. - // - // We come here if the user is asking -Xlog:aot or -Xlog:aot+foo. Let's see if we can - // translate to -Xlog:cds or -Xlog:cds+foo - 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; - } - } - return *this; -} -#endif - LogSelection LogSelection::parse(const char* str, outputStream* error_stream) { char* copy = os::strdup_check_oom(str, mtLogging); LogSelection s = parse_internal(copy, error_stream); -#if INCLUDE_CDS - if (PrintCDSLogsAsAOTLogs) { - s = s.translate_aot_tag_aliases(); - } -#endif os::free(copy); return s; } diff --git a/src/hotspot/share/logging/logSelection.hpp b/src/hotspot/share/logging/logSelection.hpp index 988868712a23c..4555590295a5d 100644 --- a/src/hotspot/share/logging/logSelection.hpp +++ b/src/hotspot/share/logging/logSelection.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,8 +44,6 @@ class LogSelection : public StackObj { LogSelection(); - LogSelection translate_aot_tag_aliases() const; - public: static const LogSelection Invalid; diff --git a/src/hotspot/share/logging/logSelectionList.cpp b/src/hotspot/share/logging/logSelectionList.cpp index f5023be359cec..f7eab1bd407ea 100644 --- a/src/hotspot/share/logging/logSelectionList.cpp +++ b/src/hotspot/share/logging/logSelectionList.cpp @@ -92,14 +92,18 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { _selections[_nselections++] = selection; #if INCLUDE_CDS - if (PrintCDSLogsAsAOTLogs && strncmp(cur, "aot*", 4) == 0) { - // Special case: because -Xlog:aot* matches with (unaliased) aot logs, we - // need to inject an "cds*" tag as well. + if (PrintCDSLogsAsAOTLogs && + cur[0] == 'a' && + cur[1] == 'o' && + cur[2] == 't' && + (cur[3] < 'a' || 'z' > cur[3])) { + // If the user has specified any log that starts with "aot", try to (also) + // match any existing LogSets that start with "cds". E.g., // - // This is not necessary for -Xlog:aot+mirror*, because this will not - // match any aot logs (guarateed by LogTagSet::verify_for_aot_aliases()). - // The alias matching will be done inside LogSelection::parse(). + // -Xlog:aot*= -> -Xlog:cds*= + // -Xlog:aot+heap=debug -> -Xlog:cds+heap=debug + // We can't use resource allocation yet. Hence malloc. size_t len = strlen(cur); char* alias = (char*)os::malloc(len + 1, mtLogging); strcpy(alias, cur); @@ -110,11 +114,10 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { selection = LogSelection::parse(alias, errstream); os::free(alias); - if (selection == LogSelection::Invalid) { - success = false; - break; + if (selection != LogSelection::Invalid) { + // If we don't get any matches, that's not an error! + _selections[_nselections++] = selection; } - _selections[_nselections++] = selection; } #endif diff --git a/src/hotspot/share/logging/logTagSet.cpp b/src/hotspot/share/logging/logTagSet.cpp index fe4eccb98c5e8..9388fc78af263 100644 --- a/src/hotspot/share/logging/logTagSet.cpp +++ b/src/hotspot/share/logging/logTagSet.cpp @@ -227,51 +227,3 @@ void LogTagSet::list_all_tagsets(outputStream* out) { out->cr(); FREE_C_HEAP_ARRAY(char*, tagset_labels); } - -void LogTagSet::verify_for_aot_aliases() { -#if !defined(PRODUCT) && INCLUDE_CDS - // If we had both log_info(cds, abc) and log_info(aot, abc) in the C++ code, it would make - // LogSelection::translate_aot_tag_aliases() more complicated. We scan all the LogTagSets - // that are used in the C++ code to make sure we don't have such combinations. - - // Rules: - // [1] The stand-alone Tagset (aot) must not be used. - // [2] If we have a LogTagSet that starts with cds, then we cannot have another LogTagSet - // that starts with aot, where the second tag of both LogTagSets are the same. - // - // Uncomment one or more of the following lines to test the verification code. All cases are - // forbidden. - // - // log_info(aot, heap)("bad"); - // log_info(aot)("bad"); - - for (LogTagSet* x = first(); x != nullptr; x = x->next()) { - if (x->tag(0) == LogTag::_cds) { - for (LogTagSet* y = first(); y != nullptr; y = y->next()) { - if (y->tag(0) == LogTag::_aot) { - bool bad = 0; - if (x->ntags() == 1 && y->ntags() == 1) { - bad = true; - } else if (x->ntags() > 1 && y->ntags() > 1 && x->tag(1) == y->tag(1)) { - bad = true; - } - if (bad) { - ResourceMark rm; - PrintCDSLogsAsAOTLogs = false; - stringStream ss; - ss.print("Limitation: in C++ logging code, you cannot use both of these two log sets: "); - ss.print("("); - x->label(&ss); - ss.print("), and ("); - y->label(&ss); - ss.print("). They must all start with 'cds', or all start with 'aot'"); - fatal("%s", ss.freeze()); - } - } - } - } - } -#endif -} - - diff --git a/src/hotspot/share/logging/logTagSet.hpp b/src/hotspot/share/logging/logTagSet.hpp index bfeca62600a20..f8b37e1a777c3 100644 --- a/src/hotspot/share/logging/logTagSet.hpp +++ b/src/hotspot/share/logging/logTagSet.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,7 +30,6 @@ #include "logging/logPrefix.hpp" #include "logging/logTag.hpp" #include "utilities/globalDefinitions.hpp" -#include "utilities/macros.hpp" class LogMessageBuffer; @@ -67,7 +66,6 @@ class LogTagSet { public: static void describe_tagsets(outputStream* out); static void list_all_tagsets(outputStream* out); - static void verify_for_aot_aliases() PRODUCT_RETURN; void wait_until_no_readers() const { _output_list.wait_until_no_readers(); From ac109c39d0940074eb0b180e40cf78fd50efd792 Mon Sep 17 00:00:00 2001 From: iklam Date: Tue, 6 May 2025 13:25:15 -0700 Subject: [PATCH 07/15] Much more simplification --- src/hotspot/share/logging/logSelection.cpp | 10 +++++- .../share/logging/logSelectionList.cpp | 31 ------------------- src/hotspot/share/logging/logTagSet.cpp | 1 + 3 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/hotspot/share/logging/logSelection.cpp b/src/hotspot/share/logging/logSelection.cpp index 476fdebc9c540..018c013dfc3e5 100644 --- a/src/hotspot/share/logging/logSelection.cpp +++ b/src/hotspot/share/logging/logSelection.cpp @@ -21,6 +21,8 @@ * questions. * */ + +#include "cds/cds_globals.hpp" #include "jvm_io.h" #include "logging/log.hpp" #include "logging/logSelection.hpp" @@ -180,7 +182,13 @@ bool LogSelection::selects(const LogTagSet& ts) const { if (!_wildcard && _ntags != ts.ntags()) { return false; } - for (size_t i = 0; i < _ntags; i++) { + size_t i = 0; + if (PrintCDSLogsAsAOTLogs && _ntags > 0 && _tags[0] == LogTag::_aot && ts.tag(0) == LogTag::_cds) { + // Consider it a match + i ++; + } + + for (; i < _ntags; i++) { if (!ts.contains(_tags[i])) { return false; } diff --git a/src/hotspot/share/logging/logSelectionList.cpp b/src/hotspot/share/logging/logSelectionList.cpp index f7eab1bd407ea..f8c2d9e7cfb69 100644 --- a/src/hotspot/share/logging/logSelectionList.cpp +++ b/src/hotspot/share/logging/logSelectionList.cpp @@ -22,7 +22,6 @@ * */ -#include "cds/cds_globals.hpp" #include "logging/logSelectionList.hpp" #include "logging/logTagSet.hpp" #include "runtime/os.hpp" @@ -91,36 +90,6 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) { } _selections[_nselections++] = selection; -#if INCLUDE_CDS - if (PrintCDSLogsAsAOTLogs && - cur[0] == 'a' && - cur[1] == 'o' && - cur[2] == 't' && - (cur[3] < 'a' || 'z' > cur[3])) { - // If the user has specified any log that starts with "aot", try to (also) - // match any existing LogSets that start with "cds". E.g., - // - // -Xlog:aot*= -> -Xlog:cds*= - // -Xlog:aot+heap=debug -> -Xlog:cds+heap=debug - - // We can't use resource allocation yet. Hence malloc. - size_t len = strlen(cur); - char* alias = (char*)os::malloc(len + 1, mtLogging); - strcpy(alias, cur); - alias[0] = 'c'; - alias[1] = 'd'; - alias[2] = 's'; - - selection = LogSelection::parse(alias, errstream); - os::free(alias); - - if (selection != LogSelection::Invalid) { - // If we don't get any matches, that's not an error! - _selections[_nselections++] = selection; - } - } -#endif - if (comma_pos == nullptr) { break; } diff --git a/src/hotspot/share/logging/logTagSet.cpp b/src/hotspot/share/logging/logTagSet.cpp index 9388fc78af263..67dcf0a871c79 100644 --- a/src/hotspot/share/logging/logTagSet.cpp +++ b/src/hotspot/share/logging/logTagSet.cpp @@ -98,6 +98,7 @@ void LogTagSet::log(const LogMessageBuffer& msg) { void LogTagSet::label(outputStream* st, const char* separator) const { size_t i = 0; + #if INCLUDE_CDS if (PrintCDSLogsAsAOTLogs && _ntags > 0 && _tag[0] == LogTag::_cds) { st->print("%s", "aot"); From 88b7ea0d7ae2facd7d0fa7fa1e9cf83519beab2b Mon Sep 17 00:00:00 2001 From: iklam Date: Tue, 6 May 2025 14:06:05 -0700 Subject: [PATCH 08/15] Fixed test cases --- test/hotspot/jtreg/runtime/cds/appcds/AOTFlags.java | 4 ++-- .../appcds/aotCache/AOTCacheSupportForCustomLoaders.java | 4 ++-- .../runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java | 2 +- .../cds/appcds/aotClassLinking/FakeCodeLocation.java | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/hotspot/jtreg/runtime/cds/appcds/AOTFlags.java b/test/hotspot/jtreg/runtime/cds/appcds/AOTFlags.java index 46f76fab36859..3dc94fe0d955d 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/AOTFlags.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/AOTFlags.java @@ -74,7 +74,7 @@ static void positiveTests() throws Exception { "-cp", appJar); out = CDSTestUtils.executeAndLog(pb, "asm"); out.shouldContain("Dumping shared data to file:"); - out.shouldMatch("cds.*hello[.]aot"); + out.shouldMatch("hello[.]aot"); out.shouldHaveExitValue(0); //---------------------------------------------------------------------- @@ -142,7 +142,7 @@ static void positiveTests() throws Exception { "-cp", appJar); out = CDSTestUtils.executeAndLog(pb, "asm"); out.shouldContain("Dumping shared data to file:"); - out.shouldMatch("cds.*hello[.]aot"); + out.shouldMatch("hello[.]aot"); out.shouldHaveExitValue(0); //---------------------------------------------------------------------- diff --git a/test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTCacheSupportForCustomLoaders.java b/test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTCacheSupportForCustomLoaders.java index dabc35a46049f..6160f5f754eac 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTCacheSupportForCustomLoaders.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTCacheSupportForCustomLoaders.java @@ -49,8 +49,8 @@ public static void main(String... args) throws Exception { .addVmArgs("-Xlog:cds+class=debug", "-Xlog:cds") .appCommandLine("AppWithCustomLoaders") .setAssemblyChecker((OutputAnalyzer out) -> { - out.shouldMatch("cds,class.*unreg AppWithCustomLoaders[$]MyLoadeeA") - .shouldMatch("cds,class.*array \\[LAppWithCustomLoaders[$]MyLoadeeA;"); + out.shouldMatch(",class.*unreg AppWithCustomLoaders[$]MyLoadeeA") + .shouldMatch(",class.*array \\[LAppWithCustomLoaders[$]MyLoadeeA;"); }) .setProductionChecker((OutputAnalyzer out) -> { out.shouldContain("Using AOT-linked classes: true"); diff --git a/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java b/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java index aa34f4799366f..f6a3b32a9e2ce 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java @@ -158,7 +158,7 @@ public void checkExecution(OutputAnalyzer out, RunMode runMode) throws Exception if (isDumping(runMode)) { // Check that we are archiving classes for custom class loaders. - out.shouldMatch("cds,class.* SimpleCusty"); + out.shouldMatch(",class.* SimpleCusty"); } } } diff --git a/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/FakeCodeLocation.java b/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/FakeCodeLocation.java index 5bec6623a08d8..8c2539df6210d 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/FakeCodeLocation.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/FakeCodeLocation.java @@ -94,9 +94,9 @@ public String[] appCommandLine(RunMode runMode) { @Override public void checkExecution(OutputAnalyzer out, RunMode runMode) throws Exception { if (isDumping(runMode)) { - out.shouldMatch("cds,class.* FakeCodeLocationApp"); - out.shouldNotMatch("cds,class.* ClassNotInJar1"); - out.shouldNotMatch("cds,class.* ClassNotInJar2"); + out.shouldMatch(",class.* FakeCodeLocationApp"); + out.shouldNotMatch(",class.* ClassNotInJar1"); + out.shouldNotMatch(",class.* ClassNotInJar2"); } if (runMode.isProductionRun()) { From 43bdeac3f497fba6abfe15fa015d3702dc896fd7 Mon Sep 17 00:00:00 2001 From: iklam Date: Tue, 6 May 2025 14:42:14 -0700 Subject: [PATCH 09/15] clean up of existing UL logs for cds --- src/hotspot/share/cds/aotClassLinker.cpp | 8 +- .../share/cds/aotLinkedClassBulkLoader.cpp | 14 +- src/hotspot/share/cds/filemap.cpp | 10 +- src/hotspot/share/cds/metaspaceShared.cpp | 3 +- .../cds/appcds/aotCache/AOTLoggingTag.java | 125 ++++++++++++++++++ 5 files changed, 146 insertions(+), 14 deletions(-) create mode 100644 test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTLoggingTag.java diff --git a/src/hotspot/share/cds/aotClassLinker.cpp b/src/hotspot/share/cds/aotClassLinker.cpp index dc539eb3d553f..28159e813049d 100644 --- a/src/hotspot/share/cds/aotClassLinker.cpp +++ b/src/hotspot/share/cds/aotClassLinker.cpp @@ -117,9 +117,9 @@ void AOTClassLinker::add_new_candidate(InstanceKlass* ik) { _candidates->put_when_absent(ik, true); _sorted_candidates->append(ik); - if (log_is_enabled(Info, cds, aot, link)) { + if (log_is_enabled(Info, aot, link)) { ResourceMark rm; - log_info(cds, aot, link)("%s %s %p", class_category_name(ik), ik->external_name(), ik); + log_info(aot, link)("%s %s %p", class_category_name(ik), ik->external_name(), ik); } } @@ -149,7 +149,7 @@ bool AOTClassLinker::try_add_candidate(InstanceKlass* ik) { InstanceKlass* nest_host = ik->nest_host_not_null(); if (!try_add_candidate(nest_host)) { ResourceMark rm; - log_warning(cds, aot, link)("%s cannot be aot-linked because it nest host is not aot-linked", ik->external_name()); + log_warning(aot, link)("%s cannot be aot-linked because it nest host is not aot-linked", ik->external_name()); return false; } } @@ -232,7 +232,7 @@ Array* AOTClassLinker::write_classes(oop class_loader, bool is_j return nullptr; } else { const char* category = class_category_name(list.at(0)); - log_info(cds, aot, link)("wrote %d class(es) for category %s", list.length(), category); + log_info(aot, link)("wrote %d class(es) for category %s", list.length(), category); return ArchiveUtils::archive_array(&list); } } diff --git a/src/hotspot/share/cds/aotLinkedClassBulkLoader.cpp b/src/hotspot/share/cds/aotLinkedClassBulkLoader.cpp index 31d95024e3bfd..0c4e07d332805 100644 --- a/src/hotspot/share/cds/aotLinkedClassBulkLoader.cpp +++ b/src/hotspot/share/cds/aotLinkedClassBulkLoader.cpp @@ -179,11 +179,11 @@ void AOTLinkedClassBulkLoader::load_classes_impl(AOTLinkedClassCategory class_ca for (int i = 0; i < classes->length(); i++) { InstanceKlass* ik = classes->at(i); - if (log_is_enabled(Info, cds, aot, load)) { + if (log_is_enabled(Info, aot, load)) { ResourceMark rm(THREAD); - log_info(cds, aot, load)("%-5s %s%s%s", category_name, ik->external_name(), - ik->is_loaded() ? " (already loaded)" : "", - ik->is_hidden() ? " (hidden)" : ""); + log_info(aot, load)("%-5s %s%s%s", category_name, ik->external_name(), + ik->is_loaded() ? " (already loaded)" : "", + ik->is_hidden() ? " (hidden)" : ""); } if (!ik->is_loaded()) { @@ -236,11 +236,11 @@ void AOTLinkedClassBulkLoader::initiate_loading(JavaThread* current, const char* assert(ik->class_loader() == nullptr || ik->class_loader() == SystemDictionary::java_platform_loader(), "must be"); if (ik->is_public() && !ik->is_hidden()) { - if (log_is_enabled(Info, cds, aot, load)) { + if (log_is_enabled(Info, aot, load)) { ResourceMark rm(current); const char* defining_loader = (ik->class_loader() == nullptr ? "boot" : "plat"); - log_info(cds, aot, load)("%s %s (initiated, defined by %s)", category_name, ik->external_name(), - defining_loader); + log_info(aot, load)("%s %s (initiated, defined by %s)", category_name, ik->external_name(), + defining_loader); } SystemDictionary::add_to_initiating_loader(current, ik, loader_data); } diff --git a/src/hotspot/share/cds/filemap.cpp b/src/hotspot/share/cds/filemap.cpp index ff537ef96d668..2a95fe4c36763 100644 --- a/src/hotspot/share/cds/filemap.cpp +++ b/src/hotspot/share/cds/filemap.cpp @@ -1815,10 +1815,16 @@ bool FileMapInfo::open_as_input() { if (!open_for_read() || !init_from_file(_fd) || !validate_header()) { if (_is_static) { - MetaspaceShared::report_loading_error("Loading static archive failed."); + if (CDSConfig::is_dumping_final_static_archive()) { + MetaspaceShared::report_loading_error("Loading AOT configuration failed: %s", _full_path); + } else if (CDSConfig::new_aot_flags_used()) { + MetaspaceShared::report_loading_error("Loading AOT cache failed: %s", _full_path); + } else { + MetaspaceShared::report_loading_error("Loading static archive failed: %s", _full_path); + } return false; } else { - MetaspaceShared::report_loading_error("Loading dynamic archive failed."); + MetaspaceShared::report_loading_error("Loading dynamic archive failed: %s", _full_path); if (AutoCreateSharedArchive) { CDSConfig::enable_dumping_dynamic_archive(_full_path); } diff --git a/src/hotspot/share/cds/metaspaceShared.cpp b/src/hotspot/share/cds/metaspaceShared.cpp index 654c2e7ecd780..9b5ba681926ed 100644 --- a/src/hotspot/share/cds/metaspaceShared.cpp +++ b/src/hotspot/share/cds/metaspaceShared.cpp @@ -1141,7 +1141,8 @@ void MetaspaceShared::report_loading_error(const char* format, ...) { static bool printed_error = false; if (!printed_error) { // No need for locks. Loading error checks happen only in main thread. - ls.print_cr("An error has occurred while processing the %s. Run with -Xlog:cds for details.", CDSConfig::type_of_archive_being_loaded()); + ls.print_cr("An error has occurred while processing the %s. Run with -Xlog:%s for details.", + CDSConfig::type_of_archive_being_loaded(), PrintCDSLogsAsAOTLogs ? "aot" : "cds"); printed_error = true; } diff --git a/test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTLoggingTag.java b/test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTLoggingTag.java new file mode 100644 index 0000000000000..8e4168778f21b --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTLoggingTag.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + + +/* + * @test + * @summary when AOT cache options are used, old "cds" logs should be aliased to "aot". + * @requires vm.cds + * @requires vm.flagless + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes + * @build Hello + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar hello.jar Hello + * @run driver AOTLoggingTag + */ + +import java.io.File; +import jdk.test.lib.cds.CDSTestUtils; +import jdk.test.lib.helpers.ClassFileInstaller; +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +public class AOTLoggingTag { + static String appJar = ClassFileInstaller.getJarPath("hello.jar"); + static String aotConfigFile = "hello.aotconfig"; + static String aotCacheFile = "hello.aot"; + static String helloClass = "Hello"; + + public static void main(String[] args) throws Exception { + ProcessBuilder pb; + OutputAnalyzer out; + + //---------------------------------------------------------------------- + printTestCase("Training Run"); + pb = ProcessTools.createLimitedTestJavaProcessBuilder( + "-XX:AOTMode=record", + "-XX:AOTConfiguration=" + aotConfigFile, + "-Xlog:aot", + "-cp", appJar, helloClass); + + out = CDSTestUtils.executeAndLog(pb, "train"); + out.shouldContain("[info][aot] Writing binary AOTConfiguration file:"); + out.shouldHaveExitValue(0); + + //---------------------------------------------------------------------- + printTestCase("Assembly Phase"); + pb = ProcessTools.createLimitedTestJavaProcessBuilder( + "-XX:AOTMode=create", + "-XX:AOTConfiguration=" + aotConfigFile, + "-XX:AOTCache=" + aotCacheFile, + "-Xlog:aot", + "-cp", appJar); + out = CDSTestUtils.executeAndLog(pb, "asm"); + out.shouldContain("[info][aot] Opened AOT configuration file hello.aotconfig"); + out.shouldHaveExitValue(0); + + //---------------------------------------------------------------------- + printTestCase("Production Run with AOTCache"); + pb = ProcessTools.createLimitedTestJavaProcessBuilder( + "-XX:AOTCache=" + aotCacheFile, + "-Xlog:aot", + "-cp", appJar, helloClass); + out = CDSTestUtils.executeAndLog(pb, "prod"); + out.shouldContain("[info][aot] Opened AOT cache hello.aot"); + out.shouldHaveExitValue(0); + + //---------------------------------------------------------------------- + printTestCase("-Xlog:aot+heap should alias to -Xlog:cds+heap"); + pb = ProcessTools.createLimitedTestJavaProcessBuilder( + "-XX:AOTCache=" + aotCacheFile, + "-Xlog:aot+heap", + "-cp", appJar, helloClass); + out = CDSTestUtils.executeAndLog(pb, "prod"); + out.shouldNotContain("No tag set matches selection: aot+heap"); + out.shouldContain("[info][aot,heap] resolve subgraph java.lang.Integer$IntegerCache"); + out.shouldHaveExitValue(0); + + //---------------------------------------------------------------------- + printTestCase("When running with AOT cache, -Xlog:cds should be printed using [aot] decoration"); + pb = ProcessTools.createLimitedTestJavaProcessBuilder( + "-XX:AOTCache=" + aotCacheFile, + "-Xlog:cds", + "-cp", appJar, helloClass); + out = CDSTestUtils.executeAndLog(pb, "prod"); + out.shouldContain("[info][aot] Opened AOT cache hello.aot"); + out.shouldHaveExitValue(0); + + //---------------------------------------------------------------------- + printTestCase("Production Run: errors should be printed with [aot] decoration"); + pb = ProcessTools.createLimitedTestJavaProcessBuilder( + "-XX:AOTCache=nosuchfile.aot", + "-XX:AOTMode=on", + "-cp", appJar, helloClass); + out = CDSTestUtils.executeAndLog(pb, "prod"); + out.shouldContain("[error][aot] An error has occurred while processing the AOT cache. Run with -Xlog:aot for details."); + out.shouldContain("[error][aot] Loading AOT cache failed: nosuchfile.aot"); + out.shouldNotHaveExitValue(0); + } + + static int testNum = 0; + static void printTestCase(String s) { + System.out.println("vvvvvvv TEST CASE " + testNum + ": " + s + " starts here vvvvvvv"); + testNum++; + } +} From 15a87cef87de52ce9d2d89d46d3019962e6d3957 Mon Sep 17 00:00:00 2001 From: iklam Date: Tue, 6 May 2025 17:40:46 -0700 Subject: [PATCH 10/15] Fixed comment --- src/hotspot/share/cds/cdsConfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/cds/cdsConfig.cpp b/src/hotspot/share/cds/cdsConfig.cpp index 788a2c4312b7d..9224e877dce48 100644 --- a/src/hotspot/share/cds/cdsConfig.cpp +++ b/src/hotspot/share/cds/cdsConfig.cpp @@ -411,7 +411,7 @@ void CDSConfig::check_aot_flags() { // The old "cds" log tags are deprecated, but we keep printing them for now as [cds] // for the classic workflow to be backwards compatible with older script. This will be - // removed as part of JDK-XXXXXXX. + // removed as part of JDK-8356317. PrintCDSLogsAsAOTLogs = false; return; } else { From 2c869dc11411bc258c465d4dd58e8108defb2fc2 Mon Sep 17 00:00:00 2001 From: iklam Date: Wed, 7 May 2025 08:34:46 -0700 Subject: [PATCH 11/15] @jdksjolen comment --- src/hotspot/share/logging/logSelection.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hotspot/share/logging/logSelection.cpp b/src/hotspot/share/logging/logSelection.cpp index 018c013dfc3e5..a5d75818791df 100644 --- a/src/hotspot/share/logging/logSelection.cpp +++ b/src/hotspot/share/logging/logSelection.cpp @@ -183,10 +183,13 @@ bool LogSelection::selects(const LogTagSet& ts) const { return false; } size_t i = 0; + +#if INCLUDE_CDS if (PrintCDSLogsAsAOTLogs && _ntags > 0 && _tags[0] == LogTag::_aot && ts.tag(0) == LogTag::_cds) { // Consider it a match i ++; } +#endif for (; i < _ntags; i++) { if (!ts.contains(_tags[i])) { From b772b3d4ab579fd03ced419050d65f7f2f16bb93 Mon Sep 17 00:00:00 2001 From: iklam Date: Wed, 7 May 2025 10:56:04 -0700 Subject: [PATCH 12/15] cds+aot+load -> aot+load --- .../runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java b/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java index f6a3b32a9e2ce..3b67c0792d380 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/BulkLoaderTest.java @@ -137,7 +137,7 @@ public String classpath(RunMode runMode) { @Override public String[] vmArgs(RunMode runMode) { return new String[] { - "-Xlog:cds,cds+aot+load,cds+class=debug", + "-Xlog:cds,aot+load,cds+class=debug", "-XX:+AOTClassLinking", }; } From 38dbe7ebf3969114e46f61044d7cd6fdb1c1f0c9 Mon Sep 17 00:00:00 2001 From: iklam Date: Wed, 7 May 2025 19:41:54 -0700 Subject: [PATCH 13/15] @vnkozlov and @dholmes-ora comments --- src/hotspot/share/cds/filemap.cpp | 2 +- src/hotspot/share/logging/logSelection.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/cds/filemap.cpp b/src/hotspot/share/cds/filemap.cpp index 2a95fe4c36763..48572cb9c79eb 100644 --- a/src/hotspot/share/cds/filemap.cpp +++ b/src/hotspot/share/cds/filemap.cpp @@ -1510,7 +1510,7 @@ bool FileMapInfo::can_use_heap_region() { narrow_oop_mode(), p2i(narrow_oop_base()), narrow_oop_shift()); log_info(cds)("The current max heap size = %zuM, G1HeapRegion::GrainBytes = %zu", MaxHeapSize/M, G1HeapRegion::GrainBytes); - log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", arrow_klass_pointer_bits = %d, narrow_klass_shift = %d", + log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", narrow_klass_pointer_bits = %d, narrow_klass_shift = %d", p2i(CompressedKlassPointers::base()), CompressedKlassPointers::narrow_klass_pointer_bits(), CompressedKlassPointers::shift()); log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d", CompressedOops::mode(), p2i(CompressedOops::base()), CompressedOops::shift()); diff --git a/src/hotspot/share/logging/logSelection.cpp b/src/hotspot/share/logging/logSelection.cpp index a5d75818791df..d93382c220927 100644 --- a/src/hotspot/share/logging/logSelection.cpp +++ b/src/hotspot/share/logging/logSelection.cpp @@ -187,7 +187,7 @@ bool LogSelection::selects(const LogTagSet& ts) const { #if INCLUDE_CDS if (PrintCDSLogsAsAOTLogs && _ntags > 0 && _tags[0] == LogTag::_aot && ts.tag(0) == LogTag::_cds) { // Consider it a match - i ++; + i++; } #endif From 031cbef1fb01bcc53eea407b2fabf243a90186e9 Mon Sep 17 00:00:00 2001 From: iklam Date: Wed, 7 May 2025 19:51:00 -0700 Subject: [PATCH 14/15] Reverted unrelated changes in filemap.cpp --- src/hotspot/share/cds/filemap.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/hotspot/share/cds/filemap.cpp b/src/hotspot/share/cds/filemap.cpp index 48572cb9c79eb..ff537ef96d668 100644 --- a/src/hotspot/share/cds/filemap.cpp +++ b/src/hotspot/share/cds/filemap.cpp @@ -1510,7 +1510,7 @@ bool FileMapInfo::can_use_heap_region() { narrow_oop_mode(), p2i(narrow_oop_base()), narrow_oop_shift()); log_info(cds)("The current max heap size = %zuM, G1HeapRegion::GrainBytes = %zu", MaxHeapSize/M, G1HeapRegion::GrainBytes); - log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", narrow_klass_pointer_bits = %d, narrow_klass_shift = %d", + log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", arrow_klass_pointer_bits = %d, narrow_klass_shift = %d", p2i(CompressedKlassPointers::base()), CompressedKlassPointers::narrow_klass_pointer_bits(), CompressedKlassPointers::shift()); log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d", CompressedOops::mode(), p2i(CompressedOops::base()), CompressedOops::shift()); @@ -1815,16 +1815,10 @@ bool FileMapInfo::open_as_input() { if (!open_for_read() || !init_from_file(_fd) || !validate_header()) { if (_is_static) { - if (CDSConfig::is_dumping_final_static_archive()) { - MetaspaceShared::report_loading_error("Loading AOT configuration failed: %s", _full_path); - } else if (CDSConfig::new_aot_flags_used()) { - MetaspaceShared::report_loading_error("Loading AOT cache failed: %s", _full_path); - } else { - MetaspaceShared::report_loading_error("Loading static archive failed: %s", _full_path); - } + MetaspaceShared::report_loading_error("Loading static archive failed."); return false; } else { - MetaspaceShared::report_loading_error("Loading dynamic archive failed: %s", _full_path); + MetaspaceShared::report_loading_error("Loading dynamic archive failed."); if (AutoCreateSharedArchive) { CDSConfig::enable_dumping_dynamic_archive(_full_path); } From 82e55187dc77a37881fc3867b55f047134c58227 Mon Sep 17 00:00:00 2001 From: iklam Date: Wed, 7 May 2025 19:56:34 -0700 Subject: [PATCH 15/15] Removed checks for error message that got removed from the PR --- .../hotspot/jtreg/runtime/cds/appcds/aotCache/AOTLoggingTag.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTLoggingTag.java b/test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTLoggingTag.java index 8e4168778f21b..413657f32b769 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTLoggingTag.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/aotCache/AOTLoggingTag.java @@ -113,7 +113,6 @@ public static void main(String[] args) throws Exception { "-cp", appJar, helloClass); out = CDSTestUtils.executeAndLog(pb, "prod"); out.shouldContain("[error][aot] An error has occurred while processing the AOT cache. Run with -Xlog:aot for details."); - out.shouldContain("[error][aot] Loading AOT cache failed: nosuchfile.aot"); out.shouldNotHaveExitValue(0); }