From fccc34c57f171463e871d8beeb4f97a67abc03da Mon Sep 17 00:00:00 2001
Date: Fri, 22 Sep 2023 14:44:32 +0800
Subject: add add-Count-instance-klass-when-loading-from-jsa-file

---
 hotspot/src/share/vm/classfile/classLoaderData.cpp | 5 ++++-
 hotspot/src/share/vm/oops/instanceKlass.cpp        | 1 -
 hotspot/src/share/vm/oops/instanceKlass.hpp        | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/hotspot/src/share/vm/classfile/classLoaderData.cpp b/hotspot/src/share/vm/classfile/classLoaderData.cpp
index 12b7e5036..ba86a0ebc 100644
--- a/hotspot/src/share/vm/classfile/classLoaderData.cpp
+++ b/hotspot/src/share/vm/classfile/classLoaderData.cpp
@@ -64,6 +64,7 @@
 #include "utilities/growableArray.hpp"
 #include "utilities/macros.hpp"
 #include "utilities/ostream.hpp"
+#include "oops/instanceKlass.hpp"
 
 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
 
@@ -304,7 +305,9 @@ void ClassLoaderData::add_class(Klass* k) {
   k->set_next_link(old_value);
   // link the new item into the list
   _klasses = k;
-
+  if(k->oop_is_instance()){
+    InstanceKlass::inc_instance_classes();
+  }
   if (TraceClassLoaderData && Verbose && k->class_loader_data() != NULL) {
     ResourceMark rm;
     tty->print_cr("[TraceClassLoaderData] Adding k: " PTR_FORMAT " %s to CLD: "
diff --git a/hotspot/src/share/vm/oops/instanceKlass.cpp b/hotspot/src/share/vm/oops/instanceKlass.cpp
index 993778270..00aea4377 100644
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp
@@ -232,7 +232,6 @@ InstanceKlass* InstanceKlass::allocate_instance_klass(
   // including classes in the bootstrap (NULL) class loader.
   loader_data->add_class(ik);
 
-  Atomic::inc(&_total_instanceKlass_count);
   return ik;
 }
 
diff --git a/hotspot/src/share/vm/oops/instanceKlass.hpp b/hotspot/src/share/vm/oops/instanceKlass.hpp
index 6e36fa4ce..973480341 100644
--- a/hotspot/src/share/vm/oops/instanceKlass.hpp
+++ b/hotspot/src/share/vm/oops/instanceKlass.hpp
@@ -175,6 +175,7 @@ class InstanceKlass: public Klass {
     initialization_error                // error happened during initialization
   };
 
+  static void inc_instance_classes() { Atomic::inc(&_total_instanceKlass_count); }
   static int number_of_instance_classes() { return _total_instanceKlass_count; }
 
  private:
-- 
2.22.0

