Skip to content

Commit 5a4415a

Browse files
Sonia Zaldana Calleststuefe
authored andcommitted
8331858: [nmt] VM.native_memory statistics should work in summary mode
Reviewed-by: stuefe, jsjolen
1 parent 4ba7447 commit 5a4415a

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

src/hotspot/share/nmt/memTracker.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -146,12 +146,17 @@ void MemTracker::report(bool summary_only, outputStream* output, size_t scale) {
146146
void MemTracker::tuning_statistics(outputStream* out) {
147147
// NMT statistics
148148
out->print_cr("Native Memory Tracking Statistics:");
149-
out->print_cr("State: %s", NMTUtil::tracking_level_to_string(_tracking_level));
150-
out->print_cr("Malloc allocation site table size: %d", MallocSiteTable::hash_buckets());
151-
out->print_cr(" Tracking stack depth: %d", NMT_TrackingStackDepth);
152-
out->cr();
153-
MallocSiteTable::print_tuning_statistics(out);
154-
out->cr();
149+
out->print_cr("State: %s",
150+
NMTUtil::tracking_level_to_string(_tracking_level));
151+
if (_tracking_level == NMT_detail) {
152+
out->print_cr("Malloc allocation site table size: %d",
153+
MallocSiteTable::hash_buckets());
154+
out->print_cr(" Tracking stack depth: %d",
155+
NMT_TrackingStackDepth);
156+
out->cr();
157+
MallocSiteTable::print_tuning_statistics(out);
158+
out->cr();
159+
}
155160
out->print_cr("Preinit state:");
156161
NMTPreInit::print_state(out);
157162
MallocLimitHandler::print_on(out);

src/hotspot/share/nmt/nmtDCmd.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -137,8 +137,10 @@ void NMTDCmd::execute(DCmdSource source, TRAPS) {
137137
output()->print_cr("No detail baseline for comparison");
138138
}
139139
} else if (_statistics.value()) {
140-
if (check_detail_tracking_level(output())) {
140+
if (MemTracker::enabled()) {
141141
MemTracker::tuning_statistics(output());
142+
} else {
143+
output()->print_cr("Native memory tracking is not enabled");
142144
}
143145
} else {
144146
ShouldNotReachHere();
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2024, Red Hat Inc.
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 Test the NMT scale parameter
28+
* @library /test/lib
29+
* @modules java.base/jdk.internal.misc
30+
* java.management
31+
* @run main/othervm -XX:NativeMemoryTracking=summary JcmdSummaryStatistics
32+
*/
33+
34+
import jdk.test.lib.process.OutputAnalyzer;
35+
import jdk.test.lib.JDKToolFinder;
36+
37+
public class JcmdSummaryStatistics {
38+
39+
public static void main(String[] args) throws Exception {
40+
ProcessBuilder pb = new ProcessBuilder();
41+
OutputAnalyzer output;
42+
// Grab my own PID
43+
String pid = Long.toString(jdk.test.lib.process.ProcessTools.getProcessId());
44+
45+
// Run 'jcmd <pid> VM.native_memory statistics=true'
46+
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics=true"});
47+
output = new OutputAnalyzer(pb.start());
48+
49+
output.shouldContainMultiLinePattern(
50+
"Native Memory Tracking Statistics:",
51+
"State: summary",
52+
"Preinit state:",
53+
"entries:",
54+
"pre-init mallocs:",
55+
"MallocLimit:");
56+
}
57+
}

0 commit comments

Comments
 (0)