Skip to content

Commit 73177d9

Browse files
caspernorrbinDavid Holmes
authored andcommitted
8347734: Turning off PerfData logging doesn't work
Reviewed-by: dholmes, coleenp
1 parent 96305e0 commit 73177d9

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

src/hotspot/share/logging/logConfiguration.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,9 @@ void LogConfiguration::disable_logging() {
336336
notify_update_listeners();
337337
}
338338

339-
void LogConfiguration::configure_stdout(LogLevelType level, int exact_match, ...) {
339+
LogSelectionList LogConfiguration::create_selection_list(LogLevelType level, int exact_match, va_list ap) {
340340
size_t i;
341-
va_list ap;
342341
LogTagType tags[LogTag::MaxTags];
343-
va_start(ap, exact_match);
344342
for (i = 0; i < LogTag::MaxTags; i++) {
345343
LogTagType tag = static_cast<LogTagType>(va_arg(ap, int));
346344
tags[i] = tag;
@@ -351,12 +349,32 @@ void LogConfiguration::configure_stdout(LogLevelType level, int exact_match, ...
351349
}
352350
assert(i < LogTag::MaxTags || static_cast<LogTagType>(va_arg(ap, int)) == LogTag::__NO_TAG,
353351
"Too many tags specified! Can only have up to %zu tags in a tag set.", LogTag::MaxTags);
354-
va_end(ap);
355352

356353
LogSelection selection(tags, !exact_match, level);
357354
assert(selection.tag_sets_selected() > 0,
358-
"configure_stdout() called with invalid/non-existing log selection");
359-
LogSelectionList list(selection);
355+
"create_selection_list() called with invalid/non-existing log selection");
356+
return LogSelectionList(selection);
357+
}
358+
359+
void LogConfiguration::disable_tags(int exact_match, ...) {
360+
va_list ap;
361+
va_start(ap, exact_match);
362+
LogSelectionList list = create_selection_list(LogLevel::Off, exact_match, ap);
363+
va_end(ap);
364+
365+
// Apply configuration to all outputs, with the same decorators as before.
366+
ConfigurationLock cl;
367+
for (size_t i = 0; i < _n_outputs; i++) {
368+
configure_output(i, list, _outputs[i]->decorators());
369+
}
370+
notify_update_listeners();
371+
}
372+
373+
void LogConfiguration::configure_stdout(LogLevelType level, int exact_match, ...) {
374+
va_list ap;
375+
va_start(ap, exact_match);
376+
LogSelectionList list = create_selection_list(level, exact_match, ap);
377+
va_end(ap);
360378

361379
// Apply configuration to stdout (output #0), with the same decorators as before.
362380
ConfigurationLock cl;

src/hotspot/share/logging/logConfiguration.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class LogConfiguration : public AllStatic {
9797
static void describe_available(outputStream* out);
9898
static void describe_current_configuration(outputStream* out);
9999

100+
// Create a LogSelectionList given a level and a set of tags
101+
static LogSelectionList create_selection_list(LogLevelType level, int exact_match, va_list ap);
100102

101103
public:
102104
// Initialization and finalization of log configuration, to be run at vm startup and shutdown respectively.
@@ -109,6 +111,13 @@ class LogConfiguration : public AllStatic {
109111
// Disable all logging, equivalent to -Xlog:disable.
110112
static void disable_logging();
111113

114+
// Disables logging on all outputs for the given tags.
115+
// If exact_match is true, only tagsets with precisely the specified tags will be disabled
116+
// (exact_match=false is the same as "-Xlog:<tags>*=off", and exact_match=true is "-Xlog:<tags>=off").
117+
// Tags should be specified using the LOG_TAGS macro, e.g.
118+
// LogConfiguration::disable_tags(<true/false>, LOG_TAGS(<tags>));
119+
static void disable_tags(int exact_match, ...);
120+
112121
// Configures logging on stdout for the given tags and level combination.
113122
// Intended for mappings between -XX: flags and Unified Logging configuration.
114123
// If exact_match is true, only tagsets with precisely the specified tags will be configured

src/hotspot/share/runtime/arguments.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3800,7 +3800,8 @@ jint Arguments::apply_ergo() {
38003800
if (log_is_enabled(Info, perf, class, link)) {
38013801
if (!UsePerfData) {
38023802
warning("Disabling -Xlog:perf+class+link since UsePerfData is turned off.");
3803-
LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(perf, class, link));
3803+
LogConfiguration::disable_tags(false, LOG_TAGS(perf, class, link));
3804+
assert(!log_is_enabled(Info, perf, class, link), "sanity");
38043805
}
38053806
}
38063807

test/hotspot/gtest/logging/test_logConfiguration.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,32 @@ TEST_VM_F(LogConfigurationTest, disable_output) {
216216
}
217217
}
218218

219+
TEST_VM_F(LogConfigurationTest, disable_tags) {
220+
set_log_config("stdout", "logging*=info");
221+
set_log_config(TestLogFileName, "logging*=info");
222+
223+
EXPECT_TRUE(log_is_enabled(Info, logging, gc));
224+
LogConfiguration::disable_tags(true, LOG_TAGS(logging, gc));
225+
EXPECT_FALSE(log_is_enabled(Info, logging, gc));
226+
EXPECT_TRUE(log_is_enabled(Info, logging));
227+
228+
set_log_config("stdout", "logging*=info");
229+
set_log_config(TestLogFileName, "logging*=info");
230+
231+
EXPECT_TRUE(log_is_enabled(Info, logging));
232+
LogConfiguration::disable_tags(true, LOG_TAGS(logging));
233+
EXPECT_TRUE(log_is_enabled(Info, logging, gc));
234+
EXPECT_FALSE(log_is_enabled(Info, logging));
235+
236+
set_log_config("stdout", "logging*=info");
237+
set_log_config(TestLogFileName, "logging*=info");
238+
239+
EXPECT_TRUE(log_is_enabled(Info, logging));
240+
LogConfiguration::disable_tags(false, LOG_TAGS(logging));
241+
EXPECT_FALSE(log_is_enabled(Info, logging, gc));
242+
EXPECT_FALSE(log_is_enabled(Info, logging));
243+
}
244+
219245
// Test reconfiguration of the selected decorators for an output
220246
TEST_VM_F(LogConfigurationTest, reconfigure_decorators) {
221247
// Configure stderr with all decorators

0 commit comments

Comments
 (0)