< prev index next >

src/hotspot/share/classfile/systemDictionaryShared.cpp

Print this page

  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "cds/aotClassFilter.hpp"
  26 #include "cds/aotClassLocation.hpp"
  27 #include "cds/archiveBuilder.hpp"
  28 #include "cds/archiveUtils.hpp"
  29 #include "cds/cdsConfig.hpp"
  30 #include "cds/cdsProtectionDomain.hpp"
  31 #include "cds/classListParser.hpp"
  32 #include "cds/classListWriter.hpp"
  33 #include "cds/dumpTimeClassInfo.inline.hpp"
  34 #include "cds/dynamicArchive.hpp"
  35 #include "cds/filemap.hpp"
  36 #include "cds/heapShared.hpp"

  37 #include "cds/lambdaProxyClassDictionary.hpp"
  38 #include "cds/lambdaFormInvokers.inline.hpp"
  39 #include "cds/metaspaceShared.hpp"
  40 #include "cds/runTimeClassInfo.hpp"
  41 #include "cds/unregisteredClasses.hpp"
  42 #include "classfile/classFileStream.hpp"
  43 #include "classfile/classLoader.hpp"
  44 #include "classfile/classLoaderData.inline.hpp"
  45 #include "classfile/classLoaderDataGraph.hpp"
  46 #include "classfile/classLoaderExt.hpp"
  47 #include "classfile/dictionary.hpp"
  48 #include "classfile/javaClasses.hpp"
  49 #include "classfile/javaClasses.inline.hpp"
  50 #include "classfile/symbolTable.hpp"
  51 #include "classfile/systemDictionary.hpp"
  52 #include "classfile/systemDictionaryShared.hpp"
  53 #include "classfile/verificationType.hpp"
  54 #include "classfile/vmClasses.hpp"
  55 #include "classfile/vmSymbols.hpp"
  56 #include "jfr/jfrEvents.hpp"
  57 #include "logging/log.hpp"
  58 #include "logging/logStream.hpp"
  59 #include "memory/allocation.hpp"
  60 #include "memory/metadataFactory.hpp"
  61 #include "memory/metaspaceClosure.hpp"
  62 #include "memory/oopFactory.hpp"
  63 #include "memory/resourceArea.hpp"
  64 #include "memory/universe.hpp"
  65 #include "oops/compressedKlass.inline.hpp"
  66 #include "oops/instanceKlass.hpp"
  67 #include "oops/klass.inline.hpp"

  68 #include "oops/objArrayKlass.hpp"
  69 #include "oops/objArrayOop.inline.hpp"
  70 #include "oops/oop.inline.hpp"
  71 #include "oops/oopHandle.inline.hpp"
  72 #include "oops/typeArrayOop.inline.hpp"
  73 #include "runtime/arguments.hpp"
  74 #include "runtime/handles.inline.hpp"
  75 #include "runtime/java.hpp"
  76 #include "runtime/javaCalls.hpp"
  77 #include "runtime/mutexLocker.hpp"
  78 #include "utilities/resourceHash.hpp"
  79 #include "utilities/stringUtils.hpp"
  80 
  81 SystemDictionaryShared::ArchiveInfo SystemDictionaryShared::_static_archive;
  82 SystemDictionaryShared::ArchiveInfo SystemDictionaryShared::_dynamic_archive;
  83 
  84 DumpTimeSharedClassTable* SystemDictionaryShared::_dumptime_table = nullptr;
  85 
  86 // Used by NoClassLoadingMark
  87 DEBUG_ONLY(bool SystemDictionaryShared::_class_loading_may_happen = true;)

  89 #ifdef ASSERT
  90 static void check_klass_after_loading(const Klass* k) {
  91 #ifdef _LP64
  92   if (k != nullptr && UseCompressedClassPointers && k->needs_narrow_id()) {
  93     CompressedKlassPointers::check_encodable(k);
  94   }
  95 #endif
  96 }
  97 #endif
  98 
  99 InstanceKlass* SystemDictionaryShared::load_shared_class_for_builtin_loader(
 100                  Symbol* class_name, Handle class_loader, TRAPS) {
 101   assert(CDSConfig::is_using_archive(), "must be");
 102   InstanceKlass* ik = find_builtin_class(class_name);
 103 
 104   if (ik != nullptr && !ik->shared_loading_failed()) {
 105     if ((SystemDictionary::is_system_class_loader(class_loader()) && ik->is_shared_app_class())  ||
 106         (SystemDictionary::is_platform_class_loader(class_loader()) && ik->is_shared_platform_class())) {
 107       SharedClassLoadingMark slm(THREAD, ik);
 108       PackageEntry* pkg_entry = CDSProtectionDomain::get_package_entry_from_class(ik, class_loader);
 109       Handle protection_domain =
 110         CDSProtectionDomain::init_security_info(class_loader, ik, pkg_entry, CHECK_NULL);



 111       return load_shared_class(ik, class_loader, protection_domain, nullptr, pkg_entry, THREAD);
 112     }
 113   }
 114   return nullptr;
 115 }
 116 
 117 // This function is called for loading only UNREGISTERED classes
 118 InstanceKlass* SystemDictionaryShared::lookup_from_stream(Symbol* class_name,
 119                                                           Handle class_loader,
 120                                                           Handle protection_domain,
 121                                                           const ClassFileStream* cfs,
 122                                                           TRAPS) {
 123   if (!CDSConfig::is_using_archive()) {
 124     return nullptr;
 125   }
 126   if (class_name == nullptr) {  // don't do this for hidden classes
 127     return nullptr;
 128   }
 129   if (class_loader.is_null() ||
 130       SystemDictionary::is_system_class_loader(class_loader()) ||

 276         log_info(cds)("Skipping %s because it is dynamically generated", k->name()->as_C_string());
 277         return true; // exclude without warning
 278       }
 279     } else {
 280       // These are classes loaded from unsupported locations (such as those loaded by JVMTI native
 281       // agent during dump time).
 282       return warn_excluded(k, "Unsupported location");
 283     }
 284   }
 285   if (k->signers() != nullptr) {
 286     // We cannot include signed classes in the archive because the certificates
 287     // used during dump time may be different than those used during
 288     // runtime (due to expiration, etc).
 289     return warn_excluded(k, "Signed JAR");
 290   }
 291   if (is_jfr_event_class(k)) {
 292     // We cannot include JFR event classes because they need runtime-specific
 293     // instrumentation in order to work with -XX:FlightRecorderOptions:retransform=false.
 294     // There are only a small number of these classes, so it's not worthwhile to
 295     // support them and make CDS more complicated.
 296     return warn_excluded(k, "JFR event class");


 297   }
 298 
 299   if (!k->is_linked()) {
 300     if (has_class_failed_verification(k)) {
 301       return warn_excluded(k, "Failed verification");
 302     } else if (CDSConfig::is_dumping_aot_linked_classes()) {
 303       // Most loaded classes should have been speculatively linked by MetaspaceShared::link_class_for_cds().
 304       // However, we do not speculatively link old classes, as they are not recorded by
 305       // SystemDictionaryShared::record_linking_constraint(). As a result, such an unlinked
 306       // class may fail to verify in AOTLinkedClassBulkLoader::init_required_classes_for_loader(),
 307       // causing the JVM to fail at bootstrap.
 308       return warn_excluded(k, "Unlinked class not supported by AOTClassLinking");
 309     } else if (CDSConfig::is_dumping_preimage_static_archive()) {
 310       // When dumping the final static archive, we will unconditionally load and link all
 311       // classes from tje preimage. We don't want to get a VerifyError when linking this class.
 312       return warn_excluded(k, "Unlinked class not supported by AOTConfiguration");
 313     }
 314   } else {
 315     if (!k->can_be_verified_at_dumptime()) {
 316       // We have an old class that has been linked (e.g., it's been executed during
 317       // dump time). This class has been verified using the old verifier, which
 318       // doesn't save the verification constraints, so check_verification_constraints()
 319       // won't work at runtime.
 320       // As a result, we cannot store this class. It must be loaded and fully verified
 321       // at runtime.
 322       return warn_excluded(k, "Old class has been linked");
 323     }
 324   }
 325 
 326   InstanceKlass* super = k->java_super();
 327   if (super != nullptr && check_for_exclusion(super, nullptr)) {
 328     ResourceMark rm;
 329     log_warning(cds)("Skipping %s: super class %s is excluded", k->name()->as_C_string(), super->name()->as_C_string());
 330     return true;
 331   }
 332 
 333   Array<InstanceKlass*>* interfaces = k->local_interfaces();
 334   int len = interfaces->length();
 335   for (int i = 0; i < len; i++) {
 336     InstanceKlass* intf = interfaces->at(i);
 337     if (check_for_exclusion(intf, nullptr)) {
 338       ResourceMark rm;
 339       log_warning(cds)("Skipping %s: interface %s is excluded", k->name()->as_C_string(), intf->name()->as_C_string());
 340       return true;
 341     }
 342   }
 343 
 344   if (k == UnregisteredClasses::UnregisteredClassLoader_klass()) {
 345     ResourceMark rm;
 346     log_info(cds)("Skipping %s: used only when dumping CDS archive", k->name()->as_C_string());






 347     return true;
 348   }
 349 

 350   return false; // false == k should NOT be excluded
 351 }
 352 
 353 bool SystemDictionaryShared::is_builtin_loader(ClassLoaderData* loader_data) {
 354   oop class_loader = loader_data->class_loader();
 355   return (class_loader == nullptr ||
 356           SystemDictionary::is_system_class_loader(class_loader) ||
 357           SystemDictionary::is_platform_class_loader(class_loader));
 358 }
 359 
 360 bool SystemDictionaryShared::has_platform_or_app_classes() {
 361   if (FileMapInfo::current_info()->has_platform_or_app_classes()) {
 362     return true;
 363   }
 364   if (DynamicArchive::is_mapped() &&
 365       FileMapInfo::dynamic_info()->has_platform_or_app_classes()) {
 366     return true;
 367   }
 368   return false;
 369 }

 738   assert_lock_strong(DumpTimeTable_lock);
 739 
 740   auto do_klass = [&] (InstanceKlass* k, DumpTimeClassInfo& info) {
 741     if (CDSConfig::is_dumping_final_static_archive() && !k->is_loaded()) {
 742       assert(k->is_shared_unregistered_class(), "must be");
 743       info.metaspace_pointers_do(it);
 744     } else if (k->is_loader_alive() && !info.is_excluded()) {
 745       info.metaspace_pointers_do(it);
 746     }
 747   };
 748   _dumptime_table->iterate_all_live_classes(do_klass);
 749 
 750   if (CDSConfig::is_dumping_lambdas_in_legacy_mode()) {
 751     LambdaProxyClassDictionary::dumptime_classes_do(it);
 752   }
 753 }
 754 
 755 bool SystemDictionaryShared::add_verification_constraint(InstanceKlass* k, Symbol* name,
 756          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) {
 757   assert(CDSConfig::is_dumping_archive(), "sanity");











 758   DumpTimeClassInfo* info = get_info(k);
 759   info->add_verification_constraint(k, name, from_name, from_field_is_protected,
 760                                     from_is_array, from_is_object);
 761 
 762   if (CDSConfig::is_dumping_dynamic_archive()) {
 763     // For dynamic dumping, we can resolve all the constraint classes for all class loaders during
 764     // the initial run prior to creating the archive before vm exit. We will also perform verification
 765     // check when running with the archive.
 766     return false;
 767   } else {
 768     if (is_builtin(k)) {
 769       // For builtin class loaders, we can try to complete the verification check at dump time,
 770       // because we can resolve all the constraint classes. We will also perform verification check
 771       // when running with the archive.
 772       return false;
 773     } else {
 774       // For non-builtin class loaders, we cannot complete the verification check at dump time,
 775       // because at dump time we don't know how to resolve classes for such loaders.
 776       return true;
 777     }

 957 
 958 void SystemDictionaryShared::copy_linking_constraints_from_preimage(InstanceKlass* klass) {
 959   assert(CDSConfig::is_using_archive(), "called at run time with CDS enabled only");
 960   JavaThread* current = JavaThread::current();
 961   if (klass->is_shared_platform_class() || klass->is_shared_app_class()) {
 962     RunTimeClassInfo* rt_info = RunTimeClassInfo::get_for(klass); // from preimage
 963 
 964     if (rt_info->num_loader_constraints() > 0) {
 965       for (int i = 0; i < rt_info->num_loader_constraints(); i++) {
 966         RunTimeClassInfo::RTLoaderConstraint* lc = rt_info->loader_constraint_at(i);
 967         Symbol* name = lc->constraint_name();
 968         Handle loader1(current, get_class_loader_by(lc->_loader_type1));
 969         Handle loader2(current, get_class_loader_by(lc->_loader_type2));
 970         record_linking_constraint(name, klass, loader1, loader2);
 971       }
 972     }
 973   }
 974 }
 975 
 976 unsigned int SystemDictionaryShared::hash_for_shared_dictionary(address ptr) {
 977   if (ArchiveBuilder::is_active()) {
 978     uintx offset = ArchiveBuilder::current()->any_to_offset(ptr);
 979     unsigned int hash = primitive_hash<uintx>(offset);
 980     DEBUG_ONLY({
 981         if (MetaspaceObj::is_shared((const MetaspaceObj*)ptr)) {
 982           assert(hash == SystemDictionaryShared::hash_for_shared_dictionary_quick(ptr), "must be");
 983         }
 984       });
 985     return hash;
 986   } else {
 987     return SystemDictionaryShared::hash_for_shared_dictionary_quick(ptr);
 988   }
 989 }
 990 
 991 class CopySharedClassInfoToArchive : StackObj {
 992   CompactHashtableWriter* _writer;
 993   bool _is_builtin;
 994   ArchiveBuilder *_builder;
 995 public:
 996   CopySharedClassInfoToArchive(CompactHashtableWriter* writer,
 997                                bool is_builtin)

1195   print_shared_archive(st, false);
1196 }
1197 
1198 void SystemDictionaryShared::print_table_statistics(outputStream* st) {
1199   if (CDSConfig::is_using_archive()) {
1200     _static_archive.print_table_statistics("Static ", st, true);
1201     if (DynamicArchive::is_mapped()) {
1202       _dynamic_archive.print_table_statistics("Dynamic ", st, false);
1203     }
1204   }
1205 }
1206 
1207 bool SystemDictionaryShared::is_dumptime_table_empty() {
1208   assert_lock_strong(DumpTimeTable_lock);
1209   _dumptime_table->update_counts();
1210   if (_dumptime_table->count_of(true) == 0 && _dumptime_table->count_of(false) == 0){
1211     return true;
1212   }
1213   return false;
1214 }























































  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "cds/aotClassFilter.hpp"
  26 #include "cds/aotClassLocation.hpp"
  27 #include "cds/archiveBuilder.hpp"
  28 #include "cds/archiveUtils.hpp"
  29 #include "cds/cdsConfig.hpp"
  30 #include "cds/cdsProtectionDomain.hpp"
  31 #include "cds/classListParser.hpp"
  32 #include "cds/classListWriter.hpp"
  33 #include "cds/dumpTimeClassInfo.inline.hpp"
  34 #include "cds/dynamicArchive.hpp"
  35 #include "cds/filemap.hpp"
  36 #include "cds/heapShared.hpp"
  37 #include "cds/lambdaFormInvokers.inline.hpp"
  38 #include "cds/lambdaProxyClassDictionary.hpp"
  39 #include "cds/lambdaFormInvokers.inline.hpp"
  40 #include "cds/metaspaceShared.hpp"
  41 #include "cds/runTimeClassInfo.hpp"
  42 #include "cds/unregisteredClasses.hpp"
  43 #include "classfile/classFileStream.hpp"
  44 #include "classfile/classLoader.hpp"
  45 #include "classfile/classLoaderData.inline.hpp"
  46 #include "classfile/classLoaderDataGraph.hpp"
  47 #include "classfile/classLoaderExt.hpp"
  48 #include "classfile/dictionary.hpp"
  49 #include "classfile/javaClasses.hpp"
  50 #include "classfile/javaClasses.inline.hpp"
  51 #include "classfile/symbolTable.hpp"
  52 #include "classfile/systemDictionary.hpp"
  53 #include "classfile/systemDictionaryShared.hpp"
  54 #include "classfile/verificationType.hpp"
  55 #include "classfile/vmClasses.hpp"
  56 #include "classfile/vmSymbols.hpp"
  57 #include "jfr/jfrEvents.hpp"
  58 #include "logging/log.hpp"
  59 #include "logging/logStream.hpp"
  60 #include "memory/allocation.hpp"
  61 #include "memory/metadataFactory.hpp"
  62 #include "memory/metaspaceClosure.hpp"
  63 #include "memory/oopFactory.hpp"
  64 #include "memory/resourceArea.hpp"
  65 #include "memory/universe.hpp"
  66 #include "oops/compressedKlass.inline.hpp"
  67 #include "oops/instanceKlass.hpp"
  68 #include "oops/klass.inline.hpp"
  69 #include "oops/methodData.hpp"
  70 #include "oops/objArrayKlass.hpp"
  71 #include "oops/objArrayOop.inline.hpp"
  72 #include "oops/oop.inline.hpp"
  73 #include "oops/oopHandle.inline.hpp"
  74 #include "oops/typeArrayOop.inline.hpp"
  75 #include "runtime/arguments.hpp"
  76 #include "runtime/handles.inline.hpp"
  77 #include "runtime/java.hpp"
  78 #include "runtime/javaCalls.hpp"
  79 #include "runtime/mutexLocker.hpp"
  80 #include "utilities/resourceHash.hpp"
  81 #include "utilities/stringUtils.hpp"
  82 
  83 SystemDictionaryShared::ArchiveInfo SystemDictionaryShared::_static_archive;
  84 SystemDictionaryShared::ArchiveInfo SystemDictionaryShared::_dynamic_archive;
  85 
  86 DumpTimeSharedClassTable* SystemDictionaryShared::_dumptime_table = nullptr;
  87 
  88 // Used by NoClassLoadingMark
  89 DEBUG_ONLY(bool SystemDictionaryShared::_class_loading_may_happen = true;)

  91 #ifdef ASSERT
  92 static void check_klass_after_loading(const Klass* k) {
  93 #ifdef _LP64
  94   if (k != nullptr && UseCompressedClassPointers && k->needs_narrow_id()) {
  95     CompressedKlassPointers::check_encodable(k);
  96   }
  97 #endif
  98 }
  99 #endif
 100 
 101 InstanceKlass* SystemDictionaryShared::load_shared_class_for_builtin_loader(
 102                  Symbol* class_name, Handle class_loader, TRAPS) {
 103   assert(CDSConfig::is_using_archive(), "must be");
 104   InstanceKlass* ik = find_builtin_class(class_name);
 105 
 106   if (ik != nullptr && !ik->shared_loading_failed()) {
 107     if ((SystemDictionary::is_system_class_loader(class_loader()) && ik->is_shared_app_class())  ||
 108         (SystemDictionary::is_platform_class_loader(class_loader()) && ik->is_shared_platform_class())) {
 109       SharedClassLoadingMark slm(THREAD, ik);
 110       PackageEntry* pkg_entry = CDSProtectionDomain::get_package_entry_from_class(ik, class_loader);
 111       Handle protection_domain;
 112       if (!class_name->starts_with("jdk/proxy")) // java/lang/reflect/Proxy$ProxyBuilder defines the proxy classes with a null protection domain.
 113       {
 114         protection_domain = CDSProtectionDomain::init_security_info(class_loader, ik, pkg_entry, CHECK_NULL);
 115       }
 116       return load_shared_class(ik, class_loader, protection_domain, nullptr, pkg_entry, THREAD);
 117     }
 118   }
 119   return nullptr;
 120 }
 121 
 122 // This function is called for loading only UNREGISTERED classes
 123 InstanceKlass* SystemDictionaryShared::lookup_from_stream(Symbol* class_name,
 124                                                           Handle class_loader,
 125                                                           Handle protection_domain,
 126                                                           const ClassFileStream* cfs,
 127                                                           TRAPS) {
 128   if (!CDSConfig::is_using_archive()) {
 129     return nullptr;
 130   }
 131   if (class_name == nullptr) {  // don't do this for hidden classes
 132     return nullptr;
 133   }
 134   if (class_loader.is_null() ||
 135       SystemDictionary::is_system_class_loader(class_loader()) ||

 281         log_info(cds)("Skipping %s because it is dynamically generated", k->name()->as_C_string());
 282         return true; // exclude without warning
 283       }
 284     } else {
 285       // These are classes loaded from unsupported locations (such as those loaded by JVMTI native
 286       // agent during dump time).
 287       return warn_excluded(k, "Unsupported location");
 288     }
 289   }
 290   if (k->signers() != nullptr) {
 291     // We cannot include signed classes in the archive because the certificates
 292     // used during dump time may be different than those used during
 293     // runtime (due to expiration, etc).
 294     return warn_excluded(k, "Signed JAR");
 295   }
 296   if (is_jfr_event_class(k)) {
 297     // We cannot include JFR event classes because they need runtime-specific
 298     // instrumentation in order to work with -XX:FlightRecorderOptions:retransform=false.
 299     // There are only a small number of these classes, so it's not worthwhile to
 300     // support them and make CDS more complicated.
 301     if (!CDSConfig::is_dumping_reflection_data()) { // FIXME: !!! HACK !!!
 302       return warn_excluded(k, "JFR event class");
 303     }
 304   }
 305 
 306   if (!k->is_linked()) {
 307     if (has_class_failed_verification(k)) {
 308       return warn_excluded(k, "Failed verification");
 309     } else if (CDSConfig::is_dumping_aot_linked_classes()) {
 310       // Most loaded classes should have been speculatively linked by MetaspaceShared::link_class_for_cds().
 311       // However, we do not speculatively link old classes, as they are not recorded by
 312       // SystemDictionaryShared::record_linking_constraint(). As a result, such an unlinked
 313       // class may fail to verify in AOTLinkedClassBulkLoader::init_required_classes_for_loader(),
 314       // causing the JVM to fail at bootstrap.
 315       return warn_excluded(k, "Unlinked class not supported by AOTClassLinking");
 316     } else if (CDSConfig::is_dumping_preimage_static_archive()) {
 317       // When dumping the final static archive, we will unconditionally load and link all
 318       // classes from tje preimage. We don't want to get a VerifyError when linking this class.
 319       return warn_excluded(k, "Unlinked class not supported by AOTConfiguration");
 320     }
 321   } else {
 322     if (!k->can_be_verified_at_dumptime() && !CDSConfig::preserve_all_dumptime_verification_states(k)) {
 323       // We have an old class that has been linked (e.g., it's been executed during
 324       // dump time). This class has been verified using the old verifier, which
 325       // doesn't save the verification constraints, so check_verification_constraints()
 326       // won't work at runtime.
 327       // As a result, we cannot store this class. It must be loaded and fully verified
 328       // at runtime.
 329       return warn_excluded(k, "Old class has been linked");
 330     }
 331   }
 332 
 333   InstanceKlass* super = k->java_super();
 334   if (super != nullptr && check_for_exclusion(super, nullptr)) {
 335     ResourceMark rm;
 336     log_warning(cds)("Skipping %s: super class %s is excluded", k->name()->as_C_string(), super->name()->as_C_string());
 337     return true;
 338   }
 339 
 340   Array<InstanceKlass*>* interfaces = k->local_interfaces();
 341   int len = interfaces->length();
 342   for (int i = 0; i < len; i++) {
 343     InstanceKlass* intf = interfaces->at(i);
 344     if (check_for_exclusion(intf, nullptr)) {
 345       ResourceMark rm;
 346       log_warning(cds)("Skipping %s: interface %s is excluded", k->name()->as_C_string(), intf->name()->as_C_string());
 347       return true;
 348     }
 349   }
 350 
 351   if (k == UnregisteredClasses::UnregisteredClassLoader_klass()) {
 352     ResourceMark rm;
 353     log_debug(cds)("Skipping %s: used only when dumping CDS archive", k->name()->as_C_string());
 354     return true;
 355   }
 356 
 357   if (k->name()->equals("jdk/internal/misc/CDS$DummyForDynamicArchive") && !CDSConfig::is_dumping_dynamic_archive()) {
 358     ResourceMark rm;
 359     log_debug(cds)("Skipping %s: used only when dumping dynamic CDS archive", k->name()->as_C_string());
 360     return true;
 361   }
 362 
 363 
 364   return false; // false == k should NOT be excluded
 365 }
 366 
 367 bool SystemDictionaryShared::is_builtin_loader(ClassLoaderData* loader_data) {
 368   oop class_loader = loader_data->class_loader();
 369   return (class_loader == nullptr ||
 370           SystemDictionary::is_system_class_loader(class_loader) ||
 371           SystemDictionary::is_platform_class_loader(class_loader));
 372 }
 373 
 374 bool SystemDictionaryShared::has_platform_or_app_classes() {
 375   if (FileMapInfo::current_info()->has_platform_or_app_classes()) {
 376     return true;
 377   }
 378   if (DynamicArchive::is_mapped() &&
 379       FileMapInfo::dynamic_info()->has_platform_or_app_classes()) {
 380     return true;
 381   }
 382   return false;
 383 }

 752   assert_lock_strong(DumpTimeTable_lock);
 753 
 754   auto do_klass = [&] (InstanceKlass* k, DumpTimeClassInfo& info) {
 755     if (CDSConfig::is_dumping_final_static_archive() && !k->is_loaded()) {
 756       assert(k->is_shared_unregistered_class(), "must be");
 757       info.metaspace_pointers_do(it);
 758     } else if (k->is_loader_alive() && !info.is_excluded()) {
 759       info.metaspace_pointers_do(it);
 760     }
 761   };
 762   _dumptime_table->iterate_all_live_classes(do_klass);
 763 
 764   if (CDSConfig::is_dumping_lambdas_in_legacy_mode()) {
 765     LambdaProxyClassDictionary::dumptime_classes_do(it);
 766   }
 767 }
 768 
 769 bool SystemDictionaryShared::add_verification_constraint(InstanceKlass* k, Symbol* name,
 770          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) {
 771   assert(CDSConfig::is_dumping_archive(), "sanity");
 772   if (CDSConfig::is_dumping_dynamic_archive() && k->is_shared()) {
 773     // k is a new class in the static archive, but one of its supertypes is an old class, so k wasn't
 774     // verified during dump time. No need to record constraints as k won't be included in the dynamic archive.
 775     return false;
 776   }
 777   if (CDSConfig::is_dumping_aot_linked_classes() && is_builtin(k)) {
 778     // There's no need to save verification constraints
 779     // TODO -- double check the logic before integrating into mainline!!
 780     return false;
 781   }
 782 
 783   DumpTimeClassInfo* info = get_info(k);
 784   info->add_verification_constraint(k, name, from_name, from_field_is_protected,
 785                                     from_is_array, from_is_object);
 786 
 787   if (CDSConfig::is_dumping_dynamic_archive()) {
 788     // For dynamic dumping, we can resolve all the constraint classes for all class loaders during
 789     // the initial run prior to creating the archive before vm exit. We will also perform verification
 790     // check when running with the archive.
 791     return false;
 792   } else {
 793     if (is_builtin(k)) {
 794       // For builtin class loaders, we can try to complete the verification check at dump time,
 795       // because we can resolve all the constraint classes. We will also perform verification check
 796       // when running with the archive.
 797       return false;
 798     } else {
 799       // For non-builtin class loaders, we cannot complete the verification check at dump time,
 800       // because at dump time we don't know how to resolve classes for such loaders.
 801       return true;
 802     }

 982 
 983 void SystemDictionaryShared::copy_linking_constraints_from_preimage(InstanceKlass* klass) {
 984   assert(CDSConfig::is_using_archive(), "called at run time with CDS enabled only");
 985   JavaThread* current = JavaThread::current();
 986   if (klass->is_shared_platform_class() || klass->is_shared_app_class()) {
 987     RunTimeClassInfo* rt_info = RunTimeClassInfo::get_for(klass); // from preimage
 988 
 989     if (rt_info->num_loader_constraints() > 0) {
 990       for (int i = 0; i < rt_info->num_loader_constraints(); i++) {
 991         RunTimeClassInfo::RTLoaderConstraint* lc = rt_info->loader_constraint_at(i);
 992         Symbol* name = lc->constraint_name();
 993         Handle loader1(current, get_class_loader_by(lc->_loader_type1));
 994         Handle loader2(current, get_class_loader_by(lc->_loader_type2));
 995         record_linking_constraint(name, klass, loader1, loader2);
 996       }
 997     }
 998   }
 999 }
1000 
1001 unsigned int SystemDictionaryShared::hash_for_shared_dictionary(address ptr) {
1002   if (ArchiveBuilder::is_active() && ArchiveBuilder::current()->is_in_buffer_space(ptr)) {
1003     uintx offset = ArchiveBuilder::current()->any_to_offset(ptr);
1004     unsigned int hash = primitive_hash<uintx>(offset);
1005     DEBUG_ONLY({
1006         if (MetaspaceObj::is_shared((const MetaspaceObj*)ptr)) {
1007           assert(hash == SystemDictionaryShared::hash_for_shared_dictionary_quick(ptr), "must be");
1008         }
1009       });
1010     return hash;
1011   } else {
1012     return SystemDictionaryShared::hash_for_shared_dictionary_quick(ptr);
1013   }
1014 }
1015 
1016 class CopySharedClassInfoToArchive : StackObj {
1017   CompactHashtableWriter* _writer;
1018   bool _is_builtin;
1019   ArchiveBuilder *_builder;
1020 public:
1021   CopySharedClassInfoToArchive(CompactHashtableWriter* writer,
1022                                bool is_builtin)

1220   print_shared_archive(st, false);
1221 }
1222 
1223 void SystemDictionaryShared::print_table_statistics(outputStream* st) {
1224   if (CDSConfig::is_using_archive()) {
1225     _static_archive.print_table_statistics("Static ", st, true);
1226     if (DynamicArchive::is_mapped()) {
1227       _dynamic_archive.print_table_statistics("Dynamic ", st, false);
1228     }
1229   }
1230 }
1231 
1232 bool SystemDictionaryShared::is_dumptime_table_empty() {
1233   assert_lock_strong(DumpTimeTable_lock);
1234   _dumptime_table->update_counts();
1235   if (_dumptime_table->count_of(true) == 0 && _dumptime_table->count_of(false) == 0){
1236     return true;
1237   }
1238   return false;
1239 }
1240 
1241 void SystemDictionaryShared::create_loader_positive_lookup_cache(TRAPS) {
1242   GrowableArray<InstanceKlass*> shared_classes_list;
1243   {
1244     // With static dumping, we have only a single Java thread (see JVM_StartThread) so
1245     // no no other threads should be loading classes. Otherwise, the code below may miss some
1246     // classes that are loaded concurrently.
1247     assert(CDSConfig::is_dumping_static_archive(), "no other threads should be loading classes");
1248 
1249     MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag);
1250     _dumptime_table->iterate_all_classes_in_builtin_loaders([&](InstanceKlass* k, DumpTimeClassInfo& info) {
1251         if (!k->is_hidden() && !check_for_exclusion(k, &info)) {
1252           shared_classes_list.append(k);
1253         }
1254       }
1255     );
1256   }
1257 
1258   InstanceKlass* ik = vmClasses::Class_klass();
1259   objArrayOop r = oopFactory::new_objArray(ik, shared_classes_list.length(), CHECK);
1260   objArrayHandle array_h(THREAD, r);
1261 
1262   for (int i = 0; i < shared_classes_list.length(); i++) {
1263     oop mirror = shared_classes_list.at(i)->java_mirror();
1264     Handle mirror_h(THREAD, mirror);
1265     array_h->obj_at_put(i, mirror_h());
1266   }
1267 
1268   TempNewSymbol method = SymbolTable::new_symbol("generatePositiveLookupCache");
1269   TempNewSymbol signature = SymbolTable::new_symbol("([Ljava/lang/Class;)V");
1270 
1271   JavaCallArguments args(Handle(THREAD, SystemDictionary::java_system_loader()));
1272   args.push_oop(array_h);
1273   JavaValue result(T_VOID);
1274   JavaCalls::call_virtual(&result,
1275                           vmClasses::jdk_internal_loader_ClassLoaders_AppClassLoader_klass(),
1276                           method,
1277                           signature,
1278                           &args,
1279                           CHECK);
1280 
1281   if (HAS_PENDING_EXCEPTION) {
1282     Handle exc_handle(THREAD, PENDING_EXCEPTION);
1283     CLEAR_PENDING_EXCEPTION;
1284     ResourceMark rm(THREAD);
1285 
1286     log_warning(cds)("Exception during AppClassLoader::generatePositiveLookupCache() call");
1287     LogStreamHandle(Debug, cds) log;
1288     if (log.is_enabled()) {
1289       java_lang_Throwable::print_stack_trace(exc_handle, &log);
1290     }
1291     return;
1292   }
1293 }
< prev index next >