hotspot/src/share/vm/memory/heapInspection.hpp
author acorn
Thu, 05 Mar 2009 22:07:29 -0500
changeset 2140 07437c6a4cd4
parent 670 ddf3e9583f2f
child 2141 e9a644aaff87
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
670
ddf3e9583f2f 6719955: Update copyright year
xdono
parents: 184
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#ifndef SERVICES_KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// HeapInspection
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// KlassInfoTable is a bucket hash table that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// maps klassOops to extra information:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
//    instance count and instance word size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// A KlassInfoBucket is the head of a link list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// of KlassInfoEntry's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// KlassInfoHisto is a growable array of pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// to KlassInfoEntry's and is used to sort
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// the entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
class KlassInfoEntry: public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  KlassInfoEntry* _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  klassOop        _klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  long            _instance_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  size_t          _instance_words;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  KlassInfoEntry(klassOop k, KlassInfoEntry* next) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    _klass(k), _instance_count(0), _instance_words(0), _next(next)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  KlassInfoEntry* next()     { return _next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  bool is_equal(klassOop k)  { return k == _klass; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  klassOop klass()           { return _klass; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  long count()               { return _instance_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  void set_count(long ct)    { _instance_count = ct; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  size_t words()             { return _instance_words; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  void set_words(size_t wds) { _instance_words = wds; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  int compare(KlassInfoEntry* e1, KlassInfoEntry* e2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  void print_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
class KlassInfoClosure: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // Called for each KlassInfoEntry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  virtual void do_cinfo(KlassInfoEntry* cie) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
class KlassInfoBucket: public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  KlassInfoEntry* _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  KlassInfoEntry* list()           { return _list; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  void set_list(KlassInfoEntry* l) { _list = l; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  KlassInfoEntry* lookup(const klassOop k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  void initialize() { _list = NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  void empty();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  void iterate(KlassInfoClosure* cic);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
class KlassInfoTable: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  int _size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // An aligned reference address (typically the least
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // address in the perm gen) used for hashing klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  HeapWord* _ref;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  KlassInfoBucket* _buckets;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  uint hash(klassOop p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  KlassInfoEntry* lookup(const klassOop k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // Table size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    cit_size = 20011
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  KlassInfoTable(int size, HeapWord* ref);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  ~KlassInfoTable();
184
a2da5efb871c 6621728: Heap inspection should not crash in the face of C-heap exhaustion
ysr
parents: 1
diff changeset
   101
  bool record_instance(const oop obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  void iterate(KlassInfoClosure* cic);
184
a2da5efb871c 6621728: Heap inspection should not crash in the face of C-heap exhaustion
ysr
parents: 1
diff changeset
   103
  bool allocation_failed() { return _buckets == NULL; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
class KlassInfoHisto : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  GrowableArray<KlassInfoEntry*>* _elements;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  GrowableArray<KlassInfoEntry*>* elements() const { return _elements; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  const char* _title;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  const char* title() const { return _title; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  static int sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  void print_elements(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    histo_initial_size = 1000
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  KlassInfoHisto(const char* title,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
             int estimatedCount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  ~KlassInfoHisto();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  void add(KlassInfoEntry* cie);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  void print_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  void sort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
#endif // SERVICES_KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
class HeapInspection : public AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  static void heap_inspection(outputStream* st) KERNEL_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  static void find_instances_at_safepoint(klassOop k, GrowableArray<oop>* result) KERNEL_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
};