author | zgu |
Tue, 07 Nov 2017 09:37:45 -0500 | |
changeset 47802 | 18dccdc438d7 |
parent 47216 | 71c04702a3d5 |
child 49053 | 0b61efd5a439 |
permissions | -rw-r--r-- |
13195 | 1 |
/* |
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. |
13195 | 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 |
#include "precompiled.hpp" |
|
29201
fee2bbb2ec1d
8073389: Remove the include of resourceArea.hpp from classFileParser.hpp
stefank
parents:
28953
diff
changeset
|
25 |
#include "memory/resourceArea.hpp" |
25946 | 26 |
#include "runtime/mutexLocker.hpp" |
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
27 |
#include "runtime/vmThread.hpp" |
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
28 |
#include "runtime/vm_operations.hpp" |
13195 | 29 |
#include "services/nmtDCmd.hpp" |
30 |
#include "services/memReporter.hpp" |
|
31 |
#include "services/memTracker.hpp" |
|
32 |
#include "utilities/globalDefinitions.hpp" |
|
33 |
||
34 |
NMTDCmd::NMTDCmd(outputStream* output, |
|
35 |
bool heap): DCmdWithParser(output, heap), |
|
36 |
_summary("summary", "request runtime to report current memory summary, " \ |
|
37 |
"which includes total reserved and committed memory, along " \ |
|
38 |
"with memory usage summary by each subsytem.", |
|
39 |
"BOOLEAN", false, "false"), |
|
40 |
_detail("detail", "request runtime to report memory allocation >= " |
|
41 |
"1K by each callsite.", |
|
42 |
"BOOLEAN", false, "false"), |
|
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
43 |
_metadata("metadata", "request runtime to report metadata information", |
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
44 |
"BOOLEAN", false, "false"), |
13195 | 45 |
_baseline("baseline", "request runtime to baseline current memory usage, " \ |
46 |
"so it can be compared against in later time.", |
|
47 |
"BOOLEAN", false, "false"), |
|
48 |
_summary_diff("summary.diff", "request runtime to report memory summary " \ |
|
49 |
"comparison against previous baseline.", |
|
50 |
"BOOLEAN", false, "false"), |
|
51 |
_detail_diff("detail.diff", "request runtime to report memory detail " \ |
|
52 |
"comparison against previous baseline, which shows the memory " \ |
|
53 |
"allocation activities at different callsites.", |
|
54 |
"BOOLEAN", false, "false"), |
|
55 |
_shutdown("shutdown", "request runtime to shutdown itself and free the " \ |
|
56 |
"memory used by runtime.", |
|
57 |
"BOOLEAN", false, "false"), |
|
25946 | 58 |
_statistics("statistics", "print tracker statistics for tuning purpose.", \ |
13195 | 59 |
"BOOLEAN", false, "false"), |
60 |
_scale("scale", "Memory usage in which scale, KB, MB or GB", |
|
61 |
"STRING", false, "KB") { |
|
62 |
_dcmdparser.add_dcmd_option(&_summary); |
|
63 |
_dcmdparser.add_dcmd_option(&_detail); |
|
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
64 |
_dcmdparser.add_dcmd_option(&_metadata); |
13195 | 65 |
_dcmdparser.add_dcmd_option(&_baseline); |
66 |
_dcmdparser.add_dcmd_option(&_summary_diff); |
|
67 |
_dcmdparser.add_dcmd_option(&_detail_diff); |
|
68 |
_dcmdparser.add_dcmd_option(&_shutdown); |
|
25946 | 69 |
_dcmdparser.add_dcmd_option(&_statistics); |
13195 | 70 |
_dcmdparser.add_dcmd_option(&_scale); |
71 |
} |
|
72 |
||
25946 | 73 |
|
74 |
size_t NMTDCmd::get_scale(const char* scale) const { |
|
75 |
if (scale == NULL) return 0; |
|
76 |
return NMTUtil::scale_from_name(scale); |
|
77 |
} |
|
78 |
||
17296
68557efd8583
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
16436
diff
changeset
|
79 |
void NMTDCmd::execute(DCmdSource source, TRAPS) { |
25946 | 80 |
// Check NMT state |
81 |
// native memory tracking has to be on |
|
82 |
if (MemTracker::tracking_level() == NMT_off) { |
|
83 |
output()->print_cr("Native memory tracking is not enabled"); |
|
84 |
return; |
|
85 |
} else if (MemTracker::tracking_level() == NMT_minimal) { |
|
86 |
output()->print_cr("Native memory tracking has been shutdown"); |
|
87 |
return; |
|
88 |
} |
|
89 |
||
13195 | 90 |
const char* scale_value = _scale.value(); |
25946 | 91 |
size_t scale_unit = get_scale(scale_value); |
92 |
if (scale_unit == 0) { |
|
13195 | 93 |
output()->print_cr("Incorrect scale value: %s", scale_value); |
94 |
return; |
|
95 |
} |
|
96 |
||
97 |
int nopt = 0; |
|
16436
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
14819
diff
changeset
|
98 |
if (_summary.is_set() && _summary.value()) { ++nopt; } |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
14819
diff
changeset
|
99 |
if (_detail.is_set() && _detail.value()) { ++nopt; } |
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
100 |
if (_metadata.is_set() && _metadata.value()) { ++nopt; } |
16436
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
14819
diff
changeset
|
101 |
if (_baseline.is_set() && _baseline.value()) { ++nopt; } |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
14819
diff
changeset
|
102 |
if (_summary_diff.is_set() && _summary_diff.value()) { ++nopt; } |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
14819
diff
changeset
|
103 |
if (_detail_diff.is_set() && _detail_diff.value()) { ++nopt; } |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
14819
diff
changeset
|
104 |
if (_shutdown.is_set() && _shutdown.value()) { ++nopt; } |
25946 | 105 |
if (_statistics.is_set() && _statistics.value()) { ++nopt; } |
13195 | 106 |
|
16436
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
14819
diff
changeset
|
107 |
if (nopt > 1) { |
13195 | 108 |
output()->print_cr("At most one of the following option can be specified: " \ |
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
109 |
"summary, detail, metadata, baseline, summary.diff, detail.diff, shutdown"); |
13195 | 110 |
return; |
14819
15be618136c6
8004802: jcmd VM.native_memory baseline=false crashes VM
zgu
parents:
13195
diff
changeset
|
111 |
} else if (nopt == 0) { |
15be618136c6
8004802: jcmd VM.native_memory baseline=false crashes VM
zgu
parents:
13195
diff
changeset
|
112 |
if (_summary.is_set()) { |
15be618136c6
8004802: jcmd VM.native_memory baseline=false crashes VM
zgu
parents:
13195
diff
changeset
|
113 |
output()->print_cr("No command to execute"); |
15be618136c6
8004802: jcmd VM.native_memory baseline=false crashes VM
zgu
parents:
13195
diff
changeset
|
114 |
return; |
15be618136c6
8004802: jcmd VM.native_memory baseline=false crashes VM
zgu
parents:
13195
diff
changeset
|
115 |
} else { |
13195 | 116 |
_summary.set_value(true); |
14819
15be618136c6
8004802: jcmd VM.native_memory baseline=false crashes VM
zgu
parents:
13195
diff
changeset
|
117 |
} |
13195 | 118 |
} |
119 |
||
25946 | 120 |
// Serialize NMT query |
121 |
MutexLocker locker(MemTracker::query_lock()); |
|
13195 | 122 |
|
123 |
if (_summary.value()) { |
|
25946 | 124 |
report(true, scale_unit); |
13195 | 125 |
} else if (_detail.value()) { |
25946 | 126 |
if (!check_detail_tracking_level(output())) { |
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
127 |
return; |
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
128 |
} |
25946 | 129 |
report(false, scale_unit); |
47802
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
130 |
} else if (_metadata.value()) { |
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
131 |
size_t scale = get_scale(_scale.value()); |
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
132 |
VM_PrintMetadata op(output(), scale); |
18dccdc438d7
8189688: NMT: Report per-class load metadata information
zgu
parents:
47216
diff
changeset
|
133 |
VMThread::execute(&op); |
13195 | 134 |
} else if (_baseline.value()) { |
25946 | 135 |
MemBaseline& baseline = MemTracker::get_baseline(); |
136 |
if (!baseline.baseline(MemTracker::tracking_level() != NMT_detail)) { |
|
137 |
output()->print_cr("Baseline failed"); |
|
13195 | 138 |
} else { |
25946 | 139 |
output()->print_cr("Baseline succeeded"); |
13195 | 140 |
} |
141 |
} else if (_summary_diff.value()) { |
|
25946 | 142 |
MemBaseline& baseline = MemTracker::get_baseline(); |
143 |
if (baseline.baseline_type() >= MemBaseline::Summary_baselined) { |
|
144 |
report_diff(true, scale_unit); |
|
13195 | 145 |
} else { |
25946 | 146 |
output()->print_cr("No baseline for comparison"); |
13195 | 147 |
} |
148 |
} else if (_detail_diff.value()) { |
|
25946 | 149 |
if (!check_detail_tracking_level(output())) { |
28953
75f0bfa6ea14
8068451: Kitchensink fails with assert(_size >= sz) failed: Negative size
coleenp
parents:
25946
diff
changeset
|
150 |
return; |
75f0bfa6ea14
8068451: Kitchensink fails with assert(_size >= sz) failed: Negative size
coleenp
parents:
25946
diff
changeset
|
151 |
} |
25946 | 152 |
MemBaseline& baseline = MemTracker::get_baseline(); |
153 |
if (baseline.baseline_type() == MemBaseline::Detail_baselined) { |
|
154 |
report_diff(false, scale_unit); |
|
13195 | 155 |
} else { |
25946 | 156 |
output()->print_cr("No detail baseline for comparison"); |
13195 | 157 |
} |
158 |
} else if (_shutdown.value()) { |
|
25946 | 159 |
MemTracker::shutdown(); |
160 |
output()->print_cr("Native memory tracking has been turned off"); |
|
161 |
} else if (_statistics.value()) { |
|
162 |
if (check_detail_tracking_level(output())) { |
|
163 |
MemTracker::tuning_statistics(output()); |
|
164 |
} |
|
13195 | 165 |
} else { |
166 |
ShouldNotReachHere(); |
|
167 |
output()->print_cr("Unknown command"); |
|
168 |
} |
|
169 |
} |
|
170 |
||
171 |
int NMTDCmd::num_arguments() { |
|
172 |
ResourceMark rm; |
|
173 |
NMTDCmd* dcmd = new NMTDCmd(NULL, false); |
|
174 |
if (dcmd != NULL) { |
|
175 |
DCmdMark mark(dcmd); |
|
176 |
return dcmd->_dcmdparser.num_arguments(); |
|
177 |
} else { |
|
178 |
return 0; |
|
179 |
} |
|
180 |
} |
|
181 |
||
25946 | 182 |
void NMTDCmd::report(bool summaryOnly, size_t scale_unit) { |
183 |
MemBaseline baseline; |
|
184 |
if (baseline.baseline(summaryOnly)) { |
|
185 |
if (summaryOnly) { |
|
186 |
MemSummaryReporter rpt(baseline, output(), scale_unit); |
|
187 |
rpt.report(); |
|
188 |
} else { |
|
189 |
MemDetailReporter rpt(baseline, output(), scale_unit); |
|
190 |
rpt.report(); |
|
191 |
} |
|
192 |
} |
|
193 |
} |
|
194 |
||
195 |
void NMTDCmd::report_diff(bool summaryOnly, size_t scale_unit) { |
|
196 |
MemBaseline& early_baseline = MemTracker::get_baseline(); |
|
197 |
assert(early_baseline.baseline_type() != MemBaseline::Not_baselined, |
|
198 |
"Not yet baselined"); |
|
199 |
assert(summaryOnly || early_baseline.baseline_type() == MemBaseline::Detail_baselined, |
|
200 |
"Not a detail baseline"); |
|
201 |
||
202 |
MemBaseline baseline; |
|
203 |
if (baseline.baseline(summaryOnly)) { |
|
204 |
if (summaryOnly) { |
|
205 |
MemSummaryDiffReporter rpt(early_baseline, baseline, output(), scale_unit); |
|
206 |
rpt.report_diff(); |
|
207 |
} else { |
|
208 |
MemDetailDiffReporter rpt(early_baseline, baseline, output(), scale_unit); |
|
209 |
rpt.report_diff(); |
|
210 |
} |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
bool NMTDCmd::check_detail_tracking_level(outputStream* out) { |
|
215 |
if (MemTracker::tracking_level() == NMT_detail) { |
|
216 |
return true; |
|
217 |
} else if (MemTracker::cmdline_tracking_level() == NMT_detail) { |
|
218 |
out->print_cr("Tracking level has been downgraded due to lack of resources"); |
|
219 |
return false; |
|
220 |
} else { |
|
221 |
out->print_cr("Detail tracking is not enabled"); |
|
222 |
return false; |
|
223 |
} |
|
224 |
} |