< prev index next >

src/hotspot/share/services/diagnosticCommand.cpp

Print this page
rev 58388 : 8237354: Add option to jcmd to write a gzipped heap dump
Reviewed-by:


 488   assert(count_res != NULL && name_res != NULL, "Unexpected layout of FinalizerHistogramEntry");
 489 
 490   output()->print_cr("Unreachable instances waiting for finalization");
 491   output()->print_cr("#instances  class name");
 492   output()->print_cr("-----------------------");
 493 
 494   for (int i = 0; i < result_oop->length(); ++i) {
 495     oop element_oop = result_oop->obj_at(i);
 496     oop str_oop = element_oop->obj_field(name_fd.offset());
 497     char *name = java_lang_String::as_utf8_string(str_oop);
 498     int count = element_oop->int_field(count_fd.offset());
 499     output()->print_cr("%10d  %s", count, name);
 500   }
 501 }
 502 
 503 #if INCLUDE_SERVICES // Heap dumping/inspection supported
 504 HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) :
 505                            DCmdWithParser(output, heap),
 506   _filename("filename","Name of the dump file", "STRING",true),
 507   _all("-all", "Dump all objects, including unreachable objects",
 508        "BOOLEAN", false, "false") {



 509   _dcmdparser.add_dcmd_option(&_all);
 510   _dcmdparser.add_dcmd_argument(&_filename);


 511 }
 512 
 513 void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {











 514   // Request a full GC before heap dump if _all is false
 515   // This helps reduces the amount of unreachable objects in the dump
 516   // and makes it easier to browse.
 517   HeapDumper dumper(!_all.value() /* request GC if _all is false*/);
 518   dumper.dump(_filename.value(), output());
 519 }
 520 
 521 int HeapDumpDCmd::num_arguments() {
 522   ResourceMark rm;
 523   HeapDumpDCmd* dcmd = new HeapDumpDCmd(NULL, false);
 524   if (dcmd != NULL) {
 525     DCmdMark mark(dcmd);
 526     return dcmd->_dcmdparser.num_arguments();
 527   } else {
 528     return 0;
 529   }
 530 }
 531 
 532 ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
 533                                        DCmdWithParser(output, heap),
 534   _all("-all", "Inspect all objects, including unreachable objects",
 535        "BOOLEAN", false, "false") {
 536   _dcmdparser.add_dcmd_option(&_all);
 537 }
 538 




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


< prev index next >