487 assert(count_res != NULL && name_res != NULL, "Unexpected layout of FinalizerHistogramEntry");
488
489 output()->print_cr("Unreachable instances waiting for finalization");
490 output()->print_cr("#instances class name");
491 output()->print_cr("-----------------------");
492
493 for (int i = 0; i < result_oop->length(); ++i) {
494 oop element_oop = result_oop->obj_at(i);
495 oop str_oop = element_oop->obj_field(name_fd.offset());
496 char *name = java_lang_String::as_utf8_string(str_oop);
497 int count = element_oop->int_field(count_fd.offset());
498 output()->print_cr("%10d %s", count, name);
499 }
500 }
501
502 #if INCLUDE_SERVICES // Heap dumping/inspection supported
503 HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) :
504 DCmdWithParser(output, heap),
505 _filename("filename","Name of the dump file", "STRING",true),
506 _all("-all", "Dump all objects, including unreachable objects",
507 "BOOLEAN", false, "false") {
508 _dcmdparser.add_dcmd_option(&_all);
509 _dcmdparser.add_dcmd_argument(&_filename);
510 }
511
512 void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {
513 // Request a full GC before heap dump if _all is false
514 // This helps reduces the amount of unreachable objects in the dump
515 // and makes it easier to browse.
516 HeapDumper dumper(!_all.value() /* request GC if _all is false*/);
517 dumper.dump(_filename.value(), output());
518 }
519
520 int HeapDumpDCmd::num_arguments() {
521 ResourceMark rm;
522 HeapDumpDCmd* dcmd = new HeapDumpDCmd(NULL, false);
523 if (dcmd != NULL) {
524 DCmdMark mark(dcmd);
525 return dcmd->_dcmdparser.num_arguments();
526 } else {
527 return 0;
528 }
529 }
530
531 ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
532 DCmdWithParser(output, heap),
533 _all("-all", "Inspect all objects, including unreachable objects",
534 "BOOLEAN", false, "false") {
535 _dcmdparser.add_dcmd_option(&_all);
536 }
537
|
487 assert(count_res != NULL && name_res != NULL, "Unexpected layout of FinalizerHistogramEntry");
488
489 output()->print_cr("Unreachable instances waiting for finalization");
490 output()->print_cr("#instances class name");
491 output()->print_cr("-----------------------");
492
493 for (int i = 0; i < result_oop->length(); ++i) {
494 oop element_oop = result_oop->obj_at(i);
495 oop str_oop = element_oop->obj_field(name_fd.offset());
496 char *name = java_lang_String::as_utf8_string(str_oop);
497 int count = element_oop->int_field(count_fd.offset());
498 output()->print_cr("%10d %s", count, name);
499 }
500 }
501
502 #if INCLUDE_SERVICES // Heap dumping/inspection supported
503 HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) :
504 DCmdWithParser(output, heap),
505 _filename("filename","Name of the dump file", "STRING",true),
506 _all("-all", "Dump all objects, including unreachable objects",
507 "BOOLEAN", false, "false"),
508 _gzip("-gz", "Write in gzipped format.", "BOOLEAN", false, "false"),
509 _gzip_level("-gz-level", "The compression level from 0 (store) to 9 (best) when writing in gzipped format.",
510 "INT", false, "1") {
511 _dcmdparser.add_dcmd_option(&_all);
512 _dcmdparser.add_dcmd_argument(&_filename);
513 _dcmdparser.add_dcmd_option(&_gzip);
514 _dcmdparser.add_dcmd_option(&_gzip_level);
515 }
516
517 void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {
518 jlong level = -1; // -1 means no compression.
519
520 if (_gzip.value()) {
521 level = _gzip_level.value();
522
523 if (level < 0 || level > 9) {
524 output()->print_cr("Compression level out of range (0-9): " JLONG_FORMAT, level);
525 return;
526 }
527 }
528
529 // Request a full GC before heap dump if _all is false
530 // This helps reduces the amount of unreachable objects in the dump
531 // and makes it easier to browse.
532 HeapDumper dumper(!_all.value() /* request GC if _all is false*/);
533 dumper.dump(_filename.value(), output(), (int) level);
534 }
535
536 int HeapDumpDCmd::num_arguments() {
537 ResourceMark rm;
538 HeapDumpDCmd* dcmd = new HeapDumpDCmd(NULL, false);
539 if (dcmd != NULL) {
540 DCmdMark mark(dcmd);
541 return dcmd->_dcmdparser.num_arguments();
542 } else {
543 return 0;
544 }
545 }
546
547 ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
548 DCmdWithParser(output, heap),
549 _all("-all", "Inspect all objects, including unreachable objects",
550 "BOOLEAN", false, "false") {
551 _dcmdparser.add_dcmd_option(&_all);
552 }
553
|