8327054: DiagnosticCommand Compiler.perfmap does not log on output()

Reviewed-by: lmesnik, stuefe, kevinw, cjplummer
This commit is contained in:
Sonia Zaldana Calles 2024-07-23 15:49:34 +00:00
parent 0e555b5ded
commit 8e1f17e351
5 changed files with 18 additions and 6 deletions

View File

@ -1788,7 +1788,7 @@ void CodeCache::log_state(outputStream* st) {
}
#ifdef LINUX
void CodeCache::write_perf_map(const char* filename) {
void CodeCache::write_perf_map(const char* filename, outputStream* st) {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
// Perf expects to find the map file at /tmp/perf-<pid>.map
@ -1801,7 +1801,7 @@ void CodeCache::write_perf_map(const char* filename) {
fileStream fs(filename, "w");
if (!fs.is_open()) {
log_warning(codecache)("Failed to create %s for perf map", filename);
st->print_cr("Warning: Failed to create %s for perf map", filename);
return;
}

View File

@ -223,7 +223,7 @@ class CodeCache : AllStatic {
static void print_trace(const char* event, CodeBlob* cb, uint size = 0) PRODUCT_RETURN;
static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage
static void log_state(outputStream* st);
LINUX_ONLY(static void write_perf_map(const char* filename = nullptr);)
LINUX_ONLY(static void write_perf_map(const char* filename, outputStream* st);) // Prints warnings and error messages to outputStream
static const char* get_code_heap_name(CodeBlobType code_blob_type) { return (heap_available(code_blob_type) ? get_code_heap(code_blob_type)->name() : "Unused"); }
static void report_codemem_full(CodeBlobType code_blob_type, bool print);

View File

@ -484,7 +484,7 @@ void before_exit(JavaThread* thread, bool halt) {
#ifdef LINUX
if (DumpPerfMapAtExit) {
CodeCache::write_perf_map();
CodeCache::write_perf_map(nullptr, tty);
}
if (PrintMemoryMapAtExit) {
MemMapPrinter::print_all_mappings(tty);

View File

@ -865,7 +865,7 @@ void PerfMapDCmd::execute(DCmdSource source, TRAPS) {
// The check for _filename.is_set() is because we don't want to use
// DEFAULT_PERFMAP_FILENAME, since it is meant as a description
// of the default, not the actual default.
CodeCache::write_perf_map(_filename.is_set() ? _filename.value() : nullptr);
CodeCache::write_perf_map(_filename.is_set() ? _filename.value() : nullptr, output());
}
#endif // LINUX

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, Arm Limited. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -113,4 +113,16 @@ public class PerfMapTest {
run(new JMXExecutor(), "Compiler.perfmap " + path.toString(), path);
Files.deleteIfExists(path);
}
@Test
public void logErrorsDcmdOutputStream() throws IOException {
String test_dir = System.getProperty("test.dir", ".");
Path path = Paths.get("nonexistent", test_dir);
try {
OutputAnalyzer output = new JMXExecutor().execute("Compiler.perfmap %s".formatted(path));
output.shouldContain("Warning: Failed to create nonexistent/%s for perf map".formatted(test_dir));
} finally {
Files.deleteIfExists(path);
}
}
}