8334026: Provide a diagnostic PrintMemoryMapAtExit switch on Linux

Reviewed-by: dholmes, mbaesken
This commit is contained in:
Thomas Stuefe 2024-06-20 08:30:52 +00:00
parent cabd1046d0
commit c6f3bf4bd6
4 changed files with 65 additions and 5 deletions

View File

@ -94,7 +94,9 @@
product(bool, UseMadvPopulateWrite, true, DIAGNOSTIC, \ product(bool, UseMadvPopulateWrite, true, DIAGNOSTIC, \
"Use MADV_POPULATE_WRITE in os::pd_pretouch_memory.") \ "Use MADV_POPULATE_WRITE in os::pd_pretouch_memory.") \
\ \
product(bool, PrintMemoryMapAtExit, false, DIAGNOSTIC, \
"Print an annotated memory map at exit") \
\
// end of RUNTIME_OS_FLAGS // end of RUNTIME_OS_FLAGS
// //

View File

@ -30,16 +30,17 @@
#include "logging/logAsyncWriter.hpp" #include "logging/logAsyncWriter.hpp"
#include "gc/shared/collectedHeap.hpp" #include "gc/shared/collectedHeap.hpp"
#include "memory/universe.hpp" #include "memory/universe.hpp"
#include "memory/resourceArea.hpp"
#include "nmt/memflags.hpp" #include "nmt/memflags.hpp"
#include "nmt/memFlagBitmap.hpp"
#include "nmt/memMapPrinter.hpp"
#include "nmt/memTracker.hpp"
#include "nmt/virtualMemoryTracker.hpp"
#include "runtime/nonJavaThread.hpp" #include "runtime/nonJavaThread.hpp"
#include "runtime/osThread.hpp" #include "runtime/osThread.hpp"
#include "runtime/thread.hpp" #include "runtime/thread.hpp"
#include "runtime/threadSMR.hpp" #include "runtime/threadSMR.hpp"
#include "runtime/vmThread.hpp" #include "runtime/vmThread.hpp"
#include "nmt/memFlagBitmap.hpp"
#include "nmt/memMapPrinter.hpp"
#include "nmt/memTracker.hpp"
#include "nmt/virtualMemoryTracker.hpp"
#include "utilities/globalDefinitions.hpp" #include "utilities/globalDefinitions.hpp"
#include "utilities/growableArray.hpp" #include "utilities/growableArray.hpp"
#include "utilities/ostream.hpp" #include "utilities/ostream.hpp"
@ -203,6 +204,8 @@ static void print_thread_details(uintx thread_id, const char* name, outputStream
// Given a region [from, to), if it intersects a known thread stack, print detail infos about that thread. // Given a region [from, to), if it intersects a known thread stack, print detail infos about that thread.
static void print_thread_details_for_supposed_stack_address(const void* from, const void* to, outputStream* st) { static void print_thread_details_for_supposed_stack_address(const void* from, const void* to, outputStream* st) {
ResourceMark rm;
#define HANDLE_THREAD(T) \ #define HANDLE_THREAD(T) \
if (T != nullptr && vma_touches_thread_stack(from, to, T)) { \ if (T != nullptr && vma_touches_thread_stack(from, to, T)) { \
print_thread_details((uintx)(T->osthread()->thread_id()), T->name(), st); \ print_thread_details((uintx)(T->osthread()->thread_id()), T->name(), st); \

View File

@ -48,6 +48,7 @@
#include "memory/oopFactory.hpp" #include "memory/oopFactory.hpp"
#include "memory/resourceArea.hpp" #include "memory/resourceArea.hpp"
#include "memory/universe.hpp" #include "memory/universe.hpp"
#include "nmt/memMapPrinter.hpp"
#include "nmt/memTracker.hpp" #include "nmt/memTracker.hpp"
#include "oops/constantPool.hpp" #include "oops/constantPool.hpp"
#include "oops/generateOopMap.hpp" #include "oops/generateOopMap.hpp"
@ -485,6 +486,9 @@ void before_exit(JavaThread* thread, bool halt) {
if (DumpPerfMapAtExit) { if (DumpPerfMapAtExit) {
CodeCache::write_perf_map(); CodeCache::write_perf_map();
} }
if (PrintMemoryMapAtExit) {
MemMapPrinter::print_all_mappings(tty, false);
}
#endif #endif
if (JvmtiExport::should_post_thread_life()) { if (JvmtiExport::should_post_thread_life()) {

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, Red Hat, Inc. 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 Verify PrintMemoryMapAtExit on normal JVM exit for summary tracking level
* @requires os.family == "linux"
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @run driver PrintMemoryMapAtExitTest
*/
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
public class PrintMemoryMapAtExitTest {
public static void main(String args[]) throws Exception {
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
"-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintMemoryMapAtExit",
"-XX:NativeMemoryTracking=summary", "-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldHaveExitValue(0);
output.shouldContain("Memory mappings");
output.shouldContain("JAVAHEAP");
output.shouldHaveExitValue(0);
}
}