src/share/vm/services/memBaseline.hpp

Mon, 31 Mar 2014 13:09:35 -0700

author
minqi
date
Mon, 31 Mar 2014 13:09:35 -0700
changeset 6535
f42c10a3d4b1
parent 4980
fbca7eaeac2e
child 6876
710a3c8b516e
child 7074
833b0f92429a
permissions
-rw-r--r--

7090324: gclog rotation via external tool
Summary: GC log rotation can be set via java command line, but customer sometime need to sync with OS level rotation setting.
Reviewed-by: sla, minqi, ehelin
Contributed-by: suenaga.yasumasa@lab.ntt.co.jp

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

mercurial