src/share/vm/services/nmtDCmd.cpp

Fri, 01 Feb 2013 23:48:08 +0100

author
ctornqvi
date
Fri, 01 Feb 2013 23:48:08 +0100
changeset 4512
4102b59539ce
parent 4348
3f84e17b6bca
child 4810
06db4c0afbf3
permissions
-rw-r--r--

8005012: Add WB APIs to better support NMT testing
Summary: Add WB API functions to enable better NMT testing
Reviewed-by: dholmes, zgu

zgu@3900 1 /*
zgu@3900 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
zgu@3900 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
zgu@3900 4 *
zgu@3900 5 * This code is free software; you can redistribute it and/or modify it
zgu@3900 6 * under the terms of the GNU General Public License version 2 only, as
zgu@3900 7 * published by the Free Software Foundation.
zgu@3900 8 *
zgu@3900 9 * This code is distributed in the hope that it will be useful, but WITHOUT
zgu@3900 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
zgu@3900 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
zgu@3900 12 * version 2 for more details (a copy is included in the LICENSE file that
zgu@3900 13 * accompanied this code).
zgu@3900 14 *
zgu@3900 15 * You should have received a copy of the GNU General Public License version
zgu@3900 16 * 2 along with this work; if not, write to the Free Software Foundation,
zgu@3900 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
zgu@3900 18 *
zgu@3900 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
zgu@3900 20 * or visit www.oracle.com if you need additional information or have any
zgu@3900 21 * questions.
zgu@3900 22 *
zgu@3900 23 */
zgu@3900 24 #include "precompiled.hpp"
zgu@3900 25 #include "services/nmtDCmd.hpp"
zgu@3900 26 #include "services/memReporter.hpp"
zgu@3900 27 #include "services/memTracker.hpp"
zgu@3900 28 #include "utilities/globalDefinitions.hpp"
zgu@3900 29
zgu@3900 30 NMTDCmd::NMTDCmd(outputStream* output,
zgu@3900 31 bool heap): DCmdWithParser(output, heap),
zgu@3900 32 _summary("summary", "request runtime to report current memory summary, " \
zgu@3900 33 "which includes total reserved and committed memory, along " \
zgu@3900 34 "with memory usage summary by each subsytem.",
zgu@3900 35 "BOOLEAN", false, "false"),
zgu@3900 36 _detail("detail", "request runtime to report memory allocation >= "
zgu@3900 37 "1K by each callsite.",
zgu@3900 38 "BOOLEAN", false, "false"),
zgu@3900 39 _baseline("baseline", "request runtime to baseline current memory usage, " \
zgu@3900 40 "so it can be compared against in later time.",
zgu@3900 41 "BOOLEAN", false, "false"),
zgu@3900 42 _summary_diff("summary.diff", "request runtime to report memory summary " \
zgu@3900 43 "comparison against previous baseline.",
zgu@3900 44 "BOOLEAN", false, "false"),
zgu@3900 45 _detail_diff("detail.diff", "request runtime to report memory detail " \
zgu@3900 46 "comparison against previous baseline, which shows the memory " \
zgu@3900 47 "allocation activities at different callsites.",
zgu@3900 48 "BOOLEAN", false, "false"),
zgu@3900 49 _shutdown("shutdown", "request runtime to shutdown itself and free the " \
zgu@3900 50 "memory used by runtime.",
zgu@3900 51 "BOOLEAN", false, "false"),
zgu@3900 52 #ifndef PRODUCT
zgu@3900 53 _debug("debug", "print tracker statistics. Debug only, not thread safe", \
zgu@3900 54 "BOOLEAN", false, "false"),
zgu@3900 55 #endif
zgu@3900 56 _scale("scale", "Memory usage in which scale, KB, MB or GB",
zgu@3900 57 "STRING", false, "KB") {
zgu@3900 58 _dcmdparser.add_dcmd_option(&_summary);
zgu@3900 59 _dcmdparser.add_dcmd_option(&_detail);
zgu@3900 60 _dcmdparser.add_dcmd_option(&_baseline);
zgu@3900 61 _dcmdparser.add_dcmd_option(&_summary_diff);
zgu@3900 62 _dcmdparser.add_dcmd_option(&_detail_diff);
zgu@3900 63 _dcmdparser.add_dcmd_option(&_shutdown);
zgu@3900 64 #ifndef PRODUCT
zgu@3900 65 _dcmdparser.add_dcmd_option(&_debug);
zgu@3900 66 #endif
zgu@3900 67 _dcmdparser.add_dcmd_option(&_scale);
zgu@3900 68 }
zgu@3900 69
zgu@3900 70 void NMTDCmd::execute(TRAPS) {
zgu@3900 71 const char* scale_value = _scale.value();
zgu@3900 72 size_t scale_unit;
zgu@3900 73 if (strcmp(scale_value, "KB") == 0 || strcmp(scale_value, "kb") == 0) {
zgu@3900 74 scale_unit = K;
zgu@3900 75 } else if (strcmp(scale_value, "MB") == 0 ||
zgu@3900 76 strcmp(scale_value, "mb") == 0) {
zgu@3900 77 scale_unit = M;
zgu@3900 78 } else if (strcmp(scale_value, "GB") == 0 ||
zgu@3900 79 strcmp(scale_value, "gb") == 0) {
zgu@3900 80 scale_unit = G;
zgu@3900 81 } else {
zgu@3900 82 output()->print_cr("Incorrect scale value: %s", scale_value);
zgu@3900 83 return;
zgu@3900 84 }
zgu@3900 85
zgu@3900 86 int nopt = 0;
zgu@4348 87 if(_summary.is_set() && _summary.value()) { ++nopt; }
zgu@4348 88 if(_detail.is_set() && _detail.value()) { ++nopt; }
zgu@4348 89 if(_baseline.is_set() && _baseline.value()) { ++nopt; }
zgu@4348 90 if(_summary_diff.is_set() && _summary_diff.value()) { ++nopt; }
zgu@4348 91 if(_detail_diff.is_set() && _detail_diff.value()) { ++nopt; }
zgu@4348 92 if(_shutdown.is_set() && _shutdown.value()) { ++nopt; }
zgu@3900 93 #ifndef PRODUCT
zgu@4348 94 if(_debug.is_set() && _debug.value()) { ++nopt; }
zgu@3900 95 #endif
zgu@3900 96
zgu@3900 97 if(nopt > 1) {
zgu@3900 98 output()->print_cr("At most one of the following option can be specified: " \
zgu@3900 99 "summary, detail, baseline, summary.diff, detail.diff, shutdown"
zgu@3900 100 #ifndef PRODUCT
zgu@4348 101 ", debug"
zgu@3900 102 #endif
zgu@3900 103 );
zgu@3900 104 return;
zgu@4348 105 } else if (nopt == 0) {
zgu@4348 106 if (_summary.is_set()) {
zgu@4348 107 output()->print_cr("No command to execute");
zgu@4348 108 return;
zgu@4348 109 } else {
zgu@3900 110 _summary.set_value(true);
zgu@4348 111 }
zgu@3900 112 }
zgu@3900 113
zgu@3900 114 #ifndef PRODUCT
zgu@3900 115 if (_debug.value()) {
zgu@3900 116 output()->print_cr("debug command is NOT thread-safe, may cause crash");
zgu@3900 117 MemTracker::print_tracker_stats(output());
zgu@3900 118 return;
zgu@3900 119 }
zgu@3900 120 #endif
zgu@3900 121
zgu@3900 122 // native memory tracking has to be on
zgu@3900 123 if (!MemTracker::is_on() || MemTracker::shutdown_in_progress()) {
zgu@3900 124 // if it is not on, what's the reason?
zgu@3900 125 output()->print_cr(MemTracker::reason());
zgu@3900 126 return;
zgu@3900 127 }
zgu@3900 128
zgu@3900 129 if (_summary.value()) {
zgu@3900 130 BaselineTTYOutputer outputer(output());
zgu@3900 131 MemTracker::print_memory_usage(outputer, scale_unit, true);
zgu@3900 132 } else if (_detail.value()) {
zgu@3900 133 BaselineTTYOutputer outputer(output());
zgu@3900 134 MemTracker::print_memory_usage(outputer, scale_unit, false);
zgu@3900 135 } else if (_baseline.value()) {
zgu@3900 136 if (MemTracker::baseline()) {
zgu@3900 137 output()->print_cr("Successfully baselined.");
zgu@3900 138 } else {
zgu@3900 139 output()->print_cr("Baseline failed.");
zgu@3900 140 }
zgu@3900 141 } else if (_summary_diff.value()) {
zgu@3900 142 if (MemTracker::has_baseline()) {
zgu@3900 143 BaselineTTYOutputer outputer(output());
zgu@3900 144 MemTracker::compare_memory_usage(outputer, scale_unit, true);
zgu@3900 145 } else {
zgu@3900 146 output()->print_cr("No baseline to compare, run 'baseline' command first");
zgu@3900 147 }
zgu@3900 148 } else if (_detail_diff.value()) {
zgu@3900 149 if (MemTracker::has_baseline()) {
zgu@3900 150 BaselineTTYOutputer outputer(output());
zgu@3900 151 MemTracker::compare_memory_usage(outputer, scale_unit, false);
zgu@3900 152 } else {
zgu@3900 153 output()->print_cr("No baseline to compare to, run 'baseline' command first");
zgu@3900 154 }
zgu@3900 155 } else if (_shutdown.value()) {
zgu@3900 156 MemTracker::shutdown(MemTracker::NMT_shutdown_user);
zgu@3900 157 output()->print_cr("Shutdown is in progress, it will take a few moments to " \
zgu@3900 158 "completely shutdown");
zgu@3900 159 } else {
zgu@3900 160 ShouldNotReachHere();
zgu@3900 161 output()->print_cr("Unknown command");
zgu@3900 162 }
zgu@3900 163 }
zgu@3900 164
zgu@3900 165 int NMTDCmd::num_arguments() {
zgu@3900 166 ResourceMark rm;
zgu@3900 167 NMTDCmd* dcmd = new NMTDCmd(NULL, false);
zgu@3900 168 if (dcmd != NULL) {
zgu@3900 169 DCmdMark mark(dcmd);
zgu@3900 170 return dcmd->_dcmdparser.num_arguments();
zgu@3900 171 } else {
zgu@3900 172 return 0;
zgu@3900 173 }
zgu@3900 174 }
zgu@3900 175

mercurial