Add dumping for number of classes initialized

For --dump-stats, dump how many classes are each status after
attempting initialization.

Test: <compile_apk> --instruction-set=arm64 --app-image-file=generated.art --dump-stats

Sample output:
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 100% of instance fields resolved for 1575 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 1.88679% of check-casts removed based on type information for 53 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status NotReady for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status Retired for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status ErrorResolved for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status ErrorUnresolved for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status Idx for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status Loaded for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status Resolving for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status Resolved for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status Verifying for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0.0186596% of classes with status RetryVerificationAtRuntime for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status VerifyingAtRuntime for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 28.1916% of classes with status Verified for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status SuperclassValidated for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 0% of classes with status Initializing for 32155 cases
dex2oat I 12-21 19:18:56 58439 58439 compiler_driver.cc:109] 71.7898% of classes with status Initialized for 32155 cases

Bug: 70735003
Test: test-art-host

Change-Id: I57e8a977ee202c0ce85030208caa183344a5567a
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index f52c566..8f4969c 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -112,19 +112,7 @@
 class CompilerDriver::AOTCompilationStats {
  public:
   AOTCompilationStats()
-      : stats_lock_("AOT compilation statistics lock"),
-        resolved_instance_fields_(0), unresolved_instance_fields_(0),
-        resolved_local_static_fields_(0), resolved_static_fields_(0), unresolved_static_fields_(0),
-        type_based_devirtualization_(0),
-        safe_casts_(0), not_safe_casts_(0) {
-    for (size_t i = 0; i <= kMaxInvokeType; i++) {
-      resolved_methods_[i] = 0;
-      unresolved_methods_[i] = 0;
-      virtual_made_direct_[i] = 0;
-      direct_calls_to_boot_[i] = 0;
-      direct_methods_to_boot_[i] = 0;
-    }
-  }
+      : stats_lock_("AOT compilation statistics lock") {}
 
   void Dump() {
     DumpStat(resolved_instance_fields_, unresolved_instance_fields_, "instance fields resolved");
@@ -141,6 +129,16 @@
              type_based_devirtualization_,
              "virtual/interface calls made direct based on type information");
 
+    const size_t total = std::accumulate(
+        class_status_count_,
+        class_status_count_ + static_cast<size_t>(ClassStatus::kLast) + 1,
+        0u);
+    for (size_t i = 0; i <= static_cast<size_t>(ClassStatus::kLast); ++i) {
+      std::ostringstream oss;
+      oss << "classes with status " << static_cast<ClassStatus>(i);
+      DumpStat(class_status_count_[i], total - class_status_count_[i], oss.str().c_str());
+    }
+
     for (size_t i = 0; i <= kMaxInvokeType; i++) {
       std::ostringstream oss;
       oss << static_cast<InvokeType>(i) << " methods were AOT resolved";
@@ -219,26 +217,34 @@
     not_safe_casts_++;
   }
 
+  // Register a class status.
+  void AddClassStatus(ClassStatus status) REQUIRES(!stats_lock_) {
+    STATS_LOCK();
+    ++class_status_count_[static_cast<size_t>(status)];
+  }
+
  private:
   Mutex stats_lock_;
 
-  size_t resolved_instance_fields_;
-  size_t unresolved_instance_fields_;
+  size_t resolved_instance_fields_ = 0u;
+  size_t unresolved_instance_fields_ = 0u;
 
-  size_t resolved_local_static_fields_;
-  size_t resolved_static_fields_;
-  size_t unresolved_static_fields_;
+  size_t resolved_local_static_fields_ = 0u;
+  size_t resolved_static_fields_ = 0u;
+  size_t unresolved_static_fields_ = 0u;
   // Type based devirtualization for invoke interface and virtual.
-  size_t type_based_devirtualization_;
+  size_t type_based_devirtualization_ = 0u;
 
-  size_t resolved_methods_[kMaxInvokeType + 1];
-  size_t unresolved_methods_[kMaxInvokeType + 1];
-  size_t virtual_made_direct_[kMaxInvokeType + 1];
-  size_t direct_calls_to_boot_[kMaxInvokeType + 1];
-  size_t direct_methods_to_boot_[kMaxInvokeType + 1];
+  size_t resolved_methods_[kMaxInvokeType + 1] = {};
+  size_t unresolved_methods_[kMaxInvokeType + 1] = {};
+  size_t virtual_made_direct_[kMaxInvokeType + 1] = {};
+  size_t direct_calls_to_boot_[kMaxInvokeType + 1] = {};
+  size_t direct_methods_to_boot_[kMaxInvokeType + 1] = {};
 
-  size_t safe_casts_;
-  size_t not_safe_casts_;
+  size_t safe_casts_ = 0u;
+  size_t not_safe_casts_ = 0u;
+
+  size_t class_status_count_[static_cast<size_t>(ClassStatus::kLast) + 1] = {};
 
   DISALLOW_COPY_AND_ASSIGN(AOTCompilationStats);
 };
@@ -2102,8 +2108,11 @@
     Handle<mirror::Class> klass(
         hs.NewHandle(manager_->GetClassLinker()->FindClass(soa.Self(), descriptor, class_loader)));
 
-    if (klass != nullptr && !SkipClass(manager_->GetClassLoader(), dex_file, klass.Get())) {
-      TryInitializeClass(klass, class_loader);
+    if (klass != nullptr) {
+      if (!SkipClass(manager_->GetClassLoader(), dex_file, klass.Get())) {
+        TryInitializeClass(klass, class_loader);
+      }
+      manager_->GetCompiler()->stats_->AddClassStatus(klass->GetStatus());
     }
     // Clear any class not found or verification exceptions.
     soa.Self()->ClearException();