src/share/vm/memory/heapInspection.hpp

Print this page
rev 4462 : 8012086: The object count event should only send events for instances occupying more than 0.5% of the heap


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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_VM_MEMORY_HEAPINSPECTION_HPP
  26 #define SHARE_VM_MEMORY_HEAPINSPECTION_HPP
  27 
  28 #include "memory/allocation.inline.hpp"

  29 #include "oops/oop.inline.hpp"
  30 
  31 
  32 // HeapInspection
  33 
  34 // KlassInfoTable is a bucket hash table that
  35 // maps klassOops to extra information:
  36 //    instance count and instance word size.
  37 //
  38 // A KlassInfoBucket is the head of a link list
  39 // of KlassInfoEntry's
  40 //
  41 // KlassInfoHisto is a growable array of pointers
  42 // to KlassInfoEntry's and is used to sort
  43 // the entries.
  44 
  45 class KlassInfoEntry: public CHeapObj<mtInternal> {
  46  private:
  47   KlassInfoEntry* _next;
  48   klassOop        _klass;
  49   long            _instance_count;
  50   size_t          _instance_words;
  51 
  52  public:
  53   KlassInfoEntry(klassOop k, KlassInfoEntry* next) :
  54     _klass(k), _instance_count(0), _instance_words(0), _next(next)
  55   {}
  56   KlassInfoEntry* next()     { return _next; }
  57   bool is_equal(klassOop k)  { return k == _klass; }
  58   klassOop klass()           { return _klass; }
  59   long count()               { return _instance_count; }
  60   void set_count(long ct)    { _instance_count = ct; }
  61   size_t words()             { return _instance_words; }
  62   void set_words(size_t wds) { _instance_words = wds; }
  63   int compare(KlassInfoEntry* e1, KlassInfoEntry* e2);
  64   void print_on(outputStream* st) const;
  65 };
  66 
  67 class KlassInfoClosure: public StackObj {
  68  public:
  69   // Called for each KlassInfoEntry.
  70   virtual void do_cinfo(KlassInfoEntry* cie) = 0;
  71 };
  72 
  73 class KlassInfoBucket: public CHeapObj<mtInternal> {
  74  private:
  75   KlassInfoEntry* _list;
  76   KlassInfoEntry* list()           { return _list; }
  77   void set_list(KlassInfoEntry* l) { _list = l; }
  78  public:
  79   KlassInfoEntry* lookup(const klassOop k);
  80   void initialize() { _list = NULL; }
  81   void empty();
  82   void iterate(KlassInfoClosure* cic);
  83 };
  84 
  85 class KlassInfoTable: public StackObj {
  86  private:
  87   int _size;
  88   static const int _num_buckets = 20011;

  89 
  90   // An aligned reference address (typically the least
  91   // address in the perm gen) used for hashing klass
  92   // objects.
  93   HeapWord* _ref;
  94 
  95   KlassInfoBucket* _buckets;
  96   uint hash(klassOop p);
  97   KlassInfoEntry* lookup(const klassOop k);
  98 
  99  public:
 100   KlassInfoTable(HeapWord* ref);
 101   ~KlassInfoTable();
 102   bool record_instance(const oop obj);
 103   void iterate(KlassInfoClosure* cic);
 104   bool allocation_failed() { return _buckets == NULL; }

 105 };
 106 
 107 class KlassInfoHisto : public StackObj {
 108  private:
 109   GrowableArray<KlassInfoEntry*>* _elements;
 110   GrowableArray<KlassInfoEntry*>* elements() const { return _elements; }
 111   const char* _title;
 112   const char* title() const { return _title; }
 113   static int sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2);
 114   void print_elements(outputStream* st) const;
 115   static const int _histo_initial_size = 1000;
 116  public:
 117   KlassInfoHisto(const char* title);
 118   ~KlassInfoHisto();
 119   void add(KlassInfoEntry* cie);
 120   void print_on(outputStream* st) const;
 121   void sort();
 122 };
 123 
 124 
 125 class HeapInspection : public AllStatic {
 126  public:
 127   static void heap_inspection(outputStream* st, bool need_prologue);
 128   static size_t instance_inspection(KlassInfoTable* cit,
 129                                     KlassInfoClosure* cl,
 130                                     bool need_prologue,
 131                                     BoolObjectClosure* filter = NULL);
 132   static HeapWord* start_of_perm_gen();
 133   static void find_instances_at_safepoint(klassOop k, GrowableArray<oop>* result);
 134  private:
 135   static bool is_shared_heap();
 136   static void prologue();
 137   static void epilogue();
 138 };
 139 
 140 #endif // SHARE_VM_MEMORY_HEAPINSPECTION_HPP


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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_VM_MEMORY_HEAPINSPECTION_HPP
  26 #define SHARE_VM_MEMORY_HEAPINSPECTION_HPP
  27 
  28 #include "memory/allocation.inline.hpp"
  29 #include "memory/klassInfoClosure.hpp"
  30 #include "oops/oop.inline.hpp"
  31 
  32 
  33 // HeapInspection
  34 
  35 // KlassInfoTable is a bucket hash table that
  36 // maps klassOops to extra information:
  37 //    instance count and instance word size.
  38 //
  39 // A KlassInfoBucket is the head of a link list
  40 // of KlassInfoEntry's
  41 //
  42 // KlassInfoHisto is a growable array of pointers
  43 // to KlassInfoEntry's and is used to sort
  44 // the entries.
  45 
  46 class KlassInfoEntry: public CHeapObj<mtInternal> {
  47  private:
  48   KlassInfoEntry* _next;
  49   klassOop        _klass;
  50   long            _instance_count;
  51   size_t          _instance_words;
  52 
  53  public:
  54   KlassInfoEntry(klassOop k, KlassInfoEntry* next) :
  55     _klass(k), _instance_count(0), _instance_words(0), _next(next)
  56   {}
  57   KlassInfoEntry* next()     { return _next; }
  58   bool is_equal(klassOop k)  { return k == _klass; }
  59   klassOop klass()           { return _klass; }
  60   long count()               { return _instance_count; }
  61   void set_count(long ct)    { _instance_count = ct; }
  62   size_t words()             { return _instance_words; }
  63   void set_words(size_t wds) { _instance_words = wds; }
  64   int compare(KlassInfoEntry* e1, KlassInfoEntry* e2);
  65   void print_on(outputStream* st) const;
  66 };
  67 






  68 class KlassInfoBucket: public CHeapObj<mtInternal> {
  69  private:
  70   KlassInfoEntry* _list;
  71   KlassInfoEntry* list()           { return _list; }
  72   void set_list(KlassInfoEntry* l) { _list = l; }
  73  public:
  74   KlassInfoEntry* lookup(const klassOop k);
  75   void initialize() { _list = NULL; }
  76   void empty();
  77   void iterate(KlassInfoClosure* cic);
  78 };
  79 
  80 class KlassInfoTable: public StackObj {
  81  private:
  82   int _size;
  83   static const int _num_buckets = 20011;
  84   size_t _size_of_instances_in_words;
  85 
  86   // An aligned reference address (typically the least
  87   // address in the perm gen) used for hashing klass
  88   // objects.
  89   HeapWord* _ref;
  90 
  91   KlassInfoBucket* _buckets;
  92   uint hash(klassOop p);
  93   KlassInfoEntry* lookup(const klassOop k);
  94 
  95  public:
  96   KlassInfoTable(HeapWord* ref);
  97   ~KlassInfoTable();
  98   bool record_instance(const oop obj);
  99   void iterate(KlassInfoClosure* cic);
 100   bool allocation_failed() { return _buckets == NULL; }
 101   size_t size_of_instances_in_words() const;
 102 };
 103 
 104 class KlassInfoHisto : public StackObj {
 105  private:
 106   GrowableArray<KlassInfoEntry*>* _elements;
 107   GrowableArray<KlassInfoEntry*>* elements() const { return _elements; }
 108   const char* _title;
 109   const char* title() const { return _title; }
 110   static int sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2);
 111   void print_elements(outputStream* st) const;
 112   static const int _histo_initial_size = 1000;
 113  public:
 114   KlassInfoHisto(const char* title);
 115   ~KlassInfoHisto();
 116   void add(KlassInfoEntry* cie);
 117   void print_on(outputStream* st) const;
 118   void sort();
 119 };
 120 
 121 
 122 class HeapInspection : public AllStatic {
 123  public:
 124   static void heap_inspection(outputStream* st, bool need_prologue);
 125   static size_t populate_table(KlassInfoTable* cit,

 126                                bool need_prologue,
 127                                BoolObjectClosure* filter = NULL);
 128   static HeapWord* start_of_perm_gen();
 129   static void find_instances_at_safepoint(klassOop k, GrowableArray<oop>* result);
 130  private:
 131   static bool is_shared_heap();
 132   static void prologue();
 133   static void epilogue();
 134 };
 135 
 136 #endif // SHARE_VM_MEMORY_HEAPINSPECTION_HPP