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 35 PrintCLDMetaspaceInfoClosure::PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale, bool do_print, bool break_down_by_chunktype) 36 : _out(out), _scale(scale), _do_print(do_print), _break_down_by_chunktype(break_down_by_chunktype) 37 , _num_loaders(0) 38 { 39 memset(_num_loaders_by_spacetype, 0, sizeof(_num_loaders_by_spacetype)); 40 } 41 42 void PrintCLDMetaspaceInfoClosure::do_cld(ClassLoaderData* cld) { 43 44 assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint"); 45 46 ClassLoaderMetaspace* msp = cld->metaspace_or_null(); 47 if (msp == NULL) { 48 return; 49 } 50 51 // Collect statistics for this class loader metaspace 52 ClassLoaderMetaspaceStatistics this_cld_stat; 53 msp->add_to_statistics(&this_cld_stat); 54 55 // And add it to the running totals 56 _stats_total.add(this_cld_stat); 57 _num_loaders ++; 58 _stats_by_spacetype[msp->space_type()].add(this_cld_stat); 59 _num_loaders_by_spacetype[msp->space_type()] ++; 60 61 // Optionally, print. 62 if (_do_print) { 63 64 _out->print(UINTX_FORMAT_W(4) ": ", _num_loaders); 65 66 if (cld->is_anonymous()) { 67 _out->print("ClassLoaderData " PTR_FORMAT " for anonymous class", p2i(cld)); 68 } else { 69 ResourceMark rm; 70 _out->print("ClassLoaderData " PTR_FORMAT " for %s", p2i(cld), cld->loader_name()); 71 } 72 73 if (cld->is_unloading()) { 74 _out->print(" (unloading)"); 75 } 76 77 this_cld_stat.print_on(_out, _scale, _break_down_by_chunktype); 78 _out->cr(); 79 80 } 81 82 } 83 84 } // namespace metaspace 85