8026985: Rewrite SystemDictionary::classes_do and Dictionary::classes_do to use KlassClosure
authorcoleenp
Wed, 12 Apr 2017 08:02:29 -0400
changeset 46380 4a51438196cf
parent 46379 43ec76e10184
child 46381 020219e46c86
8026985: Rewrite SystemDictionary::classes_do and Dictionary::classes_do to use KlassClosure Summary: Actually remove unused functions like classes_do and methods_do. Reviewed-by: iveresov, sspitsyn, dholmes
hotspot/src/share/vm/classfile/classLoaderData.cpp
hotspot/src/share/vm/classfile/classLoaderData.hpp
hotspot/src/share/vm/classfile/dictionary.cpp
hotspot/src/share/vm/classfile/dictionary.hpp
hotspot/src/share/vm/classfile/loaderConstraints.cpp
hotspot/src/share/vm/classfile/loaderConstraints.hpp
hotspot/src/share/vm/classfile/placeholders.cpp
hotspot/src/share/vm/classfile/placeholders.hpp
hotspot/src/share/vm/classfile/systemDictionary.cpp
hotspot/src/share/vm/classfile/systemDictionary.hpp
hotspot/src/share/vm/memory/universe.hpp
hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp
hotspot/src/share/vm/prims/privilegedStack.cpp
hotspot/src/share/vm/prims/privilegedStack.hpp
hotspot/src/share/vm/runtime/java.cpp
hotspot/src/share/vm/runtime/reflectionUtils.hpp
hotspot/src/share/vm/services/heapDumper.cpp
--- a/hotspot/src/share/vm/classfile/classLoaderData.cpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classLoaderData.cpp	Wed Apr 12 08:02:29 2017 -0400
@@ -247,7 +247,7 @@
 void ClassLoaderData::methods_do(void f(Method*)) {
   // Lock-free access requires load_ptr_acquire
   for (Klass* k = load_ptr_acquire(&_klasses); k != NULL; k = k->next_link()) {
-    if (k->is_instance_klass()) {
+    if (k->is_instance_klass() && InstanceKlass::cast(k)->is_loaded()) {
       InstanceKlass::cast(k)->methods_do(f);
     }
   }
--- a/hotspot/src/share/vm/classfile/classLoaderData.hpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/classfile/classLoaderData.hpp	Wed Apr 12 08:02:29 2017 -0400
@@ -94,6 +94,10 @@
   static void keep_alive_cld_do(CLDClosure* cl);
   static void always_strong_cld_do(CLDClosure* cl);
   // klass do
+  // Walking classes through the ClassLoaderDataGraph include array classes.  It also includes
+  // classes that are allocated but not loaded, classes that have errors, and scratch classes
+  // for redefinition.  These classes are removed during the next class unloading.
+  // Walking the ClassLoaderDataGraph also includes anonymous classes.
   static void classes_do(KlassClosure* klass_closure);
   static void classes_do(void f(Klass* const));
   static void methods_do(void f(Method*));
--- a/hotspot/src/share/vm/classfile/dictionary.cpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/classfile/dictionary.cpp	Wed Apr 12 08:02:29 2017 -0400
@@ -266,23 +266,6 @@
   _pd_cache_table->always_strong_oops_do(blk);
 }
 
-
-void Dictionary::always_strong_classes_do(KlassClosure* closure) {
-  // Follow all system classes and temporary placeholders in dictionary
-  for (int index = 0; index < table_size(); index++) {
-    for (DictionaryEntry* probe = bucket(index);
-                          probe != NULL;
-                          probe = probe->next()) {
-      Klass* e = probe->klass();
-      ClassLoaderData* loader_data = probe->loader_data();
-      if (is_strongly_reachable(loader_data, e)) {
-        closure->do_klass(e);
-      }
-    }
-  }
-}
-
-
 //   Just the classes from defining class loaders
 void Dictionary::classes_do(void f(Klass*)) {
   for (int index = 0; index < table_size(); index++) {
@@ -331,20 +314,6 @@
   _pd_cache_table->oops_do(f);
 }
 
-void Dictionary::methods_do(void f(Method*)) {
-  for (int index = 0; index < table_size(); index++) {
-    for (DictionaryEntry* probe = bucket(index);
-                          probe != NULL;
-                          probe = probe->next()) {
-      Klass* k = probe->klass();
-      if (probe->loader_data() == k->class_loader_data()) {
-        // only take klass is we have the entry with the defining class loader
-        InstanceKlass::cast(k)->methods_do(f);
-      }
-    }
-  }
-}
-
 void Dictionary::unlink(BoolObjectClosure* is_alive) {
   // Only the protection domain cache table may contain references to the heap
   // that need to be unlinked.
@@ -651,25 +620,6 @@
   return p;
 }
 
-void ProtectionDomainCacheTable::free(ProtectionDomainCacheEntry* to_delete) {
-  unsigned int hash = compute_hash(Handle(Thread::current(), to_delete->protection_domain()));
-  int index = hash_to_index(hash);
-
-  ProtectionDomainCacheEntry** p = bucket_addr(index);
-  ProtectionDomainCacheEntry* entry = bucket(index);
-  while (true) {
-    assert(entry != NULL, "sanity");
-
-    if (entry == to_delete) {
-      *p = entry->next();
-      Hashtable<oop, mtClass>::free_entry(entry);
-      break;
-    } else {
-      p = entry->next_addr();
-      entry = *p;
-    }
-  }
-}
 
 SymbolPropertyTable::SymbolPropertyTable(int table_size)
   : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry))
