568 JavaCalls::call_static(&result, classLoaders_klass, vmSymbols::toFileURL_name(),
569 vmSymbols::toFileURL_signature(),
570 location_string, CHECK_NH);
571 url = Handle(THREAD, (oop)result.get_jobject());
572 }
573
574 Handle pd = get_protection_domain_from_classloader(class_loader, url,
575 CHECK_NH);
576 mod->set_shared_protection_domain(loader_data, pd);
577 }
578 }
579
580 Handle protection_domain(THREAD, mod->shared_protection_domain());
581 assert(protection_domain.not_null(), "sanity");
582 return protection_domain;
583 }
584
585 // Initializes the java.lang.Package and java.security.ProtectionDomain objects associated with
586 // the given InstanceKlass.
587 // Returns the ProtectionDomain for the InstanceKlass.
588 Handle SystemDictionaryShared::init_security_info(Handle class_loader, InstanceKlass* ik, TRAPS) {
589 Handle pd;
590
591 if (ik != NULL) {
592 int index = ik->shared_classpath_index();
593 assert(index >= 0, "Sanity");
594 SharedClassPathEntry* ent = FileMapInfo::shared_path(index);
595 Symbol* class_name = ik->name();
596
597 if (ent->is_modules_image()) {
598 // For shared app/platform classes originated from the run-time image:
599 // The ProtectionDomains are cached in the corresponding ModuleEntries
600 // for fast access by the VM.
601 ResourceMark rm;
602 ClassLoaderData *loader_data =
603 ClassLoaderData::class_loader_data(class_loader());
604 PackageEntryTable* pkgEntryTable = loader_data->packages();
605 TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
606 if (pkg_name != NULL) {
607 PackageEntry* pkg_entry = pkgEntryTable->lookup_only(pkg_name);
608 if (pkg_entry != NULL) {
609 ModuleEntry* mod_entry = pkg_entry->module();
610 pd = get_shared_protection_domain(class_loader, mod_entry, THREAD);
611 define_shared_package(class_name, class_loader, mod_entry, CHECK_(pd));
612 }
613 }
614 } else {
615 // For shared app/platform classes originated from JAR files on the class path:
616 // Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length
617 // as the shared classpath table in the shared archive (see
618 // FileMap::_shared_path_table in filemap.hpp for details).
619 //
620 // If a shared InstanceKlass k is loaded from the class path, let
621 //
622 // index = k->shared_classpath_index():
623 //
624 // FileMap::_shared_path_table[index] identifies the JAR file that contains k.
625 //
626 // k's protection domain is:
627 //
628 // ProtectionDomain pd = _shared_protection_domains[index];
629 //
630 // and k's Package is initialized using
631 //
632 // manifest = _shared_jar_manifests[index];
633 // url = _shared_jar_urls[index];
832 check_loader_lock_contention(lockObject, THREAD);
833 ObjectLocker ol(lockObject, THREAD, DoObjectLock);
834
835 {
836 MutexLocker mu(THREAD, SystemDictionary_lock);
837 InstanceKlass* check = find_class(d_hash, name, dictionary);
838 if (check != NULL) {
839 return check;
840 }
841 }
842
843 k = load_shared_class_for_builtin_loader(name, class_loader, THREAD);
844 if (k != NULL) {
845 define_instance_class(k, CHECK_NULL);
846 }
847 }
848 }
849 return k;
850 }
851
852 InstanceKlass* SystemDictionaryShared::load_shared_class_for_builtin_loader(
853 Symbol* class_name, Handle class_loader, TRAPS) {
854 assert(UseSharedSpaces, "must be");
855 InstanceKlass* ik = find_builtin_class(class_name);
856
857 if (ik != NULL) {
858 if ((ik->is_shared_app_class() &&
859 SystemDictionary::is_system_class_loader(class_loader())) ||
860 (ik->is_shared_platform_class() &&
861 SystemDictionary::is_platform_class_loader(class_loader()))) {
862 Handle protection_domain =
863 SystemDictionaryShared::init_security_info(class_loader, ik, CHECK_NULL);
864 return load_shared_class(ik, class_loader, protection_domain, NULL, THREAD);
865 }
866 }
867 return NULL;
868 }
869
870 void SystemDictionaryShared::oops_do(OopClosure* f) {
871 f->do_oop((oop*)&_shared_protection_domains);
872 f->do_oop((oop*)&_shared_jar_urls);
873 f->do_oop((oop*)&_shared_jar_manifests);
874 }
875
876 void SystemDictionaryShared::allocate_shared_protection_domain_array(int size, TRAPS) {
877 if (_shared_protection_domains == NULL) {
878 _shared_protection_domains = oopFactory::new_objArray(
879 SystemDictionary::ProtectionDomain_klass(), size, CHECK);
880 }
881 }
882
883 void SystemDictionaryShared::allocate_shared_jar_url_array(int size, TRAPS) {
884 if (_shared_jar_urls == NULL) {
943 const ClassFileStream *cfs,
944 TRAPS) {
945 ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
946
947 {
948 MutexLocker mu(THREAD, SharedDictionary_lock);
949 if (ik->class_loader_data() != NULL) {
950 // ik is already loaded (by this loader or by a different loader)
951 // or ik is being loaded by a different thread (by this loader or by a different loader)
952 return NULL;
953 }
954
955 // No other thread has acquired this yet, so give it to *this thread*
956 ik->set_class_loader_data(loader_data);
957 }
958
959 // No longer holding SharedDictionary_lock
960 // No need to lock, as <ik> can be held only by a single thread.
961 loader_data->add_class(ik);
962
963 // Load and check super/interfaces, restore unsharable info
964 InstanceKlass* shared_klass = load_shared_class(ik, class_loader, protection_domain,
965 cfs, THREAD);
966 if (shared_klass == NULL || HAS_PENDING_EXCEPTION) {
967 // TODO: clean up <ik> so it can be used again
968 return NULL;
969 }
970
971 return shared_klass;
972 }
973
974 static ResourceHashtable<
975 Symbol*, bool,
976 primitive_hash<Symbol*>,
977 primitive_equals<Symbol*>,
978 6661, // prime number
979 ResourceObj::C_HEAP> _loaded_unregistered_classes;
980
981 bool SystemDictionaryShared::add_unregistered_class(InstanceKlass* k, TRAPS) {
982 assert(DumpSharedSpaces, "only when dumping");
983
984 Symbol* name = k->name();
985 if (_loaded_unregistered_classes.get(name) != NULL) {
|
568 JavaCalls::call_static(&result, classLoaders_klass, vmSymbols::toFileURL_name(),
569 vmSymbols::toFileURL_signature(),
570 location_string, CHECK_NH);
571 url = Handle(THREAD, (oop)result.get_jobject());
572 }
573
574 Handle pd = get_protection_domain_from_classloader(class_loader, url,
575 CHECK_NH);
576 mod->set_shared_protection_domain(loader_data, pd);
577 }
578 }
579
580 Handle protection_domain(THREAD, mod->shared_protection_domain());
581 assert(protection_domain.not_null(), "sanity");
582 return protection_domain;
583 }
584
585 // Initializes the java.lang.Package and java.security.ProtectionDomain objects associated with
586 // the given InstanceKlass.
587 // Returns the ProtectionDomain for the InstanceKlass.
588 Handle SystemDictionaryShared::init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS) {
589 Handle pd;
590
591 if (ik != NULL) {
592 int index = ik->shared_classpath_index();
593 assert(index >= 0, "Sanity");
594 SharedClassPathEntry* ent = FileMapInfo::shared_path(index);
595 Symbol* class_name = ik->name();
596
597 if (ent->is_modules_image()) {
598 // For shared app/platform classes originated from the run-time image:
599 // The ProtectionDomains are cached in the corresponding ModuleEntries
600 // for fast access by the VM.
601 if (pkg_entry != NULL) {
602 ModuleEntry* mod_entry = pkg_entry->module();
603 pd = get_shared_protection_domain(class_loader, mod_entry, THREAD);
604 define_shared_package(class_name, class_loader, mod_entry, CHECK_(pd));
605 }
606 } else {
607 // For shared app/platform classes originated from JAR files on the class path:
608 // Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length
609 // as the shared classpath table in the shared archive (see
610 // FileMap::_shared_path_table in filemap.hpp for details).
611 //
612 // If a shared InstanceKlass k is loaded from the class path, let
613 //
614 // index = k->shared_classpath_index():
615 //
616 // FileMap::_shared_path_table[index] identifies the JAR file that contains k.
617 //
618 // k's protection domain is:
619 //
620 // ProtectionDomain pd = _shared_protection_domains[index];
621 //
622 // and k's Package is initialized using
623 //
624 // manifest = _shared_jar_manifests[index];
625 // url = _shared_jar_urls[index];
824 check_loader_lock_contention(lockObject, THREAD);
825 ObjectLocker ol(lockObject, THREAD, DoObjectLock);
826
827 {
828 MutexLocker mu(THREAD, SystemDictionary_lock);
829 InstanceKlass* check = find_class(d_hash, name, dictionary);
830 if (check != NULL) {
831 return check;
832 }
833 }
834
835 k = load_shared_class_for_builtin_loader(name, class_loader, THREAD);
836 if (k != NULL) {
837 define_instance_class(k, CHECK_NULL);
838 }
839 }
840 }
841 return k;
842 }
843
844 PackageEntry* SystemDictionaryShared::get_package_entry_from_class_name(Handle class_loader, Symbol* class_name) {
845 PackageEntry* pkg_entry = NULL;
846 TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
847 if (pkg_name != NULL) {
848 pkg_entry = class_loader_data(class_loader)->packages()->lookup_only(pkg_name);
849 }
850 return pkg_entry;
851 }
852
853 InstanceKlass* SystemDictionaryShared::load_shared_class_for_builtin_loader(
854 Symbol* class_name, Handle class_loader, TRAPS) {
855 assert(UseSharedSpaces, "must be");
856 InstanceKlass* ik = find_builtin_class(class_name);
857
858 if (ik != NULL) {
859 if ((ik->is_shared_app_class() &&
860 SystemDictionary::is_system_class_loader(class_loader())) ||
861 (ik->is_shared_platform_class() &&
862 SystemDictionary::is_platform_class_loader(class_loader()))) {
863 PackageEntry* pkg_entry = get_package_entry_from_class_name(class_loader, class_name);
864 Handle protection_domain =
865 SystemDictionaryShared::init_security_info(class_loader, ik, pkg_entry, CHECK_NULL);
866 return load_shared_class(ik, class_loader, protection_domain, NULL, pkg_entry, THREAD);
867 }
868 }
869 return NULL;
870 }
871
872 void SystemDictionaryShared::oops_do(OopClosure* f) {
873 f->do_oop((oop*)&_shared_protection_domains);
874 f->do_oop((oop*)&_shared_jar_urls);
875 f->do_oop((oop*)&_shared_jar_manifests);
876 }
877
878 void SystemDictionaryShared::allocate_shared_protection_domain_array(int size, TRAPS) {
879 if (_shared_protection_domains == NULL) {
880 _shared_protection_domains = oopFactory::new_objArray(
881 SystemDictionary::ProtectionDomain_klass(), size, CHECK);
882 }
883 }
884
885 void SystemDictionaryShared::allocate_shared_jar_url_array(int size, TRAPS) {
886 if (_shared_jar_urls == NULL) {
945 const ClassFileStream *cfs,
946 TRAPS) {
947 ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
948
949 {
950 MutexLocker mu(THREAD, SharedDictionary_lock);
951 if (ik->class_loader_data() != NULL) {
952 // ik is already loaded (by this loader or by a different loader)
953 // or ik is being loaded by a different thread (by this loader or by a different loader)
954 return NULL;
955 }
956
957 // No other thread has acquired this yet, so give it to *this thread*
958 ik->set_class_loader_data(loader_data);
959 }
960
961 // No longer holding SharedDictionary_lock
962 // No need to lock, as <ik> can be held only by a single thread.
963 loader_data->add_class(ik);
964
965 // Get the package entry.
966 PackageEntry* pkg_entry = get_package_entry_from_class_name(class_loader, ik->name());
967
968 // Load and check super/interfaces, restore unsharable info
969 InstanceKlass* shared_klass = load_shared_class(ik, class_loader, protection_domain,
970 cfs, pkg_entry, THREAD);
971 if (shared_klass == NULL || HAS_PENDING_EXCEPTION) {
972 // TODO: clean up <ik> so it can be used again
973 return NULL;
974 }
975
976 return shared_klass;
977 }
978
979 static ResourceHashtable<
980 Symbol*, bool,
981 primitive_hash<Symbol*>,
982 primitive_equals<Symbol*>,
983 6661, // prime number
984 ResourceObj::C_HEAP> _loaded_unregistered_classes;
985
986 bool SystemDictionaryShared::add_unregistered_class(InstanceKlass* k, TRAPS) {
987 assert(DumpSharedSpaces, "only when dumping");
988
989 Symbol* name = k->name();
990 if (_loaded_unregistered_classes.get(name) != NULL) {
|