author | zgu |
Mon, 24 Jul 2017 15:19:46 -0400 | |
changeset 46711 | 0ccef2260315 |
parent 27162 | 0a4a7276949b |
permissions | -rw-r--r-- |
13195 | 1 |
/* |
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
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_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 |
*/ |
25946 | 45 |
class MemBaseline VALUE_OBJ_CLASS_SPEC { |
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; |
|
25946 | 68 |
|
69 |
size_t _class_count; |
|
13195 | 70 |
|
25946 | 71 |
// Allocation sites information |
72 |
// Malloc allocation sites |
|
26288 | 73 |
LinkedListImpl<MallocSite> _malloc_sites; |
25946 | 74 |
|
75 |
// All virtual memory allocations |
|
26288 | 76 |
LinkedListImpl<ReservedMemoryRegion> _virtual_memory_allocations; |
13195 | 77 |
|
25946 | 78 |
// Virtual memory allocations by allocation sites, always in by_address |
79 |
// order |
|
26288 | 80 |
LinkedListImpl<VirtualMemoryAllocationSite> _virtual_memory_sites; |
25946 | 81 |
|
82 |
SortingOrder _malloc_sites_order; |
|
83 |
SortingOrder _virtual_memory_sites_order; |
|
84 |
||
85 |
BaselineType _baseline_type; |
|
13195 | 86 |
|
87 |
public: |
|
25946 | 88 |
// create a memory baseline |
89 |
MemBaseline(): |
|
90 |
_baseline_type(Not_baselined), |
|
26288 | 91 |
_class_count(0) { |
13195 | 92 |
} |
93 |
||
25946 | 94 |
bool baseline(bool summaryOnly = true); |
13195 | 95 |
|
25946 | 96 |
BaselineType baseline_type() const { return _baseline_type; } |
13195 | 97 |
|
26288 | 98 |
MallocMemorySnapshot* malloc_memory_snapshot() { |
99 |
return &_malloc_memory_snapshot; |
|
13195 | 100 |
} |
101 |
||
26288 | 102 |
VirtualMemorySnapshot* virtual_memory_snapshot() { |
103 |
return &_virtual_memory_snapshot; |
|
13195 | 104 |
} |
105 |
||
25946 | 106 |
MallocSiteIterator malloc_sites(SortingOrder order); |
107 |
VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order); |
|
13195 | 108 |
|
25946 | 109 |
// Virtual memory allocation iterator always returns in virtual memory |
110 |
// base address order. |
|
111 |
VirtualMemoryAllocationIterator virtual_memory_allocations() { |
|
112 |
assert(!_virtual_memory_allocations.is_empty(), "Not detail baseline"); |
|
113 |
return VirtualMemoryAllocationIterator(_virtual_memory_allocations.head()); |
|
13195 | 114 |
} |
115 |
||
25946 | 116 |
// Total reserved memory = total malloc'd memory + total reserved virtual |
117 |
// memory |
|
118 |
size_t total_reserved_memory() const { |
|
119 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 120 |
size_t amount = _malloc_memory_snapshot.total() + |
121 |
_virtual_memory_snapshot.total_reserved(); |
|
25946 | 122 |
return amount; |
13195 | 123 |
} |
124 |
||
25946 | 125 |
// Total committed memory = total malloc'd memory + total committed |
126 |
// virtual memory |
|
127 |
size_t total_committed_memory() const { |
|
128 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 129 |
size_t amount = _malloc_memory_snapshot.total() + |
130 |
_virtual_memory_snapshot.total_committed(); |
|
25946 | 131 |
return amount; |
13195 | 132 |
} |
133 |
||
25946 | 134 |
size_t total_arena_memory() const { |
135 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 136 |
return _malloc_memory_snapshot.total_arena(); |
13195 | 137 |
} |
138 |
||
25946 | 139 |
size_t malloc_tracking_overhead() const { |
140 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 141 |
MemBaseline* bl = const_cast<MemBaseline*>(this); |
142 |
return bl->_malloc_memory_snapshot.malloc_overhead()->size(); |
|
13195 | 143 |
} |
144 |
||
26288 | 145 |
MallocMemory* malloc_memory(MEMFLAGS flag) { |
146 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
147 |
return _malloc_memory_snapshot.by_type(flag); |
|
13195 | 148 |
} |
149 |
||
26288 | 150 |
VirtualMemory* virtual_memory(MEMFLAGS flag) { |
151 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
152 |
return _virtual_memory_snapshot.by_type(flag); |
|
13195 | 153 |
} |
154 |
||
155 |
||
25946 | 156 |
size_t class_count() const { |
157 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
158 |
return _class_count; |
|
13195 | 159 |
} |
160 |
||
25946 | 161 |
size_t thread_count() const { |
162 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 163 |
return _malloc_memory_snapshot.thread_count(); |
13195 | 164 |
} |
165 |
||
166 |
// reset the baseline for reuse |
|
25946 | 167 |
void reset() { |
168 |
_baseline_type = Not_baselined; |
|
27162
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26288
diff
changeset
|
169 |
// _malloc_memory_snapshot and _virtual_memory_snapshot are copied over. |
25946 | 170 |
_class_count = 0; |
13195 | 171 |
|
26288 | 172 |
_malloc_sites.clear(); |
173 |
_virtual_memory_sites.clear(); |
|
174 |
_virtual_memory_allocations.clear(); |
|
13195 | 175 |
} |
176 |
||
25946 | 177 |
private: |
178 |
// Baseline summary information |
|
179 |
bool baseline_summary(); |
|
13195 | 180 |
|
25946 | 181 |
// Baseline allocation sites (detail tracking only) |
182 |
bool baseline_allocation_sites(); |
|
183 |
||
184 |
// Aggregate virtual memory allocation by allocation sites |
|
185 |
bool aggregate_virtual_memory_allocation_sites(); |
|
13195 | 186 |
|
25946 | 187 |
// Sorting allocation sites in different orders |
188 |
// Sort allocation sites in size order |
|
189 |
void malloc_sites_to_size_order(); |
|
190 |
// Sort allocation sites in call site address order |
|
191 |
void malloc_sites_to_allocation_site_order(); |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
192 |
// 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
|
193 |
void malloc_sites_to_allocation_site_and_type_order(); |
13195 | 194 |
|
25946 | 195 |
// Sort allocation sites in reserved size order |
196 |
void virtual_memory_sites_to_size_order(); |
|
197 |
// Sort allocation sites in call site address order |
|
198 |
void virtual_memory_sites_to_reservation_site_order(); |
|
13195 | 199 |
}; |
200 |
||
25946 | 201 |
#endif // INCLUDE_NMT |
13195 | 202 |
|
203 |
#endif // SHARE_VM_SERVICES_MEM_BASELINE_HPP |