hotspot/src/share/vm/memory/heapInspection.hpp
author jwilhelm
Thu, 19 Feb 2015 12:56:50 +0100
changeset 29085 7b01b134b727
parent 29081 c61eb4914428
parent 29071 73f45d04ad7a
child 33604 ad1cd9269bd4
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
29071
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2141
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2141
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2141
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_MEMORY_HEAPINSPECTION_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_MEMORY_HEAPINSPECTION_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 27677
diff changeset
    28
#include "memory/allocation.hpp"
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 27677
diff changeset
    29
#include "oops/objArrayOop.hpp"
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 27677
diff changeset
    30
#include "oops/oop.hpp"
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    31
#include "oops/annotations.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 13975
diff changeset
    32
#include "utilities/macros.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    34
#if INCLUDE_SERVICES
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// HeapInspection
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// KlassInfoTable is a bucket hash table that
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    40
// maps Klass*s to extra information:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//    instance count and instance word size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// A KlassInfoBucket is the head of a link list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// of KlassInfoEntry's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// KlassInfoHisto is a growable array of pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// to KlassInfoEntry's and is used to sort
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// the entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    50
#define HEAP_INSPECTION_COLUMNS_DO(f) \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    51
    f(inst_size, InstSize, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    52
        "Size of each object instance of the Java class") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    53
    f(inst_count, InstCount, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    54
        "Number of object instances of the Java class")  \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    55
    f(inst_bytes, InstBytes, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    56
        "This is usually (InstSize * InstNum). The only exception is " \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    57
        "java.lang.Class, whose InstBytes also includes the slots " \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    58
        "used to store static fields. InstBytes is not counted in " \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    59
        "ROAll, RWAll or Total") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    60
    f(mirror_bytes, Mirror, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    61
        "Size of the Klass::java_mirror() object") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    62
    f(klass_bytes, KlassBytes, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    63
        "Size of the InstanceKlass or ArrayKlass for this class. " \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    64
        "Note that this includes VTab, ITab, OopMap") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    65
    f(secondary_supers_bytes, K_secondary_supers, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    66
        "Number of bytes used by the Klass::secondary_supers() array") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    67
    f(vtab_bytes, VTab, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    68
        "Size of the embedded vtable in InstanceKlass") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    69
    f(itab_bytes, ITab, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    70
        "Size of the embedded itable in InstanceKlass") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    71
    f(nonstatic_oopmap_bytes, OopMap, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    72
        "Size of the embedded nonstatic_oop_map in InstanceKlass") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    73
    f(methods_array_bytes, IK_methods, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    74
        "Number of bytes used by the InstanceKlass::methods() array") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    75
    f(method_ordering_bytes, IK_method_ordering, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    76
        "Number of bytes used by the InstanceKlass::method_ordering() array") \
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20282
diff changeset
    77
    f(default_methods_array_bytes, IK_default_methods, \
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20282
diff changeset
    78
        "Number of bytes used by the InstanceKlass::default_methods() array") \
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20282
diff changeset
    79
    f(default_vtable_indices_bytes, IK_default_vtable_indices, \
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20282
diff changeset
    80
        "Number of bytes used by the InstanceKlass::default_vtable_indices() array") \
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    81
    f(local_interfaces_bytes, IK_local_interfaces, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    82
        "Number of bytes used by the InstanceKlass::local_interfaces() array") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    83
    f(transitive_interfaces_bytes, IK_transitive_interfaces, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    84
        "Number of bytes used by the InstanceKlass::transitive_interfaces() array") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    85
    f(fields_bytes, IK_fields, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    86
        "Number of bytes used by the InstanceKlass::fields() array") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    87
    f(inner_classes_bytes, IK_inner_classes, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    88
        "Number of bytes used by the InstanceKlass::inner_classes() array") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    89
    f(signers_bytes, IK_signers, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    90
        "Number of bytes used by the InstanceKlass::singers() array") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    91
    f(class_annotations_bytes, class_annotations, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    92
        "Size of class annotations") \
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15484
diff changeset
    93
    f(class_type_annotations_bytes, class_type_annotations, \
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15484
diff changeset
    94
        "Size of class type annotations") \
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    95
    f(fields_annotations_bytes, fields_annotations, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    96
        "Size of field annotations") \
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15484
diff changeset
    97
    f(fields_type_annotations_bytes, fields_type_annotations, \
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15484
diff changeset
    98
        "Size of field type annotations") \
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
    99
    f(methods_annotations_bytes, methods_annotations, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   100
        "Size of method annotations") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   101
    f(methods_parameter_annotations_bytes, methods_parameter_annotations, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   102
        "Size of method parameter annotations") \
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15484
diff changeset
   103
    f(methods_type_annotations_bytes, methods_type_annotations, \
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15484
diff changeset
   104
        "Size of methods type annotations") \
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   105
    f(methods_default_annotations_bytes, methods_default_annotations, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   106
        "Size of methods default annotations") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   107
    f(annotations_bytes, annotations, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   108
        "Size of all annotations") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   109
    f(cp_bytes, Cp, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   110
        "Size of InstanceKlass::constants()") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   111
    f(cp_tags_bytes, CpTags, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   112
        "Size of InstanceKlass::constants()->tags()") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   113
    f(cp_cache_bytes, CpCache, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   114
        "Size of InstanceKlass::constants()->cache()") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   115
    f(cp_operands_bytes, CpOperands, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   116
        "Size of InstanceKlass::constants()->operands()") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   117
    f(cp_refmap_bytes, CpRefMap, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   118
        "Size of InstanceKlass::constants()->reference_map()") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   119
    f(cp_all_bytes, CpAll, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   120
        "Sum of Cp + CpTags + CpCache + CpOperands + CpRefMap") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   121
    f(method_count, MethodCount, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   122
        "Number of methods in this class") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   123
    f(method_bytes, MethodBytes, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   124
        "Size of the Method object") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   125
    f(const_method_bytes, ConstMethod, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   126
        "Size of the ConstMethod object") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   127
    f(method_data_bytes, MethodData, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   128
        "Size of the MethodData object") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   129
    f(stackmap_bytes, StackMap, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   130
        "Size of the stackmap_data") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   131
    f(bytecode_bytes, Bytecodes, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   132
        "Of the MethodBytes column, how much are the space taken up by bytecodes") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   133
    f(method_all_bytes, MethodAll, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   134
        "Sum of MethodBytes + Constmethod + Stackmap + Methoddata") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   135
    f(ro_bytes, ROAll, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   136
        "Size of all class meta data that could (potentially) be placed " \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   137
        "in read-only memory. (This could change with CDS design)") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   138
    f(rw_bytes, RWAll, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   139
        "Size of all class meta data that must be placed in read/write " \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   140
        "memory. (This could change with CDS design) ") \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   141
    f(total_bytes, Total, \
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   142
        "ROAll + RWAll. Note that this does NOT include InstBytes.")
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   143
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   144
// Size statistics for a Klass - filled in by Klass::collect_statistics()
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   145
class KlassSizeStats {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   146
public:
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   147
#define COUNT_KLASS_SIZE_STATS_FIELD(field, name, help)   _index_ ## field,
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   148
#define DECLARE_KLASS_SIZE_STATS_FIELD(field, name, help) julong _ ## field;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   149
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   150
  enum {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   151
    HEAP_INSPECTION_COLUMNS_DO(COUNT_KLASS_SIZE_STATS_FIELD)
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   152
    _num_columns
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   153
  };
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   154
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   155
  HEAP_INSPECTION_COLUMNS_DO(DECLARE_KLASS_SIZE_STATS_FIELD)
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   156
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   157
  static int count(oop x) {
20282
7f9cbdf89af2 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 18704
diff changeset
   158
    return (HeapWordSize * (((x) != NULL) ? (x)->size() : 0));
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   159
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   160
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   161
  static int count_array(objArrayOop x) {
20282
7f9cbdf89af2 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 18704
diff changeset
   162
    return (HeapWordSize * (((x) != NULL) ? (x)->size() : 0));
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   163
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   164
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   165
  template <class T> static int count(T* x) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   166
    return (HeapWordSize * ((x) ? (x)->size() : 0));
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   167
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   168
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   169
  template <class T> static int count_array(T* x) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   170
    if (x == NULL) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   171
      return 0;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   172
    }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   173
    if (x->length() == 0) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   174
      // This is a shared array, e.g., Universe::the_empty_int_array(). Don't
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   175
      // count it to avoid double-counting.
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   176
      return 0;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   177
    }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   178
    return HeapWordSize * x->size();
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   179
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   180
};
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   181
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   182
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   183
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   184
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   185
class KlassInfoEntry: public CHeapObj<mtInternal> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  KlassInfoEntry* _next;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   188
  Klass*          _klass;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  long            _instance_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  size_t          _instance_words;
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   191
  long            _index;
