/* * Copyright (c) 2016, 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. *
*/
// Returns true if this package specifies m as a qualified export, including through an unnamed export bool PackageEntry::is_qexported_to(ModuleEntry* m) const {
assert(Module_lock->owned_by_self(), "should have the Module_lock");
assert(m != NULL, "No module to lookup in this package's qualified exports list"); if (is_exported_allUnnamed() && !m->is_named()) { returntrue;
} elseif (!has_qual_exports_list()) { returnfalse;
} else { return _qualified_exports->contains(m);
}
}
// Add a module to the package's qualified export list. void PackageEntry::add_qexport(ModuleEntry* m) {
assert(Module_lock->owned_by_self(), "should have the Module_lock"); if (!has_qual_exports_list()) { // Lazily create a package's qualified exports list. // Initial size is small, do not anticipate export lists to be large.
_qualified_exports = new (mtModule) GrowableArray<ModuleEntry*>(QUAL_EXP_SIZE, mtModule);
}
// Determine, based on this newly established export to module m, // if this package's export list should be walked at a GC safepoint.
set_export_walk_required(m->loader_data());
// Establish exportability to module m
_qualified_exports->append_if_missing(m);
}
// If the module's loader, that an export is being established to, is // not the same loader as this module's and is not one of the 3 builtin // class loaders, then this package's export list must be walked at GC // safepoint. Modules have the same life cycle as their defining class // loaders and should be removed if dead. void PackageEntry::set_export_walk_required(ClassLoaderData* m_loader_data) {
assert_locked_or_safepoint(Module_lock);
ModuleEntry* this_pkg_mod = module(); if (!_must_walk_exports &&
(this_pkg_mod == NULL || this_pkg_mod->loader_data() != m_loader_data) &&
!m_loader_data->is_builtin_class_loader_data()) {
_must_walk_exports = true; if (log_is_enabled(Trace, module)) {
ResourceMark rm;
assert(name() != NULL, "PackageEntry without a valid name");
log_trace(module)("PackageEntry::set_export_walk_required(): package %s defined in module %s, exports list must be walked",
name()->as_C_string(),
(this_pkg_mod == NULL || this_pkg_mod->name() == NULL) ?
UNNAMED_MODULE : this_pkg_mod->name()->as_C_string());
}
}
}
// Set the package's exported states based on the value of the ModuleEntry. void PackageEntry::set_exported(ModuleEntry* m) {
assert(Module_lock->owned_by_self(), "should have the Module_lock"); if (is_unqual_exported()) { // An exception could be thrown, but choose to simply ignore. // Illegal to convert an unqualified exported package to be qualifiedly exported return;
}
if (m == NULL) { // NULL indicates the package is being unqualifiedly exported. Clean up // the qualified list at the next safepoint.
set_unqual_exported();
} else { // Add the exported module
add_qexport(m);
}
}
// Set the package as exported to all unnamed modules unless the package is // already unqualifiedly exported. void PackageEntry::set_is_exported_allUnnamed() {
assert(!module()->is_open(), "should have been checked already");
assert(Module_lock->owned_by_self(), "should have the Module_lock"); if (!is_unqual_exported()) {
_export_flags = PKG_EXP_ALLUNNAMED;
}
}
// Remove dead module entries within the package's exported list. Note that // if all of the modules on the _qualified_exports get purged the list does not // get deleted. This prevents the package from illegally transitioning from // exported to non-exported. void PackageEntry::purge_qualified_exports() {
assert_locked_or_safepoint(Module_lock); if (_must_walk_exports &&
_qualified_exports != NULL &&
!_qualified_exports->is_empty()) {
// This package's _must_walk_exports flag will be reset based // on the remaining live modules on the exports list.
_must_walk_exports = false;
if (log_is_enabled(Trace, module)) {
ResourceMark rm;
assert(name() != NULL, "PackageEntry without a valid name");
ModuleEntry* pkg_mod = module();
log_trace(module)("PackageEntry::purge_qualified_exports(): package %s defined in module %s, exports list being walked",
name()->as_C_string(),
(pkg_mod == NULL || pkg_mod->name() == NULL) ? UNNAMED_MODULE : pkg_mod->name()->as_C_string());
}
// Go backwards because this removes entries that are dead. int len = _qualified_exports->length(); for (int idx = len - 1; idx >= 0; idx--) {
ModuleEntry* module_idx = _qualified_exports->at(idx);
ClassLoaderData* cld_idx = module_idx->loader_data(); if (cld_idx->is_unloading()) {
_qualified_exports->delete_at(idx);
} else { // Update the need to walk this package's exports based on live modules
set_export_walk_required(cld_idx);
}
}
}
}
PackageEntryTableDeleter deleter;
_table.unlink(&deleter);
assert(_table.number_of_entries() == 0, "should have removed all entries");
}
#if INCLUDE_CDS_JAVA_HEAP typedef ResourceHashtable< const PackageEntry*,
PackageEntry*,
557, // prime number
AnyObj::C_HEAP> ArchivedPackageEntries; static ArchivedPackageEntries* _archived_packages_entries = NULL;
PackageEntry* PackageEntry::allocate_archived_entry() const {
assert(!in_unnamed_module(), "unnamed packages/modules are not archived");
PackageEntry* archived_entry = (PackageEntry*)ArchiveBuilder::rw_region_alloc(sizeof(PackageEntry));
memcpy((void*)archived_entry, (void*)this, sizeof(PackageEntry));
if (_archived_packages_entries == NULL) {
_archived_packages_entries = new (mtClass)ArchivedPackageEntries();
}
assert(_archived_packages_entries->get(this) == NULL, "Each PackageEntry must not be shared across PackageEntryTables");
_archived_packages_entries->put(this, archived_entry);
staticint compare_package_by_name(PackageEntry* a, PackageEntry* b) {
assert(a == b || a->name() != b->name(), "no duplicated names"); return a->name()->fast_compare(b->name());
}
Array<PackageEntry*>* PackageEntryTable::allocate_archived_entries() { // First count the packages in named modules int n = 0; auto count = [&] (const SymbolHandle& key, PackageEntry*& p) { if (p->module()->is_named()) {
n++;
}
};
_table.iterate_all(count);
Array<PackageEntry*>* archived_packages = ArchiveBuilder::new_rw_array<PackageEntry*>(n); // reset n
n = 0; auto grab = [&] (const SymbolHandle& key, PackageEntry*& p) { if (p->module()->is_named()) { // We don't archive unnamed modules, or packages in unnamed modules. They will be // created on-demand at runtime as classes in such packages are loaded.
archived_packages->at_put(n++, p);
}
};
_table.iterate_all(grab);
if (n > 1) {
QuickSort::sort(archived_packages->data(), n, (_sort_Fn)compare_package_by_name, true);
} for (int i = 0; i < n; i++) {
archived_packages->at_put(i, archived_packages->at(i)->allocate_archived_entry());
ArchivePtrMarker::mark_pointer((address*)archived_packages->adr_at(i));
} return archived_packages;
}
void PackageEntryTable::init_archived_entries(Array<PackageEntry*>* archived_packages) { for (int i = 0; i < archived_packages->length(); i++) {
PackageEntry* archived_entry = archived_packages->at(i);
archived_entry->init_as_archived_entry();
}
}
for (int i = 0; i < archived_packages->length(); i++) {
PackageEntry* archived_entry = archived_packages->at(i);
archived_entry->load_from_archive();
_table.put(archived_entry->name(), archived_entry);
}
}
#endif// INCLUDE_CDS_JAVA_HEAP
// Create package entry in loader's package entry table. Assume Module lock // was taken by caller. void PackageEntryTable::locked_create_entry(Symbol* name, ModuleEntry* module) {
assert(Module_lock->owned_by_self(), "should have the Module_lock");
assert(locked_lookup_only(name) == NULL, "Package entry already exists");
PackageEntry* entry = new PackageEntry(name, module); bool created = _table.put(name, entry);
assert(created, "must be");
}
// Create package entry in loader's package entry table if it does not already // exist. Assume Module lock was taken by caller.
PackageEntry* PackageEntryTable::locked_create_entry_if_absent(Symbol* name, ModuleEntry* module) {
assert(Module_lock->owned_by_self(), "should have the Module_lock"); // Check if package entry already exists. If not, create it. bool created;
PackageEntry* entry = new PackageEntry(name, module);
PackageEntry** old_entry = _table.put_if_absent(name, entry, &created); if (created) { return entry;
} else { delete entry; return *old_entry;
}
}
PackageEntry* PackageEntryTable::lookup_only(Symbol* name) {
assert(!Module_lock->owned_by_self(), "should not have the Module_lock - use locked_lookup_only");
MutexLocker ml(Module_lock); return locked_lookup_only(name);
}
// Remove dead entries from all packages' exported list void PackageEntryTable::purge_all_package_exports() {
assert_locked_or_safepoint(Module_lock); auto purge = [&] (const SymbolHandle& name, PackageEntry*& entry) { if (entry->exported_pending_delete()) { // exported list is pending deletion due to a transition // from qualified to unqualified
entry->delete_qualified_exports();
} elseif (entry->is_qual_exported()) {
entry->purge_qualified_exports();
}
};
_table.iterate_all(purge);
}
void PackageEntryTable::packages_do(void f(PackageEntry*)) { auto doit = [&] (const SymbolHandle&name, PackageEntry*& entry) {
f(entry);
};
assert_locked_or_safepoint(Module_lock);
_table.iterate_all(doit);
}
GrowableArray<PackageEntry*>* PackageEntryTable::get_system_packages() {
GrowableArray<PackageEntry*>* loaded_class_pkgs = new GrowableArray<PackageEntry*>(50); auto grab = [&] (const SymbolHandle& name, PackageEntry*& entry) { if (entry->has_loaded_class()) {
loaded_class_pkgs->append(entry);
}
};
MutexLocker ml(Module_lock);
_table.iterate_all(grab); // Returns a resource allocated object so caller must have ResourceMark return loaded_class_pkgs;
}
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 ist noch experimentell.