< prev index next >

src/hotspot/share/cds/cdsProtectionDomain.cpp

Print this page

 43 OopHandle CDSProtectionDomain::_shared_protection_domains;
 44 OopHandle CDSProtectionDomain::_shared_jar_urls;
 45 OopHandle CDSProtectionDomain::_shared_jar_manifests;
 46 
 47 // Initializes the java.lang.Package and java.security.ProtectionDomain objects associated with
 48 // the given InstanceKlass.
 49 // Returns the ProtectionDomain for the InstanceKlass.
 50 Handle CDSProtectionDomain::init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS) {
 51   int index = ik->shared_classpath_index();
 52   assert(index >= 0, "Sanity");
 53   SharedClassPathEntry* ent = FileMapInfo::shared_path(index);
 54   Symbol* class_name = ik->name();
 55 
 56   if (ent->is_modules_image()) {
 57     // For shared app/platform classes originated from the run-time image:
 58     //   The ProtectionDomains are cached in the corresponding ModuleEntries
 59     //   for fast access by the VM.
 60     // all packages from module image are already created during VM bootstrap in
 61     // Modules::define_module().
 62     assert(pkg_entry != nullptr, "archived class in module image cannot be from unnamed package");




 63     ModuleEntry* mod_entry = pkg_entry->module();
 64     return get_shared_protection_domain(class_loader, mod_entry, THREAD);
 65   } else {
 66     // For shared app/platform classes originated from JAR files on the class path:
 67     //   Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length
 68     //   as the shared classpath table in the shared archive (see
 69     //   FileMap::_shared_path_table in filemap.hpp for details).
 70     //
 71     //   If a shared InstanceKlass k is loaded from the class path, let
 72     //
 73     //     index = k->shared_classpath_index():
 74     //
 75     //   FileMap::_shared_path_table[index] identifies the JAR file that contains k.
 76     //
 77     //   k's protection domain is:
 78     //
 79     //     ProtectionDomain pd = _shared_protection_domains[index];
 80     //
 81     //   and k's Package is initialized using
 82     //
 83     //     manifest = _shared_jar_manifests[index];
 84     //     url = _shared_jar_urls[index];
 85     //     define_shared_package(class_name, class_loader, manifest, url, CHECK_NH);
 86     //
 87     //   Note that if an element of these 3 _shared_xxx arrays is null, it will be initialized by
 88     //   the corresponding SystemDictionaryShared::get_shared_xxx() function.
 89     Handle manifest = get_shared_jar_manifest(index, CHECK_NH);
 90     Handle url = get_shared_jar_url(index, CHECK_NH);
 91     int index_offset = index - ClassLoaderExt::app_class_paths_start_index();
 92     if (index_offset < PackageEntry::max_index_for_defined_in_class_path()) {
 93       if (pkg_entry == nullptr || !pkg_entry->is_defined_by_cds_in_class_path(index_offset)) {
 94         // define_shared_package only needs to be called once for each package in a jar specified
 95         // in the shared class path.
 96         define_shared_package(class_name, class_loader, manifest, url, CHECK_NH);
 97         if (pkg_entry != nullptr) {
 98           pkg_entry->set_defined_by_cds_in_class_path(index_offset);


 99         }


100       }
101     } else {
102       define_shared_package(class_name, class_loader, manifest, url, CHECK_NH);


103     }
104     return get_shared_protection_domain(class_loader, index, url, THREAD);
105   }
106 }
107 
108 Handle CDSProtectionDomain::get_package_name(Symbol* class_name, TRAPS) {
109   ResourceMark rm(THREAD);
110   Handle pkgname_string;
111   TempNewSymbol pkg = ClassLoader::package_from_class_name(class_name);
112   if (pkg != nullptr) { // Package prefix found
113     const char* pkgname = pkg->as_klass_external_name();
114     pkgname_string = java_lang_String::create_from_str(pkgname,
115                                                        CHECK_(pkgname_string));
116   }
117   return pkgname_string;
118 }
119 
120 PackageEntry* CDSProtectionDomain::get_package_entry_from_class(InstanceKlass* ik, Handle class_loader) {
121   PackageEntry* pkg_entry = ik->package();
122   if (CDSConfig::is_using_full_module_graph() && ik->is_shared() && pkg_entry != nullptr) {

192     atomic_set_shared_jar_manifest(shared_path_index, manifest());
193   }
194   manifest = Handle(THREAD, shared_jar_manifest(shared_path_index));
195   assert(manifest.not_null(), "sanity");
196   return manifest;
197 }
198 
199 Handle CDSProtectionDomain::get_shared_jar_url(int shared_path_index, TRAPS) {
200   Handle url_h;
201   if (shared_jar_url(shared_path_index) == nullptr) {
202     const char* path = FileMapInfo::shared_path_name(shared_path_index);
203     oop result_oop = to_file_URL(path, url_h, CHECK_(url_h));
204     atomic_set_shared_jar_url(shared_path_index, result_oop);
205   }
206 
207   url_h = Handle(THREAD, shared_jar_url(shared_path_index));
208   assert(url_h.not_null(), "sanity");
209   return url_h;
210 }
211 






























