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