< prev index next >

src/hotspot/share/memory/heapInspection.hpp

Print this page




  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_MEMORY_HEAPINSPECTION_HPP
  26 #define SHARE_MEMORY_HEAPINSPECTION_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "oops/objArrayOop.hpp"
  30 #include "oops/oop.hpp"
  31 #include "oops/annotations.hpp"
  32 #include "utilities/macros.hpp"

  33 
  34 #if INCLUDE_SERVICES
  35 
  36 
  37 // HeapInspection
  38 
  39 // KlassInfoTable is a bucket hash table that
  40 // maps Klass*s to extra information:
  41 //    instance count and instance word size.
  42 //
  43 // A KlassInfoBucket is the head of a link list
  44 // of KlassInfoEntry's
  45 //
  46 // KlassInfoHisto is a growable array of pointers
  47 // to KlassInfoEntry's and is used to sort
  48 // the entries.
  49 
  50 class KlassInfoEntry: public CHeapObj<mtInternal> {
  51  private:
  52   KlassInfoEntry* _next;


 105   size_t _size_of_instances_in_words;
 106 
 107   // An aligned reference address (typically the least
 108   // address in the perm gen) used for hashing klass
 109   // objects.
 110   HeapWord* _ref;
 111 
 112   KlassInfoBucket* _buckets;
 113   uint hash(const Klass* p);
 114   KlassInfoEntry* lookup(Klass* k); // allocates if not found!
 115 
 116   class AllClassesFinder;
 117 
 118  public:
 119   KlassInfoTable(bool add_all_classes);
 120   ~KlassInfoTable();
 121   bool record_instance(const oop obj);
 122   void iterate(KlassInfoClosure* cic);
 123   bool allocation_failed() { return _buckets == NULL; }
 124   size_t size_of_instances_in_words() const;


 125 
 126   friend class KlassInfoHisto;
 127   friend class KlassHierarchy;
 128 };
 129 
 130 class KlassHierarchy : AllStatic {
 131  public:
 132   static void print_class_hierarchy(outputStream* st, bool print_interfaces,  bool print_subclasses,
 133                                     char* classname);
 134 
 135  private:
 136   static void set_do_print_for_class_hierarchy(KlassInfoEntry* cie, KlassInfoTable* cit,
 137                                                bool print_subclasse);
 138   static void print_class(outputStream* st, KlassInfoEntry* cie, bool print_subclasses);
 139 };
 140 
 141 class KlassInfoHisto : public StackObj {
 142  private:
 143   static const int _histo_initial_size = 1000;
 144   KlassInfoTable *_cit;


 194     return w + 1;
 195   }
 196 
 197  public:
 198   KlassInfoHisto(KlassInfoTable* cit);
 199   ~KlassInfoHisto();
 200   void add(KlassInfoEntry* cie);
 201   void print_histo_on(outputStream* st);
 202   void sort();
 203 };
 204 
 205 #endif // INCLUDE_SERVICES
 206 
 207 // These declarations are needed since the declaration of KlassInfoTable and
 208 // KlassInfoClosure are guarded by #if INLCUDE_SERVICES
 209 class KlassInfoTable;
 210 class KlassInfoClosure;
 211 
 212 class HeapInspection : public StackObj {
 213  public:
 214   void heap_inspection(outputStream* st) NOT_SERVICES_RETURN;
 215   size_t populate_table(KlassInfoTable* cit, BoolObjectClosure* filter = NULL) NOT_SERVICES_RETURN_(0);
 216   static void find_instances_at_safepoint(Klass* k, GrowableArray<oop>* result) NOT_SERVICES_RETURN;
 217  private:
 218   void iterate_over_heap(KlassInfoTable* cit, BoolObjectClosure* filter = NULL);


































 219 };
 220 
 221 #endif // SHARE_MEMORY_HEAPINSPECTION_HPP


  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_MEMORY_HEAPINSPECTION_HPP
  26 #define SHARE_MEMORY_HEAPINSPECTION_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "oops/objArrayOop.hpp"
  30 #include "oops/oop.hpp"
  31 #include "oops/annotations.hpp"
  32 #include "utilities/macros.hpp"
  33 #include "gc/shared/workgroup.hpp"
  34 
  35 #if INCLUDE_SERVICES
  36 
  37 
  38 // HeapInspection
  39 
  40 // KlassInfoTable is a bucket hash table that
  41 // maps Klass*s to extra information:
  42 //    instance count and instance word size.
  43 //
  44 // A KlassInfoBucket is the head of a link list
  45 // of KlassInfoEntry's
  46 //
  47 // KlassInfoHisto is a growable array of pointers
  48 // to KlassInfoEntry's and is used to sort
  49 // the entries.
  50 
  51 class KlassInfoEntry: public CHeapObj<mtInternal> {
  52  private:
  53   KlassInfoEntry* _next;


 106   size_t _size_of_instances_in_words;
 107 
 108   // An aligned reference address (typically the least
 109   // address in the perm gen) used for hashing klass
 110   // objects.
 111   HeapWord* _ref;
 112 
 113   KlassInfoBucket* _buckets;
 114   uint hash(const Klass* p);
 115   KlassInfoEntry* lookup(Klass* k); // allocates if not found!
 116 
 117   class AllClassesFinder;
 118 
 119  public:
 120   KlassInfoTable(bool add_all_classes);
 121   ~KlassInfoTable();
 122   bool record_instance(const oop obj);
 123   void iterate(KlassInfoClosure* cic);
 124   bool allocation_failed() { return _buckets == NULL; }
 125   size_t size_of_instances_in_words() const;
 126   bool merge(KlassInfoTable* table);
 127   bool merge_entry(const KlassInfoEntry* cie);
 128 
 129   friend class KlassInfoHisto;
 130   friend class KlassHierarchy;
 131 };
 132 
 133 class KlassHierarchy : AllStatic {
 134  public:
 135   static void print_class_hierarchy(outputStream* st, bool print_interfaces,  bool print_subclasses,
 136                                     char* classname);
 137 
 138  private:
 139   static void set_do_print_for_class_hierarchy(KlassInfoEntry* cie, KlassInfoTable* cit,
 140                                                bool print_subclasse);
 141   static void print_class(outputStream* st, KlassInfoEntry* cie, bool print_subclasses);
 142 };
 143 
 144 class KlassInfoHisto : public StackObj {
 145  private:
 146   static const int _histo_initial_size = 1000;
 147   KlassInfoTable *_cit;


 197     return w + 1;
 198   }
 199 
 200  public:
 201   KlassInfoHisto(KlassInfoTable* cit);
 202   ~KlassInfoHisto();
 203   void add(KlassInfoEntry* cie);
 204   void print_histo_on(outputStream* st);
 205   void sort();
 206 };
 207 
 208 #endif // INCLUDE_SERVICES
 209 
 210 // These declarations are needed since the declaration of KlassInfoTable and
 211 // KlassInfoClosure are guarded by #if INLCUDE_SERVICES
 212 class KlassInfoTable;
 213 class KlassInfoClosure;
 214 
 215 class HeapInspection : public StackObj {
 216  public:
 217   void heap_inspection(outputStream* st, size_t parallel_thread_num = 1) NOT_SERVICES_RETURN;
 218   size_t populate_table(KlassInfoTable* cit, BoolObjectClosure* filter = NULL, size_t parallel_thread_num = 1) NOT_SERVICES_RETURN_(0);
 219   static void find_instances_at_safepoint(Klass* k, GrowableArray<oop>* result) NOT_SERVICES_RETURN;
 220  private:
 221   void iterate_over_heap(KlassInfoTable* cit, BoolObjectClosure* filter = NULL);
 222 };
 223 
 224 class ParHeapInspectTask : public AbstractGangTask {
 225  private:
 226   CollectedHeap* _heap;
 227   KlassInfoTable* _shared_cit;
 228   BoolObjectClosure* _filter;
 229   size_t* _shared_missed_count;
 230   bool _success;
 231   Mutex _mutex;
 232   size_t _par_thread_num;
 233 
 234  public:
 235   ParHeapInspectTask(CollectedHeap* heap, KlassInfoTable* shared_cit,
 236                      BoolObjectClosure* filter, size_t* shared_missed_count,
 237                      size_t parallel_thread_num) :
 238       AbstractGangTask("Iterating heap"),
 239       _heap(heap),
 240       _shared_cit(shared_cit),
 241       _filter(filter),
 242       _shared_missed_count(shared_missed_count),
 243       _success(true),
 244       _mutex(Mutex::leaf, "Parallel heap iteration data merge lock"),
 245       _par_thread_num(parallel_thread_num) { }
 246 
 247   bool is_success() {
 248     return _success;
 249   }
 250 
 251   CollectedHeap* getHeap() {
 252     return _heap;
 253   }
 254   virtual void work(uint worker_id);
 255   virtual void do_object_iterate_parallel(ObjectClosure* closure, uint worker_id) = 0;
 256 };
 257 
 258 #endif // SHARE_MEMORY_HEAPINSPECTION_HPP
< prev index next >