author | jwilhelm |
Wed, 07 Feb 2018 03:43:29 +0100 | |
changeset 48874 | f09fdaad7321 |
parent 48873 | 9536c39ac6de |
child 48884 | 7e17b00dc245 |
permissions | -rw-r--r-- |
13195 | 1 |
/* |
48874
f09fdaad7321
8196924: [BACKOUT] NMT: Report array class count in NMT summary
jwilhelm
parents:
48873
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 |
||
25 |
#ifndef SHARE_VM_SERVICES_MEM_REPORTER_HPP |
|
26 |
#define SHARE_VM_SERVICES_MEM_REPORTER_HPP |
|
27 |
||
25946 | 28 |
#if INCLUDE_NMT |
29 |
||
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
30 |
#include "memory/metaspace.hpp" |
25946 | 31 |
#include "oops/instanceKlass.hpp" |
13195 | 32 |
#include "services/memBaseline.hpp" |
25946 | 33 |
#include "services/nmtCommon.hpp" |
34 |
#include "services/mallocTracker.hpp" |
|
35 |
#include "services/virtualMemoryTracker.hpp" |
|
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
36 |
|
13195 | 37 |
/* |
25946 | 38 |
* Base class that provides helpers |
39 |
*/ |
|
40 |
class MemReporterBase : public StackObj { |
|
41 |
private: |
|
42 |
size_t _scale; // report in this scale |
|
43 |
outputStream* _output; // destination |
|
44 |
||
13195 | 45 |
public: |
25946 | 46 |
MemReporterBase(outputStream* out = NULL, size_t scale = K) |
47 |
: _scale(scale) { |
|
48 |
_output = (out == NULL) ? tty : out; |
|
49 |
} |
|
13195 | 50 |
|
25946 | 51 |
protected: |
52 |
inline outputStream* output() const { |
|
53 |
return _output; |
|
54 |
} |
|
55 |
// Current reporting scale |
|
56 |
inline const char* current_scale() const { |
|
57 |
return NMTUtil::scale_name(_scale); |
|
58 |
} |
|
59 |
// Convert memory amount in bytes to current reporting scale |
|
60 |
inline size_t amount_in_current_scale(size_t amount) const { |
|
61 |
return NMTUtil::amount_in_scale(amount, _scale); |
|
62 |
} |
|
13195 | 63 |
|
25946 | 64 |
// Convert diff amount in bytes to current reporting scale |
65 |
inline long diff_in_current_scale(size_t s1, size_t s2) const { |
|
66 |
long amount = (long)(s1 - s2); |
|
67 |
long scale = (long)_scale; |
|
68 |
amount = (amount > 0) ? (amount + scale / 2) : (amount - scale / 2); |
|
69 |
return amount / scale; |
|
70 |
} |
|
13195 | 71 |
|
25946 | 72 |
// Helper functions |
73 |
// Calculate total reserved and committed amount |
|
74 |
size_t reserved_total(const MallocMemory* malloc, const VirtualMemory* vm) const; |
|
75 |
size_t committed_total(const MallocMemory* malloc, const VirtualMemory* vm) const; |
|
13195 | 76 |
|
77 |
||
25946 | 78 |
// Print summary total, malloc and virtual memory |
79 |
void print_total(size_t reserved, size_t committed) const; |
|
46489
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
27162
diff
changeset
|
80 |
void print_malloc(size_t amount, size_t count, MEMFLAGS flag = mtNone) const; |
25946 | 81 |
void print_virtual_memory(size_t reserved, size_t committed) const; |
13195 | 82 |
|
25946 | 83 |
void print_malloc_line(size_t amount, size_t count) const; |
84 |
void print_virtual_memory_line(size_t reserved, size_t committed) const; |
|
85 |
void print_arena_line(size_t amount, size_t count) const; |
|
13195 | 86 |
|
25946 | 87 |
void print_virtual_memory_region(const char* type, address base, size_t size) const; |
88 |
}; |
|
13195 | 89 |
|
25946 | 90 |
/* |
91 |
* The class is for generating summary tracking report. |
|
92 |
*/ |
|
93 |
class MemSummaryReporter : public MemReporterBase { |
|
94 |
private: |
|
95 |
MallocMemorySnapshot* _malloc_snapshot; |
|
96 |
VirtualMemorySnapshot* _vm_snapshot; |
|
48874
f09fdaad7321
8196924: [BACKOUT] NMT: Report array class count in NMT summary
jwilhelm
parents:
48873
diff
changeset
|
97 |
size_t _class_count; |
13195 | 98 |
|
25946 | 99 |
public: |
100 |
// This constructor is for normal reporting from a recent baseline. |
|
101 |
MemSummaryReporter(MemBaseline& baseline, outputStream* output, |
|
102 |
size_t scale = K) : MemReporterBase(output, scale), |
|
103 |
_malloc_snapshot(baseline.malloc_memory_snapshot()), |
|
104 |
_vm_snapshot(baseline.virtual_memory_snapshot()), |
|
48874
f09fdaad7321
8196924: [BACKOUT] NMT: Report array class count in NMT summary
jwilhelm
parents:
48873
diff
changeset
|
105 |
_class_count(baseline.class_count()) { } |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13975
diff
changeset
|
106 |
|
13195 | 107 |
|
25946 | 108 |
// Generate summary report |
109 |
virtual void report(); |
|
110 |
private: |
|
111 |
// Report summary for each memory type |
|
112 |
void report_summary_of_type(MEMFLAGS type, MallocMemory* malloc_memory, |
|
113 |
VirtualMemory* virtual_memory); |
|
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
114 |
|
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
115 |
void report_metadata(Metaspace::MetadataType type) const; |
13195 | 116 |
}; |
117 |
||
118 |
/* |
|
25946 | 119 |
* The class is for generating detail tracking report. |
13195 | 120 |
*/ |
25946 | 121 |
class MemDetailReporter : public MemSummaryReporter { |
13195 | 122 |
private: |
25946 | 123 |
MemBaseline& _baseline; |
13195 | 124 |
|
125 |
public: |
|
25946 | 126 |
MemDetailReporter(MemBaseline& baseline, outputStream* output, size_t scale = K) : |
127 |
MemSummaryReporter(baseline, output, scale), |
|
128 |
_baseline(baseline) { } |
|
129 |
||
130 |
// Generate detail report. |
|
131 |
// The report contains summary and detail sections. |
|
132 |
virtual void report() { |
|
133 |
MemSummaryReporter::report(); |
|
134 |
report_virtual_memory_map(); |
|
135 |
report_detail(); |
|
13195 | 136 |
} |
137 |
||
138 |
private: |
|
25946 | 139 |
// Report detail tracking data. |
140 |
void report_detail(); |
|
141 |
// Report virtual memory map |
|
142 |
void report_virtual_memory_map(); |
|
143 |
// Report malloc allocation sites |
|
144 |
void report_malloc_sites(); |
|
145 |
// Report virtual memory reservation sites |
|
146 |
void report_virtual_memory_allocation_sites(); |
|
13195 | 147 |
|
25946 | 148 |
// Report a virtual memory region |
149 |
void report_virtual_memory_region(const ReservedMemoryRegion* rgn); |
|
13195 | 150 |
}; |
151 |
||
152 |
/* |
|
25946 | 153 |
* The class is for generating summary comparison report. |
154 |
* It compares current memory baseline against an early baseline. |
|
13195 | 155 |
*/ |
25946 | 156 |
class MemSummaryDiffReporter : public MemReporterBase { |
157 |
protected: |
|
158 |
MemBaseline& _early_baseline; |
|
159 |
MemBaseline& _current_baseline; |
|
13195 | 160 |
|
161 |
public: |
|
25946 | 162 |
MemSummaryDiffReporter(MemBaseline& early_baseline, MemBaseline& current_baseline, |
163 |
outputStream* output, size_t scale = K) : MemReporterBase(output, scale), |
|
164 |
_early_baseline(early_baseline), _current_baseline(current_baseline) { |
|
165 |
assert(early_baseline.baseline_type() != MemBaseline::Not_baselined, "Not baselined"); |
|
166 |
assert(current_baseline.baseline_type() != MemBaseline::Not_baselined, "Not baselined"); |
|
13195 | 167 |
} |
168 |
||
25946 | 169 |
// Generate summary comparison report |
170 |
virtual void report_diff(); |
|
13195 | 171 |
|
25946 | 172 |
private: |
173 |
// report the comparison of each memory type |
|
174 |
void diff_summary_of_type(MEMFLAGS type, |
|
175 |
const MallocMemory* early_malloc, const VirtualMemory* early_vm, |
|
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
176 |
const MetaspaceSnapshot* early_ms, |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
177 |
const MallocMemory* current_malloc, const VirtualMemory* current_vm, |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
178 |
const MetaspaceSnapshot* current_ms) const; |
13195 | 179 |
|
25946 | 180 |
protected: |
181 |
void print_malloc_diff(size_t current_amount, size_t current_count, |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
182 |
size_t early_amount, size_t early_count, MEMFLAGS flags) const; |
25946 | 183 |
void print_virtual_memory_diff(size_t current_reserved, size_t current_committed, |
184 |
size_t early_reserved, size_t early_committed) const; |
|
185 |
void print_arena_diff(size_t current_amount, size_t current_count, |
|
186 |
size_t early_amount, size_t early_count) const; |
|
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
187 |
|
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
188 |
void print_metaspace_diff(const MetaspaceSnapshot* current_ms, |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
189 |
const MetaspaceSnapshot* early_ms) const; |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
190 |
void print_metaspace_diff(Metaspace::MetadataType type, |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
191 |
const MetaspaceSnapshot* current_ms, const MetaspaceSnapshot* early_ms) const; |
13195 | 192 |
}; |
193 |
||
25946 | 194 |
/* |
195 |
* The class is for generating detail comparison report. |
|
196 |
* It compares current memory baseline against an early baseline, |
|
197 |
* both baselines have to be detail baseline. |
|
198 |
*/ |
|
199 |
class MemDetailDiffReporter : public MemSummaryDiffReporter { |
|
200 |
public: |
|
201 |
MemDetailDiffReporter(MemBaseline& early_baseline, MemBaseline& current_baseline, |
|
202 |
outputStream* output, size_t scale = K) : |
|
203 |
MemSummaryDiffReporter(early_baseline, current_baseline, output, scale) { } |
|
204 |
||
205 |
// Generate detail comparison report |
|
206 |
virtual void report_diff(); |
|
207 |
||
208 |
// Malloc allocation site comparison |
|
209 |
void diff_malloc_sites() const; |
|
210 |
// Virutal memory reservation site comparison |
|
211 |
void diff_virtual_memory_sites() const; |
|
212 |
||
213 |
// New malloc allocation site in recent baseline |
|
214 |
void new_malloc_site (const MallocSite* site) const; |
|
215 |
// The malloc allocation site is not in recent baseline |
|
216 |
void old_malloc_site (const MallocSite* site) const; |
|
217 |
// Compare malloc allocation site, it is in both baselines |
|
218 |
void diff_malloc_site(const MallocSite* early, const MallocSite* current) const; |
|
219 |
||
220 |
// New virtual memory allocation site in recent baseline |
|
221 |
void new_virtual_memory_site (const VirtualMemoryAllocationSite* callsite) const; |
|
222 |
// The virtual memory allocation site is not in recent baseline |
|
223 |
void old_virtual_memory_site (const VirtualMemoryAllocationSite* callsite) const; |
|
224 |
// Compare virtual memory allocation site, it is in both baseline |
|
225 |
void diff_virtual_memory_site(const VirtualMemoryAllocationSite* early, |
|
226 |
const VirtualMemoryAllocationSite* current) const; |
|
227 |
||
228 |
void diff_malloc_site(const NativeCallStack* stack, size_t current_size, |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
229 |
size_t currrent_count, size_t early_size, size_t early_count, MEMFLAGS flags) const; |
25946 | 230 |
void diff_virtual_memory_site(const NativeCallStack* stack, size_t current_reserved, |
231 |
size_t current_committed, size_t early_reserved, size_t early_committed) const; |
|
232 |
}; |
|
13195 | 233 |
|
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
234 |
#endif // INCLUDE_NMT |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
235 |
|
25946 | 236 |
#endif |
237 |