Path: blob/master/src/hotspot/share/classfile/moduleEntry.cpp
40949 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "jni.h"26#include "cds/archiveBuilder.hpp"27#include "cds/archiveUtils.hpp"28#include "cds/filemap.hpp"29#include "cds/heapShared.hpp"30#include "classfile/classLoader.hpp"31#include "classfile/classLoaderData.inline.hpp"32#include "classfile/javaClasses.inline.hpp"33#include "classfile/moduleEntry.hpp"34#include "logging/log.hpp"35#include "memory/resourceArea.hpp"36#include "memory/universe.hpp"37#include "oops/oopHandle.inline.hpp"38#include "oops/symbol.hpp"39#include "runtime/handles.inline.hpp"40#include "runtime/safepoint.hpp"41#include "utilities/events.hpp"42#include "utilities/growableArray.hpp"43#include "utilities/hashtable.inline.hpp"44#include "utilities/ostream.hpp"45#include "utilities/quickSort.hpp"46#include "utilities/resourceHash.hpp"4748ModuleEntry* ModuleEntryTable::_javabase_module = NULL;4950oop ModuleEntry::module() const { return _module.resolve(); }5152void ModuleEntry::set_location(Symbol* location) {53if (_location != NULL) {54// _location symbol's refcounts are managed by ModuleEntry,55// must decrement the old one before updating.56_location->decrement_refcount();57}5859_location = location;6061if (location != NULL) {62location->increment_refcount();63CDS_ONLY(if (UseSharedSpaces) {64_shared_path_index = FileMapInfo::get_module_shared_path_index(location);65});66}67}6869// Return true if the module's version should be displayed in error messages,70// logging, etc.71// Return false if the module's version is null, if it is unnamed, or if the72// module is not an upgradeable module.73// Detect if the module is not upgradeable by checking:74// 1. Module location is "jrt:/java." and its loader is boot or platform75// 2. Module location is "jrt:/jdk.", its loader is one of the builtin loaders76// and its version is the same as module java.base's version77// The above check is imprecise but should work in almost all cases.78bool ModuleEntry::should_show_version() {79if (version() == NULL || !is_named()) return false;8081if (location() != NULL) {82ResourceMark rm;83const char* loc = location()->as_C_string();84ClassLoaderData* cld = loader_data();8586assert(!cld->has_class_mirror_holder(), "module's cld should have a ClassLoader holder not a Class holder");87if ((cld->is_the_null_class_loader_data() || cld->is_platform_class_loader_data()) &&88(strncmp(loc, "jrt:/java.", 10) == 0)) {89return false;90}91if ((ModuleEntryTable::javabase_moduleEntry()->version()->fast_compare(version()) == 0) &&92cld->is_permanent_class_loader_data() && (strncmp(loc, "jrt:/jdk.", 9) == 0)) {93return false;94}95}96return true;97}9899void ModuleEntry::set_version(Symbol* version) {100if (_version != NULL) {101// _version symbol's refcounts are managed by ModuleEntry,102// must decrement the old one before updating.103_version->decrement_refcount();104}105106_version = version;107108if (version != NULL) {109version->increment_refcount();110}111}112113// Returns the shared ProtectionDomain114oop ModuleEntry::shared_protection_domain() {115return _shared_pd.resolve();116}117118// Set the shared ProtectionDomain atomically119void ModuleEntry::set_shared_protection_domain(ClassLoaderData *loader_data,120Handle pd_h) {121// Create a handle for the shared ProtectionDomain and save it atomically.122// init_handle_locked checks if someone beats us setting the _shared_pd cache.123loader_data->init_handle_locked(_shared_pd, pd_h);124}125126// Returns true if this module can read module m127bool ModuleEntry::can_read(ModuleEntry* m) const {128assert(m != NULL, "No module to lookup in this module's reads list");129130// Unnamed modules read everyone and all modules131// read java.base. If either of these conditions132// hold, readability has been established.133if (!this->is_named() ||134(m == ModuleEntryTable::javabase_moduleEntry())) {135return true;136}137138MutexLocker m1(Module_lock);139// This is a guard against possible race between agent threads that redefine140// or retransform classes in this module. Only one of them is adding the141// default read edges to the unnamed modules of the boot and app class loaders142// with an upcall to jdk.internal.module.Modules.transformedByAgent.143// At the same time, another thread can instrument the module classes by144// injecting dependencies that require the default read edges for resolution.145if (this->has_default_read_edges() && !m->is_named()) {146ClassLoaderData* cld = m->loader_data();147assert(!cld->has_class_mirror_holder(), "module's cld should have a ClassLoader holder not a Class holder");148if (cld->is_the_null_class_loader_data() || cld->is_system_class_loader_data()) {149return true; // default read edge150}151}152if (!has_reads_list()) {153return false;154} else {155return _reads->contains(m);156}157}158159// Add a new module to this module's reads list160void ModuleEntry::add_read(ModuleEntry* m) {161// Unnamed module is special cased and can read all modules162if (!is_named()) {163return;164}165166MutexLocker m1(Module_lock);167if (m == NULL) {168set_can_read_all_unnamed();169} else {170if (_reads == NULL) {171// Lazily create a module's reads list172_reads = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleEntry*>(MODULE_READS_SIZE, mtModule);173}174175// Determine, based on this newly established read edge to module m,176// if this module's read list should be walked at a GC safepoint.177set_read_walk_required(m->loader_data());178179// Establish readability to module m180_reads->append_if_missing(m);181}182}183184// If the module's loader, that a read edge is being established to, is185// not the same loader as this module's and is not one of the 3 builtin186// class loaders, then this module's reads list must be walked at GC187// safepoint. Modules have the same life cycle as their defining class188// loaders and should be removed if dead.189void ModuleEntry::set_read_walk_required(ClassLoaderData* m_loader_data) {190assert(is_named(), "Cannot call set_read_walk_required on unnamed module");191assert_locked_or_safepoint(Module_lock);192if (!_must_walk_reads &&193loader_data() != m_loader_data &&194!m_loader_data->is_builtin_class_loader_data()) {195_must_walk_reads = true;196if (log_is_enabled(Trace, module)) {197ResourceMark rm;198log_trace(module)("ModuleEntry::set_read_walk_required(): module %s reads list must be walked",199(name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);200}201}202}203204// Set whether the module is open, i.e. all its packages are unqualifiedly exported205void ModuleEntry::set_is_open(bool is_open) {206assert_lock_strong(Module_lock);207_is_open = is_open;208}209210// Returns true if the module has a non-empty reads list. As such, the unnamed211// module will return false.212bool ModuleEntry::has_reads_list() const {213assert_locked_or_safepoint(Module_lock);214return ((_reads != NULL) && !_reads->is_empty());215}216217// Purge dead module entries out of reads list.218void ModuleEntry::purge_reads() {219assert_locked_or_safepoint(Module_lock);220221if (_must_walk_reads && has_reads_list()) {222// This module's _must_walk_reads flag will be reset based223// on the remaining live modules on the reads list.224_must_walk_reads = false;225226if (log_is_enabled(Trace, module)) {227ResourceMark rm;228log_trace(module)("ModuleEntry::purge_reads(): module %s reads list being walked",229(name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);230}231232// Go backwards because this removes entries that are dead.233int len = _reads->length();234for (int idx = len - 1; idx >= 0; idx--) {235ModuleEntry* module_idx = _reads->at(idx);236ClassLoaderData* cld_idx = module_idx->loader_data();237if (cld_idx->is_unloading()) {238_reads->delete_at(idx);239} else {240// Update the need to walk this module's reads based on live modules241set_read_walk_required(cld_idx);242}243}244}245}246247void ModuleEntry::module_reads_do(ModuleClosure* f) {248assert_locked_or_safepoint(Module_lock);249assert(f != NULL, "invariant");250251if (has_reads_list()) {252int reads_len = _reads->length();253for (int i = 0; i < reads_len; ++i) {254f->do_module(_reads->at(i));255}256}257}258259void ModuleEntry::delete_reads() {260delete _reads;261_reads = NULL;262}263264ModuleEntry* ModuleEntry::create_unnamed_module(ClassLoaderData* cld) {265// The java.lang.Module for this loader's266// corresponding unnamed module can be found in the java.lang.ClassLoader object.267oop module = java_lang_ClassLoader::unnamedModule(cld->class_loader());268269// Ensure that the unnamed module was correctly set when the class loader was constructed.270// Guarantee will cause a recognizable crash if the user code has circumvented calling the ClassLoader constructor.271ResourceMark rm;272guarantee(java_lang_Module::is_instance(module),273"The unnamed module for ClassLoader %s, is null or not an instance of java.lang.Module. The class loader has not been initialized correctly.",274cld->loader_name_and_id());275276ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(Thread::current(), module), cld);277278// Store pointer to the ModuleEntry in the unnamed module's java.lang.Module object.279java_lang_Module::set_module_entry(module, unnamed_module);280281return unnamed_module;282}283284ModuleEntry* ModuleEntry::create_boot_unnamed_module(ClassLoaderData* cld) {285// For the boot loader, the java.lang.Module for the unnamed module286// is not known until a call to JVM_SetBootLoaderUnnamedModule is made. At287// this point initially create the ModuleEntry for the unnamed module.288ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(), cld);289assert(unnamed_module != NULL, "boot loader unnamed module should not be null");290return unnamed_module;291}292293// When creating an unnamed module, this is called without holding the Module_lock.294// This is okay because the unnamed module gets created before the ClassLoaderData295// is available to other threads.296ModuleEntry* ModuleEntry::new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld) {297ModuleEntry* entry = NEW_C_HEAP_OBJ(ModuleEntry, mtModule);298299// Initialize everything BasicHashtable would300entry->set_next(NULL);301entry->set_hash(0);302entry->set_literal(NULL);303304// Initialize fields specific to a ModuleEntry305entry->init();306307// Unnamed modules can read all other unnamed modules.308entry->set_can_read_all_unnamed();309310if (!module_handle.is_null()) {311entry->set_module(cld->add_handle(module_handle));312}313314entry->set_loader_data(cld);315entry->_is_open = true;316317JFR_ONLY(INIT_ID(entry);)318319return entry;320}321322void ModuleEntry::delete_unnamed_module() {323// Do not need unlink_entry() since the unnamed module is not in the hashtable324FREE_C_HEAP_OBJ(this);325}326327ModuleEntryTable::ModuleEntryTable(int table_size)328: Hashtable<Symbol*, mtModule>(table_size, sizeof(ModuleEntry))329{330}331332ModuleEntryTable::~ModuleEntryTable() {333// Walk through all buckets and all entries in each bucket,334// freeing each entry.335for (int i = 0; i < table_size(); ++i) {336for (ModuleEntry* m = bucket(i); m != NULL;) {337ModuleEntry* to_remove = m;338// read next before freeing.339m = m->next();340341ResourceMark rm;342if (to_remove->name() != NULL) {343log_info(module, unload)("unloading module %s", to_remove->name()->as_C_string());344}345log_debug(module)("ModuleEntryTable: deleting module: %s", to_remove->name() != NULL ?346to_remove->name()->as_C_string() : UNNAMED_MODULE);347348// Clean out the C heap allocated reads list first before freeing the entry349to_remove->delete_reads();350if (to_remove->name() != NULL) {351to_remove->name()->decrement_refcount();352}353if (to_remove->version() != NULL) {354to_remove->version()->decrement_refcount();355}356if (to_remove->location() != NULL) {357to_remove->location()->decrement_refcount();358}359BasicHashtable<mtModule>::free_entry(to_remove);360}361}362assert(number_of_entries() == 0, "should have removed all entries");363}364365void ModuleEntry::set_loader_data(ClassLoaderData* cld) {366assert(!cld->has_class_mirror_holder(), "Unexpected has_class_mirror_holder cld");367_loader_data = cld;368}369370#if INCLUDE_CDS_JAVA_HEAP371typedef ResourceHashtable<372const ModuleEntry*,373ModuleEntry*,374primitive_hash<const ModuleEntry*>,375primitive_equals<const ModuleEntry*>,376557, // prime number377ResourceObj::C_HEAP> ArchivedModuleEntries;378static ArchivedModuleEntries* _archive_modules_entries = NULL;379380ModuleEntry* ModuleEntry::allocate_archived_entry() const {381assert(is_named(), "unnamed packages/modules are not archived");382ModuleEntry* archived_entry = (ModuleEntry*)ArchiveBuilder::rw_region_alloc(sizeof(ModuleEntry));383memcpy((void*)archived_entry, (void*)this, sizeof(ModuleEntry));384385if (_archive_modules_entries == NULL) {386_archive_modules_entries = new (ResourceObj::C_HEAP, mtClass)ArchivedModuleEntries();387}388assert(_archive_modules_entries->get(this) == NULL, "Each ModuleEntry must not be shared across ModuleEntryTables");389_archive_modules_entries->put(this, archived_entry);390391return archived_entry;392}393394ModuleEntry* ModuleEntry::get_archived_entry(ModuleEntry* orig_entry) {395ModuleEntry** ptr = _archive_modules_entries->get(orig_entry);396assert(ptr != NULL && *ptr != NULL, "must have been allocated");397return *ptr;398}399400// This function is used to archive ModuleEntry::_reads and PackageEntry::_qualified_exports.401// GrowableArray cannot be directly archived, as it needs to be expandable at runtime.402// Write it out as an Array, and convert it back to GrowableArray at runtime.403Array<ModuleEntry*>* ModuleEntry::write_growable_array(GrowableArray<ModuleEntry*>* array) {404Array<ModuleEntry*>* archived_array = NULL;405int length = (array == NULL) ? 0 : array->length();406if (length > 0) {407archived_array = ArchiveBuilder::new_ro_array<ModuleEntry*>(length);408for (int i = 0; i < length; i++) {409ModuleEntry* archived_entry = get_archived_entry(array->at(i));410archived_array->at_put(i, archived_entry);411ArchivePtrMarker::mark_pointer((address*)archived_array->adr_at(i));412}413}414415return archived_array;416}417418GrowableArray<ModuleEntry*>* ModuleEntry::restore_growable_array(Array<ModuleEntry*>* archived_array) {419GrowableArray<ModuleEntry*>* array = NULL;420int length = (archived_array == NULL) ? 0 : archived_array->length();421if (length > 0) {422array = new (ResourceObj::C_HEAP, mtModule)GrowableArray<ModuleEntry*>(length, mtModule);423for (int i = 0; i < length; i++) {424ModuleEntry* archived_entry = archived_array->at(i);425array->append(archived_entry);426}427}428429return array;430}431432void ModuleEntry::iterate_symbols(MetaspaceClosure* closure) {433closure->push(literal_addr()); // name434closure->push(&_version);435closure->push(&_location);436}437438void ModuleEntry::init_as_archived_entry() {439Array<ModuleEntry*>* archived_reads = write_growable_array(_reads);440441set_next(NULL);442set_hash(0x0); // re-init at runtime443_loader_data = NULL; // re-init at runtime444_shared_path_index = FileMapInfo::get_module_shared_path_index(_location);445if (literal() != NULL) {446set_literal(ArchiveBuilder::get_relocated_symbol(literal()));447ArchivePtrMarker::mark_pointer((address*)literal_addr());448}449_reads = (GrowableArray<ModuleEntry*>*)archived_reads;450if (_version != NULL) {451_version = ArchiveBuilder::get_relocated_symbol(_version);452}453if (_location != NULL) {454_location = ArchiveBuilder::get_relocated_symbol(_location);455}456JFR_ONLY(set_trace_id(0));// re-init at runtime457458ArchivePtrMarker::mark_pointer((address*)&_reads);459ArchivePtrMarker::mark_pointer((address*)&_version);460ArchivePtrMarker::mark_pointer((address*)&_location);461}462463void ModuleEntry::init_archived_oops() {464assert(DumpSharedSpaces, "static dump only");465oop module_obj = module();466if (module_obj != NULL) {467oop m = HeapShared::find_archived_heap_object(module_obj);468assert(m != NULL, "sanity");469_archived_module_index = HeapShared::append_root(m);470}471assert(shared_protection_domain() == NULL, "never set during -Xshare:dump");472// Clear handles and restore at run time. Handles cannot be archived.473OopHandle null_handle;474_module = null_handle;475}476477void ModuleEntry::load_from_archive(ClassLoaderData* loader_data) {478set_loader_data(loader_data);479_reads = restore_growable_array((Array<ModuleEntry*>*)_reads);480JFR_ONLY(INIT_ID(this);)481}482483void ModuleEntry::restore_archived_oops(ClassLoaderData* loader_data) {484Handle module_handle(Thread::current(), HeapShared::get_root(_archived_module_index, /*clear=*/true));485assert(module_handle.not_null(), "huh");486set_module(loader_data->add_handle(module_handle));487488// This was cleared to zero during dump time -- we didn't save the value489// because it may be affected by archive relocation.490java_lang_Module::set_module_entry(module_handle(), this);491492if (loader_data->class_loader() != NULL) {493java_lang_Module::set_loader(module_handle(), loader_data->class_loader());494}495}496497void ModuleEntry::clear_archived_oops() {498HeapShared::clear_root(_archived_module_index);499}500501static int compare_module_by_name(ModuleEntry* a, ModuleEntry* b) {502assert(a == b || a->name() != b->name(), "no duplicated names");503return a->name()->fast_compare(b->name());504}505506void ModuleEntryTable::iterate_symbols(MetaspaceClosure* closure) {507for (int i = 0; i < table_size(); ++i) {508for (ModuleEntry* m = bucket(i); m != NULL; m = m->next()) {509m->iterate_symbols(closure);510}511}512}513514Array<ModuleEntry*>* ModuleEntryTable::allocate_archived_entries() {515Array<ModuleEntry*>* archived_modules = ArchiveBuilder::new_rw_array<ModuleEntry*>(number_of_entries());516int n = 0;517for (int i = 0; i < table_size(); ++i) {518for (ModuleEntry* m = bucket(i); m != NULL; m = m->next()) {519archived_modules->at_put(n++, m);520}521}522if (n > 1) {523// Always allocate in the same order to produce deterministic archive.524QuickSort::sort(archived_modules->data(), n, (_sort_Fn)compare_module_by_name, true);525}526for (int i = 0; i < n; i++) {527archived_modules->at_put(i, archived_modules->at(i)->allocate_archived_entry());528ArchivePtrMarker::mark_pointer((address*)archived_modules->adr_at(i));529}530return archived_modules;531}532533void ModuleEntryTable::init_archived_entries(Array<ModuleEntry*>* archived_modules) {534assert(DumpSharedSpaces, "dump time only");535for (int i = 0; i < archived_modules->length(); i++) {536ModuleEntry* archived_entry = archived_modules->at(i);537archived_entry->init_as_archived_entry();538}539}540541void ModuleEntryTable::init_archived_oops(Array<ModuleEntry*>* archived_modules) {542assert(DumpSharedSpaces, "dump time only");543for (int i = 0; i < archived_modules->length(); i++) {544ModuleEntry* archived_entry = archived_modules->at(i);545archived_entry->init_archived_oops();546}547}548549void ModuleEntryTable::load_archived_entries(ClassLoaderData* loader_data,550Array<ModuleEntry*>* archived_modules) {551assert(UseSharedSpaces, "runtime only");552553for (int i = 0; i < archived_modules->length(); i++) {554ModuleEntry* archived_entry = archived_modules->at(i);555archived_entry->load_from_archive(loader_data);556557unsigned int hash = compute_hash(archived_entry->name());558archived_entry->set_hash(hash);559add_entry(hash_to_index(hash), archived_entry);560}561}562563void ModuleEntryTable::restore_archived_oops(ClassLoaderData* loader_data, Array<ModuleEntry*>* archived_modules) {564assert(UseSharedSpaces, "runtime only");565for (int i = 0; i < archived_modules->length(); i++) {566ModuleEntry* archived_entry = archived_modules->at(i);567archived_entry->restore_archived_oops(loader_data);568}569}570#endif // INCLUDE_CDS_JAVA_HEAP571572ModuleEntry* ModuleEntryTable::new_entry(unsigned int hash, Handle module_handle,573bool is_open, Symbol* name,574Symbol* version, Symbol* location,575ClassLoaderData* loader_data) {576assert(Module_lock->owned_by_self(), "should have the Module_lock");577ModuleEntry* entry = (ModuleEntry*)Hashtable<Symbol*, mtModule>::new_entry(hash, name);578579// Initialize fields specific to a ModuleEntry580entry->init();581if (name != NULL) {582name->increment_refcount();583} else {584// Unnamed modules can read all other unnamed modules.585entry->set_can_read_all_unnamed();586}587588if (!module_handle.is_null()) {589entry->set_module(loader_data->add_handle(module_handle));590}591592entry->set_loader_data(loader_data);593entry->set_version(version);594entry->set_location(location);595entry->set_is_open(is_open);596597if (ClassLoader::is_in_patch_mod_entries(name)) {598entry->set_is_patched();599if (log_is_enabled(Trace, module, patch)) {600ResourceMark rm;601log_trace(module, patch)("Marked module %s as patched from --patch-module",602name != NULL ? name->as_C_string() : UNNAMED_MODULE);603}604}605606JFR_ONLY(INIT_ID(entry);)607608return entry;609}610611void ModuleEntryTable::add_entry(int index, ModuleEntry* new_entry) {612assert(Module_lock->owned_by_self(), "should have the Module_lock");613Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);614}615616// Create an entry in the class loader's module_entry_table. It is the617// caller's responsibility to ensure that the entry has not already been618// created.619ModuleEntry* ModuleEntryTable::locked_create_entry(Handle module_handle,620bool is_open,621Symbol* module_name,622Symbol* module_version,623Symbol* module_location,624ClassLoaderData* loader_data) {625assert(module_name != NULL, "ModuleEntryTable locked_create_entry should never be called for unnamed module.");626assert(Module_lock->owned_by_self(), "should have the Module_lock");627assert(lookup_only(module_name) == NULL, "Module already exists");628ModuleEntry* entry = new_entry(compute_hash(module_name), module_handle, is_open, module_name,629module_version, module_location, loader_data);630add_entry(index_for(module_name), entry);631return entry;632}633634// lookup_only by Symbol* to find a ModuleEntry.635ModuleEntry* ModuleEntryTable::lookup_only(Symbol* name) {636assert(name != NULL, "name cannot be NULL");637int index = index_for(name);638for (ModuleEntry* m = bucket(index); m != NULL; m = m->next()) {639if (m->name()->fast_compare(name) == 0) {640return m;641}642}643return NULL;644}645646// Remove dead modules from all other alive modules' reads list.647// This should only occur at class unloading.648void ModuleEntryTable::purge_all_module_reads() {649assert_locked_or_safepoint(Module_lock);650for (int i = 0; i < table_size(); i++) {651for (ModuleEntry* entry = bucket(i);652entry != NULL;653entry = entry->next()) {654entry->purge_reads();655}656}657}658659void ModuleEntryTable::finalize_javabase(Handle module_handle, Symbol* version, Symbol* location) {660assert(Module_lock->owned_by_self(), "should have the Module_lock");661ClassLoaderData* boot_loader_data = ClassLoaderData::the_null_class_loader_data();662ModuleEntryTable* module_table = boot_loader_data->modules();663664assert(module_table != NULL, "boot loader's ModuleEntryTable not defined");665666if (module_handle.is_null()) {667fatal("Unable to finalize module definition for " JAVA_BASE_NAME);668}669670// Set java.lang.Module, version and location for java.base671ModuleEntry* jb_module = javabase_moduleEntry();672assert(jb_module != NULL, JAVA_BASE_NAME " ModuleEntry not defined");673jb_module->set_version(version);674jb_module->set_location(location);675// Once java.base's ModuleEntry _module field is set with the known676// java.lang.Module, java.base is considered "defined" to the VM.677jb_module->set_module(boot_loader_data->add_handle(module_handle));678679// Store pointer to the ModuleEntry for java.base in the java.lang.Module object.680java_lang_Module::set_module_entry(module_handle(), jb_module);681}682683// Within java.lang.Class instances there is a java.lang.Module field that must684// be set with the defining module. During startup, prior to java.base's definition,685// classes needing their module field set are added to the fixup_module_list.686// Their module field is set once java.base's java.lang.Module is known to the VM.687void ModuleEntryTable::patch_javabase_entries(Handle module_handle) {688if (module_handle.is_null()) {689fatal("Unable to patch the module field of classes loaded prior to "690JAVA_BASE_NAME "'s definition, invalid java.lang.Module");691}692693// Do the fixups for the basic primitive types694java_lang_Class::set_module(Universe::int_mirror(), module_handle());695java_lang_Class::set_module(Universe::float_mirror(), module_handle());696java_lang_Class::set_module(Universe::double_mirror(), module_handle());697java_lang_Class::set_module(Universe::byte_mirror(), module_handle());698java_lang_Class::set_module(Universe::bool_mirror(), module_handle());699java_lang_Class::set_module(Universe::char_mirror(), module_handle());700java_lang_Class::set_module(Universe::long_mirror(), module_handle());701java_lang_Class::set_module(Universe::short_mirror(), module_handle());702java_lang_Class::set_module(Universe::void_mirror(), module_handle());703704// Do the fixups for classes that have already been created.705GrowableArray <Klass*>* list = java_lang_Class::fixup_module_field_list();706int list_length = list->length();707for (int i = 0; i < list_length; i++) {708Klass* k = list->at(i);709assert(k->is_klass(), "List should only hold classes");710java_lang_Class::fixup_module_field(k, module_handle);711k->class_loader_data()->dec_keep_alive();712}713714delete java_lang_Class::fixup_module_field_list();715java_lang_Class::set_fixup_module_field_list(NULL);716}717718void ModuleEntryTable::print(outputStream* st) {719st->print_cr("Module Entry Table (table_size=%d, entries=%d)",720table_size(), number_of_entries());721for (int i = 0; i < table_size(); i++) {722for (ModuleEntry* probe = bucket(i);723probe != NULL;724probe = probe->next()) {725probe->print(st);726}727}728}729730void ModuleEntry::print(outputStream* st) {731ResourceMark rm;732st->print_cr("entry " PTR_FORMAT " name %s module " PTR_FORMAT " loader %s version %s location %s strict %s next " PTR_FORMAT,733p2i(this),734name() == NULL ? UNNAMED_MODULE : name()->as_C_string(),735p2i(module()),736loader_data()->loader_name_and_id(),737version() != NULL ? version()->as_C_string() : "NULL",738location() != NULL ? location()->as_C_string() : "NULL",739BOOL_TO_STR(!can_read_all_unnamed()), p2i(next()));740}741742void ModuleEntryTable::verify() {743verify_table<ModuleEntry>("Module Entry Table");744}745746void ModuleEntry::verify() {747guarantee(loader_data() != NULL, "A module entry must be associated with a loader.");748}749750751