687 void do_object(oop obj) {
688 if (should_visit(obj)) {
689 if (!_cit->record_instance(obj)) {
690 _missed_count++;
691 }
692 }
693 }
694
695 size_t missed_count() { return _missed_count; }
696
697 private:
698 bool should_visit(oop obj) {
699 return _filter == NULL || _filter->do_object_b(obj);
700 }
701 };
702
703 size_t HeapInspection::populate_table(KlassInfoTable* cit, BoolObjectClosure *filter) {
704 ResourceMark rm;
705
706 RecordInstanceClosure ric(cit, filter);
707 Universe::heap()->object_iterate(&ric);
708 return ric.missed_count();
709 }
710
711 void HeapInspection::heap_inspection(outputStream* st) {
712 ResourceMark rm;
713
714 if (_print_help) {
715 for (int c=0; c<KlassSizeStats::_num_columns; c++) {
716 st->print("%s:\n\t", name_table[c]);
717 const int max_col = 60;
718 int col = 0;
719 for (const char *p = help_table[c]; *p; p++,col++) {
720 if (col >= max_col && *p == ' ') {
721 st->print("\n\t");
722 col = 0;
723 } else {
724 st->print("%c", *p);
725 }
726 }
727 st->print_cr(".\n");
756 class FindInstanceClosure : public ObjectClosure {
757 private:
758 Klass* _klass;
759 GrowableArray<oop>* _result;
760
761 public:
762 FindInstanceClosure(Klass* k, GrowableArray<oop>* result) : _klass(k), _result(result) {};
763
764 void do_object(oop obj) {
765 if (obj->is_a(_klass)) {
766 _result->append(obj);
767 }
768 }
769 };
770
771 void HeapInspection::find_instances_at_safepoint(Klass* k, GrowableArray<oop>* result) {
772 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
773 assert(Heap_lock->is_locked(), "should have the Heap_lock");
774
775 // Ensure that the heap is parsable
776 Universe::heap()->ensure_parsability(false); // no need to retire TALBs
777
778 // Iterate over objects in the heap
779 FindInstanceClosure fic(k, result);
780 // If this operation encounters a bad object when using CMS,
781 // consider using safe_object_iterate() which avoids metadata
782 // objects that may contain bad references.
783 Universe::heap()->object_iterate(&fic);
784 }
|
687 void do_object(oop obj) {
688 if (should_visit(obj)) {
689 if (!_cit->record_instance(obj)) {
690 _missed_count++;
691 }
692 }
693 }
694
695 size_t missed_count() { return _missed_count; }
696
697 private:
698 bool should_visit(oop obj) {
699 return _filter == NULL || _filter->do_object_b(obj);
700 }
701 };
702
703 size_t HeapInspection::populate_table(KlassInfoTable* cit, BoolObjectClosure *filter) {
704 ResourceMark rm;
705
706 RecordInstanceClosure ric(cit, filter);
707 GC::gc()->heap()->object_iterate(&ric);
708 return ric.missed_count();
709 }
710
711 void HeapInspection::heap_inspection(outputStream* st) {
712 ResourceMark rm;
713
714 if (_print_help) {
715 for (int c=0; c<KlassSizeStats::_num_columns; c++) {
716 st->print("%s:\n\t", name_table[c]);
717 const int max_col = 60;
718 int col = 0;
719 for (const char *p = help_table[c]; *p; p++,col++) {
720 if (col >= max_col && *p == ' ') {
721 st->print("\n\t");
722 col = 0;
723 } else {
724 st->print("%c", *p);
725 }
726 }
727 st->print_cr(".\n");
756 class FindInstanceClosure : public ObjectClosure {
757 private:
758 Klass* _klass;
759 GrowableArray<oop>* _result;
760
761 public:
762 FindInstanceClosure(Klass* k, GrowableArray<oop>* result) : _klass(k), _result(result) {};
763
764 void do_object(oop obj) {
765 if (obj->is_a(_klass)) {
766 _result->append(obj);
767 }
768 }
769 };
770
771 void HeapInspection::find_instances_at_safepoint(Klass* k, GrowableArray<oop>* result) {
772 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
773 assert(Heap_lock->is_locked(), "should have the Heap_lock");
774
775 // Ensure that the heap is parsable
776 GC::gc()->heap()->ensure_parsability(false); // no need to retire TALBs
777
778 // Iterate over objects in the heap
779 FindInstanceClosure fic(k, result);
780 // If this operation encounters a bad object when using CMS,
781 // consider using safe_object_iterate() which avoids metadata
782 // objects that may contain bad references.
783 GC::gc()->heap()->object_iterate(&fic);
784 }
|