< prev index next >

src/hotspot/share/classfile/classLoaderStats.cpp

Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2020, 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.

@@ -24,10 +24,11 @@
 
 #include "precompiled.hpp"
 #include "classfile/classLoaderData.inline.hpp"
 #include "classfile/classLoaderDataGraph.hpp"
 #include "classfile/classLoaderStats.hpp"
+#include "oops/objArrayKlass.hpp"
 #include "oops/oop.inline.hpp"
 #include "utilities/globalDefinitions.hpp"
 
 
 class ClassStatsClosure : public KlassClosure {

@@ -57,11 +58,11 @@
     _total_loaders++;
   } else {
     cls = *cls_ptr;
   }
 
-  if (!cld->is_unsafe_anonymous()) {
+  if (!cld->has_class_mirror_holder()) {
     cls->_cld = cld;
   }
 
   cls->_class_loader = cl;
   if (cl != NULL) {

@@ -69,22 +70,39 @@
     addEmptyParents(cls->_parent);
   }
 
   ClassStatsClosure csc;
   cld->classes_do(&csc);
-  if(cld->is_unsafe_anonymous()) {
+  bool is_hidden = false;
+  if(cld->has_class_mirror_holder()) {
+    // if cld has a class holder then it must be either hidden or unsafe anonymous.
+    Klass* k = cld->klasses();
+    // if it's an array class then need to see if bottom class is hidden.
+    if (k->is_array_klass()) {
+      k = ObjArrayKlass::cast(k)->bottom_klass();
+    }
+    is_hidden = k->is_hidden();
+    if (is_hidden) {
+      cls->_hidden_classes_count += csc._num_classes;
+    } else {
     cls->_anon_classes_count += csc._num_classes;
+    }
   } else {
     cls->_classes_count = csc._num_classes;
   }
   _total_classes += csc._num_classes;
 
   ClassLoaderMetaspace* ms = cld->metaspace_or_null();
   if (ms != NULL) {
-    if(cld->is_unsafe_anonymous()) {
+    if(cld->has_class_mirror_holder()) {
+      if (is_hidden) {
+        cls->_hidden_chunk_sz += ms->allocated_chunks_bytes();
+        cls->_hidden_block_sz += ms->allocated_blocks_bytes();
+      } else {
       cls->_anon_chunk_sz += ms->allocated_chunks_bytes();
       cls->_anon_block_sz += ms->allocated_blocks_bytes();
+      }
     } else {
       cls->_chunk_sz = ms->allocated_chunks_bytes();
       cls->_block_sz = ms->allocated_blocks_bytes();
     }
     _total_chunk_sz += ms->allocated_chunks_bytes();

@@ -119,10 +137,16 @@
     _out->print_cr(SPACE SPACE SPACE "                                    " UINTX_FORMAT_W(6) "  " SIZE_FORMAT_W(8) "  " SIZE_FORMAT_W(8) "   + unsafe anonymous classes",
         "", "", "",
         cls->_anon_classes_count,
         cls->_anon_chunk_sz, cls->_anon_block_sz);
   }
+  if (cls->_hidden_classes_count > 0) {
+    _out->print_cr(SPACE SPACE SPACE "                                    " UINTX_FORMAT_W(6) "  " SIZE_FORMAT_W(8) "  " SIZE_FORMAT_W(8) "   + hidden classes",
+        "", "", "",
+        cls->_hidden_classes_count,
+        cls->_hidden_chunk_sz, cls->_hidden_block_sz);
+  }
   return true;
 }
 
 
 void ClassLoaderStatsClosure::print() {
< prev index next >