1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 #include "precompiled.hpp" 25 #include "classfile/classLoaderData.hpp" 26 #include "memory/metaspace/printCLDMetaspaceInfoClosure.hpp" 27 #include "memory/resourceArea.hpp" 28 #include "runtime/safepoint.hpp" 29 #include "utilities/globalDefinitions.hpp" 30 #include "utilities/ostream.hpp" 31 32 33 namespace metaspace { 34 namespace internals { 35 36 PrintCLDMetaspaceInfoClosure::PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale, bool do_print, bool break_down_by_chunktype) 37 : _out(out), _scale(scale), _do_print(do_print), _break_down_by_chunktype(break_down_by_chunktype) 38 , _num_loaders(0) 39 { 40 memset(_num_loaders_by_spacetype, 0, sizeof(_num_loaders_by_spacetype)); 41 } 42 43 void PrintCLDMetaspaceInfoClosure::do_cld(ClassLoaderData* cld) { 44 45 assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint"); 46 47 ClassLoaderMetaspace* msp = cld->metaspace_or_null(); 48 if (msp == NULL) { 49 return; 50 } 51 52 // Collect statistics for this class loader metaspace 53 ClassLoaderMetaspaceStatistics this_cld_stat; 54 msp->add_to_statistics(&this_cld_stat); 55 56 // And add it to the running totals 57 _stats_total.add(this_cld_stat); 58 _num_loaders ++; 59 _stats_by_spacetype[msp->space_type()].add(this_cld_stat); 60 _num_loaders_by_spacetype[msp->space_type()] ++; 61 62 // Optionally, print. 63 if (_do_print) { 64 65 _out->print(UINTX_FORMAT_W(4) ": ", _num_loaders); 66 67 if (cld->is_anonymous()) { 68 _out->print("ClassLoaderData " PTR_FORMAT " for anonymous class", p2i(cld)); 69 } else { 70 ResourceMark rm; 71 _out->print("ClassLoaderData " PTR_FORMAT " for %s", p2i(cld), cld->loader_name()); 72 } 73 74 if (cld->is_unloading()) { 75 _out->print(" (unloading)"); 76 } 77 78 this_cld_stat.print_on(_out, _scale, _break_down_by_chunktype); 79 _out->cr(); 80 81 } 82 83 } 84 85 } // namespace metaspace 86 } // namespace internals