< prev index next >

src/hotspot/share/classfile/classLoaderStats.cpp

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
--- 1,7 ---
  /*
!  * Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

*** 30,20 ***
  #include "oops/oop.inline.hpp"
  #include "utilities/globalDefinitions.hpp"
  
  
  class ClassStatsClosure : public KlassClosure {
  public:
    int _num_classes;
  
    ClassStatsClosure() :
      _num_classes(0) {
    }
  
    virtual void do_klass(Klass* k) {
!     _num_classes++;
    }
  };
  
  void ClassLoaderStatsClosure::do_cld(ClassLoaderData* cld) {
    // Class loaders are not kept alive so this closure must only be
    // used during a safepoint.
--- 30,33 ---
  #include "oops/oop.inline.hpp"
  #include "utilities/globalDefinitions.hpp"
  
  
  class ClassStatsClosure : public KlassClosure {
+   // Some klasses should not be reported by ClassStatistics
+   bool exclude_klass(Klass* k) const {
+     // Direct instances of ObjArrayKlass represent the Java types that Java code can see.
+     // RefArrayKlass/FlatArrayKlass describe different implementations of the arrays, filter them out.
+     if (k->is_objArray_klass() && k->kind() != Klass::KlassKind::ObjArrayKlassKind) {
+       return true;
+     }
+     return false;
+   }
+ 
  public:
    int _num_classes;
  
    ClassStatsClosure() :
      _num_classes(0) {
    }
  
    virtual void do_klass(Klass* k) {
!     if (!exclude_klass(k)) {
+       _num_classes++;
+     }
    }
+ 
  };
  
  void ClassLoaderStatsClosure::do_cld(ClassLoaderData* cld) {
    // Class loaders are not kept alive so this closure must only be
    // used during a safepoint.
< prev index next >