Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/classfile/classLoaderStats.cpp
32285 views
/*1* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/classLoaderStats.hpp"26#include "utilities/globalDefinitions.hpp"272829class ClassStatsClosure : public KlassClosure {30public:31int _num_classes;3233ClassStatsClosure() :34_num_classes(0) {35}3637virtual void do_klass(Klass* k) {38_num_classes++;39}40};414243void ClassLoaderStatsClosure::do_cld(ClassLoaderData* cld) {44oop cl = cld->class_loader();45ClassLoaderStats* cls;4647// The hashtable key is the ClassLoader oop since we want to account48// for "real" classes and anonymous classes together49ClassLoaderStats** cls_ptr = _stats->get(cl);50if (cls_ptr == NULL) {51cls = new ClassLoaderStats();52_stats->put(cl, cls);53_total_loaders++;54} else {55cls = *cls_ptr;56}5758if (!cld->is_anonymous()) {59cls->_cld = cld;60}6162cls->_class_loader = cl;63if (cl != NULL) {64cls->_parent = java_lang_ClassLoader::parent(cl);65addEmptyParents(cls->_parent);66}6768ClassStatsClosure csc;69cld->classes_do(&csc);70if(cld->is_anonymous()) {71cls->_anon_classes_count += csc._num_classes;72} else {73cls->_classes_count = csc._num_classes;74}75_total_classes += csc._num_classes;7677Metaspace* ms = cld->metaspace_or_null();78if (ms != NULL) {79if(cld->is_anonymous()) {80cls->_anon_chunk_sz += ms->allocated_chunks_bytes();81cls->_anon_block_sz += ms->allocated_blocks_bytes();82} else {83cls->_chunk_sz = ms->allocated_chunks_bytes();84cls->_block_sz = ms->allocated_blocks_bytes();85}86_total_chunk_sz += ms->allocated_chunks_bytes();87_total_block_sz += ms->allocated_blocks_bytes();88}89}909192// Handles the difference in pointer width on 32 and 64 bit platforms93#ifdef _LP6494#define SPACE "%8s"95#else96#define SPACE "%s"97#endif9899100bool ClassLoaderStatsClosure::do_entry(oop const& key, ClassLoaderStats* const& cls) {101Klass* class_loader_klass = (cls->_class_loader == NULL ? NULL : cls->_class_loader->klass());102Klass* parent_klass = (cls->_parent == NULL ? NULL : cls->_parent->klass());103104_out->print(INTPTR_FORMAT " " INTPTR_FORMAT " " INTPTR_FORMAT " " UINTX_FORMAT_W(6) " " SIZE_FORMAT_W(8) " " SIZE_FORMAT_W(8) " ",105p2i(class_loader_klass), p2i(parent_klass), p2i(cls->_cld),106cls->_classes_count,107cls->_chunk_sz, cls->_block_sz);108if (class_loader_klass != NULL) {109_out->print("%s", class_loader_klass->external_name());110} else {111_out->print("<boot class loader>");112}113_out->cr();114if (cls->_anon_classes_count > 0) {115_out->print_cr(SPACE SPACE SPACE " " UINTX_FORMAT_W(6) " " SIZE_FORMAT_W(8) " " SIZE_FORMAT_W(8) " + unsafe anonymous classes",116"", "", "",117cls->_anon_classes_count,118cls->_anon_chunk_sz, cls->_anon_block_sz);119}120return true;121}122123124void ClassLoaderStatsClosure::print() {125_out->print_cr("ClassLoader" SPACE " Parent" SPACE " CLD*" SPACE " Classes ChunkSz BlockSz Type", "", "", "");126_stats->iterate(this);127_out->print("Total = " UINTX_FORMAT_W(-6), _total_loaders);128_out->print(SPACE SPACE SPACE " ", "", "", "");129_out->print_cr(UINTX_FORMAT_W(6) " " SIZE_FORMAT_W(8) " " SIZE_FORMAT_W(8) " ",130_total_classes,131_total_chunk_sz,132_total_block_sz);133_out->print_cr("ChunkSz: Total size of all allocated metaspace chunks");134_out->print_cr("BlockSz: Total size of all allocated metaspace blocks (each chunk has several blocks)");135}136137138void ClassLoaderStatsClosure::addEmptyParents(oop cl) {139while (cl != NULL && java_lang_ClassLoader::loader_data(cl) == NULL) {140// This classloader has not loaded any classes141ClassLoaderStats** cls_ptr = _stats->get(cl);142if (cls_ptr == NULL) {143// It does not exist in our table - add it144ClassLoaderStats* cls = new ClassLoaderStats();145cls->_class_loader = cl;146cls->_parent = java_lang_ClassLoader::parent(cl);147_stats->put(cl, cls);148_total_loaders++;149}150151cl = java_lang_ClassLoader::parent(cl);152}153}154155156void ClassLoaderStatsVMOperation::doit() {157ClassLoaderStatsClosure clsc (_out);158ClassLoaderDataGraph::cld_do(&clsc);159clsc.print();160}161162163void ClassLoaderStatsDCmd::execute(DCmdSource source, TRAPS) {164ClassLoaderStatsVMOperation op(output());165VMThread::execute(&op);166}167168169