212 oop CDSProtectionDomain::to_file_URL(const char* path, Handle url_h, TRAPS) {
213   JavaValue result(T_OBJECT);
214   Handle path_string = java_lang_String::create_from_str(path, CHECK_NULL);
215   JavaCalls::call_static(&result,
216                          vmClasses::jdk_internal_loader_ClassLoaders_klass(),
217                          vmSymbols::toFileURL_name(),
218                          vmSymbols::toFileURL_signature(),
219                          path_string, CHECK_NULL);
220   return result.get_oop();
221 }
222 
223 // Get the ProtectionDomain associated with the CodeSource from the classloader.
224 Handle CDSProtectionDomain::get_protection_domain_from_classloader(Handle class_loader,
225                                                                       Handle url, TRAPS) {
226   // CodeSource cs = new CodeSource(url, null);
227   Handle cs = JavaCalls::construct_new_instance(vmClasses::CodeSource_klass(),
228                   vmSymbols::url_code_signer_array_void_signature(),
229                   url, Handle(), CHECK_NH);
230 
231   // protection_domain = SecureClassLoader.getProtectionDomain(cs);

 43 OopHandle CDSProtectionDomain::_shared_protection_domains;
 44 OopHandle CDSProtectionDomain::_shared_jar_urls;
 45 OopHandle CDSProtectionDomain::_shared_jar_manifests;
 46 
 47 // Initializes the java.lang.Package and java.security.ProtectionDomain objects associated with
 48 // the given InstanceKlass.
 49 // Returns the ProtectionDomain for the InstanceKlass.
 50 Handle CDSProtectionDomain::init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS) {
 51   int index = ik->shared_classpath_index();
 52   assert(index >= 0, "Sanity");
 53   SharedClassPathEntry* ent = FileMapInfo::shared_path(index);
 54   Symbol* class_name = ik->name();
 55 
 56   if (ent->is_modules_image()) {
 57     // For shared app/platform classes originated from the run-time image:
 58     //   The ProtectionDomains are cached in the corresponding ModuleEntries
 59     //   for fast access by the VM.
 60     // all packages from module image are already created during VM bootstrap in
 61     // Modules::define_module().
 62     assert(pkg_entry != nullptr, "archived class in module image cannot be from unnamed package");
 63     Handle archived_pd = get_archived_protection_domain(THREAD, ik);
 64     if (archived_pd.not_null()) {
 65       return archived_pd;
 66     }
 67     ModuleEntry* mod_entry = pkg_entry->module();
 68     return get_shared_protection_domain(class_loader, mod_entry, THREAD);
 69   } else {
 70     // For shared app/platform classes originated from JAR files on the class path:
 71     //   Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length
 72     //   as the shared classpath table in the shared archive (see
 73     //   FileMap::_shared_path_table in filemap.hpp for details).
 74     //
 75     //   If a shared InstanceKlass k is loaded from the class path, let
 76     //
 77     //     index = k->shared_classpath_index():
 78     //
 79     //   FileMap::_shared_path_table[index] identifies the JAR file that contains k.
 80     //
 81     //   k's protection domain is:
 82     //
 83     //     ProtectionDomain pd = _shared_protection_domains[index];
 84     //
 85     //   and k's Package is initialized using
 86     //
 87     //     manifest = _shared_jar_manifests[index];
 88     //     url = _shared_jar_urls[index];
 89     //     define_shared_package(class_name, class_loader, manifest, url, CHECK_NH);
 90     //
 91     //   Note that if an element of these 3 _shared_xxx arrays is null, it will be initialized by
 92     //   the corresponding SystemDictionaryShared::get_shared_xxx() function.
 93     Handle manifest = get_shared_jar_manifest(index, CHECK_NH);
 94     Handle url = get_shared_jar_url(index, CHECK_NH);
 95     if (!CDSConfig::is_loading_packages()) {
 96       int index_offset = index - ClassLoaderExt::app_class_paths_start_index();
 97       if (index_offset < PackageEntry::max_index_for_defined_in_class_path()) {
 98         if (pkg_entry == nullptr || !pkg_entry->is_defined_by_cds_in_class_path(index_offset)) {
 99           // define_shared_package only needs to be called once for each package in a jar specified
100           // in the shared class path.
101           define_shared_package(class_name, class_loader, manifest, url, CHECK_NH);
102           if (pkg_entry != nullptr) {
103             pkg_entry->set_defined_by_cds_in_class_path(index_offset);
104           }
105         }
106       } else {
107         define_shared_package(class_name, class_loader, manifest, url, CHECK_NH);
108       }
109     }
110     Handle archived_pd = get_archived_protection_domain(THREAD, ik);
111     if (archived_pd.not_null()) {
112       return archived_pd;
113     }
114     return get_shared_protection_domain(class_loader, index, url, THREAD);
115   }
116 }
117 
118 Handle CDSProtectionDomain::get_package_name(Symbol* class_name, TRAPS) {
119   ResourceMark rm(THREAD);
120   Handle pkgname_string;
121   TempNewSymbol pkg = ClassLoader::package_from_class_name(class_name);
122   if (pkg != nullptr) { // Package prefix found
123     const char* pkgname = pkg->as_klass_external_name();
124     pkgname_string = java_lang_String::create_from_str(pkgname,
125                                                        CHECK_(pkgname_string));
126   }
127   return pkgname_string;
128 }
129 
130 PackageEntry* CDSProtectionDomain::get_package_entry_from_class(InstanceKlass* ik, Handle class_loader) {
131   PackageEntry* pkg_entry = ik->package();
132   if (CDSConfig::is_using_full_module_graph() && ik->is_shared() && pkg_entry != nullptr) {

202     atomic_set_shared_jar_manifest(shared_path_index, manifest());
203   }
204   manifest = Handle(THREAD, shared_jar_manifest(shared_path_index));
205   assert(manifest.not_null(), "sanity");
206   return manifest;
207 }
208 
209 Handle CDSProtectionDomain::get_shared_jar_url(int shared_path_index, TRAPS) {
210   Handle url_h;
211   if (shared_jar_url(shared_path_index) == nullptr) {
212     const char* path = FileMapInfo::shared_path_name(shared_path_index);
213     oop result_oop = to_file_URL(path, url_h, CHECK_(url_h));
214     atomic_set_shared_jar_url(shared_path_index, result_oop);
215   }
216 
217   url_h = Handle(THREAD, shared_jar_url(shared_path_index));
218   assert(url_h.not_null(), "sanity");
219   return url_h;
220 }
221 
222 
223 Handle CDSProtectionDomain::get_archived_protection_domain(JavaThread* current, InstanceKlass* klass) {
224   oop pd = nullptr;
225 
226   if (CDSConfig::is_loading_protection_domains()) {
227     oop mirror;
228     if (klass->has_archived_mirror_index()) {
229       mirror = klass->archived_java_mirror();
230     } else {
231       mirror = klass->java_mirror();
232     }
233 
234     if (mirror != nullptr) {
235       pd = java_lang_Class::protection_domain(mirror);
236     }
237   }
238 
239   if (log_is_enabled(Info, cds, protectiondomain)) {
240     ResourceMark rm;
241     log_info(cds, protectiondomain)("Archived protection domain for %s = %s", klass->external_name(),
242                                     (pd == nullptr) ? "none" : "found");
243   }
244 
245   if (pd == nullptr) {
246     return Handle();
247   } else {
248     return Handle(current, pd);
249   }
250 }
251 
252 oop CDSProtectionDomain::to_file_URL(const char* path, Handle url_h, TRAPS) {
253   JavaValue result(T_OBJECT);
254   Handle path_string = java_lang_String::create_from_str(path, CHECK_NULL);
255   JavaCalls::call_static(&result,
256                          vmClasses::jdk_internal_loader_ClassLoaders_klass(),
257                          vmSymbols::toFileURL_name(),
258                          vmSymbols::toFileURL_signature(),
259                          path_string, CHECK_NULL);
260   return result.get_oop();
261 }
262 
263 // Get the ProtectionDomain associated with the CodeSource from the classloader.
264 Handle CDSProtectionDomain::get_protection_domain_from_classloader(Handle class_loader,
265                                                                       Handle url, TRAPS) {
266   // CodeSource cs = new CodeSource(url, null);
267   Handle cs = JavaCalls::construct_new_instance(vmClasses::CodeSource_klass(),
268                   vmSymbols::url_code_signer_array_void_signature(),
269                   url, Handle(), CHECK_NH);
270 
271   // protection_domain = SecureClassLoader.getProtectionDomain(cs);
< prev index next >