Wed, 03 Jul 2019 20:42:37 +0800
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) { |
dbuck@9063 | 104 | unsigned hash = (unsigned)((uintptr_t)&s1); |
dbuck@9063 | 105 | return hash ^ (hash >> LogMinObjAlignment); |
dbuck@9063 | 106 | } |
dbuck@9063 | 107 | |
dbuck@9063 | 108 | typedef ResourceHashtable<oop, ClassLoaderStats*, |
dbuck@9063 | 109 | ClassLoaderStatsClosure::oop_hash, ClassLoaderStatsClosure::oop_equals> StatsTable; |
dbuck@9063 | 110 | |
dbuck@9063 | 111 | outputStream* _out; |
dbuck@9063 | 112 | StatsTable* _stats; |
dbuck@9063 | 113 | uintx _total_loaders; |
dbuck@9063 | 114 | uintx _total_classes; |
dbuck@9063 | 115 | size_t _total_chunk_sz; |
dbuck@9063 | 116 | size_t _total_block_sz; |
dbuck@9063 | 117 | |
dbuck@9063 | 118 | public: |
dbuck@9063 | 119 | ClassLoaderStatsClosure(outputStream* out) : |
dbuck@9063 | 120 | _out(out), |
dbuck@9063 | 121 | _total_loaders(0), |
dbuck@9063 | 122 | _total_block_sz(0), |
dbuck@9063 | 123 | _total_chunk_sz(0), |
dbuck@9063 | 124 | _total_classes(0), |
dbuck@9063 | 125 | _stats(new StatsTable()) { |
dbuck@9063 | 126 | } |
dbuck@9063 | 127 | |
dbuck@9063 | 128 | virtual void do_cld(ClassLoaderData* cld); |
dbuck@9063 | 129 | virtual bool do_entry(oop const& key, ClassLoaderStats* const& cls); |
dbuck@9063 | 130 | void print(); |
dbuck@9063 | 131 | |
dbuck@9063 | 132 | private: |
dbuck@9063 | 133 | void addEmptyParents(oop cl); |
dbuck@9063 | 134 | }; |
dbuck@9063 | 135 | |
dbuck@9063 | 136 | |
dbuck@9063 | 137 | class ClassLoaderStatsVMOperation : public VM_Operation { |
dbuck@9063 | 138 | outputStream* _out; |
dbuck@9063 | 139 | |
dbuck@9063 | 140 | public: |
dbuck@9063 | 141 | ClassLoaderStatsVMOperation(outputStream* out) : |
dbuck@9063 | 142 | _out(out) { |
dbuck@9063 | 143 | } |
dbuck@9063 | 144 | |
dbuck@9063 | 145 | VMOp_Type type() const { |
dbuck@9063 | 146 | return VMOp_ClassLoaderStatsOperation; |
dbuck@9063 | 147 | } |
dbuck@9063 | 148 | |
dbuck@9063 | 149 | void doit(); |
dbuck@9063 | 150 | }; |
dbuck@9063 | 151 | |
dbuck@9063 | 152 | #endif // SHARE_VM_CLASSFILE_CLASSLOADERSTATS_HPP |