Skip to content

Commit c6f3bf4

Browse files
committed
8334026: Provide a diagnostic PrintMemoryMapAtExit switch on Linux
Reviewed-by: dholmes, mbaesken
1 parent cabd104 commit c6f3bf4

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

src/hotspot/os/linux/globals_linux.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@
9494
product(bool, UseMadvPopulateWrite, true, DIAGNOSTIC, \
9595
"Use MADV_POPULATE_WRITE in os::pd_pretouch_memory.") \
9696
\
97-
97+
product(bool, PrintMemoryMapAtExit, false, DIAGNOSTIC, \
98+
"Print an annotated memory map at exit") \
99+
\
98100
// end of RUNTIME_OS_FLAGS
99101

100102
//

src/hotspot/share/nmt/memMapPrinter.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@
3030
#include "logging/logAsyncWriter.hpp"
3131
#include "gc/shared/collectedHeap.hpp"
3232
#include "memory/universe.hpp"
33+
#include "memory/resourceArea.hpp"
3334
#include "nmt/memflags.hpp"
35+
#include "nmt/memFlagBitmap.hpp"
36+
#include "nmt/memMapPrinter.hpp"
37+
#include "nmt/memTracker.hpp"
38+
#include "nmt/virtualMemoryTracker.hpp"
3439
#include "runtime/nonJavaThread.hpp"
3540
#include "runtime/osThread.hpp"
3641
#include "runtime/thread.hpp"
3742
#include "runtime/threadSMR.hpp"
3843
#include "runtime/vmThread.hpp"
39-
#include "nmt/memFlagBitmap.hpp"
40-
#include "nmt/memMapPrinter.hpp"
41-
#include "nmt/memTracker.hpp"
42-
#include "nmt/virtualMemoryTracker.hpp"
4344
#include "utilities/globalDefinitions.hpp"
4445
#include "utilities/growableArray.hpp"
4546
#include "utilities/ostream.hpp"
@@ -203,6 +204,8 @@ static void print_thread_details(uintx thread_id, const char* name, outputStream
203204
// Given a region [from, to), if it intersects a known thread stack, print detail infos about that thread.
204205
static void print_thread_details_for_supposed_stack_address(const void* from, const void* to, outputStream* st) {
205206

207+
ResourceMark rm;
208+
206209
#define HANDLE_THREAD(T) \
207210
if (T != nullptr && vma_touches_thread_stack(from, to, T)) { \
208211
print_thread_details((uintx)(T->osthread()->thread_id()), T->name(), st); \

src/hotspot/share/runtime/java.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "memory/oopFactory.hpp"
4949
#include "memory/resourceArea.hpp"
5050
#include "memory/universe.hpp"
51+
#include "nmt/memMapPrinter.hpp"
5152
#include "nmt/memTracker.hpp"
5253
#include "oops/constantPool.hpp"
5354
#include "oops/generateOopMap.hpp"
@@ -485,6 +486,9 @@ void before_exit(JavaThread* thread, bool halt) {
485486
if (DumpPerfMapAtExit) {
486487
CodeCache::write_perf_map();
487488
}
489+
if (PrintMemoryMapAtExit) {
490+
MemMapPrinter::print_all_mappings(tty, false);
491+
}
488492
#endif
489493

490494
if (JvmtiExport::should_post_thread_life()) {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2024, Red Hat, Inc. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
/*
26+
* @test
27+
* @summary Verify PrintMemoryMapAtExit on normal JVM exit for summary tracking level
28+
* @requires os.family == "linux"
29+
* @modules java.base/jdk.internal.misc
30+
* @library /test/lib
31+
* @run driver PrintMemoryMapAtExitTest
32+
*/
33+
34+
import jdk.test.lib.process.OutputAnalyzer;
35+
import jdk.test.lib.process.ProcessTools;
36+
37+
public class PrintMemoryMapAtExitTest {
38+
39+
public static void main(String args[]) throws Exception {
40+
41+
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
42+
"-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintMemoryMapAtExit",
43+
"-XX:NativeMemoryTracking=summary", "-version");
44+
45+
OutputAnalyzer output = new OutputAnalyzer(pb.start());
46+
output.shouldHaveExitValue(0);
47+
output.shouldContain("Memory mappings");
48+
output.shouldContain("JAVAHEAP");
49+
output.shouldHaveExitValue(0);
50+
}
51+
}

0 commit comments

Comments
 (0)