< prev index next >

src/hotspot/share/cds/cdsProtectionDomain.cpp

Print this page

  1 /*
  2  * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 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/aotClassLocation.hpp"
 26 #include "cds/cdsConfig.hpp"
 27 #include "cds/cdsProtectionDomain.hpp"
 28 #include "classfile/classLoader.hpp"
 29 #include "classfile/classLoaderData.inline.hpp"
 30 #include "classfile/javaClasses.hpp"
 31 #include "classfile/moduleEntry.hpp"
 32 #include "classfile/systemDictionaryShared.hpp"
 33 #include "classfile/vmClasses.hpp"
 34 #include "classfile/vmSymbols.hpp"
 35 #include "memory/oopFactory.hpp"
 36 #include "memory/resourceArea.hpp"
 37 #include "memory/universe.hpp"
 38 #include "oops/instanceKlass.hpp"


 39 #include "oops/symbol.hpp"
 40 #include "runtime/javaCalls.hpp"
 41 
 42 OopHandle CDSProtectionDomain::_shared_protection_domains;
 43 OopHandle CDSProtectionDomain::_shared_jar_urls;
 44 OopHandle CDSProtectionDomain::_shared_jar_manifests;
 45 
 46 // Initializes the java.lang.Package and java.security.ProtectionDomain objects associated with
 47 // the given InstanceKlass.
 48 // Returns the ProtectionDomain for the InstanceKlass.
 49 Handle CDSProtectionDomain::init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS) {
 50   int index = ik->shared_classpath_index();
 51   assert(index >= 0, "Sanity");
 52   const AOTClassLocation* cl = AOTClassLocationConfig::runtime()->class_location_at(index);
 53   Symbol* class_name = ik->name();
 54 
 55   if (cl->is_modules_image()) {
 56     // For shared app/platform classes originated from the run-time image:
 57     //   The ProtectionDomains are cached in the corresponding ModuleEntries
 58     //   for fast access by the VM.

277                                location_string, CHECK_NH);
278         url = Handle(THREAD, result.get_oop());
279       }
280 
281       Handle pd = get_protection_domain_from_classloader(class_loader, url,
282                                                          CHECK_NH);
283       mod->set_shared_protection_domain(loader_data, pd);
284     }
285   }
286 
287   Handle protection_domain(THREAD, mod->shared_protection_domain());
288   assert(protection_domain.not_null(), "sanity");
289   return protection_domain;
290 }
291 
292 void CDSProtectionDomain::atomic_set_array_index(OopHandle array, int index, oop o) {
293   // Benign race condition:  array.obj_at(index) may already be filled in.
294   // The important thing here is that all threads pick up the same result.
295   // It doesn't matter which racing thread wins, as long as only one
296   // result is used by all threads, and all future queries.
297   ((objArrayOop)array.resolve())->replace_if_null(index, o);
298 }
299 
300 oop CDSProtectionDomain::shared_protection_domain(int index) {
301   return ((objArrayOop)_shared_protection_domains.resolve())->obj_at(index);
302 }
303 
304 void CDSProtectionDomain::allocate_shared_protection_domain_array(int size, TRAPS) {
305   if (_shared_protection_domains.resolve() == nullptr) {
306     oop spd = oopFactory::new_objArray(
307         vmClasses::ProtectionDomain_klass(), size, CHECK);
308     _shared_protection_domains = OopHandle(Universe::vm_global(), spd);
309   }
310 }
311 
312 oop CDSProtectionDomain::shared_jar_url(int index) {
313   return ((objArrayOop)_shared_jar_urls.resolve())->obj_at(index);
314 }
315 
316 void CDSProtectionDomain::allocate_shared_jar_url_array(int size, TRAPS) {
317   if (_shared_jar_urls.resolve() == nullptr) {
318     oop sju = oopFactory::new_objArray(
319         vmClasses::URL_klass(), size, CHECK);
320     _shared_jar_urls = OopHandle(Universe::vm_global(), sju);
321   }
322 }
323 
324 oop CDSProtectionDomain::shared_jar_manifest(int index) {
325   return ((objArrayOop)_shared_jar_manifests.resolve())->obj_at(index);
326 }
327 
328 void CDSProtectionDomain::allocate_shared_jar_manifest_array(int size, TRAPS) {
329   if (_shared_jar_manifests.resolve() == nullptr) {
330     oop sjm = oopFactory::new_objArray(
331         vmClasses::Jar_Manifest_klass(), size, CHECK);
332     _shared_jar_manifests = OopHandle(Universe::vm_global(), sjm);
333   }
334 }

  1 /*
  2  * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 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/aotClassLocation.hpp"
 26 #include "cds/cdsConfig.hpp"
 27 #include "cds/cdsProtectionDomain.hpp"
 28 #include "classfile/classLoader.hpp"
 29 #include "classfile/classLoaderData.inline.hpp"
 30 #include "classfile/javaClasses.hpp"
 31 #include "classfile/moduleEntry.hpp"
 32 #include "classfile/systemDictionaryShared.hpp"
 33 #include "classfile/vmClasses.hpp"
 34 #include "classfile/vmSymbols.hpp"
 35 #include "memory/oopFactory.hpp"
 36 #include "memory/resourceArea.hpp"
 37 #include "memory/universe.hpp"
 38 #include "oops/instanceKlass.hpp"
 39 #include "oops/oopCast.inline.hpp"
 40 #include "oops/refArrayOop.hpp"
 41 #include "oops/symbol.hpp"
 42 #include "runtime/javaCalls.hpp"
 43 
 44 OopHandle CDSProtectionDomain::_shared_protection_domains;
 45 OopHandle CDSProtectionDomain::_shared_jar_urls;
 46 OopHandle CDSProtectionDomain::_shared_jar_manifests;
 47 
 48 // Initializes the java.lang.Package and java.security.ProtectionDomain objects associated with
 49 // the given InstanceKlass.
 50 // Returns the ProtectionDomain for the InstanceKlass.
 51 Handle CDSProtectionDomain::init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS) {
 52   int index = ik->shared_classpath_index();
 53   assert(index >= 0, "Sanity");
 54   const AOTClassLocation* cl = AOTClassLocationConfig::runtime()->class_location_at(index);
 55   Symbol* class_name = ik->name();
 56 
 57   if (cl->is_modules_image()) {
 58     // For shared app/platform classes originated from the run-time image:
 59     //   The ProtectionDomains are cached in the corresponding ModuleEntries
 60     //   for fast access by the VM.

279                                location_string, CHECK_NH);
280         url = Handle(THREAD, result.get_oop());
281       }
282 
283       Handle pd = get_protection_domain_from_classloader(class_loader, url,
284                                                          CHECK_NH);
285       mod->set_shared_protection_domain(loader_data, pd);
286     }
287   }
288 
289   Handle protection_domain(THREAD, mod->shared_protection_domain());
290   assert(protection_domain.not_null(), "sanity");
291   return protection_domain;
292 }
293 
294 void CDSProtectionDomain::atomic_set_array_index(OopHandle array, int index, oop o) {
295   // Benign race condition:  array.obj_at(index) may already be filled in.
296   // The important thing here is that all threads pick up the same result.
297   // It doesn't matter which racing thread wins, as long as only one
298   // result is used by all threads, and all future queries.
299   oop_cast<refArrayOop>(array.resolve())->replace_if_null(index, o);
300 }
301 
302 oop CDSProtectionDomain::shared_protection_domain(int index) {
303   return oop_cast<refArrayOop>(_shared_protection_domains.resolve())->obj_at(index);
304 }
305 
306 void CDSProtectionDomain::allocate_shared_protection_domain_array(int size, TRAPS) {
307   if (_shared_protection_domains.resolve() == nullptr) {
308     oop spd = oopFactory::new_refArray(vmClasses::ProtectionDomain_klass(), size, CHECK);

309     _shared_protection_domains = OopHandle(Universe::vm_global(), spd);
310   }
311 }
312 
313 oop CDSProtectionDomain::shared_jar_url(int index) {
314   return oop_cast<refArrayOop>(_shared_jar_urls.resolve())->obj_at(index);
315 }
316 
317 void CDSProtectionDomain::allocate_shared_jar_url_array(int size, TRAPS) {
318   if (_shared_jar_urls.resolve() == nullptr) {
319     oop sju = oopFactory::new_refArray(vmClasses::URL_klass(), size, CHECK);

320     _shared_jar_urls = OopHandle(Universe::vm_global(), sju);
321   }
322 }
323 
324 oop CDSProtectionDomain::shared_jar_manifest(int index) {
325   return oop_cast<refArrayOop>(_shared_jar_manifests.resolve())->obj_at(index);
326 }
327 
328 void CDSProtectionDomain::allocate_shared_jar_manifest_array(int size, TRAPS) {
329   if (_shared_jar_manifests.resolve() == nullptr) {
330     oop sjm = oopFactory::new_refArray(vmClasses::Jar_Manifest_klass(), size, CHECK);

331     _shared_jar_manifests = OopHandle(Universe::vm_global(), sjm);
332   }
333 }
< prev index next >