Skip to content

Commit c9d5060

Browse files
committed
8208499: NMT: Missing memory tag for Safepoint polling page
Added missing memory tag and cleanup memory type enum Reviewed-by: shade, coleenp
1 parent c277f9e commit c9d5060

5 files changed

Lines changed: 88 additions & 25 deletions

File tree

src/hotspot/share/memory/allocation.hpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,30 @@ class AllocatedObj {
113113
*/
114114
enum MemoryType {
115115
// Memory type by sub systems. It occupies lower byte.
116-
mtJavaHeap = 0x00, // Java heap
117-
mtClass = 0x01, // memory class for Java classes
118-
mtThread = 0x02, // memory for thread objects
119-
mtThreadStack = 0x03,
120-
mtCode = 0x04, // memory for generated code
121-
mtGC = 0x05, // memory for GC
122-
mtCompiler = 0x06, // memory for compiler
123-
mtInternal = 0x07, // memory used by VM, but does not belong to
124-
// any of above categories, and not used for
125-
// native memory tracking
126-
mtOther = 0x08, // memory not used by VM
127-
mtSymbol = 0x09, // symbol
128-
mtNMT = 0x0A, // memory used by native memory tracking
129-
mtClassShared = 0x0B, // class data sharing
130-
mtChunk = 0x0C, // chunk that holds content of arenas
131-
mtTest = 0x0D, // Test type for verifying NMT
132-
mtTracing = 0x0E, // memory used for Tracing
133-
mtLogging = 0x0F, // memory for logging
134-
mtArguments = 0x10, // memory for argument processing
135-
mtModule = 0x11, // memory for module processing
136-
mtNone = 0x12, // undefined
137-
mt_number_of_types = 0x13 // number of memory types (mtDontTrack
138-
// is not included as validate type)
116+
mtJavaHeap, // Java heap
117+
mtClass, // memory class for Java classes
118+
mtThread, // memory for thread objects
119+
mtThreadStack,
120+
mtCode, // memory for generated code
121+
mtGC, // memory for GC
122+
mtCompiler, // memory for compiler
123+
mtInternal, // memory used by VM, but does not belong to
124+
// any of above categories, and not used for
125+
// native memory tracking
126+
mtOther, // memory not used by VM
127+
mtSymbol, // symbol
128+
mtNMT, // memory used by native memory tracking
129+
mtClassShared, // class data sharing
130+
mtChunk, // chunk that holds content of arenas
131+
mtTest, // Test type for verifying NMT
132+
mtTracing, // memory used for Tracing
133+
mtLogging, // memory for logging
134+
mtArguments, // memory for argument processing
135+
mtModule, // memory for module processing
136+
mtSafepoint, // memory for safepoint support
137+
mtNone, // undefined
138+
mt_number_of_types // number of memory types (mtDontTrack
139+
// is not included as validate type)
139140
};
140141

141142
typedef MemoryType MEMFLAGS;

src/hotspot/share/runtime/safepointMechanism.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void SafepointMechanism::default_initialize() {
5151
const size_t allocation_size = 2 * page_size;
5252
char* polling_page = os::reserve_memory(allocation_size, NULL, page_size);
5353
os::commit_memory_or_exit(polling_page, allocation_size, false, "Unable to commit Safepoint polling page");
54-
MemTracker::record_virtual_memory_type((address)polling_page, mtInternal);
54+
MemTracker::record_virtual_memory_type((address)polling_page, mtSafepoint);
5555

5656
char* bad_page = polling_page;
5757
char* good_page = polling_page + page_size;
@@ -76,6 +76,7 @@ void SafepointMechanism::default_initialize() {
7676
char* polling_page = os::reserve_memory(page_size, NULL, page_size);
7777
os::commit_memory_or_exit(polling_page, page_size, false, "Unable to commit Safepoint polling page");
7878
os::protect_memory(polling_page, page_size, os::MEM_PROT_READ);
79+
MemTracker::record_virtual_memory_type((address)polling_page, mtSafepoint);
7980

8081
log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
8182
os::set_polling_page((address)(polling_page));

src/hotspot/share/services/memTracker.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "services/memReporter.hpp"
3333
#include "services/mallocTracker.inline.hpp"
3434
#include "services/memTracker.hpp"
35+
#include "utilities/debug.hpp"
3536
#include "utilities/defaultStream.hpp"
3637
#include "utilities/vmError.hpp"
3738

@@ -50,6 +51,10 @@ bool MemTracker::_is_nmt_env_valid = true;
5051

5152

5253
NMT_TrackingLevel MemTracker::init_tracking_level() {
54+
// Memory type is encoded into tracking header as a byte field,
55+
// make sure that we don't overflow it.
56+
STATIC_ASSERT(mt_number_of_types <= max_jubyte);
57+
5358
NMT_TrackingLevel level = NMT_off;
5459
char buf[64];
5560
jio_snprintf(buf, sizeof(buf), "NMT_LEVEL_%d", os::current_process_id());

src/hotspot/share/services/nmtCommon.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2018, 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
@@ -44,6 +44,7 @@ const char* NMTUtil::_memory_type_names[] = {
4444
"Logging",
4545
"Arguments",
4646
"Module",
47+
"Safepoint",
4748
"Unknown"
4849
};
4950

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8208499
27+
* @summary NMT should report safepoint polling page(s)
28+
* @key nmt jcmd
29+
* @library /test/lib
30+
* @modules java.base/jdk.internal.misc
31+
* java.management
32+
* @run main/othervm -Xbootclasspath/a:. -XX:NativeMemoryTracking=summary -XX:+ThreadLocalHandshakes SafepointPollingPages
33+
* @run main/othervm -Xbootclasspath/a:. -XX:NativeMemoryTracking=summary -XX:-ThreadLocalHandshakes SafepointPollingPages
34+
*/
35+
36+
import jdk.test.lib.process.ProcessTools;
37+
import jdk.test.lib.process.OutputAnalyzer;
38+
import jdk.test.lib.JDKToolFinder;
39+
import jdk.internal.misc.Unsafe;
40+
41+
public class SafepointPollingPages {
42+
public static void main(String args[]) throws Exception {
43+
OutputAnalyzer output;
44+
45+
// Grab my own PID
46+
String pid = Long.toString(ProcessTools.getProcessId());
47+
ProcessBuilder pb = new ProcessBuilder();
48+
49+
// Run 'jcmd <pid> VM.native_memory summary'
50+
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
51+
output = new OutputAnalyzer(pb.start());
52+
output.shouldContain("Safepoint (reserved=");
53+
}
54+
}
55+

0 commit comments

Comments
 (0)