13195
|
1 |
/*
|
25946
|
2 |
* Copyright (c) 2012, 2014, 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 {
|
|
58 |
by_address, // by memory address
|
|
59 |
by_size, // by memory size
|
|
60 |
by_site // by call site where the memory is allocated from
|
13195
|
61 |
};
|
|
62 |
|
25946
|
63 |
private:
|
|
64 |
// All baseline data is stored in this arena
|
|
65 |
Arena* _arena;
|
|
66 |
|
|
67 |
// Summary information
|
|
68 |
MallocMemorySnapshot* _malloc_memory_snapshot;
|
|
69 |
VirtualMemorySnapshot* _virtual_memory_snapshot;
|
|
70 |
|
|
71 |
size_t _class_count;
|
13195
|
72 |
|
25946
|
73 |
// Allocation sites information
|
|
74 |
// Malloc allocation sites
|
|
75 |
LinkedListImpl<MallocSite, ResourceObj::ARENA>
|
|
76 |
_malloc_sites;
|
|
77 |
|
|
78 |
// All virtual memory allocations
|
|
79 |
LinkedListImpl<ReservedMemoryRegion, ResourceObj::ARENA>
|
|
80 |
_virtual_memory_allocations;
|
13195
|
81 |
|
25946
|
82 |
// Virtual memory allocations by allocation sites, always in by_address
|
|
83 |
// order
|
|
84 |
LinkedListImpl<VirtualMemoryAllocationSite, ResourceObj::ARENA>
|
|
85 |
_virtual_memory_sites;
|
|
86 |
|
|
87 |
SortingOrder _malloc_sites_order;
|
|
88 |
SortingOrder _virtual_memory_sites_order;
|
|
89 |
|
|
90 |
BaselineType _baseline_type;
|
13195
|
91 |
|
|
92 |
public:
|
25946
|
93 |
// create a memory baseline
|
|
94 |
MemBaseline():
|
|
95 |
_baseline_type(Not_baselined),
|
|
96 |
_class_count(0),
|
|
97 |
_arena(NULL),
|
|
98 |
_malloc_memory_snapshot(NULL),
|
|
99 |
_virtual_memory_snapshot(NULL),
|
|
100 |
_malloc_sites(NULL) {
|
13195
|
101 |
}
|
|
102 |
|
25946
|
103 |
~MemBaseline() {
|
|
104 |
reset();
|
|
105 |
if (_arena != NULL) {
|
|
106 |
delete _arena;
|
|
107 |
}
|
13195
|
108 |
}
|
|
109 |
|
25946
|
110 |
bool baseline(bool summaryOnly = true);
|
13195
|
111 |
|
25946
|
112 |
BaselineType baseline_type() const { return _baseline_type; }
|
13195
|
113 |
|
25946
|
114 |
MallocMemorySnapshot* malloc_memory_snapshot() const {
|
|
115 |
return _malloc_memory_snapshot;
|
13195
|
116 |
}
|
|
117 |
|
25946
|
118 |
VirtualMemorySnapshot* virtual_memory_snapshot() const {
|
|
119 |
return _virtual_memory_snapshot;
|
13195
|
120 |
}
|
|
121 |
|
25946
|
122 |
MallocSiteIterator malloc_sites(SortingOrder order);
|
|
123 |
VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order);
|
13195
|
124 |
|
25946
|
125 |
// Virtual memory allocation iterator always returns in virtual memory
|
|
126 |
// base address order.
|
|
127 |
VirtualMemoryAllocationIterator virtual_memory_allocations() {
|
|
128 |
assert(!_virtual_memory_allocations.is_empty(), "Not detail baseline");
|
|
129 |
return VirtualMemoryAllocationIterator(_virtual_memory_allocations.head());
|
13195
|
130 |
}
|
|
131 |
|
25946
|
132 |
// Total reserved memory = total malloc'd memory + total reserved virtual
|
|
133 |
// memory
|
|
134 |
size_t total_reserved_memory() const {
|
|
135 |
assert(baseline_type() != Not_baselined, "Not yet baselined");
|
|
136 |
assert(_virtual_memory_snapshot != NULL, "No virtual memory snapshot");
|
|
137 |
assert(_malloc_memory_snapshot != NULL, "No malloc memory snapshot");
|
|
138 |
size_t amount = _malloc_memory_snapshot->total() +
|
|
139 |
_virtual_memory_snapshot->total_reserved();
|
|
140 |
return amount;
|
13195
|
141 |
}
|
|
142 |
|
25946
|
143 |
// Total committed memory = total malloc'd memory + total committed
|
|
144 |
// virtual memory
|
|
145 |
size_t total_committed_memory() const {
|
|
146 |
assert(baseline_type() != Not_baselined, "Not yet baselined");
|
|
147 |
assert(_virtual_memory_snapshot != NULL,
|
|
148 |
"Not a snapshot");
|
|
149 |
size_t amount = _malloc_memory_snapshot->total() +
|
|
150 |
_virtual_memory_snapshot->total_committed();
|
|
151 |
return amount;
|
13195
|
152 |
}
|
|
153 |
|
25946
|
154 |
size_t total_arena_memory() const {
|
|
155 |
assert(baseline_type() != Not_baselined, "Not yet baselined");
|
|
156 |
assert(_malloc_memory_snapshot != NULL, "Not yet baselined");
|
|
157 |
return _malloc_memory_snapshot->total_arena();
|
13195
|
158 |
}
|
|
159 |
|
25946
|
160 |
size_t malloc_tracking_overhead() const {
|
|
161 |
assert(baseline_type() != Not_baselined, "Not yet baselined");
|
|
162 |
return _malloc_memory_snapshot->malloc_overhead()->size();
|
13195
|
163 |
}
|
|
164 |
|
25946
|
165 |
const MallocMemory* malloc_memory(MEMFLAGS flag) const {
|
|
166 |
assert(_malloc_memory_snapshot != NULL, "Not a snapshot");
|
|
167 |
return _malloc_memory_snapshot->by_type(flag);
|
13195
|
168 |
}
|
|
169 |
|
25946
|
170 |
const VirtualMemory* virtual_memory(MEMFLAGS flag) const {
|
|
171 |
assert(_virtual_memory_snapshot != NULL, "Not a snapshot");
|
|
172 |
return _virtual_memory_snapshot->by_type(flag);
|
13195
|
173 |
}
|
|
174 |
|
|
175 |
|
25946
|
176 |
size_t class_count() const {
|
|
177 |
assert(baseline_type() != Not_baselined, "Not yet baselined");
|
|
178 |
return _class_count;
|
13195
|
179 |
}
|
|
180 |
|
25946
|
181 |
size_t thread_count() const {
|
|
182 |
assert(baseline_type() != Not_baselined, "Not yet baselined");
|
|
183 |
assert(_malloc_memory_snapshot != NULL, "Baselined?");
|
|
184 |
return _malloc_memory_snapshot->thread_count();
|
13195
|
185 |
}
|
|
186 |
|
|
187 |
// reset the baseline for reuse
|
25946
|
188 |
void reset() {
|
|
189 |
_baseline_type = Not_baselined;
|
|
190 |
_malloc_memory_snapshot = NULL;
|
|
191 |
_virtual_memory_snapshot = NULL;
|
|
192 |
_class_count = 0;
|
13195
|
193 |
|
25946
|
194 |
_malloc_sites = NULL;
|
|
195 |
_virtual_memory_sites = NULL;
|
|
196 |
_virtual_memory_allocations = NULL;
|
|
197 |
|
|
198 |
if (_arena != NULL) {
|
|
199 |
_arena->destruct_contents();
|
|
200 |
}
|
13195
|
201 |
}
|
|
202 |
|
25946
|
203 |
private:
|
|
204 |
// Baseline summary information
|
|
205 |
bool baseline_summary();
|
13195
|
206 |
|
25946
|
207 |
// Baseline allocation sites (detail tracking only)
|
|
208 |
bool baseline_allocation_sites();
|
|
209 |
|
|
210 |
// Aggregate virtual memory allocation by allocation sites
|
|
211 |
bool aggregate_virtual_memory_allocation_sites();
|
13195
|
212 |
|
25946
|
213 |
Arena* arena() { return _arena; }
|
13195
|
214 |
|
25946
|
215 |
// Sorting allocation sites in different orders
|
|
216 |
// Sort allocation sites in size order
|
|
217 |
void malloc_sites_to_size_order();
|
|
218 |
// Sort allocation sites in call site address order
|
|
219 |
void malloc_sites_to_allocation_site_order();
|
13195
|
220 |
|
25946
|
221 |
// Sort allocation sites in reserved size order
|
|
222 |
void virtual_memory_sites_to_size_order();
|
|
223 |
// Sort allocation sites in call site address order
|
|
224 |
void virtual_memory_sites_to_reservation_site_order();
|
13195
|
225 |
};
|
|
226 |
|
25946
|
227 |
#endif // INCLUDE_NMT
|
13195
|
228 |
|
|
229 |
#endif // SHARE_VM_SERVICES_MEM_BASELINE_HPP
|