--- a/hotspot/src/share/vm/classfile/dictionary.hpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/classfile/dictionary.hpp	Wed Apr 12 08:02:29 2017 -0400
@@ -75,8 +75,6 @@
 
   DictionaryEntry* new_entry(unsigned int hash, InstanceKlass* klass, ClassLoaderData* loader_data);
 
-  DictionaryEntry* new_entry();
-
   void free_entry(DictionaryEntry* entry);
 
   void add_klass(Symbol* class_name, ClassLoaderData* loader_data, InstanceKlass* obj);
@@ -94,14 +92,10 @@
   void always_strong_oops_do(OopClosure* blk);
   void roots_oops_do(OopClosure* strong, OopClosure* weak);
 
-  void always_strong_classes_do(KlassClosure* closure);
-
   void classes_do(void f(Klass*));
   void classes_do(void f(Klass*, TRAPS), TRAPS);
   void classes_do(void f(Klass*, ClassLoaderData*));
 
-  void methods_do(void f(Method*));
-
   void unlink(BoolObjectClosure* is_alive);
   void remove_classes_in_error_state();
 
@@ -211,7 +205,6 @@
   ProtectionDomainCacheTable(int table_size);
 
   ProtectionDomainCacheEntry* get(Handle protection_domain);
-  void free(ProtectionDomainCacheEntry* entry);
 
   void unlink(BoolObjectClosure* cl);
 
@@ -278,7 +271,6 @@
   void add_protection_domain(Dictionary* dict, Handle protection_domain);
 
   InstanceKlass* klass() const { return (InstanceKlass*)literal(); }
