hotspot/src/share/vm/classfile/classLoaderStats.hpp
author mchung
Tue, 24 Nov 2015 14:59:17 -0800
changeset 34280 72bfaaffee36
parent 25051 8110ec6e7340
permissions -rw-r--r--
8143911: Reintegrate JEP 259: Stack-Walking API Reviewed-by: coleenp, dfuchs, bchristi, psandoz, sspitsyn Contributed-by: Mandy Chung <mandy.chung@oracle.com>, Brent Christian <brent.christian@oracle.com>, Daniel Fuchs <daniel.fuchs@oracle.com>, Hamlin Li <huaming.li@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25051
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
     1
/*
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
     4
 *
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
     8
 *
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    13
 * accompanied this code).
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    14
 *
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    18
 *
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    21
 * questions.
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    22
 *
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    23
 */
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    24
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    25
#ifndef SHARE_VM_CLASSFILE_CLASSLOADERSTATS_HPP
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    26
#define SHARE_VM_CLASSFILE_CLASSLOADERSTATS_HPP
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    27
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    28
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    29
#include "classfile/classLoaderData.hpp"
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    30
#include "oops/klass.hpp"
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    31
#include "oops/oopsHierarchy.hpp"
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    32
#include "runtime/vm_operations.hpp"
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    33
#include "services/diagnosticCommand.hpp"
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    34
#include "utilities/resourceHash.hpp"
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    35
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    36
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    37
class ClassLoaderStatsDCmd : public DCmd {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    38
public:
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    39
  ClassLoaderStatsDCmd(outputStream* output, bool heap) :
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    40
    DCmd(output, heap) {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    41
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    42
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    43
  static const char* name() {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    44
    return "VM.classloader_stats";
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    45
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    46
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    47
  static const char* description() {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    48
    return "Print statistics about all ClassLoaders.";
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    49
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    50
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    51
  static const char* impact() {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    52
    return "Low";
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    53
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    54
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    55
  virtual void execute(DCmdSource source, TRAPS);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    56
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    57
  static int num_arguments() {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    58
    return 0;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    59
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    60
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    61
  static const JavaPermission permission() {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    62
    JavaPermission p = {"java.lang.management.ManagementPermission",
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    63
                        "monitor", NULL};
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    64
    return p;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    65
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    66
};
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    67
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    68
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    69
class ClassLoaderStats : public ResourceObj {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    70
public:
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    71
  ClassLoaderData*  _cld;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    72
  oop               _class_loader;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    73
  oop               _parent;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    74
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    75
  size_t            _chunk_sz;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    76
  size_t            _block_sz;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    77
  uintx             _classes_count;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    78
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    79
  size_t            _anon_chunk_sz;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    80
  size_t            _anon_block_sz;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    81
  uintx             _anon_classes_count;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    82
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    83
  ClassLoaderStats() :
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    84
    _cld(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    85
    _class_loader(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    86
    _parent(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    87
    _chunk_sz(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    88
    _block_sz(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    89
    _classes_count(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    90
    _anon_block_sz(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    91
    _anon_chunk_sz(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    92
    _anon_classes_count(0) {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    93
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    94
};
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    95
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    96
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    97
class ClassLoaderStatsClosure : public CLDClosure {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    98
protected:
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
    99
  static bool oop_equals(oop const& s1, oop const& s2) {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   100
    return s1 == s2;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   101
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   102
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   103
  static unsigned oop_hash(oop const& s1) {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   104
    unsigned hash = (unsigned)((uintptr_t)&s1);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   105
    return hash ^ (hash >> LogMinObjAlignment);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   106
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   107
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   108
  typedef ResourceHashtable<oop, ClassLoaderStats*,
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   109
      ClassLoaderStatsClosure::oop_hash, ClassLoaderStatsClosure::oop_equals> StatsTable;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   110
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   111
  outputStream* _out;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   112
  StatsTable* _stats;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   113
  uintx   _total_loaders;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   114
  uintx   _total_classes;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   115
  size_t  _total_chunk_sz;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   116
  size_t  _total_block_sz;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   117
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   118
public:
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   119
  ClassLoaderStatsClosure(outputStream* out) :
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   120
    _out(out),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   121
    _total_loaders(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   122
    _total_block_sz(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   123
    _total_chunk_sz(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   124
    _total_classes(0),
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   125
    _stats(new StatsTable()) {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   126
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   127
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   128
  virtual void do_cld(ClassLoaderData* cld);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   129
  virtual bool do_entry(oop const& key, ClassLoaderStats* const& cls);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   130
  void print();
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   131
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   132
private:
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   133
  void addEmptyParents(oop cl);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   134
};
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   135
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   136
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   137
class ClassLoaderStatsVMOperation : public VM_Operation {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   138
  outputStream* _out;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   139
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   140
public:
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   141
  ClassLoaderStatsVMOperation(outputStream* out) :
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   142
    _out(out) {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   143
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   144
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   145
  VMOp_Type type() const {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   146
    return VMOp_ClassLoaderStatsOperation;
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   147
  }
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   148
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   149
  void doit();
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   150
};
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   151
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents:
diff changeset
   152
#endif // SHARE_VM_CLASSFILE_CLASSLOADERSTATS_HPP