Skip to content

Commit

Permalink
8334026: Provide a diagnostic PrintMemoryMapAtExit switch on Linux
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, mbaesken
  • Loading branch information
tstuefe committed Jun 20, 2024
1 parent cabd104 commit c6f3bf4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/hotspot/os/linux/globals_linux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@
product(bool, UseMadvPopulateWrite, true, DIAGNOSTIC, \
"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

//
Expand Down
11 changes: 7 additions & 4 deletions src/hotspot/share/nmt/memMapPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@
#include "logging/logAsyncWriter.hpp"
#include "gc/shared/collectedHeap.hpp"
#include "memory/universe.hpp"
#include "memory/resourceArea.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/osThread.hpp"
#include "runtime/thread.hpp"
#include "runtime/threadSMR.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/growableArray.hpp"
#include "utilities/ostream.hpp"
Expand Down Expand Up @@ -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.
static void print_thread_details_for_supposed_stack_address(const void* from, const void* to, outputStream* st) {

ResourceMark rm;

#define HANDLE_THREAD(T) \
if (T != nullptr && vma_touches_thread_stack(from, to, T)) { \
print_thread_details((uintx)(T->osthread()->thread_id()), T->name(), st); \
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/runtime/java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "memory/oopFactory.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "nmt/memMapPrinter.hpp"
#include "nmt/memTracker.hpp"
#include "oops/constantPool.hpp"
#include "oops/generateOopMap.hpp"
Expand Down Expand Up @@ -485,6 +486,9 @@ void before_exit(JavaThread* thread, bool halt) {
if (DumpPerfMapAtExit) {
CodeCache::write_perf_map();
}
if (PrintMemoryMapAtExit) {
MemMapPrinter::print_all_mappings(tty, false);
}
#endif

if (JvmtiExport::should_post_thread_life()) {
Expand Down
51 changes: 51 additions & 0 deletions test/hotspot/jtreg/runtime/NMT/PrintMemoryMapAtExitTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

3 comments on commit c6f3bf4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JesperIRL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/tag jdk-24+3

@openjdk
Copy link

@openjdk openjdk bot commented on c6f3bf4 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JesperIRL The tag jdk-24+3 was successfully created.

Please sign in to comment.