/* * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// Initializes the java.lang.Package and java.security.ProtectionDomain objects associated with // the given InstanceKlass. // Returns the ProtectionDomain for the InstanceKlass.
Handle CDSProtectionDomain::init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS) { int index = ik->shared_classpath_index();
assert(index >= 0, "Sanity");
SharedClassPathEntry* ent = FileMapInfo::shared_path(index);
Symbol* class_name = ik->name();
if (ent->is_modules_image()) { // For shared app/platform classes originated from the run-time image: // The ProtectionDomains are cached in the corresponding ModuleEntries // for fast access by the VM. // all packages from module image are already created during VM bootstrap in // Modules::define_module().
assert(pkg_entry != NULL, "archived class in module image cannot be from unnamed package");
ModuleEntry* mod_entry = pkg_entry->module(); return get_shared_protection_domain(class_loader, mod_entry, THREAD);
} else { // For shared app/platform classes originated from JAR files on the class path: // Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length // as the shared classpath table in the shared archive (see // FileMap::_shared_path_table in filemap.hpp for details). // // If a shared InstanceKlass k is loaded from the class path, let // // index = k->shared_classpath_index(): // // FileMap::_shared_path_table[index] identifies the JAR file that contains k. // // k's protection domain is: // // ProtectionDomain pd = _shared_protection_domains[index]; // // and k's Package is initialized using // // manifest = _shared_jar_manifests[index]; // url = _shared_jar_urls[index]; // define_shared_package(class_name, class_loader, manifest, url, CHECK_NH); // // Note that if an element of these 3 _shared_xxx arrays is NULL, it will be initialized by // the corresponding SystemDictionaryShared::get_shared_xxx() function.
Handle manifest = get_shared_jar_manifest(index, CHECK_NH);
Handle url = get_shared_jar_url(index, CHECK_NH); int index_offset = index - ClassLoaderExt::app_class_paths_start_index(); if (index_offset < PackageEntry::max_index_for_defined_in_class_path()) { if (pkg_entry == NULL || !pkg_entry->is_defined_by_cds_in_class_path(index_offset)) { // define_shared_package only needs to be called once for each package in a jar specified // in the shared class path.
define_shared_package(class_name, class_loader, manifest, url, CHECK_NH); if (pkg_entry != NULL) {
pkg_entry->set_defined_by_cds_in_class_path(index_offset);
}
}
} else {
define_shared_package(class_name, class_loader, manifest, url, CHECK_NH);
} return get_shared_protection_domain(class_loader, index, url, THREAD);
}
}
// Get the ProtectionDomain associated with the CodeSource from the classloader.
Handle CDSProtectionDomain::get_protection_domain_from_classloader(Handle class_loader,
Handle url, TRAPS) { // CodeSource cs = new CodeSource(url, null);
Handle cs = JavaCalls::construct_new_instance(vmClasses::CodeSource_klass(),
vmSymbols::url_code_signer_array_void_signature(),
url, Handle(), CHECK_NH);
// Returns the ProtectionDomain associated with the JAR file identified by the url.
Handle CDSProtectionDomain::get_shared_protection_domain(Handle class_loader, int shared_path_index,
Handle url,
TRAPS) {
Handle protection_domain; if (shared_protection_domain(shared_path_index) == NULL) {
Handle pd = get_protection_domain_from_classloader(class_loader, url, THREAD);
atomic_set_shared_protection_domain(shared_path_index, pd());
}
// Acquire from the cache because if another thread beats the current one to // set the shared protection_domain and the atomic_set fails, the current thread // needs to get the updated protection_domain from the cache.
protection_domain = Handle(THREAD, shared_protection_domain(shared_path_index));
assert(protection_domain.not_null(), "sanity"); return protection_domain;
}
void CDSProtectionDomain::atomic_set_array_index(OopHandle array, int index, oop o) { // Benign race condition: array.obj_at(index) may already be filled in. // The important thing here is that all threads pick up the same result. // It doesn't matter which racing thread wins, as long as only one // result is used by all threads, and all future queries.
((objArrayOop)array.resolve())->atomic_compare_exchange_oop(index, o, NULL);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.