src/share/vm/classfile/classLoaderStats.hpp

Wed, 14 Oct 2020 17:44:48 +0800

author
aoqi
date
Wed, 14 Oct 2020 17:44:48 +0800
changeset 9931
fd44df5e3bc3
parent 9918
1848821ee85d
permissions
-rw-r--r--

Merge

dbuck@9063 1 /*
dbuck@9063 2 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
dbuck@9063 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dbuck@9063 4 *
dbuck@9063 5 * This code is free software; you can redistribute it and/or modify it
dbuck@9063 6 * under the terms of the GNU General Public License version 2 only, as
dbuck@9063 7 * published by the Free Software Foundation.
dbuck@9063 8 *
dbuck@9063 9 * This code is distributed in the hope that it will be useful, but WITHOUT
dbuck@9063 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dbuck@9063 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
dbuck@9063 12 * version 2 for more details (a copy is included in the LICENSE file that
dbuck@9063 13 * accompanied this code).
dbuck@9063 14 *
dbuck@9063 15 * You should have received a copy of the GNU General Public License version
dbuck@9063 16 * 2 along with this work; if not, write to the Free Software Foundation,
dbuck@9063 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dbuck@9063 18 *
dbuck@9063 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dbuck@9063 20 * or visit www.oracle.com if you need additional information or have any
dbuck@9063 21 * questions.
dbuck@9063 22 *
dbuck@9063 23 */
dbuck@9063 24
dbuck@9063 25 #ifndef SHARE_VM_CLASSFILE_CLASSLOADERSTATS_HPP
dbuck@9063 26 #define SHARE_VM_CLASSFILE_CLASSLOADERSTATS_HPP
dbuck@9063 27
dbuck@9063 28
dbuck@9063 29 #include "classfile/classLoaderData.hpp"
dbuck@9063 30 #include "oops/klass.hpp"
dbuck@9063 31 #include "oops/oopsHierarchy.hpp"
dbuck@9063 32 #include "runtime/vm_operations.hpp"
dbuck@9063 33 #include "services/diagnosticCommand.hpp"
dbuck@9063 34 #include "utilities/resourceHash.hpp"
dbuck@9063 35
dbuck@9063 36
dbuck@9063 37 class ClassLoaderStatsDCmd : public DCmd {
dbuck@9063 38 public:
dbuck@9063 39 ClassLoaderStatsDCmd(outputStream* output, bool heap) :
dbuck@9063 40 DCmd(output, heap) {
dbuck@9063 41 }
dbuck@9063 42
dbuck@9063 43 static const char* name() {
dbuck@9063 44 return "VM.classloader_stats";
dbuck@9063 45 }
dbuck@9063 46
dbuck@9063 47 static const char* description() {
dbuck@9063 48 return "Print statistics about all ClassLoaders.";
dbuck@9063 49 }
dbuck@9063 50
dbuck@9063 51 static const char* impact() {
dbuck@9063 52 return "Low";
dbuck@9063 53 }
dbuck@9063 54
dbuck@9063 55 virtual void execute(DCmdSource source, TRAPS);
dbuck@9063 56
dbuck@9063 57 static int num_arguments() {
dbuck@9063 58 return 0;
dbuck@9063 59 }
dbuck@9063 60
dbuck@9063 61 static const JavaPermission permission() {
dbuck@9063 62 JavaPermission p = {"java.lang.management.ManagementPermission",
dbuck@9063 63 "monitor", NULL};
dbuck@9063 64 return p;
dbuck@9063 65 }
dbuck@9063 66 };
dbuck@9063 67
dbuck@9063 68
dbuck@9063 69 class ClassLoaderStats : public ResourceObj {
dbuck@9063 70 public:
dbuck@9063 71 ClassLoaderData* _cld;
dbuck@9063 72 oop _class_loader;
dbuck@9063 73 oop _parent;
dbuck@9063 74
dbuck@9063 75 size_t _chunk_sz;
dbuck@9063 76 size_t _block_sz;
dbuck@9063 77 uintx _classes_count;
dbuck@9063 78
dbuck@9063 79 size_t _anon_chunk_sz;
dbuck@9063 80 size_t _anon_block_sz;
dbuck@9063 81 uintx _anon_classes_count;
dbuck@9063 82
dbuck@9063 83 ClassLoaderStats() :
dbuck@9063 84 _cld(0),
dbuck@9063 85 _class_loader(0),
dbuck@9063 86 _parent(0),
dbuck@9063 87 _chunk_sz(0),
dbuck@9063 88 _block_sz(0),
dbuck@9063 89 _classes_count(0),
dbuck@9063 90 _anon_block_sz(0),
dbuck@9063 91 _anon_chunk_sz(0),
dbuck@9063 92 _anon_classes_count(0) {
dbuck@9063 93 }
dbuck@9063 94 };
dbuck@9063 95
dbuck@9063 96
dbuck@9063 97 class ClassLoaderStatsClosure : public CLDClosure {
dbuck@9063 98 protected:
dbuck@9063 99 static bool oop_equals(oop const& s1, oop const& s2) {
dbuck@9063 100 return s1 == s2;
dbuck@9063 101 }
dbuck@9063 102
dbuck@9063 103 static unsigned oop_hash(oop const& s1) {
stuefe@9918 104 // Robert Jenkins 1996 & Thomas Wang 1997
stuefe@9918 105 // http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm
stuefe@9918 106 uintptr_t tmp = cast_from_oop<uintptr_t>(s1);
stuefe@9918 107 unsigned hash = (unsigned)tmp;
stuefe@9918 108 hash = ~hash + (hash << 15);
stuefe@9918 109 hash = hash ^ (hash >> 12);
stuefe@9918 110 hash = hash + (hash << 2);
stuefe@9918 111 hash = hash ^ (hash >> 4);
stuefe@9918 112 hash = hash * 2057;
stuefe@9918 113 hash = hash ^ (hash >> 16);
stuefe@9918 114 return hash;
dbuck@9063 115 }
dbuck@9063 116
dbuck@9063 117 typedef ResourceHashtable<oop, ClassLoaderStats*,
dbuck@9063 118 ClassLoaderStatsClosure::oop_hash, ClassLoaderStatsClosure::oop_equals> StatsTable;
dbuck@9063 119
dbuck@9063 120 outputStream* _out;
dbuck@9063 121 StatsTable* _stats;
dbuck@9063 122 uintx _total_loaders;
dbuck@9063 123 uintx _total_classes;
dbuck@9063 124 size_t _total_chunk_sz;
dbuck@9063 125 size_t _total_block_sz;
dbuck@9063 126
dbuck@9063 127 public:
dbuck@9063 128 ClassLoaderStatsClosure(outputStream* out) :
dbuck@9063 129 _out(out),
dbuck@9063 130 _total_loaders(0),
dbuck@9063 131 _total_block_sz(0),
dbuck@9063 132 _total_chunk_sz(0),
dbuck@9063 133 _total_classes(0),
dbuck@9063 134 _stats(new StatsTable()) {
dbuck@9063 135 }
dbuck@9063 136
dbuck@9063 137 virtual void do_cld(ClassLoaderData* cld);
dbuck@9063 138 virtual bool do_entry(oop const& key, ClassLoaderStats* const& cls);
dbuck@9063 139 void print();
dbuck@9063 140
dbuck@9063 141 private:
dbuck@9063 142 void addEmptyParents(oop cl);
dbuck@9063 143 };
dbuck@9063 144
dbuck@9063 145
dbuck@9063 146 class ClassLoaderStatsVMOperation : public VM_Operation {
dbuck@9063 147 outputStream* _out;
dbuck@9063 148
dbuck@9063 149 public:
dbuck@9063 150 ClassLoaderStatsVMOperation(outputStream* out) :
dbuck@9063 151 _out(out) {
dbuck@9063 152 }
dbuck@9063 153
dbuck@9063 154 VMOp_Type type() const {
dbuck@9063 155 return VMOp_ClassLoaderStatsOperation;
dbuck@9063 156 }
dbuck@9063 157
dbuck@9063 158 void doit();
dbuck@9063 159 };
dbuck@9063 160
dbuck@9063 161 #endif // SHARE_VM_CLASSFILE_CLASSLOADERSTATS_HPP

mercurial