< prev index next >

src/share/vm/memory/heapInspection.cpp

Print this page




 209   } else {
 210     return false;
 211   }
 212 }
 213 
 214 void KlassInfoTable::iterate(KlassInfoClosure* cic) {
 215   assert(_size == 0 || _buckets != NULL, "Allocation failure should have been caught");
 216   for (int index = 0; index < _size; index++) {
 217     _buckets[index].iterate(cic);
 218   }
 219 }
 220 
 221 size_t KlassInfoTable::size_of_instances_in_words() const {
 222   return _size_of_instances_in_words;
 223 }
 224 
 225 int KlassInfoHisto::sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2) {
 226   return (*e1)->compare(*e1,*e2);
 227 }
 228 
 229 KlassInfoHisto::KlassInfoHisto(KlassInfoTable* cit, const char* title) :
 230   _cit(cit),
 231   _title(title) {
 232   _elements = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<KlassInfoEntry*>(_histo_initial_size, true);
 233 }
 234 
 235 KlassInfoHisto::~KlassInfoHisto() {
 236   delete _elements;
 237 }
 238 
 239 void KlassInfoHisto::add(KlassInfoEntry* cie) {
 240   elements()->append(cie);
 241 }
 242 
 243 void KlassInfoHisto::sort() {
 244   elements()->sort(KlassInfoHisto::sort_helper);
 245 }
 246 
 247 void KlassInfoHisto::print_elements(outputStream* st) const {
 248   // simplify the formatting (ILP32 vs LP64) - store the sum in 64-bit
 249   int64_t total = 0;
 250   uint64_t totalw = 0;
 251   for(int i=0; i < elements()->length(); i++) {


 631     print_title(st, csv_format, selected, width_table, name_table);
 632   }
 633 }
 634 
 635 julong KlassInfoHisto::annotations_bytes(Array<AnnotationArray*>* p) const {
 636   julong bytes = 0;
 637   if (p != NULL) {
 638     for (int i = 0; i < p->length(); i++) {
 639       bytes += count_bytes_array(p->at(i));
 640     }
 641     bytes += count_bytes_array(p);
 642   }
 643   return bytes;
 644 }
 645 
 646 void KlassInfoHisto::print_histo_on(outputStream* st, bool print_stats,
 647                                     bool csv_format, const char *columns) {
 648   if (print_stats) {
 649     print_class_stats(st, csv_format, columns);
 650   } else {
 651     st->print_cr("%s",title());

 652     print_elements(st);
 653   }
 654 }
 655 
 656 class HistoClosure : public KlassInfoClosure {
 657  private:
 658   KlassInfoHisto* _cih;
 659  public:
 660   HistoClosure(KlassInfoHisto* cih) : _cih(cih) {}
 661 
 662   void do_cinfo(KlassInfoEntry* cie) {
 663     _cih->add(cie);
 664   }
 665 };
 666 
 667 class RecordInstanceClosure : public ObjectClosure {
 668  private:
 669   KlassInfoTable* _cit;
 670   size_t _missed_count;
 671   BoolObjectClosure* _filter;


 712         } else {
 713           st->print("%c", *p);
 714         }
 715       }
 716       st->print_cr(".\n");
 717     }
 718     return;
 719   }
 720 
 721   KlassInfoTable cit(_print_class_stats);
 722   if (!cit.allocation_failed()) {
 723     // populate table with object allocation info
 724     size_t missed_count = populate_table(&cit);
 725     if (missed_count != 0) {
 726       st->print_cr("WARNING: Ran out of C-heap; undercounted " SIZE_FORMAT
 727                    " total instances in data below",
 728                    missed_count);
 729     }
 730 
 731     // Sort and print klass instance info
 732     const char *title = "\n"
 733               " num     #instances         #bytes  class name\n"
 734               "----------------------------------------------";
 735     KlassInfoHisto histo(&cit, title);
 736     HistoClosure hc(&histo);
 737 
 738     cit.iterate(&hc);
 739 
 740     histo.sort();
 741     histo.print_histo_on(st, _print_class_stats, _csv_format, _columns);
 742   } else {
 743     st->print_cr("ERROR: Ran out of C-heap; histogram not generated");
 744   }
 745   st->flush();
 746 }
 747 
 748 class FindInstanceClosure : public ObjectClosure {
 749  private:
 750   Klass* _klass;
 751   GrowableArray<oop>* _result;
 752 
 753  public:
 754   FindInstanceClosure(Klass* k, GrowableArray<oop>* result) : _klass(k), _result(result) {};
 755 




 209   } else {
 210     return false;
 211   }
 212 }
 213 
 214 void KlassInfoTable::iterate(KlassInfoClosure* cic) {
 215   assert(_size == 0 || _buckets != NULL, "Allocation failure should have been caught");
 216   for (int index = 0; index < _size; index++) {
 217     _buckets[index].iterate(cic);
 218   }
 219 }
 220 
 221 size_t KlassInfoTable::size_of_instances_in_words() const {
 222   return _size_of_instances_in_words;
 223 }
 224 
 225 int KlassInfoHisto::sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2) {
 226   return (*e1)->compare(*e1,*e2);
 227 }
 228 
 229 KlassInfoHisto::KlassInfoHisto(KlassInfoTable* cit) :
 230   _cit(cit) {

 231   _elements = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<KlassInfoEntry*>(_histo_initial_size, true);
 232 }
 233 
 234 KlassInfoHisto::~KlassInfoHisto() {
 235   delete _elements;
 236 }
 237 
 238 void KlassInfoHisto::add(KlassInfoEntry* cie) {
 239   elements()->append(cie);
 240 }
 241 
 242 void KlassInfoHisto::sort() {
 243   elements()->sort(KlassInfoHisto::sort_helper);
 244 }
 245 
 246 void KlassInfoHisto::print_elements(outputStream* st) const {
 247   // simplify the formatting (ILP32 vs LP64) - store the sum in 64-bit
 248   int64_t total = 0;
 249   uint64_t totalw = 0;
 250   for(int i=0; i < elements()->length(); i++) {


 630     print_title(st, csv_format, selected, width_table, name_table);
 631   }
 632 }
 633 
 634 julong KlassInfoHisto::annotations_bytes(Array<AnnotationArray*>* p) const {
 635   julong bytes = 0;
 636   if (p != NULL) {
 637     for (int i = 0; i < p->length(); i++) {
 638       bytes += count_bytes_array(p->at(i));
 639     }
 640     bytes += count_bytes_array(p);
 641   }
 642   return bytes;
 643 }
 644 
 645 void KlassInfoHisto::print_histo_on(outputStream* st, bool print_stats,
 646                                     bool csv_format, const char *columns) {
 647   if (print_stats) {
 648     print_class_stats(st, csv_format, columns);
 649   } else {
 650     st->print_cr(" num     #instances         #bytes  class name");
 651     st->print_cr("----------------------------------------------");
 652     print_elements(st);
 653   }
 654 }
 655 
 656 class HistoClosure : public KlassInfoClosure {
 657  private:
 658   KlassInfoHisto* _cih;
 659  public:
 660   HistoClosure(KlassInfoHisto* cih) : _cih(cih) {}
 661 
 662   void do_cinfo(KlassInfoEntry* cie) {
 663     _cih->add(cie);
 664   }
 665 };
 666 
 667 class RecordInstanceClosure : public ObjectClosure {
 668  private:
 669   KlassInfoTable* _cit;
 670   size_t _missed_count;
 671   BoolObjectClosure* _filter;


 712         } else {
 713           st->print("%c", *p);
 714         }
 715       }
 716       st->print_cr(".\n");
 717     }
 718     return;
 719   }
 720 
 721   KlassInfoTable cit(_print_class_stats);
 722   if (!cit.allocation_failed()) {
 723     // populate table with object allocation info
 724     size_t missed_count = populate_table(&cit);
 725     if (missed_count != 0) {
 726       st->print_cr("WARNING: Ran out of C-heap; undercounted " SIZE_FORMAT
 727                    " total instances in data below",
 728                    missed_count);
 729     }
 730 
 731     // Sort and print klass instance info
 732     KlassInfoHisto histo(&cit);



 733     HistoClosure hc(&histo);
 734 
 735     cit.iterate(&hc);
 736 
 737     histo.sort();
 738     histo.print_histo_on(st, _print_class_stats, _csv_format, _columns);
 739   } else {
 740     st->print_cr("ERROR: Ran out of C-heap; histogram not generated");
 741   }
 742   st->flush();
 743 }
 744 
 745 class FindInstanceClosure : public ObjectClosure {
 746  private:
 747   Klass* _klass;
 748   GrowableArray<oop>* _result;
 749 
 750  public:
 751   FindInstanceClosure(Klass* k, GrowableArray<oop>* result) : _klass(k), _result(result) {};
 752 


< prev index next >