< prev index next >

src/hotspot/share/memory/heapInspection.hpp

Print this page
rev 60374 : 8215624: add parallel heap iteration for jmap histo (G1)


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


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


 199     return w + 1;
 200   }
 201 
 202  public:
 203   KlassInfoHisto(KlassInfoTable* cit);
 204   ~KlassInfoHisto();
 205   void add(KlassInfoEntry* cie);
 206   void print_histo_on(outputStream* st);
 207   void sort();
 208 };
 209 
 210 #endif // INCLUDE_SERVICES
 211 
 212 // These declarations are needed since the declaration of KlassInfoTable and
 213 // KlassInfoClosure are guarded by #if INLCUDE_SERVICES
 214 class KlassInfoTable;
 215 class KlassInfoClosure;
 216 
 217 class HeapInspection : public StackObj {
 218  public:
 219   void heap_inspection(outputStream* st, uint parallel_thread_num = 1) NOT_SERVICES_RETURN;
 220   uint populate_table(KlassInfoTable* cit, BoolObjectClosure* filter = NULL, uint parallel_thread_num = 1) NOT_SERVICES_RETURN_(0);
 221   static void find_instances_at_safepoint(Klass* k, GrowableArray<oop>* result) NOT_SERVICES_RETURN;
 222  private:
 223   void iterate_over_heap(KlassInfoTable* cit, BoolObjectClosure* filter = NULL);
 224 };
 225 
 226 // Parallel heap inspection task. Parallel inspection can fail due to
 227 // a native OOM when allocating memory for TL-KlassInfoTable.
 228 // _success will be set false on an OOM, and serial inspection tried.
 229 class ParHeapInspectTask : public AbstractGangTask {
 230  private:
 231   ParallelObjectIterator* _poi;
 232   KlassInfoTable* _shared_cit;
 233   BoolObjectClosure* _filter;
 234   uint _missed_count;
 235   bool _success;
 236   Mutex _mutex;
 237 
 238  public:
 239   ParHeapInspectTask(ParallelObjectIterator* poi,
 240                      KlassInfoTable* shared_cit,
 241                      BoolObjectClosure* filter) :
 242       AbstractGangTask("Iterating heap"),
 243       _poi(poi),
 244       _shared_cit(shared_cit),
 245       _filter(filter),
 246       _missed_count(0),
 247       _success(true),
 248       _mutex(Mutex::leaf, "Parallel heap iteration data merge lock") {}
 249 
 250   uint missed_count() const {
 251     return _missed_count;
 252   }
 253 
 254   bool success() {
 255     return _success;
 256   }
 257 
 258   virtual void work(uint worker_id);
 259 };
 260 
 261 
 262 
 263 #endif // SHARE_MEMORY_HEAPINSPECTION_HPP
< prev index next >