29071
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   192
  bool            _do_print; // True if we should print this class when printing the class hierarchy.
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   193
  GrowableArray<KlassInfoEntry*>* _subclasses;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
 public:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   196
  KlassInfoEntry(Klass* k, KlassInfoEntry* next) :
29071
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   197
    _klass(k), _instance_count(0), _instance_words(0), _next(next), _index(-1),
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   198
    _do_print(false), _subclasses(NULL)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  {}
29071
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   200
  ~KlassInfoEntry();
17370
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 15601
diff changeset
   201
  KlassInfoEntry* next() const   { return _next; }
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 15601
diff changeset
   202
  bool is_equal(const Klass* k)  { return k == _klass; }
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 15601
diff changeset
   203
  Klass* klass()  const      { return _klass; }
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 15601
diff changeset
   204
  long count()    const      { return _instance_count; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  void set_count(long ct)    { _instance_count = ct; }
17370
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 15601
diff changeset
   206
  size_t words()  const      { return _instance_words; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  void set_words(size_t wds) { _instance_words = wds; }
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   208
  void set_index(long index) { _index = index; }
17370
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 15601
diff changeset
   209
  long index()    const      { return _index; }
29071
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   210
  GrowableArray<KlassInfoEntry*>* subclasses() const { return _subclasses; }
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   211
  void add_subclass(KlassInfoEntry* cie);
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   212
  void set_do_print(bool do_print) { _do_print = do_print; }
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   213
  bool do_print() const      { return _do_print; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  int compare(KlassInfoEntry* e1, KlassInfoEntry* e2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  void print_on(outputStream* st) const;
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   216
  const char* name() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
18704
226ce98e75e6 8015972: Refactor the sending of the object count after GC event
ehelin
parents: 18025
diff changeset
   219
class KlassInfoClosure : public StackObj {
226ce98e75e6 8015972: Refactor the sending of the object count after GC event
ehelin
parents: 18025
diff changeset
   220
 public:
226ce98e75e6 8015972: Refactor the sending of the object count after GC event
ehelin
parents: 18025
diff changeset
   221
  // Called for each KlassInfoEntry.
226ce98e75e6 8015972: Refactor the sending of the object count after GC event
ehelin
parents: 18025
diff changeset
   222
  virtual void do_cinfo(KlassInfoEntry* cie) = 0;
226ce98e75e6 8015972: Refactor the sending of the object count after GC event
ehelin
parents: 18025
diff changeset
   223
};
226ce98e75e6 8015972: Refactor the sending of the object count after GC event
ehelin
parents: 18025
diff changeset
   224
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   225
class KlassInfoBucket: public CHeapObj<mtInternal> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  KlassInfoEntry* _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  KlassInfoEntry* list()           { return _list; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  void set_list(KlassInfoEntry* l) { _list = l; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
 public:
17370
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 15601
diff changeset
   231
  KlassInfoEntry* lookup(Klass* k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  void initialize() { _list = NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  void empty();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  void iterate(KlassInfoClosure* cic);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
class KlassInfoTable: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  int _size;
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   240
  static const int _num_buckets = 20011;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   241
  size_t _size_of_instances_in_words;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  // An aligned reference address (typically the least
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // address in the perm gen) used for hashing klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  // objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  HeapWord* _ref;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  KlassInfoBucket* _buckets;
17370
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 15601
diff changeset
   249
  uint hash(const Klass* p);
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 15601
diff changeset
   250
  KlassInfoEntry* lookup(Klass* k); // allocates if not found!
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   251
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   252
  class AllClassesFinder : public KlassClosure {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   253
    KlassInfoTable *_table;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   254
   public:
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   255
    AllClassesFinder(KlassInfoTable* table) : _table(table) {}
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   256
    virtual void do_klass(Klass* k);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   257
  };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
 public:
29071
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   260
  KlassInfoTable(bool add_all_classes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  ~KlassInfoTable();
184
a2da5efb871c 6621728: Heap inspection should not crash in the face of C-heap exhaustion
ysr
parents: 1
diff changeset
   262
  bool record_instance(const oop obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  void iterate(KlassInfoClosure* cic);
184
a2da5efb871c 6621728: Heap inspection should not crash in the face of C-heap exhaustion
ysr
parents: 1
diff changeset
   264
  bool allocation_failed() { return _buckets == NULL; }
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   265
  size_t size_of_instances_in_words() const;
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   266
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   267
  friend class KlassInfoHisto;
29071
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   268
  friend class KlassHierarchy;
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   269
};
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   270
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   271
class KlassHierarchy : AllStatic {
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   272
 public:
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   273
  static void print_class_hierarchy(outputStream* st, bool print_interfaces,  bool print_subclasses,
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   274
                                    char* classname);
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   275
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   276
 private:
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   277
  static void set_do_print_for_class_hierarchy(KlassInfoEntry* cie, KlassInfoTable* cit,
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   278
                                               bool print_subclasse);
73f45d04ad7a 8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents: 27677
diff changeset
   279
  static void print_class(outputStream* st, KlassInfoEntry* cie, bool print_subclasses);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
class KlassInfoHisto : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
 private:
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   284
  static const int _histo_initial_size = 1000;
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   285
  KlassInfoTable *_cit;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  GrowableArray<KlassInfoEntry*>* _elements;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  GrowableArray<KlassInfoEntry*>* elements() const { return _elements; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  const char* _title;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  const char* title() const { return _title; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  static int sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  void print_elements(outputStream* st) const;
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   292
  void print_class_stats(outputStream* st, bool csv_format, const char *columns);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   293
  julong annotations_bytes(Array<AnnotationArray*>* p) const;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   294
  const char *_selected_columns;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   295
  bool is_selected(const char *col_name);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   296
  void print_title(outputStream* st, bool csv_format,
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   297
                   bool selected_columns_table[], int width_table[],
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   298
                   const char *name_table[]);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   299
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   300
  template <class T> static int count_bytes(T* x) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   301
    return (HeapWordSize * ((x) ? (x)->size() : 0));
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   302
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   303
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   304
  template <class T> static int count_bytes_array(T* x) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   305
    if (x == NULL) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   306
      return 0;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   307
    }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   308
    if (x->length() == 0) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   309
      // This is a shared array, e.g., Universe::the_empty_int_array(). Don't
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   310
      // count it to avoid double-counting.
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   311
      return 0;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   312
    }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   313
    return HeapWordSize * x->size();
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   314
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   315
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   316
  // returns a format string to print a julong with the given width. E.g,
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   317
  // printf(num_fmt(6), julong(10)) would print out the number 10 with 4
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   318
  // leading spaces.
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22551
diff changeset
   319
PRAGMA_DIAG_PUSH
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22551
diff changeset
   320
PRAGMA_FORMAT_NONLITERAL_IGNORED
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22551
diff changeset
   321
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   322
  static void print_julong(outputStream* st, int width, julong n) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   323
    int num_spaces = width - julong_width(n);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   324
    if (num_spaces > 0) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   325
      st->print(str_fmt(num_spaces), "");
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   326
    }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   327
    st->print(JULONG_FORMAT, n);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   328
  }
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22551
diff changeset
   329
PRAGMA_DIAG_POP
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   330
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   331
  static char* perc_fmt(int width) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   332
    static char buf[32];
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   333
    jio_snprintf(buf, sizeof(buf), "%%%d.1f%%%%", width-1);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   334
    return buf;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   335
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   336
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   337
  static char* str_fmt(int width) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   338
    static char buf[32];
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   339
    jio_snprintf(buf, sizeof(buf), "%%%ds", width);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   340
    return buf;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   341
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   342
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   343
  static int julong_width(julong n) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   344
    if (n == 0) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   345
      return 1;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   346
    }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   347
    int w = 0;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   348
    while (n > 0) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   349
      n /= 10;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   350
      w += 1;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   351
    }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   352
    return w;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   353
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   354
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   355
  static int col_width(julong n, const char *name) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   356
    int w = julong_width(n);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   357
    int min = (int)(strlen(name));
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   358
    if (w < min) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   359
        w = min;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   360
    }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   361
    // add a leading space for separation.
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   362
    return w + 1;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   363
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   364
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
 public:
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   366
  KlassInfoHisto(KlassInfoTable* cit, const char* title);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  ~KlassInfoHisto();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  void add(KlassInfoEntry* cie);
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   369
  void print_histo_on(outputStream* st, bool print_class_stats, bool csv_format, const char *columns);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  void sort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   373
#endif // INCLUDE_SERVICES
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 20391
diff changeset
   375
// These declarations are needed since the declaration of KlassInfoTable and
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   376
// KlassInfoClosure are guarded by #if INLCUDE_SERVICES
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   377
class KlassInfoTable;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   378
class KlassInfoClosure;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   379
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   380
class HeapInspection : public StackObj {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   381
  bool _csv_format; // "comma separated values" format for spreadsheet.
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   382
  bool _print_help;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   383
  bool _print_class_stats;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   384
  const char* _columns;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
 public:
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   386
  HeapInspection(bool csv_format, bool print_help,
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   387
                 bool print_class_stats, const char *columns) :
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   388
      _csv_format(csv_format), _print_help(print_help),
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 13975
diff changeset
   389
      _print_class_stats(print_class_stats), _columns(columns) {}
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   390
  void heap_inspection(outputStream* st) NOT_SERVICES_RETURN;
27677
b1997f2f1b56 8062808: Turn on the -Wreturn-type warning
stefank
parents: 24424
diff changeset
   391
  size_t populate_table(KlassInfoTable* cit, BoolObjectClosure* filter = NULL) NOT_SERVICES_RETURN_(0);
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   392
  static void find_instances_at_safepoint(Klass* k, GrowableArray<oop>* result) NOT_SERVICES_RETURN;
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   393
 private:
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17370
diff changeset
   394
  void iterate_over_heap(KlassInfoTable* cit, BoolObjectClosure* filter = NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   396
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   397
#endif // SHARE_VM_MEMORY_HEAPINSPECTION_HPP