-  InstanceKlass** klass_addr() { return (InstanceKlass**)literal_addr(); }
 
   DictionaryEntry* next() const {
     return (DictionaryEntry*)HashtableEntry<InstanceKlass*, mtClass>::next();
@@ -294,8 +286,6 @@
   ProtectionDomainEntry* pd_set() const { return _pd_set; }
   void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
 
-  bool has_protection_domain() { return _pd_set != NULL; }
-
   // Tells whether the initiating class' protection can access the this _klass
   bool is_valid_protection_domain(Handle protection_domain) {
     if (!ProtectionDomainVerification) return true;
--- a/hotspot/src/share/vm/classfile/loaderConstraints.cpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/classfile/loaderConstraints.cpp	Wed Apr 12 08:02:29 2017 -0400
@@ -57,19 +57,6 @@
   Hashtable<InstanceKlass*, mtClass>::free_entry(entry);
 }
 
-// Enhanced Class Redefinition support
-void LoaderConstraintTable::classes_do(KlassClosure* f) {
-  for (int index = 0; index < table_size(); index++) {
-    for (LoaderConstraintEntry* probe = bucket(index);
-                                probe != NULL;
-                                probe = probe->next()) {
-      if (probe->klass() != NULL) {
-        f->do_klass(probe->klass());
-      }
-        }
-      }
-    }
-
 // The loaderConstraintTable must always be accessed with the
 // SystemDictionary lock held. This is true even for readers as
 // entries in the table could be being dynamically resized.
--- a/hotspot/src/share/vm/classfile/loaderConstraints.hpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/classfile/loaderConstraints.hpp	Wed Apr 12 08:02:29 2017 -0400
@@ -61,9 +61,6 @@
     return (LoaderConstraintEntry**)Hashtable<InstanceKlass*, mtClass>::bucket_addr(i);
   }
 
-  // Enhanced Class Redefinition support
-  void classes_do(KlassClosure* f);
-
   // Check class loader constraints
   bool add_entry(Symbol* name, InstanceKlass* klass1, Handle loader1,
                                     InstanceKlass* klass2, Handle loader2);
--- a/hotspot/src/share/vm/classfile/placeholders.cpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/classfile/placeholders.cpp	Wed Apr 12 08:02:29 2017 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -175,37 +175,6 @@
     : TwoOopHashtable<Symbol*, mtClass>(table_size, sizeof(PlaceholderEntry)) {
 }
 
-
-void PlaceholderTable::classes_do(KlassClosure* f) {
-  for (int index = 0; index < table_size(); index++) {
-    for (PlaceholderEntry* probe = bucket(index);
-                           probe != NULL;
-                           probe = probe->next()) {
-      probe->classes_do(f);
-    }
-  }
-}
-
-
-void PlaceholderEntry::classes_do(KlassClosure* closure) {
-  assert(klassname() != NULL, "should have a non-null klass");
-  if (_instanceKlass != NULL) {
-    closure->do_klass(instance_klass());
-  }
-}
-
-// do all entries in the placeholder table
-void PlaceholderTable::entries_do(void f(Symbol*)) {
-  for (int index = 0; index < table_size(); index++) {
-    for (PlaceholderEntry* probe = bucket(index);
-                           probe != NULL;
-                           probe = probe->next()) {
-      f(probe->klassname());
-    }
-  }
-}
-
-
 #ifndef PRODUCT
 // Note, doesn't append a cr
 void PlaceholderEntry::print() const {
--- a/hotspot/src/share/vm/classfile/placeholders.hpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/classfile/placeholders.hpp	Wed Apr 12 08:02:29 2017 -0400
@@ -98,12 +98,6 @@
                        Symbol* name, ClassLoaderData* loader_data,
                        classloadAction action, Thread* thread);
 
-  // GC support.
-  void classes_do(KlassClosure* f);
-
-  // JVMTI support
-  void entries_do(void f(Symbol*));
-
 #ifndef PRODUCT
   void print();
 #endif
@@ -329,10 +323,6 @@
     return (actionToQueue(action) == NULL);
   }
 
-  // GC support
-  // Applies "f->do_oop" to all root oops in the placeholder table.
-  void classes_do(KlassClosure* closure);
-
   // Print method doesn't append a cr
   void print() const  PRODUCT_RETURN;
   void verify() const;
--- a/hotspot/src/share/vm/classfile/systemDictionary.cpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp	Wed Apr 12 08:02:29 2017 -0400
@@ -1885,14 +1885,6 @@
   roots_oops_do(blk, NULL);
 }
 
-void SystemDictionary::always_strong_classes_do(KlassClosure* closure) {
-  // Follow all system classes and temporary placeholders in dictionary
-  dictionary()->always_strong_classes_do(closure);
-
-  // Placeholders. These represent classes we're actively loading.
-  placeholders()->classes_do(closure);
-}
-
 // Calculate a "good" systemdictionary size based
 // on predicted or current loaded classes count
 int SystemDictionary::calculate_systemdictionary_size(int classcount) {
@@ -1974,31 +1966,6 @@
   invoke_method_table()->oops_do(f);
 }
 
