< prev index next >

src/hotspot/share/classfile/classLoaderStats.cpp

Print this page

  1 /*
  2  * Copyright (c) 2014, 2025, 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 
 25 #include "classfile/classLoaderData.inline.hpp"
 26 #include "classfile/classLoaderDataGraph.hpp"
 27 #include "classfile/classLoaderStats.hpp"
 28 #include "memory/classLoaderMetaspace.hpp"
 29 #include "oops/objArrayKlass.hpp"
 30 #include "oops/oop.inline.hpp"
 31 #include "utilities/globalDefinitions.hpp"
 32 
 33 
 34 class ClassStatsClosure : public KlassClosure {







 35 public:
 36   int _num_classes;
 37 
 38   ClassStatsClosure() :
 39     _num_classes(0) {
 40   }
 41 
 42   virtual void do_klass(Klass* k) {
 43     _num_classes++;


 44   }

 45 };
 46 
 47 void ClassLoaderStatsClosure::do_cld(ClassLoaderData* cld) {
 48   // Class loaders are not kept alive so this closure must only be
 49   // used during a safepoint.
 50   assert_at_safepoint();
 51   oop cl = cld->class_loader_no_keepalive();
 52 
 53   // The hashtable key is the ClassLoader oop since we want to account
 54   // for "real" classes and hidden classes together
 55   bool added = false;
 56   ClassLoaderStats* cls = _stats->put_if_absent(cl, &added);
 57   if (added) {
 58     cls->_class_loader = cl;
 59     _total_loaders++;
 60   }
 61   assert(cls->_class_loader == cl, "Sanity");
 62 
 63   if (!cld->has_class_mirror_holder()) {
 64     cls->_cld = cld;

  1 /*
  2  * Copyright (c) 2014, 2026, 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 
 25 #include "classfile/classLoaderData.inline.hpp"
 26 #include "classfile/classLoaderDataGraph.hpp"
 27 #include "classfile/classLoaderStats.hpp"
 28 #include "memory/classLoaderMetaspace.hpp"
 29 #include "oops/objArrayKlass.hpp"
 30 #include "oops/oop.inline.hpp"
 31 #include "utilities/globalDefinitions.hpp"
 32 
 33 
 34 class ClassStatsClosure : public KlassClosure {
 35   // Some klasses should not be reported by ClassStatistics
 36   bool exclude_klass(Klass* k) const {
 37     // Direct instances of ObjArrayKlass represent the Java types that Java code can see.
 38     // RefArrayKlass/FlatArrayKlass describe different implementations of the arrays, filter them out.
 39     return k->is_objArray_klass() && k->kind() != Klass::KlassKind::ObjArrayKlassKind;
 40   }
 41 
 42 public:
 43   int _num_classes;
 44 
 45   ClassStatsClosure() :
 46     _num_classes(0) {
 47   }
 48 
 49   virtual void do_klass(Klass* k) {
 50     if (!exclude_klass(k)) {
 51       _num_classes++;
 52     }
 53   }
 54 
 55 };
 56 
 57 void ClassLoaderStatsClosure::do_cld(ClassLoaderData* cld) {
 58   // Class loaders are not kept alive so this closure must only be
 59   // used during a safepoint.
 60   assert_at_safepoint();
 61   oop cl = cld->class_loader_no_keepalive();
 62 
 63   // The hashtable key is the ClassLoader oop since we want to account
 64   // for "real" classes and hidden classes together
 65   bool added = false;
 66   ClassLoaderStats* cls = _stats->put_if_absent(cl, &added);
 67   if (added) {
 68     cls->_class_loader = cl;
 69     _total_loaders++;
 70   }
 71   assert(cls->_class_loader == cl, "Sanity");
 72 
 73   if (!cld->has_class_mirror_holder()) {
 74     cls->_cld = cld;
< prev index next >