src/hotspot/share/classfile/systemDictionary.cpp
changeset 52514 f4e3900c8d08
parent 52498 c3066f7465fa
child 52587 6cd56deebb0d
equal deleted inserted replaced
52513:d4f3e37d1fda 52514:f4e3900c8d08
    94 #if INCLUDE_JFR
    94 #if INCLUDE_JFR
    95 #include "jfr/jfr.hpp"
    95 #include "jfr/jfr.hpp"
    96 #endif
    96 #endif
    97 
    97 
    98 PlaceholderTable*      SystemDictionary::_placeholders        = NULL;
    98 PlaceholderTable*      SystemDictionary::_placeholders        = NULL;
    99 Dictionary*            SystemDictionary::_shared_dictionary   = NULL;
       
   100 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
    99 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
   101 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
   100 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
   102 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
   101 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
   103 ProtectionDomainCacheTable*   SystemDictionary::_pd_cache_table = NULL;
   102 ProtectionDomainCacheTable*   SystemDictionary::_pd_cache_table = NULL;
   104 
   103 
   353                                                        bool is_superclass,
   352                                                        bool is_superclass,
   354                                                        TRAPS) {
   353                                                        TRAPS) {
   355   assert(!FieldType::is_array(super_name), "invalid super class name");
   354   assert(!FieldType::is_array(super_name), "invalid super class name");
   356 #if INCLUDE_CDS
   355 #if INCLUDE_CDS
   357   if (DumpSharedSpaces) {
   356   if (DumpSharedSpaces) {
   358     // Special processing for CDS dump time.
   357     // Special processing for handling UNREGISTERED shared classes.
   359     InstanceKlass* k = SystemDictionaryShared::dump_time_resolve_super_or_fail(child_name,
   358     InstanceKlass* k = SystemDictionaryShared::dump_time_resolve_super_or_fail(child_name,
   360         super_name, class_loader, protection_domain, is_superclass, CHECK_NULL);
   359         super_name, class_loader, protection_domain, is_superclass, CHECK_NULL);
   361     if (k) {
   360     if (k) {
   362       return k;
   361       return k;
   363     }
   362     }
  1161 
  1160 
  1162   return k;
  1161   return k;
  1163 }
  1162 }
  1164 
  1163 
  1165 #if INCLUDE_CDS
  1164 #if INCLUDE_CDS
  1166 void SystemDictionary::set_shared_dictionary(HashtableBucket<mtClass>* t, int length,
  1165 // Load a class for boot loader from the shared spaces. This also
  1167                                              int number_of_entries) {
  1166 // forces the super class and all interfaces to be loaded.
  1168   assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces");
       
  1169   assert(length == _shared_dictionary_size * sizeof(HashtableBucket<mtClass>),
       
  1170          "bad shared dictionary size.");
       
  1171   _shared_dictionary = new Dictionary(ClassLoaderData::the_null_class_loader_data(),
       
  1172                                       _shared_dictionary_size, t, number_of_entries,
       
  1173                                       false /* explicitly set _resizable to false */);
       
  1174 }
       
  1175 
       
  1176 
       
  1177 // If there is a shared dictionary, then find the entry for the
       
  1178 // given shared system class, if any.
       
  1179 
       
  1180 InstanceKlass* SystemDictionary::find_shared_class(Symbol* class_name) {
       
  1181   if (shared_dictionary() != NULL) {
       
  1182     unsigned int d_hash = shared_dictionary()->compute_hash(class_name);
       
  1183     int d_index = shared_dictionary()->hash_to_index(d_hash);
       
  1184 
       
  1185     return shared_dictionary()->find_shared_class(d_index, d_hash, class_name);
       
  1186   } else {
       
  1187     return NULL;
       
  1188   }
       
  1189 }
       
  1190 
       
  1191 
       
  1192 // Load a class for boot loader from the shared spaces (found through
       
  1193 // the shared system dictionary). Force the super class and all interfaces
       
  1194 // to be loaded.
       
  1195 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
  1167 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
  1196                                                         TRAPS) {
  1168                                                         TRAPS) {
  1197   InstanceKlass* ik = find_shared_class(class_name);
  1169   InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
  1198   // Make sure we only return the boot class.
       
  1199   if (ik != NULL && ik->is_shared_boot_class()) {
  1170   if (ik != NULL && ik->is_shared_boot_class()) {
  1200     return load_shared_class(ik, Handle(), Handle(), THREAD);
  1171     return load_shared_class(ik, Handle(), Handle(), THREAD);
  1201   }
  1172   }
  1202   return NULL;
  1173   return NULL;
  1203 }
  1174 }
  1407         log_info(class, fingerprint)("%s :  expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, ik->external_name(), aot_fp, cds_fp);
  1378         log_info(class, fingerprint)("%s :  expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, ik->external_name(), aot_fp, cds_fp);
  1408       }
  1379       }
  1409     }
  1380     }
  1410   }
  1381   }
  1411   return ik;
  1382   return ik;
  1412 }
       
  1413 
       
  1414 void SystemDictionary::clear_invoke_method_table() {
       
  1415   SymbolPropertyEntry* spe = NULL;
       
  1416   for (int index = 0; index < _invoke_method_table->table_size(); index++) {
       
  1417     SymbolPropertyEntry* p = _invoke_method_table->bucket(index);
       
  1418     while (p != NULL) {
       
  1419       spe = p;
       
  1420       p = p->next();
       
  1421       _invoke_method_table->free_entry(spe);
       
  1422     }
       
  1423   }
       
  1424 }
  1383 }
  1425 #endif // INCLUDE_CDS
  1384 #endif // INCLUDE_CDS
  1426 
  1385 
  1427 InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
  1386 InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
  1428 
  1387 
  1898 
  1857 
  1899   // Visit extra methods
  1858   // Visit extra methods
  1900   invoke_method_table()->oops_do(f);
  1859   invoke_method_table()->oops_do(f);
  1901 }
  1860 }
  1902 
  1861 
  1903 // CDS: scan and relocate all classes in the system dictionary.
       
  1904 void SystemDictionary::classes_do(MetaspaceClosure* it) {
       
  1905   ClassLoaderData::the_null_class_loader_data()->dictionary()->classes_do(it);
       
  1906 }
       
  1907 
       
  1908 // CDS: scan and relocate all classes referenced by _well_known_klasses[].
  1862 // CDS: scan and relocate all classes referenced by _well_known_klasses[].
  1909 void SystemDictionary::well_known_klasses_do(MetaspaceClosure* it) {
  1863 void SystemDictionary::well_known_klasses_do(MetaspaceClosure* it) {
  1910   for (int id = FIRST_WKID; id < WKID_LIMIT; id++) {
  1864   for (int id = FIRST_WKID; id < WKID_LIMIT; id++) {
  1911     it->push(well_known_klass_addr((WKID)id));
  1865     it->push(well_known_klass_addr((WKID)id));
  1912   }
  1866   }
  1916   // Walk methods in loaded classes
  1870   // Walk methods in loaded classes
  1917   MutexLocker ml(ClassLoaderDataGraph_lock);
  1871   MutexLocker ml(ClassLoaderDataGraph_lock);
  1918   ClassLoaderDataGraph::methods_do(f);
  1872   ClassLoaderDataGraph::methods_do(f);
  1919   // Walk method handle intrinsics
  1873   // Walk method handle intrinsics
  1920   invoke_method_table()->methods_do(f);
  1874   invoke_method_table()->methods_do(f);
  1921 }
       
  1922 
       
  1923 class RemoveClassesClosure : public CLDClosure {
       
  1924   public:
       
  1925     void do_cld(ClassLoaderData* cld) {
       
  1926       if (cld->is_system_class_loader_data() || cld->is_platform_class_loader_data()) {
       
  1927         cld->dictionary()->remove_classes_in_error_state();
       
  1928       }
       
  1929     }
       
  1930 };
       
  1931 
       
  1932 void SystemDictionary::remove_classes_in_error_state() {
       
  1933   ClassLoaderData::the_null_class_loader_data()->dictionary()->remove_classes_in_error_state();
       
  1934   RemoveClassesClosure rcc;
       
  1935   MutexLocker ml(ClassLoaderDataGraph_lock);
       
  1936   ClassLoaderDataGraph::cld_do(&rcc);
       
  1937 }
  1875 }
  1938 
  1876 
  1939 // ----------------------------------------------------------------------------
  1877 // ----------------------------------------------------------------------------
  1940 // Initialization
  1878 // Initialization
  1941 
  1879 
  2036     // call. No mirror objects are accessed/restored in the above call.
  1974     // call. No mirror objects are accessed/restored in the above call.
  2037     // Mirrors are restored after java.lang.Class is loaded.
  1975     // Mirrors are restored after java.lang.Class is loaded.
  2038     HeapShared::fixup_mapped_heap_regions();
  1976     HeapShared::fixup_mapped_heap_regions();
  2039 
  1977 
  2040     // Initialize the constant pool for the Object_class
  1978     // Initialize the constant pool for the Object_class
       
  1979     assert(Object_klass()->is_shared(), "must be");
  2041     Object_klass()->constants()->restore_unshareable_info(CHECK);
  1980     Object_klass()->constants()->restore_unshareable_info(CHECK);
  2042     resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
  1981     resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
  2043   } else
  1982   } else
  2044 #endif
  1983 #endif
  2045   {
  1984   {
  2919 
  2858 
  2920 ProtectionDomainCacheEntry* SystemDictionary::cache_get(Handle protection_domain) {
  2859 ProtectionDomainCacheEntry* SystemDictionary::cache_get(Handle protection_domain) {
  2921   return _pd_cache_table->get(protection_domain);
  2860   return _pd_cache_table->get(protection_domain);
  2922 }
  2861 }
  2923 
  2862 
  2924 #if INCLUDE_CDS
       
  2925 void SystemDictionary::reorder_dictionary_for_sharing() {
       
  2926   ClassLoaderData::the_null_class_loader_data()->dictionary()->reorder_dictionary_for_sharing();
       
  2927 }
       
  2928 #endif
       
  2929 
       
  2930 size_t SystemDictionary::count_bytes_for_buckets() {
       
  2931   return ClassLoaderData::the_null_class_loader_data()->dictionary()->count_bytes_for_buckets();
       
  2932 }
       
  2933 
       
  2934 size_t SystemDictionary::count_bytes_for_table() {
       
  2935   return ClassLoaderData::the_null_class_loader_data()->dictionary()->count_bytes_for_table();
       
  2936 }
       
  2937 
       
  2938 void SystemDictionary::copy_buckets(char* top, char* end) {
       
  2939   ClassLoaderData::the_null_class_loader_data()->dictionary()->copy_buckets(top, end);
       
  2940 }
       
  2941 
       
  2942 void SystemDictionary::copy_table(char* top, char* end) {
       
  2943   ClassLoaderData::the_null_class_loader_data()->dictionary()->copy_table(top, end);
       
  2944 }
       
  2945 
       
  2946 // ----------------------------------------------------------------------------
  2863 // ----------------------------------------------------------------------------
  2947 void SystemDictionary::print_shared(outputStream *st) {
       
  2948   shared_dictionary()->print_on(st);
       
  2949 }
       
  2950 
  2864 
  2951 void SystemDictionary::print_on(outputStream *st) {
  2865 void SystemDictionary::print_on(outputStream *st) {
  2952   if (shared_dictionary() != NULL) {
  2866   CDS_ONLY(SystemDictionaryShared::print_on(st));
  2953     st->print_cr("Shared Dictionary");
       
  2954     shared_dictionary()->print_on(st);
       
  2955     st->cr();
       
  2956   }
       
  2957 
       
  2958   GCMutexLocker mu(SystemDictionary_lock);
  2867   GCMutexLocker mu(SystemDictionary_lock);
  2959 
  2868 
  2960   ClassLoaderDataGraph::print_dictionary(st);
  2869   ClassLoaderDataGraph::print_dictionary(st);
  2961 
  2870 
  2962   // Placeholders
  2871   // Placeholders
  2994 void SystemDictionary::dump(outputStream *st, bool verbose) {
  2903 void SystemDictionary::dump(outputStream *st, bool verbose) {
  2995   assert_locked_or_safepoint(SystemDictionary_lock);
  2904   assert_locked_or_safepoint(SystemDictionary_lock);
  2996   if (verbose) {
  2905   if (verbose) {
  2997     print_on(st);
  2906     print_on(st);
  2998   } else {
  2907   } else {
  2999     if (shared_dictionary() != NULL) {
  2908     CDS_ONLY(SystemDictionaryShared::print_table_statistics(st));
  3000       shared_dictionary()->print_table_statistics(st, "Shared Dictionary");
       
  3001     }
       
  3002     ClassLoaderDataGraph::print_dictionary_statistics(st);
  2909     ClassLoaderDataGraph::print_dictionary_statistics(st);
  3003     placeholders()->print_table_statistics(st, "Placeholder Table");
  2910     placeholders()->print_table_statistics(st, "Placeholder Table");
  3004     constraints()->print_table_statistics(st, "LoaderConstraints Table");
  2911     constraints()->print_table_statistics(st, "LoaderConstraints Table");
  3005     _pd_cache_table->print_table_statistics(st, "ProtectionDomainCache Table");
  2912     _pd_cache_table->print_table_statistics(st, "ProtectionDomainCache Table");
  3006   }
  2913   }
  3029   } else {
  2936   } else {
  3030     return 0;
  2937     return 0;
  3031   }
  2938   }
  3032 }
  2939 }
  3033 
  2940 
  3034 class CombineDictionariesClosure : public CLDClosure {
       
  3035   private:
       
  3036     Dictionary* _master_dictionary;
       
  3037   public:
       
  3038     CombineDictionariesClosure(Dictionary* master_dictionary) :
       
  3039       _master_dictionary(master_dictionary) {}
       
  3040     void do_cld(ClassLoaderData* cld) {
       
  3041       ResourceMark rm;
       
  3042       if (cld->is_unsafe_anonymous()) {
       
  3043         return;
       
  3044       }
       
  3045       if (cld->is_system_class_loader_data() || cld->is_platform_class_loader_data()) {
       
  3046         for (int i = 0; i < cld->dictionary()->table_size(); ++i) {
       
  3047           Dictionary* curr_dictionary = cld->dictionary();
       
  3048           DictionaryEntry* p = curr_dictionary->bucket(i);
       
  3049           while (p != NULL) {
       
  3050             Symbol* name = p->instance_klass()->name();
       
  3051             unsigned int d_hash = _master_dictionary->compute_hash(name);
       
  3052             int d_index = _master_dictionary->hash_to_index(d_hash);
       
  3053             DictionaryEntry* next = p->next();
       
  3054             if (p->literal()->class_loader_data() != cld) {
       
  3055               // This is an initiating class loader entry; don't use it
       
  3056               log_trace(cds)("Skipping initiating cl entry: %s", name->as_C_string());
       
  3057               curr_dictionary->free_entry(p);
       
  3058             } else {
       
  3059               log_trace(cds)("Moved to boot dictionary: %s", name->as_C_string());
       
  3060               curr_dictionary->unlink_entry(p);
       
  3061               p->set_pd_set(NULL); // pd_set is runtime only information and will be reconstructed.
       
  3062               _master_dictionary->add_entry(d_index, p);
       
  3063             }
       
  3064             p = next;
       
  3065           }
       
  3066           *curr_dictionary->bucket_addr(i) = NULL;
       
  3067         }
       
  3068       }
       
  3069     }
       
  3070 };
       
  3071 
       
  3072 // Combining platform and system loader dictionaries into boot loader dictionary.
       
  3073 // During run time, we only have one shared dictionary.
       
  3074 void SystemDictionary::combine_shared_dictionaries() {
       
  3075   assert(DumpSharedSpaces, "dump time only");
       
  3076   Dictionary* master_dictionary = ClassLoaderData::the_null_class_loader_data()->dictionary();
       
  3077   CombineDictionariesClosure cdc(master_dictionary);
       
  3078   ClassLoaderDataGraph::cld_do(&cdc);
       
  3079 
       
  3080   // These tables are no longer valid or necessary. Keeping them around will
       
  3081   // cause SystemDictionary::verify() to fail. Let's empty them.
       
  3082   _placeholders        = new PlaceholderTable(_placeholder_table_size);
       
  3083   _loader_constraints  = new LoaderConstraintTable(_loader_constraint_size);
       
  3084 
       
  3085   NOT_PRODUCT(SystemDictionary::verify());
       
  3086 }
       
  3087 
       
  3088 void SystemDictionary::initialize_oop_storage() {
  2941 void SystemDictionary::initialize_oop_storage() {
  3089   _vm_weak_oop_storage =
  2942   _vm_weak_oop_storage =
  3090     new OopStorage("VM Weak Oop Handles",
  2943     new OopStorage("VM Weak Oop Handles",
  3091                    VMWeakAlloc_lock,
  2944                    VMWeakAlloc_lock,
  3092                    VMWeakActive_lock);
  2945                    VMWeakActive_lock);