-// Extended Class redefinition support.
-// If one of these classes is replaced, we need to replace it in these places.
-// KlassClosure::do_klass should take the address of a class but we can
-// change that later.
-void SystemDictionary::preloaded_classes_do(KlassClosure* f) {
-  for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
-    f->do_klass(_well_known_klasses[k]);
-  }
-
-  {
-    for (int i = 0; i < T_VOID+1; i++) {
-      if (_box_klasses[i] != NULL) {
-        assert(i >= T_BOOLEAN, "checking");
-        f->do_klass(_box_klasses[i]);
-      }
-    }
-  }
-
-  FilteredFieldsMap::classes_do(f);
-}
-
-void SystemDictionary::lazily_loaded_classes_do(KlassClosure* f) {
-  f->do_klass(_abstract_ownable_synchronizer_klass);
-}
-
 // Just the classes from defining class loaders
 // Don't iterate over placeholders
 void SystemDictionary::classes_do(void f(Klass*)) {
@@ -2018,12 +1985,10 @@
   dictionary()->classes_do(f);
 }
 
-void SystemDictionary::placeholders_do(void f(Symbol*)) {
-  placeholders()->entries_do(f);
-}
-
 void SystemDictionary::methods_do(void f(Method*)) {
-  dictionary()->methods_do(f);
+  // Walk methods in loaded classes
+  ClassLoaderDataGraph::methods_do(f);
+  // Walk method handle intrinsics
   invoke_method_table()->methods_do(f);
 }
 
--- a/hotspot/src/share/vm/classfile/systemDictionary.hpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/classfile/systemDictionary.hpp	Wed Apr 12 08:02:29 2017 -0400
@@ -347,16 +347,14 @@
                                                            TRAPS);
 
   // Iterate over all klasses in dictionary
-  //   Just the classes from defining class loaders
+  // Just the classes from defining class loaders
   static void classes_do(void f(Klass*));
   // Added for initialize_itable_for_klass to handle exceptions
   static void classes_do(void f(Klass*, TRAPS), TRAPS);
-  //   All classes, and their class loaders
+  // All classes, and their class loaders, including initiating class loaders
   static void classes_do(void f(Klass*, ClassLoaderData*));
 
-  static void placeholders_do(void f(Symbol*));
-
-  // Iterate over all methods in all klasses in dictionary
+  // Iterate over all methods in all klasses
   static void methods_do(void f(Method*));
 
   // Garbage collection support
@@ -364,7 +362,6 @@
   // This method applies "blk->do_oop" to all the pointers to "system"
   // classes and loaders.
   static void always_strong_oops_do(OopClosure* blk);
-  static void always_strong_classes_do(KlassClosure* closure);
 
   // Unload (that is, break root links to) all unmarked classes and
   // loaders.  Returns "true" iff something was unloaded.
@@ -383,10 +380,6 @@
   // System loader lock
   static oop system_loader_lock()           { return _system_loader_lock_obj; }
 
-protected:
-  // Extended Redefine classes support (tbi)
-  static void preloaded_classes_do(KlassClosure* f);
-  static void lazily_loaded_classes_do(KlassClosure* f);
 public:
   // Sharing support.
   static void reorder_dictionary();
--- a/hotspot/src/share/vm/memory/universe.hpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/memory/universe.hpp	Wed Apr 12 08:02:29 2017 -0400
@@ -62,11 +62,6 @@
 
   Method* get_method();
 
-  // Enhanced Class Redefinition support
-  void classes_do(void f(Klass*)) {
-    f(_klass);
-  }
-
   // CDS support.  Replace the klass in this with the archive version
   // could use this for Enhanced Class Redefinition also.
   void serialize(SerializeClosure* f) {
--- a/hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp	Wed Apr 12 08:02:29 2017 -0400
@@ -213,14 +213,6 @@
     }
   }
 
