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/aotLogging.hpp"
28 #include "cds/archiveBuilder.hpp"
29 #include "cds/archiveUtils.hpp"
30 #include "cds/cdsConfig.hpp"
31 #include "cds/cdsProtectionDomain.hpp"
32 #include "cds/classListParser.hpp"
33 #include "cds/classListWriter.hpp"
34 #include "cds/dumpTimeClassInfo.inline.hpp"
35 #include "cds/dynamicArchive.hpp"
36 #include "cds/filemap.hpp"
37 #include "cds/heapShared.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/objArrayKlass.hpp"
70 #include "oops/objArrayOop.inline.hpp"
71 #include "oops/oop.inline.hpp"
72 #include "oops/oopHandle.inline.hpp"
73 #include "oops/typeArrayOop.inline.hpp"
74 #include "runtime/arguments.hpp"
75 #include "runtime/handles.inline.hpp"
76 #include "runtime/java.hpp"
77 #include "runtime/javaCalls.hpp"
78 #include "runtime/mutexLocker.hpp"
79 #include "utilities/resourceHash.hpp"
80 #include "utilities/stringUtils.hpp"
81
82 SystemDictionaryShared::ArchiveInfo SystemDictionaryShared::_static_archive;
83 SystemDictionaryShared::ArchiveInfo SystemDictionaryShared::_dynamic_archive;
84
85 DumpTimeSharedClassTable* SystemDictionaryShared::_dumptime_table = nullptr;
86
87 // Used by NoClassLoadingMark
88 DEBUG_ONLY(bool SystemDictionaryShared::_class_loading_may_happen = true;)
90 #ifdef ASSERT
91 static void check_klass_after_loading(const Klass* k) {
92 #ifdef _LP64
93 if (k != nullptr && UseCompressedClassPointers && k->needs_narrow_id()) {
94 CompressedKlassPointers::check_encodable(k);
95 }
96 #endif
97 }
98 #endif
99
100 InstanceKlass* SystemDictionaryShared::load_shared_class_for_builtin_loader(
101 Symbol* class_name, Handle class_loader, TRAPS) {
102 assert(CDSConfig::is_using_archive(), "must be");
103 InstanceKlass* ik = find_builtin_class(class_name);
104
105 if (ik != nullptr && !ik->shared_loading_failed()) {
106 if ((SystemDictionary::is_system_class_loader(class_loader()) && ik->defined_by_app_loader()) ||
107 (SystemDictionary::is_platform_class_loader(class_loader()) && ik->defined_by_platform_loader())) {
108 SharedClassLoadingMark slm(THREAD, ik);
109 PackageEntry* pkg_entry = CDSProtectionDomain::get_package_entry_from_class(ik, class_loader);
110 Handle protection_domain =
111 CDSProtectionDomain::init_security_info(class_loader, ik, pkg_entry, CHECK_NULL);
112 return load_shared_class(ik, class_loader, protection_domain, nullptr, pkg_entry, THREAD);
113 }
114 }
115 return nullptr;
116 }
117
118 // This function is called for loading only UNREGISTERED classes
119 InstanceKlass* SystemDictionaryShared::lookup_from_stream(Symbol* class_name,
120 Handle class_loader,
121 Handle protection_domain,
122 const ClassFileStream* cfs,
123 TRAPS) {
124 if (!CDSConfig::is_using_archive()) {
125 return nullptr;
126 }
127 if (class_name == nullptr) { // don't do this for hidden classes
128 return nullptr;
129 }
130 if (class_loader.is_null() ||
131 SystemDictionary::is_system_class_loader(class_loader()) ||
277 aot_log_info(aot)("Skipping %s because it is dynamically generated", k->name()->as_C_string());
278 return true; // exclude without warning
279 }
280 } else {
281 // These are classes loaded from unsupported locations (such as those loaded by JVMTI native
282 // agent during dump time).
283 return warn_excluded(k, "Unsupported location");
284 }
285 }
286 if (k->signers() != nullptr) {
287 // We cannot include signed classes in the archive because the certificates
288 // used during dump time may be different than those used during
289 // runtime (due to expiration, etc).
290 return warn_excluded(k, "Signed JAR");
291 }
292 if (is_jfr_event_class(k)) {
293 // We cannot include JFR event classes because they need runtime-specific
294 // instrumentation in order to work with -XX:FlightRecorderOptions:retransform=false.
295 // There are only a small number of these classes, so it's not worthwhile to
296 // support them and make CDS more complicated.
297 return warn_excluded(k, "JFR event class");
298 }
299
300 if (!k->is_linked()) {
301 if (has_class_failed_verification(k)) {
302 return warn_excluded(k, "Failed verification");
303 } else if (CDSConfig::is_dumping_aot_linked_classes()) {
304 // Most loaded classes should have been speculatively linked by MetaspaceShared::link_class_for_cds().
305 // However, we do not speculatively link old classes, as they are not recorded by
306 // SystemDictionaryShared::record_linking_constraint(). As a result, such an unlinked
307 // class may fail to verify in AOTLinkedClassBulkLoader::init_required_classes_for_loader(),
308 // causing the JVM to fail at bootstrap.
309 return warn_excluded(k, "Unlinked class not supported by AOTClassLinking");
310 } else if (CDSConfig::is_dumping_preimage_static_archive()) {
311 // When dumping the final static archive, we will unconditionally load and link all
312 // classes from the preimage. We don't want to get a VerifyError when linking this class.
313 return warn_excluded(k, "Unlinked class not supported by AOTConfiguration");
314 }
315 } else {
316 if (!k->can_be_verified_at_dumptime()) {
317 // We have an old class that has been linked (e.g., it's been executed during
318 // dump time). This class has been verified using the old verifier, which
319 // doesn't save the verification constraints, so check_verification_constraints()
320 // won't work at runtime.
321 // As a result, we cannot store this class. It must be loaded and fully verified
322 // at runtime.
323 return warn_excluded(k, "Old class has been linked");
324 }
325 }
326
327 if (UnregisteredClasses::check_for_exclusion(k)) {
328 ResourceMark rm;
329 aot_log_info(aot)("Skipping %s: used only when dumping CDS archive", k->name()->as_C_string());
330 return true;
331 }
332
333 InstanceKlass* super = k->java_super();
334 if (super != nullptr && check_for_exclusion(super, nullptr)) {
335 ResourceMark rm;
336 aot_log_warning(aot)("Skipping %s: super class %s is excluded", k->name()->as_C_string(), super->name()->as_C_string());
631 // We sort the classes by their loaders. This way we're likely to archive
632 // all classes in the one of the two hierarchies.
633 _list.sort(compare_by_loader);
634 for (int i = 0; i < _list.length(); i++) {
635 InstanceKlass* k = _list.at(i);
636 bool i_am_first = SystemDictionaryShared::add_unregistered_class(_thread, k);
637 if (!i_am_first) {
638 SystemDictionaryShared::warn_excluded(k, "Duplicated unregistered class");
639 SystemDictionaryShared::set_excluded_locked(k);
640 }
641 }
642 }
643 };
644
645 // Returns true if the class should be excluded. This can be called by
646 // AOTConstantPoolResolver before or after we enter the CDS safepoint.
647 // When called before the safepoint, we need to link the class so that
648 // it can be checked by check_for_exclusion().
649 bool SystemDictionaryShared::should_be_excluded(Klass* k) {
650 assert(CDSConfig::is_dumping_archive(), "sanity");
651 assert(CDSConfig::current_thread_is_vm_or_dumper(), "sanity");
652
653 if (k->is_objArray_klass()) {
654 return should_be_excluded(ObjArrayKlass::cast(k)->bottom_klass());
655 }
656
657 if (!k->is_instance_klass()) {
658 return false;
659 } else {
660 InstanceKlass* ik = InstanceKlass::cast(k);
661
662 if (CDSConfig::is_dumping_dynamic_archive() && ik->is_shared()) {
663 // ik is already part of the static archive, so it will never be considered as excluded.
664 return false;
665 }
666
667 if (!SafepointSynchronize::is_at_safepoint()) {
668 if (!ik->is_linked()) {
669 // check_for_exclusion() below doesn't link unlinked classes. We come
670 // here only when we are trying to aot-link constant pool entries, so
671 // we'd better link the class.
672 JavaThread* THREAD = JavaThread::current();
673 ik->link_class(THREAD);
674 if (HAS_PENDING_EXCEPTION) {
675 CLEAR_PENDING_EXCEPTION;
676 return true; // linking failed -- let's exclude it
677 }
678 }
679
680 MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag);
681 DumpTimeClassInfo* p = get_info_locked(ik);
682 if (p->is_excluded()) {
683 return true;
684 }
685 return check_for_exclusion(ik, p);
686 } else {
687 // No need to check for is_linked() as all eligible classes should have
769
770 if (CDSConfig::is_dumping_lambdas_in_legacy_mode()) {
771 LambdaProxyClassDictionary::dumptime_classes_do(it);
772 }
773 }
774
775 // Called from VerificationType::is_reference_assignable_from() before performing the assignability check of
776 // T1 must be assignable from T2
777 // Where:
778 // L is the class loader of <k>
779 // T1 is the type resolved by L using the name <name>
780 // T2 is the type resolved by L using the name <from_name>
781 //
782 // The meaning of (*skip_assignability_check):
783 // true: is_reference_assignable_from() should SKIP the assignability check
784 // false: is_reference_assignable_from() should COMPLETE the assignability check
785 void SystemDictionaryShared::add_verification_constraint(InstanceKlass* k, Symbol* name,
786 Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object,
787 bool* skip_assignability_check) {
788 assert(CDSConfig::is_dumping_archive(), "sanity");
789 DumpTimeClassInfo* info = get_info(k);
790 info->add_verification_constraint(k, name, from_name, from_field_is_protected,
791 from_is_array, from_is_object);
792
793 if (CDSConfig::is_dumping_classic_static_archive() && !is_builtin(k)) {
794 // This applies ONLY to the "classic" CDS static dump, which reads the list of
795 // unregistered classes (those intended for custom class loaders) from the classlist
796 // and loads them using jdk.internal.misc.CDS$UnregisteredClassLoader.
797 //
798 // When the classlist contains an unregistered class k, the supertypes of k are also
799 // recorded in the classlist. However, the classlist does not contain information about
800 // any class X that's not a supertype of k but is needed in the verification of k.
801 // As a result, CDS$UnregisteredClassLoader will not know how to resolve X.
802 //
803 // Therefore, we tell the verifier to refrain from resolving X. Instead, X is recorded
804 // (symbolically) in the verification constraints of k. In the production run,
805 // when k is loaded, we will go through its verification constraints and resolve X to complete
806 // the is_reference_assignable_from() checks.
807 *skip_assignability_check = true;
808 } else {
1229 print_shared_archive(st, false);
1230 }
1231
1232 void SystemDictionaryShared::print_table_statistics(outputStream* st) {
1233 if (CDSConfig::is_using_archive()) {
1234 _static_archive.print_table_statistics("Static ", st, true);
1235 if (DynamicArchive::is_mapped()) {
1236 _dynamic_archive.print_table_statistics("Dynamic ", st, false);
1237 }
1238 }
1239 }
1240
1241 bool SystemDictionaryShared::is_dumptime_table_empty() {
1242 assert_lock_strong(DumpTimeTable_lock);
1243 _dumptime_table->update_counts();
1244 if (_dumptime_table->count_of(true) == 0 && _dumptime_table->count_of(false) == 0){
1245 return true;
1246 }
1247 return false;
1248 }
|
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/aotLogging.hpp"
28 #include "cds/archiveBuilder.hpp"
29 #include "cds/archiveUtils.hpp"
30 #include "cds/cdsConfig.hpp"
31 #include "cds/cdsProtectionDomain.hpp"
32 #include "cds/classListParser.hpp"
33 #include "cds/classListWriter.hpp"
34 #include "cds/dumpTimeClassInfo.inline.hpp"
35 #include "cds/dynamicArchive.hpp"
36 #include "cds/filemap.hpp"
37 #include "cds/heapShared.hpp"
38 #include "cds/lambdaFormInvokers.inline.hpp"
39 #include "cds/lambdaProxyClassDictionary.hpp"
40 #include "cds/lambdaFormInvokers.inline.hpp"
41 #include "cds/metaspaceShared.hpp"
42 #include "cds/runTimeClassInfo.hpp"
43 #include "cds/unregisteredClasses.hpp"
44 #include "classfile/classFileStream.hpp"
45 #include "classfile/classLoader.hpp"
46 #include "classfile/classLoaderData.inline.hpp"
47 #include "classfile/classLoaderDataGraph.hpp"
48 #include "classfile/classLoaderExt.hpp"
49 #include "classfile/dictionary.hpp"
50 #include "classfile/javaClasses.hpp"
51 #include "classfile/javaClasses.inline.hpp"
52 #include "classfile/symbolTable.hpp"
53 #include "classfile/systemDictionary.hpp"
54 #include "classfile/systemDictionaryShared.hpp"
55 #include "classfile/verificationType.hpp"
56 #include "classfile/vmClasses.hpp"
57 #include "classfile/vmSymbols.hpp"
58 #include "jfr/jfrEvents.hpp"
59 #include "logging/log.hpp"
60 #include "logging/logStream.hpp"
61 #include "memory/allocation.hpp"
62 #include "memory/metadataFactory.hpp"
63 #include "memory/metaspaceClosure.hpp"
64 #include "memory/oopFactory.hpp"
65 #include "memory/resourceArea.hpp"
66 #include "memory/universe.hpp"
67 #include "oops/compressedKlass.inline.hpp"
68 #include "oops/instanceKlass.hpp"
69 #include "oops/klass.inline.hpp"
70 #include "oops/methodData.hpp"
71 #include "oops/objArrayKlass.hpp"
72 #include "oops/objArrayOop.inline.hpp"
73 #include "oops/oop.inline.hpp"
74 #include "oops/oopHandle.inline.hpp"
75 #include "oops/typeArrayOop.inline.hpp"
76 #include "runtime/arguments.hpp"
77 #include "runtime/handles.inline.hpp"
78 #include "runtime/java.hpp"
79 #include "runtime/javaCalls.hpp"
80 #include "runtime/mutexLocker.hpp"
81 #include "utilities/resourceHash.hpp"
82 #include "utilities/stringUtils.hpp"
83
84 SystemDictionaryShared::ArchiveInfo SystemDictionaryShared::_static_archive;
85 SystemDictionaryShared::ArchiveInfo SystemDictionaryShared::_dynamic_archive;
86
87 DumpTimeSharedClassTable* SystemDictionaryShared::_dumptime_table = nullptr;
88
89 // Used by NoClassLoadingMark
90 DEBUG_ONLY(bool SystemDictionaryShared::_class_loading_may_happen = true;)
92 #ifdef ASSERT
93 static void check_klass_after_loading(const Klass* k) {
94 #ifdef _LP64
95 if (k != nullptr && UseCompressedClassPointers && k->needs_narrow_id()) {
96 CompressedKlassPointers::check_encodable(k);
97 }
98 #endif
99 }
100 #endif
101
102 InstanceKlass* SystemDictionaryShared::load_shared_class_for_builtin_loader(
103 Symbol* class_name, Handle class_loader, TRAPS) {
104 assert(CDSConfig::is_using_archive(), "must be");
105 InstanceKlass* ik = find_builtin_class(class_name);
106
107 if (ik != nullptr && !ik->shared_loading_failed()) {
108 if ((SystemDictionary::is_system_class_loader(class_loader()) && ik->defined_by_app_loader()) ||
109 (SystemDictionary::is_platform_class_loader(class_loader()) && ik->defined_by_platform_loader())) {
110 SharedClassLoadingMark slm(THREAD, ik);
111 PackageEntry* pkg_entry = CDSProtectionDomain::get_package_entry_from_class(ik, class_loader);
112 Handle protection_domain;
113 if (!class_name->starts_with("jdk/proxy")) // java/lang/reflect/Proxy$ProxyBuilder defines the proxy classes with a null protection domain.
114 {
115 protection_domain = CDSProtectionDomain::init_security_info(class_loader, ik, pkg_entry, CHECK_NULL);
116 }
117 return load_shared_class(ik, class_loader, protection_domain, nullptr, pkg_entry, THREAD);
118 }
119 }
120 return nullptr;
121 }
122
123 // This function is called for loading only UNREGISTERED classes
124 InstanceKlass* SystemDictionaryShared::lookup_from_stream(Symbol* class_name,
125 Handle class_loader,
126 Handle protection_domain,
127 const ClassFileStream* cfs,
128 TRAPS) {
129 if (!CDSConfig::is_using_archive()) {
130 return nullptr;
131 }
132 if (class_name == nullptr) { // don't do this for hidden classes
133 return nullptr;
134 }
135 if (class_loader.is_null() ||
136 SystemDictionary::is_system_class_loader(class_loader()) ||
282 aot_log_info(aot)("Skipping %s because it is dynamically generated", k->name()->as_C_string());
283 return true; // exclude without warning
284 }
285 } else {
286 // These are classes loaded from unsupported locations (such as those loaded by JVMTI native
287 // agent during dump time).
288 return warn_excluded(k, "Unsupported location");
289 }
290 }
291 if (k->signers() != nullptr) {
292 // We cannot include signed classes in the archive because the certificates
293 // used during dump time may be different than those used during
294 // runtime (due to expiration, etc).
295 return warn_excluded(k, "Signed JAR");
296 }
297 if (is_jfr_event_class(k)) {
298 // We cannot include JFR event classes because they need runtime-specific
299 // instrumentation in order to work with -XX:FlightRecorderOptions:retransform=false.
300 // There are only a small number of these classes, so it's not worthwhile to
301 // support them and make CDS more complicated.
302 if (!CDSConfig::is_dumping_reflection_data()) { // FIXME: !!! HACK !!!
303 return warn_excluded(k, "JFR event class");
304 }
305 }
306
307 if (!k->is_linked()) {
308 if (has_class_failed_verification(k)) {
309 return warn_excluded(k, "Failed verification");
310 } else if (CDSConfig::is_dumping_aot_linked_classes()) {
311 // Most loaded classes should have been speculatively linked by MetaspaceShared::link_class_for_cds().
312 // However, we do not speculatively link old classes, as they are not recorded by
313 // SystemDictionaryShared::record_linking_constraint(). As a result, such an unlinked
314 // class may fail to verify in AOTLinkedClassBulkLoader::init_required_classes_for_loader(),
315 // causing the JVM to fail at bootstrap.
316 return warn_excluded(k, "Unlinked class not supported by AOTClassLinking");
317 } else if (CDSConfig::is_dumping_preimage_static_archive()) {
318 // When dumping the final static archive, we will unconditionally load and link all
319 // classes from the preimage. We don't want to get a VerifyError when linking this class.
320 return warn_excluded(k, "Unlinked class not supported by AOTConfiguration");
321 }
322 } else {
323 if (!k->can_be_verified_at_dumptime() && !CDSConfig::preserve_all_dumptime_verification_states(k)) {
324 // We have an old class that has been linked (e.g., it's been executed during
325 // dump time). This class has been verified using the old verifier, which
326 // doesn't save the verification constraints, so check_verification_constraints()
327 // won't work at runtime.
328 // As a result, we cannot store this class. It must be loaded and fully verified
329 // at runtime.
330 return warn_excluded(k, "Old class has been linked");
331 }
332 }
333
334 if (UnregisteredClasses::check_for_exclusion(k)) {
335 ResourceMark rm;
336 aot_log_info(aot)("Skipping %s: used only when dumping CDS archive", k->name()->as_C_string());
337 return true;
338 }
339
340 InstanceKlass* super = k->java_super();
341 if (super != nullptr && check_for_exclusion(super, nullptr)) {
342 ResourceMark rm;
343 aot_log_warning(aot)("Skipping %s: super class %s is excluded", k->name()->as_C_string(), super->name()->as_C_string());
638 // We sort the classes by their loaders. This way we're likely to archive
639 // all classes in the one of the two hierarchies.
640 _list.sort(compare_by_loader);
641 for (int i = 0; i < _list.length(); i++) {
642 InstanceKlass* k = _list.at(i);
643 bool i_am_first = SystemDictionaryShared::add_unregistered_class(_thread, k);
644 if (!i_am_first) {
645 SystemDictionaryShared::warn_excluded(k, "Duplicated unregistered class");
646 SystemDictionaryShared::set_excluded_locked(k);
647 }
648 }
649 }
650 };
651
652 // Returns true if the class should be excluded. This can be called by
653 // AOTConstantPoolResolver before or after we enter the CDS safepoint.
654 // When called before the safepoint, we need to link the class so that
655 // it can be checked by check_for_exclusion().
656 bool SystemDictionaryShared::should_be_excluded(Klass* k) {
657 assert(CDSConfig::is_dumping_archive(), "sanity");
658
659 if (k->is_objArray_klass()) {
660 return should_be_excluded(ObjArrayKlass::cast(k)->bottom_klass());
661 }
662
663 if (!k->is_instance_klass()) {
664 return false;
665 } else {
666 InstanceKlass* ik = InstanceKlass::cast(k);
667
668 if (CDSConfig::is_dumping_dynamic_archive() && ik->is_shared()) {
669 // ik is already part of the static archive, so it will never be considered as excluded.
670 return false;
671 }
672
673 if (!SafepointSynchronize::is_at_safepoint() && !Thread::current()->is_Compiler_thread()) {
674 if (!ik->is_linked()) {
675 // check_for_exclusion() below doesn't link unlinked classes. We come
676 // here only when we are trying to aot-link constant pool entries, so
677 // we'd better link the class.
678 JavaThread* THREAD = JavaThread::current();
679 ik->link_class(THREAD);
680 if (HAS_PENDING_EXCEPTION) {
681 CLEAR_PENDING_EXCEPTION;
682 return true; // linking failed -- let's exclude it
683 }
684 }
685
686 MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag);
687 DumpTimeClassInfo* p = get_info_locked(ik);
688 if (p->is_excluded()) {
689 return true;
690 }
691 return check_for_exclusion(ik, p);
692 } else {
693 // No need to check for is_linked() as all eligible classes should have
775
776 if (CDSConfig::is_dumping_lambdas_in_legacy_mode()) {
777 LambdaProxyClassDictionary::dumptime_classes_do(it);
778 }
779 }
780
781 // Called from VerificationType::is_reference_assignable_from() before performing the assignability check of
782 // T1 must be assignable from T2
783 // Where:
784 // L is the class loader of <k>
785 // T1 is the type resolved by L using the name <name>
786 // T2 is the type resolved by L using the name <from_name>
787 //
788 // The meaning of (*skip_assignability_check):
789 // true: is_reference_assignable_from() should SKIP the assignability check
790 // false: is_reference_assignable_from() should COMPLETE the assignability check
791 void SystemDictionaryShared::add_verification_constraint(InstanceKlass* k, Symbol* name,
792 Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object,
793 bool* skip_assignability_check) {
794 assert(CDSConfig::is_dumping_archive(), "sanity");
795 if (CDSConfig::is_dumping_dynamic_archive() && k->is_shared()) {
796 // k is a new class in the static archive, but one of its supertypes is an old class, so k wasn't
797 // verified during dump time. No need to record constraints as k won't be included in the dynamic archive.
798 return;
799 }
800 if (CDSConfig::is_dumping_aot_linked_classes() && is_builtin(k)) {
801 // There's no need to save verification constraints
802 // TODO -- double check the logic before integrating into mainline!!
803 return;
804 }
805
806 DumpTimeClassInfo* info = get_info(k);
807 info->add_verification_constraint(k, name, from_name, from_field_is_protected,
808 from_is_array, from_is_object);
809
810 if (CDSConfig::is_dumping_classic_static_archive() && !is_builtin(k)) {
811 // This applies ONLY to the "classic" CDS static dump, which reads the list of
812 // unregistered classes (those intended for custom class loaders) from the classlist
813 // and loads them using jdk.internal.misc.CDS$UnregisteredClassLoader.
814 //
815 // When the classlist contains an unregistered class k, the supertypes of k are also
816 // recorded in the classlist. However, the classlist does not contain information about
817 // any class X that's not a supertype of k but is needed in the verification of k.
818 // As a result, CDS$UnregisteredClassLoader will not know how to resolve X.
819 //
820 // Therefore, we tell the verifier to refrain from resolving X. Instead, X is recorded
821 // (symbolically) in the verification constraints of k. In the production run,
822 // when k is loaded, we will go through its verification constraints and resolve X to complete
823 // the is_reference_assignable_from() checks.
824 *skip_assignability_check = true;
825 } else {
1246 print_shared_archive(st, false);
1247 }
1248
1249 void SystemDictionaryShared::print_table_statistics(outputStream* st) {
1250 if (CDSConfig::is_using_archive()) {
1251 _static_archive.print_table_statistics("Static ", st, true);
1252 if (DynamicArchive::is_mapped()) {
1253 _dynamic_archive.print_table_statistics("Dynamic ", st, false);
1254 }
1255 }
1256 }
1257
1258 bool SystemDictionaryShared::is_dumptime_table_empty() {
1259 assert_lock_strong(DumpTimeTable_lock);
1260 _dumptime_table->update_counts();
1261 if (_dumptime_table->count_of(true) == 0 && _dumptime_table->count_of(false) == 0){
1262 return true;
1263 }
1264 return false;
1265 }
1266
1267 void SystemDictionaryShared::create_loader_positive_lookup_cache(TRAPS) {
1268 GrowableArray<InstanceKlass*> shared_classes_list;
1269 {
1270 // With static dumping, we have only a single Java thread (see JVM_StartThread) so
1271 // no no other threads should be loading classes. Otherwise, the code below may miss some
1272 // classes that are loaded concurrently.
1273 assert(CDSConfig::is_dumping_static_archive(), "no other threads should be loading classes");
1274
1275 MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag);
1276 _dumptime_table->iterate_all_classes_in_builtin_loaders([&](InstanceKlass* k, DumpTimeClassInfo& info) {
1277 if (!k->is_hidden() && !check_for_exclusion(k, &info)) {
1278 shared_classes_list.append(k);
1279 }
1280 }
1281 );
1282 }
1283
1284 InstanceKlass* ik = vmClasses::Class_klass();
1285 objArrayOop r = oopFactory::new_objArray(ik, shared_classes_list.length(), CHECK);
1286 objArrayHandle array_h(THREAD, r);
1287
1288 for (int i = 0; i < shared_classes_list.length(); i++) {
1289 oop mirror = shared_classes_list.at(i)->java_mirror();
1290 Handle mirror_h(THREAD, mirror);
1291 array_h->obj_at_put(i, mirror_h());
1292 }
1293
1294 TempNewSymbol method = SymbolTable::new_symbol("generatePositiveLookupCache");
1295 TempNewSymbol signature = SymbolTable::new_symbol("([Ljava/lang/Class;)V");
1296
1297 JavaCallArguments args(Handle(THREAD, SystemDictionary::java_system_loader()));
1298 args.push_oop(array_h);
1299 JavaValue result(T_VOID);
1300 JavaCalls::call_virtual(&result,
1301 vmClasses::jdk_internal_loader_ClassLoaders_AppClassLoader_klass(),
1302 method,
1303 signature,
1304 &args,
1305 CHECK);
1306
1307 if (HAS_PENDING_EXCEPTION) {
1308 Handle exc_handle(THREAD, PENDING_EXCEPTION);
1309 CLEAR_PENDING_EXCEPTION;
1310 ResourceMark rm(THREAD);
1311
1312 log_warning(cds)("Exception during AppClassLoader::generatePositiveLookupCache() call");
1313 LogStreamHandle(Debug, cds) log;
1314 if (log.is_enabled()) {
1315 java_lang_Throwable::print_stack_trace(exc_handle, &log);
1316 }
1317 return;
1318 }
1319 }
|