< 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 }

 632   }
 633 };
 634 
 635 // Returns true if the class should be excluded. This can be called by
 636 // AOTConstantPoolResolver before or after we enter the CDS safepoint.
 637 // When called before the safepoint, we need to link the class so that
 638 // it can be checked by check_for_exclusion().
 639 bool SystemDictionaryShared::should_be_excluded(Klass* k) {
 640   assert(CDSConfig::is_dumping_archive(), "sanity");
 641   assert(CDSConfig::current_thread_is_vm_or_dumper(), "sanity");
 642 
 643   if (k->is_objArray_klass()) {
 644     return should_be_excluded(ObjArrayKlass::cast(k)->bottom_klass());
 645   }
 646 
 647   if (!k->is_instance_klass()) {
 648     return false;
 649   } else {
 650     InstanceKlass* ik = InstanceKlass::cast(k);
 651 





 652     if (!SafepointSynchronize::is_at_safepoint()) {
 653       if (!ik->is_linked()) {
 654         // check_for_exclusion() below doesn't link unlinked classes. We come
 655         // here only when we are trying to aot-link constant pool entries, so
 656         // we'd better link the class.
 657         JavaThread* THREAD = JavaThread::current();
 658         ik->link_class(THREAD);
 659         if (HAS_PENDING_EXCEPTION) {
 660           CLEAR_PENDING_EXCEPTION;
 661           return true; // linking failed -- let's exclude it
 662         }
 663       }
 664 
 665       MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag);
 666       DumpTimeClassInfo* p = get_info_locked(ik);
 667       if (p->is_excluded()) {
 668         return true;
 669       }
 670       return check_for_exclusion(ik, p);
 671     } else {

 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 }

 646   }
 647 };
 648 
 649 // Returns true if the class should be excluded. This can be called by
 650 // AOTConstantPoolResolver before or after we enter the CDS safepoint.
 651 // When called before the safepoint, we need to link the class so that
 652 // it can be checked by check_for_exclusion().
 653 bool SystemDictionaryShared::should_be_excluded(Klass* k) {
 654   assert(CDSConfig::is_dumping_archive(), "sanity");
 655   assert(CDSConfig::current_thread_is_vm_or_dumper(), "sanity");
 656 
 657   if (k->is_objArray_klass()) {
 658     return should_be_excluded(ObjArrayKlass::cast(k)->bottom_klass());
 659   }
 660 
 661   if (!k->is_instance_klass()) {
 662     return false;
 663   } else {
 664     InstanceKlass* ik = InstanceKlass::cast(k);
 665 
 666     if (CDSConfig::is_dumping_dynamic_archive() && ik->is_shared()) {
 667       // ik is already part of the static archive, so it will never be considered as excluded.
 668       return false;
 669     }
 670 
 671     if (!SafepointSynchronize::is_at_safepoint()) {
 672       if (!ik->is_linked()) {
 673         // check_for_exclusion() below doesn't link unlinked classes. We come
 674         // here only when we are trying to aot-link constant pool entries, so
 675         // we'd better link the class.
 676         JavaThread* THREAD = JavaThread::current();
 677         ik->link_class(THREAD);
 678         if (HAS_PENDING_EXCEPTION) {
 679           CLEAR_PENDING_EXCEPTION;
 680           return true; // linking failed -- let's exclude it
 681         }
 682       }
 683 
 684       MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag);
 685       DumpTimeClassInfo* p = get_info_locked(ik);
 686       if (p->is_excluded()) {
 687         return true;
 688       }
 689       return check_for_exclusion(ik, p);
 690     } else {

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

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

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