-  static void prim_array_increment_with_loader(Klass* array, ClassLoaderData* loader_data) {
-    JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
-    oop class_loader = loader_data->class_loader();
-    if (class_loader == JNIHandles::resolve(that->get_initiatingLoader())) {
-      that->set_count(that->get_count() + 1);
-    }
-  }
-
   static void add_with_loader(Klass* k, ClassLoaderData* loader_data) {
     JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
     if (that->available()) {
--- a/hotspot/src/share/vm/prims/privilegedStack.cpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/prims/privilegedStack.cpp	Wed Apr 12 08:02:29 2017 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -51,14 +51,6 @@
   } while(cur != NULL);
 }
 
-void PrivilegedElement::classes_do(KlassClosure* f) {
-  PrivilegedElement *cur = this;
-  do {
-    f->do_klass(cur->_klass);
-    cur = cur->_next;
-  } while(cur != NULL);
-}
-
 //-------------------------------------------------------------------------------
 #ifndef PRODUCT
 
--- a/hotspot/src/share/vm/prims/privilegedStack.hpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/prims/privilegedStack.hpp	Wed Apr 12 08:02:29 2017 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -39,7 +39,6 @@
  public:
   void initialize(vframeStream* vf, oop context, PrivilegedElement* next, TRAPS);
   void oops_do(OopClosure* f);
-  void classes_do(KlassClosure* f);
   intptr_t* frame_id() const           { return _frame_id; }
   oop  privileged_context() const  { return _privileged_context; }
   oop  class_loader() const        { return InstanceKlass::cast(_klass)->class_loader(); }
--- a/hotspot/src/share/vm/runtime/java.cpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/runtime/java.cpp	Wed Apr 12 08:02:29 2017 -0400
@@ -112,7 +112,7 @@
     ResourceMark rm;
     HandleMark hm;
     collected_profiled_methods = new GrowableArray<Method*>(1024);
-    ClassLoaderDataGraph::methods_do(collect_profiled_methods);
+    SystemDictionary::methods_do(collect_profiled_methods);
     collected_profiled_methods->sort(&compare_methods);
 
     int count = collected_profiled_methods->length();
@@ -163,7 +163,7 @@
   collected_invoked_methods->sort(&compare_methods);
   //
   tty->cr();
-  tty->print_cr("Histogram Over MethodOop Invocation Counters (cutoff = " INTX_FORMAT "):", MethodHistogramCutoff);
+  tty->print_cr("Histogram Over Method Invocation Counters (cutoff = " INTX_FORMAT "):", MethodHistogramCutoff);
   tty->cr();
   tty->print_cr("____Count_(I+C)____Method________________________Module_________________");
   unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0,
--- a/hotspot/src/share/vm/runtime/reflectionUtils.hpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/runtime/reflectionUtils.hpp	Wed Apr 12 08:02:29 2017 -0400
@@ -196,12 +196,6 @@
     }
     return nflds;
   }
-  // Enhance Class Redefinition Support
-  static void classes_do(KlassClosure* f) {
-    for (int i = 0; i < _filtered_fields->length(); i++) {
-      f->do_klass(_filtered_fields->at(i)->klass());
-    }
-  }
 };
 
 
--- a/hotspot/src/share/vm/services/heapDumper.cpp	Wed Apr 12 08:49:08 2017 +0200
+++ b/hotspot/src/share/vm/services/heapDumper.cpp	Wed Apr 12 08:02:29 2017 -0400
@@ -1824,8 +1824,10 @@
   check_segment_length();
 
   // HPROF_GC_ROOT_STICKY_CLASS
+  // These should be classes in the NULL class loader data, and not all classes
+  // if !ClassUnloading
   StickyClassDumper class_dumper(writer());
-  SystemDictionary::always_strong_classes_do(&class_dumper);
+  ClassLoaderData::the_null_class_loader_data()->classes_do(&class_dumper);
 
   // fixes up the length of the dump record and writes the HPROF_HEAP_DUMP_END record.
   DumperSupport::end_of_dump(writer());