8208499: NMT: Missing memory tag for Safepoint polling page

Added missing memory tag and cleanup memory type enum

Reviewed-by: shade, coleenp
This commit is contained in:
Zhengyu Gu 2018-07-31 07:35:16 -04:00
parent c277f9ed8e
commit c9d506055c
5 changed files with 88 additions and 25 deletions

View File

@ -113,29 +113,30 @@ class AllocatedObj {
*/ */
enum MemoryType { enum MemoryType {
// Memory type by sub systems. It occupies lower byte. // Memory type by sub systems. It occupies lower byte.
mtJavaHeap = 0x00, // Java heap mtJavaHeap, // Java heap
mtClass = 0x01, // memory class for Java classes mtClass, // memory class for Java classes
mtThread = 0x02, // memory for thread objects mtThread, // memory for thread objects
mtThreadStack = 0x03, mtThreadStack,
mtCode = 0x04, // memory for generated code mtCode, // memory for generated code
mtGC = 0x05, // memory for GC mtGC, // memory for GC
mtCompiler = 0x06, // memory for compiler mtCompiler, // memory for compiler
mtInternal = 0x07, // memory used by VM, but does not belong to mtInternal, // memory used by VM, but does not belong to
// any of above categories, and not used for // any of above categories, and not used for
// native memory tracking // native memory tracking
mtOther = 0x08, // memory not used by VM mtOther, // memory not used by VM
mtSymbol = 0x09, // symbol mtSymbol, // symbol
mtNMT = 0x0A, // memory used by native memory tracking mtNMT, // memory used by native memory tracking
mtClassShared = 0x0B, // class data sharing mtClassShared, // class data sharing
mtChunk = 0x0C, // chunk that holds content of arenas mtChunk, // chunk that holds content of arenas
mtTest = 0x0D, // Test type for verifying NMT mtTest, // Test type for verifying NMT
mtTracing = 0x0E, // memory used for Tracing mtTracing, // memory used for Tracing
mtLogging = 0x0F, // memory for logging mtLogging, // memory for logging
mtArguments = 0x10, // memory for argument processing mtArguments, // memory for argument processing
mtModule = 0x11, // memory for module processing mtModule, // memory for module processing
mtNone = 0x12, // undefined mtSafepoint, // memory for safepoint support
mt_number_of_types = 0x13 // number of memory types (mtDontTrack mtNone, // undefined
// is not included as validate type) mt_number_of_types // number of memory types (mtDontTrack
// is not included as validate type)
}; };
typedef MemoryType MEMFLAGS; typedef MemoryType MEMFLAGS;

View File

@ -51,7 +51,7 @@ void SafepointMechanism::default_initialize() {
const size_t allocation_size = 2 * page_size; const size_t allocation_size = 2 * page_size;
char* polling_page = os::reserve_memory(allocation_size, NULL, page_size); char* polling_page = os::reserve_memory(allocation_size, NULL, page_size);
os::commit_memory_or_exit(polling_page, allocation_size, false, "Unable to commit Safepoint polling page"); os::commit_memory_or_exit(polling_page, allocation_size, false, "Unable to commit Safepoint polling page");
MemTracker::record_virtual_memory_type((address)polling_page, mtInternal); MemTracker::record_virtual_memory_type((address)polling_page, mtSafepoint);
char* bad_page = polling_page; char* bad_page = polling_page;
char* good_page = polling_page + page_size; char* good_page = polling_page + page_size;
@ -76,6 +76,7 @@ void SafepointMechanism::default_initialize() {
char* polling_page = os::reserve_memory(page_size, NULL, page_size); char* polling_page = os::reserve_memory(page_size, NULL, page_size);
os::commit_memory_or_exit(polling_page, page_size, false, "Unable to commit Safepoint polling page"); os::commit_memory_or_exit(polling_page, page_size, false, "Unable to commit Safepoint polling page");
os::protect_memory(polling_page, page_size, os::MEM_PROT_READ); os::protect_memory(polling_page, page_size, os::MEM_PROT_READ);
MemTracker::record_virtual_memory_type((address)polling_page, mtSafepoint);
log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page)); log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
os::set_polling_page((address)(polling_page)); os::set_polling_page((address)(polling_page));

View File

@ -32,6 +32,7 @@
#include "services/memReporter.hpp" #include "services/memReporter.hpp"
#include "services/mallocTracker.inline.hpp" #include "services/mallocTracker.inline.hpp"
#include "services/memTracker.hpp" #include "services/memTracker.hpp"
#include "utilities/debug.hpp"
#include "utilities/defaultStream.hpp" #include "utilities/defaultStream.hpp"
#include "utilities/vmError.hpp" #include "utilities/vmError.hpp"
@ -50,6 +51,10 @@ bool MemTracker::_is_nmt_env_valid = true;
NMT_TrackingLevel MemTracker::init_tracking_level() { NMT_TrackingLevel MemTracker::init_tracking_level() {
// Memory type is encoded into tracking header as a byte field,
// make sure that we don't overflow it.
STATIC_ASSERT(mt_number_of_types <= max_jubyte);
NMT_TrackingLevel level = NMT_off; NMT_TrackingLevel level = NMT_off;
char buf[64]; char buf[64];
jio_snprintf(buf, sizeof(buf), "NMT_LEVEL_%d", os::current_process_id()); jio_snprintf(buf, sizeof(buf), "NMT_LEVEL_%d", os::current_process_id());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -44,6 +44,7 @@ const char* NMTUtil::_memory_type_names[] = {
"Logging", "Logging",
"Arguments", "Arguments",
"Module", "Module",
"Safepoint",
"Unknown" "Unknown"
}; };

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. 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
* @bug 8208499
* @summary NMT should report safepoint polling page(s)
* @key nmt jcmd
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run main/othervm -Xbootclasspath/a:. -XX:NativeMemoryTracking=summary -XX:+ThreadLocalHandshakes SafepointPollingPages
* @run main/othervm -Xbootclasspath/a:. -XX:NativeMemoryTracking=summary -XX:-ThreadLocalHandshakes SafepointPollingPages
*/
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.JDKToolFinder;
import jdk.internal.misc.Unsafe;
public class SafepointPollingPages {
public static void main(String args[]) throws Exception {
OutputAnalyzer output;
// Grab my own PID
String pid = Long.toString(ProcessTools.getProcessId());
ProcessBuilder pb = new ProcessBuilder();
// Run 'jcmd <pid> VM.native_memory summary'
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
output = new OutputAnalyzer(pb.start());
output.shouldContain("Safepoint (reserved=");
}
}