author | coleenp |
Fri, 09 Mar 2018 10:46:02 -0500 | |
changeset 49364 | 601146c66cad |
parent 48884 | 7e17b00dc245 |
child 49621 | 5ef28d560b6f |
permissions | -rw-r--r-- |
13195 | 1 |
/* |
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
2 |
* Copyright (c) 2012, 2018, 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_BASELINE_HPP |
|
26 |
#define SHARE_VM_SERVICES_MEM_BASELINE_HPP |
|
27 |
||
25946 | 28 |
#if INCLUDE_NMT |
29 |
||
13195 | 30 |
#include "memory/allocation.hpp" |
31 |
#include "runtime/mutex.hpp" |
|
25946 | 32 |
#include "services/mallocSiteTable.hpp" |
33 |
#include "services/mallocTracker.hpp" |
|
34 |
#include "services/nmtCommon.hpp" |
|
35 |
#include "services/virtualMemoryTracker.hpp" |
|
36 |
#include "utilities/linkedlist.hpp" |
|
13195 | 37 |
|
25946 | 38 |
typedef LinkedListIterator<MallocSite> MallocSiteIterator; |
39 |
typedef LinkedListIterator<VirtualMemoryAllocationSite> VirtualMemorySiteIterator; |
|
40 |
typedef LinkedListIterator<ReservedMemoryRegion> VirtualMemoryAllocationIterator; |
|
13195 | 41 |
|
42 |
/* |
|
25946 | 43 |
* Baseline a memory snapshot |
13195 | 44 |
*/ |
49364
601146c66cad
8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents:
48884
diff
changeset
|
45 |
class MemBaseline { |
13195 | 46 |
public: |
25946 | 47 |
enum BaselineThreshold { |
48 |
SIZE_THRESHOLD = K // Only allocation size over this threshold will be baselined. |
|
49 |
}; |
|
13195 | 50 |
|
25946 | 51 |
enum BaselineType { |
52 |
Not_baselined, |
|
53 |
Summary_baselined, |
|
54 |
Detail_baselined |
|
55 |
}; |
|
13195 | 56 |
|
25946 | 57 |
enum SortingOrder { |
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
58 |
by_address, // by memory address |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
59 |
by_size, // by memory size |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
60 |
by_site, // by call site where the memory is allocated from |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
61 |
by_site_and_type // by call site and memory type |
13195 | 62 |
}; |
63 |
||
25946 | 64 |
private: |
65 |
// Summary information |
|
26288 | 66 |
MallocMemorySnapshot _malloc_memory_snapshot; |
67 |
VirtualMemorySnapshot _virtual_memory_snapshot; |
|
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
68 |
MetaspaceSnapshot _metaspace_snapshot; |
25946 | 69 |
|
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
70 |
size_t _instance_class_count; |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
71 |
size_t _array_class_count; |
13195 | 72 |
|
25946 | 73 |
// Allocation sites information |
74 |
// Malloc allocation sites |
|
26288 | 75 |
LinkedListImpl<MallocSite> _malloc_sites; |
25946 | 76 |
|
77 |
// All virtual memory allocations |
|
26288 | 78 |
LinkedListImpl<ReservedMemoryRegion> _virtual_memory_allocations; |
13195 | 79 |
|
25946 | 80 |
// Virtual memory allocations by allocation sites, always in by_address |
81 |
// order |
|
26288 | 82 |
LinkedListImpl<VirtualMemoryAllocationSite> _virtual_memory_sites; |
25946 | 83 |
|
84 |
SortingOrder _malloc_sites_order; |
|
85 |
SortingOrder _virtual_memory_sites_order; |
|
86 |
||
87 |
BaselineType _baseline_type; |
|
13195 | 88 |
|
89 |
public: |
|
25946 | 90 |
// create a memory baseline |
91 |
MemBaseline(): |
|
92 |
_baseline_type(Not_baselined), |
|
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
93 |
_instance_class_count(0), _array_class_count(0) { |
13195 | 94 |
} |
95 |
||
25946 | 96 |
bool baseline(bool summaryOnly = true); |
13195 | 97 |
|
25946 | 98 |
BaselineType baseline_type() const { return _baseline_type; } |
13195 | 99 |
|
26288 | 100 |
MallocMemorySnapshot* malloc_memory_snapshot() { |
101 |
return &_malloc_memory_snapshot; |
|
13195 | 102 |
} |
103 |
||
26288 | 104 |
VirtualMemorySnapshot* virtual_memory_snapshot() { |
105 |
return &_virtual_memory_snapshot; |
|
13195 | 106 |
} |
107 |
||
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
108 |
MetaspaceSnapshot* metaspace_snapshot() { |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
109 |
return &_metaspace_snapshot; |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
110 |
} |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
111 |
|
25946 | 112 |
MallocSiteIterator malloc_sites(SortingOrder order); |
113 |
VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order); |
|
13195 | 114 |
|
25946 | 115 |
// Virtual memory allocation iterator always returns in virtual memory |
116 |
// base address order. |
|
117 |
VirtualMemoryAllocationIterator virtual_memory_allocations() { |
|
118 |
assert(!_virtual_memory_allocations.is_empty(), "Not detail baseline"); |
|
119 |
return VirtualMemoryAllocationIterator(_virtual_memory_allocations.head()); |
|
13195 | 120 |
} |
121 |
||
25946 | 122 |
// Total reserved memory = total malloc'd memory + total reserved virtual |
123 |
// memory |
|
124 |
size_t total_reserved_memory() const { |
|
125 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 126 |
size_t amount = _malloc_memory_snapshot.total() + |
127 |
_virtual_memory_snapshot.total_reserved(); |
|
25946 | 128 |
return amount; |
13195 | 129 |
} |
130 |
||
25946 | 131 |
// Total committed memory = total malloc'd memory + total committed |
132 |
// virtual memory |
|
133 |
size_t total_committed_memory() const { |
|
134 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 135 |
size_t amount = _malloc_memory_snapshot.total() + |
136 |
_virtual_memory_snapshot.total_committed(); |
|
25946 | 137 |
return amount; |
13195 | 138 |
} |
139 |
||
25946 | 140 |
size_t total_arena_memory() const { |
141 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 142 |
return _malloc_memory_snapshot.total_arena(); |
13195 | 143 |
} |
144 |
||
25946 | 145 |
size_t malloc_tracking_overhead() const { |
146 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 147 |
MemBaseline* bl = const_cast<MemBaseline*>(this); |
148 |
return bl->_malloc_memory_snapshot.malloc_overhead()->size(); |
|
13195 | 149 |
} |
150 |
||
26288 | 151 |
MallocMemory* malloc_memory(MEMFLAGS flag) { |
152 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
153 |
return _malloc_memory_snapshot.by_type(flag); |
|
13195 | 154 |
} |
155 |
||
26288 | 156 |
VirtualMemory* virtual_memory(MEMFLAGS flag) { |
157 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
158 |
return _virtual_memory_snapshot.by_type(flag); |
|
13195 | 159 |
} |
160 |
||
161 |
||
25946 | 162 |
size_t class_count() const { |
163 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
164 |
return _instance_class_count + _array_class_count; |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
165 |
} |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
166 |
|
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
167 |
size_t instance_class_count() const { |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
168 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
169 |
return _instance_class_count; |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
170 |
} |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
171 |
|
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
172 |
size_t array_class_count() const { |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
173 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
174 |
return _array_class_count; |
13195 | 175 |
} |
176 |
||
25946 | 177 |
size_t thread_count() const { |
178 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 179 |
return _malloc_memory_snapshot.thread_count(); |
13195 | 180 |
} |
181 |
||
182 |
// reset the baseline for reuse |
|
25946 | 183 |
void reset() { |
184 |
_baseline_type = Not_baselined; |
|
27162
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26288
diff
changeset
|
185 |
// _malloc_memory_snapshot and _virtual_memory_snapshot are copied over. |
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
186 |
_instance_class_count = 0; |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
187 |
_array_class_count = 0; |
13195 | 188 |
|
26288 | 189 |
_malloc_sites.clear(); |
190 |
_virtual_memory_sites.clear(); |
|
191 |
_virtual_memory_allocations.clear(); |
|
13195 | 192 |
} |
193 |
||
25946 | 194 |
private: |
195 |
// Baseline summary information |
|
196 |
bool baseline_summary(); |
|
13195 | 197 |
|
25946 | 198 |
// Baseline allocation sites (detail tracking only) |
199 |
bool baseline_allocation_sites(); |
|
200 |
||
201 |
// Aggregate virtual memory allocation by allocation sites |
|
202 |
bool aggregate_virtual_memory_allocation_sites(); |
|
13195 | 203 |
|
25946 | 204 |
// Sorting allocation sites in different orders |
205 |
// Sort allocation sites in size order |
|
206 |
void malloc_sites_to_size_order(); |
|
207 |
// Sort allocation sites in call site address order |
|
208 |
void malloc_sites_to_allocation_site_order(); |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
209 |
// Sort allocation sites in call site address and memory type order |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
210 |
void malloc_sites_to_allocation_site_and_type_order(); |
13195 | 211 |
|
25946 | 212 |
// Sort allocation sites in reserved size order |
213 |
void virtual_memory_sites_to_size_order(); |
|
214 |
// Sort allocation sites in call site address order |
|
215 |
void virtual_memory_sites_to_reservation_site_order(); |
|
13195 | 216 |
}; |
217 |
||
25946 | 218 |
#endif // INCLUDE_NMT |
13195 | 219 |
|
220 |
#endif // SHARE_VM_SERVICES_MEM_BASELINE_HPP |