Print this page
Split |
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/services/memBaseline.hpp
+++ new/src/share/vm/services/memBaseline.hpp
1 1 /*
2 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #ifndef SHARE_VM_SERVICES_MEM_BASELINE_HPP
26 26 #define SHARE_VM_SERVICES_MEM_BASELINE_HPP
27 27
28 28 #include "memory/allocation.hpp"
29 29 #include "runtime/mutex.hpp"
30 30 #include "services/memPtr.hpp"
31 31 #include "services/memSnapshot.hpp"
32 32
33 33 // compare unsigned number
34 34 #define UNSIGNED_COMPARE(a, b) ((a > b) ? 1 : ((a == b) ? 0 : -1))
35 35
36 36 /*
37 37 * MallocCallsitePointer and VMCallsitePointer are used
38 38 * to baseline memory blocks with their callsite information.
39 39 * They are only available when detail tracking is turned
40 40 * on.
41 41 */
42 42
43 43 /* baselined malloc record aggregated by callsite */
44 44 class MallocCallsitePointer : public MemPointer {
45 45 private:
46 46 size_t _count; // number of malloc invocation from this callsite
47 47 size_t _amount; // total amount of memory malloc-ed from this callsite
48 48
49 49 public:
50 50 MallocCallsitePointer() {
51 51 _count = 0;
52 52 _amount = 0;
53 53 }
54 54
55 55 MallocCallsitePointer(address pc) : MemPointer(pc) {
56 56 _count = 0;
57 57 _amount = 0;
58 58 }
59 59
60 60 MallocCallsitePointer& operator=(const MallocCallsitePointer& p) {
61 61 MemPointer::operator=(p);
62 62 _count = p.count();
63 63 _amount = p.amount();
64 64 return *this;
65 65 }
66 66
67 67 inline void inc(size_t size) {
68 68 _count ++;
69 69 _amount += size;
70 70 };
71 71
72 72 inline size_t count() const {
73 73 return _count;
74 74 }
75 75
76 76 inline size_t amount() const {
77 77 return _amount;
78 78 }
79 79 };
80 80
81 81 // baselined virtual memory record aggregated by callsite
82 82 class VMCallsitePointer : public MemPointer {
83 83 private:
84 84 size_t _count; // number of invocation from this callsite
85 85 size_t _reserved_amount; // total reserved amount
86 86 size_t _committed_amount; // total committed amount
87 87
88 88 public:
89 89 VMCallsitePointer() {
90 90 _count = 0;
91 91 _reserved_amount = 0;
92 92 _committed_amount = 0;
93 93 }
94 94
95 95 VMCallsitePointer(address pc) : MemPointer(pc) {
96 96 _count = 0;
97 97 _reserved_amount = 0;
98 98 _committed_amount = 0;
99 99 }
100 100
101 101 VMCallsitePointer& operator=(const VMCallsitePointer& p) {
102 102 MemPointer::operator=(p);
103 103 _count = p.count();
104 104 _reserved_amount = p.reserved_amount();
105 105 _committed_amount = p.committed_amount();
106 106 return *this;
107 107 }
108 108
109 109 inline void inc(size_t reserved, size_t committed) {
110 110 _count ++;
111 111 _reserved_amount += reserved;
112 112 _committed_amount += committed;
113 113 }
114 114
115 115 inline size_t count() const {
116 116 return _count;
117 117 }
118 118
119 119 inline size_t reserved_amount() const {
120 120 return _reserved_amount;
121 121 }
122 122
123 123 inline size_t committed_amount() const {
124 124 return _committed_amount;
125 125 }
126 126 };
127 127
128 128 // maps a memory type flag to readable name
129 129 typedef struct _memType2Name {
130 130 MEMFLAGS _flag;
131 131 const char* _name;
132 132 } MemType2Name;
133 133
134 134
135 135 // This class aggregates malloc'd records by memory type
136 136 class MallocMem : public _ValueObj {
137 137 private:
138 138 MEMFLAGS _type;
139 139
140 140 size_t _count;
141 141 size_t _amount;
142 142
143 143 public:
144 144 MallocMem() {
145 145 _type = mtNone;
146 146 _count = 0;
147 147 _amount = 0;
148 148 }
149 149
150 150 MallocMem(MEMFLAGS flags) {
151 151 assert(HAS_VALID_MEMORY_TYPE(flags), "no type");
152 152 _type = FLAGS_TO_MEMORY_TYPE(flags);
153 153 _count = 0;
154 154 _amount = 0;
155 155 }
156 156
157 157 inline void set_type(MEMFLAGS flag) {
158 158 _type = flag;
159 159 }
160 160
161 161 inline void clear() {
162 162 _count = 0;
163 163 _amount = 0;
164 164 _type = mtNone;
165 165 }
166 166
167 167 MallocMem& operator=(const MallocMem& m) {
168 168 assert(_type == m.type(), "different type");
169 169 _count = m.count();
170 170 _amount = m.amount();
171 171 return *this;
172 172 }
173 173
174 174 inline void inc(size_t amt) {
175 175 _amount += amt;
176 176 _count ++;
177 177 }
178 178
179 179 inline void reduce(size_t amt) {
180 180 assert(_amount >= amt, "Just check");
181 181 _amount -= amt;
182 182 }
183 183
184 184 inline void overwrite_counter(size_t count) {
185 185 _count = count;
186 186 }
187 187
188 188 inline MEMFLAGS type() const {
189 189 return _type;
190 190 }
191 191
192 192 inline bool is_type(MEMFLAGS flags) const {
193 193 return FLAGS_TO_MEMORY_TYPE(flags) == _type;
194 194 }
195 195
196 196 inline size_t count() const {
197 197 return _count;
198 198 }
199 199
200 200 inline size_t amount() const {
201 201 return _amount;
202 202 }
203 203 };
204 204
205 205 // This class records live arena's memory usage
206 206 class ArenaMem : public MallocMem {
207 207 public:
208 208 ArenaMem(MEMFLAGS typeflag): MallocMem(typeflag) {
209 209 }
210 210 ArenaMem() { }
211 211 };
212 212
213 213 // This class aggregates virtual memory by its memory type
214 214 class VMMem : public _ValueObj {
215 215 private:
216 216 MEMFLAGS _type;
217 217
218 218 size_t _count;
219 219 size_t _reserved_amount;
220 220 size_t _committed_amount;
221 221
222 222 public:
223 223 VMMem() {
224 224 _type = mtNone;
225 225 _count = 0;
226 226 _reserved_amount = 0;
227 227 _committed_amount = 0;
228 228 }
229 229
230 230 VMMem(MEMFLAGS flags) {
231 231 assert(HAS_VALID_MEMORY_TYPE(flags), "no type");
232 232 _type = FLAGS_TO_MEMORY_TYPE(flags);
233 233 _count = 0;
234 234 _reserved_amount = 0;
235 235 _committed_amount = 0;
236 236 }
237 237
238 238 inline void clear() {
239 239 _type = mtNone;
240 240 _count = 0;
241 241 _reserved_amount = 0;
242 242 _committed_amount = 0;
243 243 }
244 244
245 245 inline void set_type(MEMFLAGS flags) {
246 246 _type = FLAGS_TO_MEMORY_TYPE(flags);
247 247 }
248 248
249 249 VMMem& operator=(const VMMem& m) {
250 250 assert(_type == m.type(), "different type");
251 251
252 252 _count = m.count();
253 253 _reserved_amount = m.reserved_amount();
254 254 _committed_amount = m.committed_amount();
255 255 return *this;
256 256 }
257 257
258 258
259 259 inline MEMFLAGS type() const {
260 260 return _type;
261 261 }
262 262
263 263 inline bool is_type(MEMFLAGS flags) const {
264 264 return FLAGS_TO_MEMORY_TYPE(flags) == _type;
265 265 }
266 266
267 267 inline void inc(size_t reserved_amt, size_t committed_amt) {
268 268 _reserved_amount += reserved_amt;
269 269 _committed_amount += committed_amt;
270 270 _count ++;
271 271 }
272 272
273 273 inline size_t count() const {
274 274 return _count;
275 275 }
276 276
277 277 inline size_t reserved_amount() const {
278 278 return _reserved_amount;
279 279 }
280 280
281 281 inline size_t committed_amount() const {
282 282 return _committed_amount;
283 283 }
284 284 };
285 285
286 286
287 287
288 288 #define NUMBER_OF_MEMORY_TYPE (mt_number_of_types + 1)
289 289
290 290 class BaselineReporter;
291 291 class BaselineComparisonReporter;
292 292
293 293 /*
294 294 * This class baselines current memory snapshot.
295 295 * A memory baseline summarizes memory usage by memory type,
296 296 * aggregates memory usage by callsites when detail tracking
297 297 * is on.
298 298 */
299 299 class MemBaseline : public _ValueObj {
300 300 friend class BaselineReporter;
301 301 friend class BaselineComparisonReporter;
302 302
303 303 private:
304 304 // overall summaries
305 305 size_t _total_malloced;
306 306 size_t _total_vm_reserved;
307 307 size_t _total_vm_committed;
308 308 size_t _number_of_classes;
309 309 size_t _number_of_threads;
310 310
311 311 // if it has properly baselined
312 312 bool _baselined;
313 313
314 314 // we categorize memory into three categories within the memory type
315 315 MallocMem _malloc_data[NUMBER_OF_MEMORY_TYPE];
316 316 VMMem _vm_data[NUMBER_OF_MEMORY_TYPE];
317 317 ArenaMem _arena_data[NUMBER_OF_MEMORY_TYPE];
318 318
319 319 // memory records that aggregate memory usage by callsites.
320 320 // only available when detail tracking is on.
321 321 MemPointerArray* _malloc_cs;
322 322 MemPointerArray* _vm_cs;
↓ open down ↓ |
310 lines elided |
↑ open up ↑ |
323 323 // virtual memory map
324 324 MemPointerArray* _vm_map;
325 325
326 326 private:
327 327 static MemType2Name MemType2NameMap[NUMBER_OF_MEMORY_TYPE];
328 328
329 329 private:
330 330 // should not use copy constructor
331 331 MemBaseline(MemBaseline& copy) { ShouldNotReachHere(); }
332 332
333 + // check and block at a safepoint
334 + static inline void check_safepoint(JavaThread* thr);
335 +
333 336 public:
334 337 // create a memory baseline
335 338 MemBaseline();
336 339
337 340 virtual ~MemBaseline();
338 341
339 342 inline bool baselined() const {
340 343 return _baselined;
341 344 }
342 345
343 346 MemBaseline& operator=(const MemBaseline& other);
344 347
345 348 // reset the baseline for reuse
346 349 void clear();
347 350
348 351 // baseline the snapshot
349 352 bool baseline(MemSnapshot& snapshot, bool summary_only = true);
350 353
351 354 bool baseline(const MemPointerArray* malloc_records,
352 355 const MemPointerArray* vm_records,
353 356 bool summary_only = true);
354 357
355 358 // total malloc'd memory of specified memory type
356 359 inline size_t malloc_amount(MEMFLAGS flag) const {
357 360 return _malloc_data[flag2index(flag)].amount();
358 361 }
359 362 // number of malloc'd memory blocks of specified memory type
360 363 inline size_t malloc_count(MEMFLAGS flag) const {
361 364 return _malloc_data[flag2index(flag)].count();
362 365 }
363 366 // total memory used by arenas of specified memory type
364 367 inline size_t arena_amount(MEMFLAGS flag) const {
365 368 return _arena_data[flag2index(flag)].amount();
366 369 }
367 370 // number of arenas of specified memory type
368 371 inline size_t arena_count(MEMFLAGS flag) const {
369 372 return _arena_data[flag2index(flag)].count();
370 373 }
371 374 // total reserved memory of specified memory type
372 375 inline size_t reserved_amount(MEMFLAGS flag) const {
373 376 return _vm_data[flag2index(flag)].reserved_amount();
374 377 }
375 378 // total committed memory of specified memory type
376 379 inline size_t committed_amount(MEMFLAGS flag) const {
377 380 return _vm_data[flag2index(flag)].committed_amount();
378 381 }
379 382 // total memory (malloc'd + mmap'd + arena) of specified
380 383 // memory type
381 384 inline size_t total_amount(MEMFLAGS flag) const {
382 385 int index = flag2index(flag);
383 386 return _malloc_data[index].amount() +
384 387 _vm_data[index].reserved_amount() +
385 388 _arena_data[index].amount();
386 389 }
387 390
388 391 /* overall summaries */
389 392
390 393 // total malloc'd memory in snapshot
391 394 inline size_t total_malloc_amount() const {
392 395 return _total_malloced;
393 396 }
394 397 // total mmap'd memory in snapshot
395 398 inline size_t total_reserved_amount() const {
396 399 return _total_vm_reserved;
397 400 }
398 401 // total committed memory in snapshot
399 402 inline size_t total_committed_amount() const {
400 403 return _total_vm_committed;
401 404 }
402 405 // number of loaded classes
403 406 inline size_t number_of_classes() const {
404 407 return _number_of_classes;
405 408 }
406 409 // number of running threads
407 410 inline size_t number_of_threads() const {
408 411 return _number_of_threads;
409 412 }
410 413 // lookup human readable name of a memory type
411 414 static const char* type2name(MEMFLAGS type);
412 415
413 416 private:
414 417 // convert memory flag to the index to mapping table
415 418 int flag2index(MEMFLAGS flag) const;
416 419
417 420 // reset baseline values
418 421 void reset();
419 422
420 423 // summarize the records in global snapshot
421 424 bool baseline_malloc_summary(const MemPointerArray* malloc_records);
422 425 bool baseline_vm_summary(const MemPointerArray* vm_records);
423 426 bool baseline_malloc_details(const MemPointerArray* malloc_records);
424 427 bool baseline_vm_details(const MemPointerArray* vm_records);
425 428
426 429 // print a line of malloc'd memory aggregated by callsite
427 430 void print_malloc_callsite(outputStream* st, address pc, size_t size,
428 431 size_t count, int diff_amt, int diff_count) const;
429 432 // print a line of mmap'd memory aggregated by callsite
430 433 void print_vm_callsite(outputStream* st, address pc, size_t rsz,
431 434 size_t csz, int diff_rsz, int diff_csz) const;
432 435
433 436 // sorting functions for raw records
434 437 static int malloc_sort_by_pc(const void* p1, const void* p2);
435 438 static int malloc_sort_by_addr(const void* p1, const void* p2);
436 439
437 440 private:
438 441 // sorting functions for baselined records
439 442 static int bl_malloc_sort_by_size(const void* p1, const void* p2);
440 443 static int bl_vm_sort_by_size(const void* p1, const void* p2);
441 444 static int bl_malloc_sort_by_pc(const void* p1, const void* p2);
442 445 static int bl_vm_sort_by_pc(const void* p1, const void* p2);
443 446 };
444 447
445 448
446 449 #endif // SHARE_VM_SERVICES_MEM_BASELINE_HPP
↓ open down ↓ |
104 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX