30 #include "classfile/vmSymbols.hpp" 31 #include "oops/oopHandle.hpp" 32 #include "oops/symbol.hpp" 33 #include "runtime/jniHandles.hpp" 34 #include "runtime/mutexLocker.hpp" 35 #include "utilities/growableArray.hpp" 36 #include "utilities/hashtable.hpp" 37 #include "utilities/macros.hpp" 38 #include "utilities/ostream.hpp" 39 #if INCLUDE_JFR 40 #include "jfr/support/jfrTraceIdExtension.hpp" 41 #endif 42 43 #define UNNAMED_MODULE "unnamed module" 44 #define UNNAMED_MODULE_LEN 14 45 #define JAVAPKG "java" 46 #define JAVAPKG_LEN 4 47 #define JAVA_BASE_NAME "java.base" 48 #define JAVA_BASE_NAME_LEN 9 49 50 class ModuleClosure; 51 52 // A ModuleEntry describes a module that has been defined by a call to JVM_DefineModule. 53 // It contains: 54 // - Symbol* containing the module's name. 55 // - pointer to the java.lang.Module for this module. 56 // - pointer to the java.security.ProtectionDomain shared by classes defined to this module. 57 // - ClassLoaderData*, class loader of this module. 58 // - a growable array containg other module entries that this module can read. 59 // - a flag indicating if this module can read all unnamed modules. 60 // 61 // The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either 62 // data structure. 63 class ModuleEntry : public HashtableEntry<Symbol*, mtModule> { 64 private: 65 OopHandle _module; // java.lang.Module 66 OopHandle _pd; // java.security.ProtectionDomain, cached 67 // for shared classes from this module 68 ClassLoaderData* _loader_data; 69 GrowableArray<ModuleEntry*>* _reads; // list of modules that are readable by this module 70 Symbol* _version; // module version number 71 Symbol* _location; // module location 72 CDS_ONLY(int _shared_path_index;) // >=0 if classes in this module are in CDS archive 73 bool _can_read_all_unnamed; 74 bool _has_default_read_edges; // JVMTI redefine/retransform support 75 bool _must_walk_reads; // walk module's reads list at GC safepoints to purge out dead modules 76 bool _is_open; // whether the packages in the module are all unqualifiedly exported 77 bool _is_patched; // whether the module is patched via --patch-module 78 JFR_ONLY(DEFINE_TRACE_ID_FIELD;) 79 enum {MODULE_READS_SIZE = 101}; // Initial size of list of modules that the module can read. 80 81 public: 82 void init() { 83 _module = OopHandle(); 84 _pd = OopHandle(); 85 _loader_data = NULL; 86 _reads = NULL; 87 _version = NULL; 88 _location = NULL; 89 _can_read_all_unnamed = false; 90 _has_default_read_edges = false; 91 _must_walk_reads = false; 92 _is_patched = false; 93 _is_open = false; 94 CDS_ONLY(_shared_path_index = -1); 95 } 96 97 Symbol* name() const { return literal(); } 98 void set_name(Symbol* n) { set_literal(n); } 99 100 oop module() const; 101 OopHandle module_handle() const { return _module; } 102 void set_module(OopHandle j) { _module = j; } 103 104 // The shared ProtectionDomain reference is set once the VM loads a shared class 171 172 // iteration support for readability 173 void module_reads_do(ModuleClosure* const f); 174 175 // Purge dead weak references out of reads list when any given class loader is unloaded. 176 void purge_reads(); 177 void delete_reads(); 178 179 // Special handling for unnamed module, one per class loader 180 static ModuleEntry* create_unnamed_module(ClassLoaderData* cld); 181 static ModuleEntry* create_boot_unnamed_module(ClassLoaderData* cld); 182 static ModuleEntry* new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld); 183 void delete_unnamed_module(); 184 185 void print(outputStream* st = tty); 186 void verify(); 187 188 CDS_ONLY(int shared_path_index() { return _shared_path_index;}) 189 190 JFR_ONLY(DEFINE_TRACE_ID_METHODS;) 191 }; 192 193 // Iterator interface 194 class ModuleClosure: public StackObj { 195 public: 196 virtual void do_module(ModuleEntry* module) = 0; 197 }; 198 199 200 // The ModuleEntryTable is a Hashtable containing a list of all modules defined 201 // by a particular class loader. Each module is represented as a ModuleEntry node. 202 // 203 // Each ModuleEntryTable contains a _javabase_module field which allows for the 204 // creation of java.base's ModuleEntry very early in bootstrapping before the 205 // corresponding JVM_DefineModule call for java.base occurs during module system 206 // initialization. Setting up java.base's ModuleEntry early enables classes, 207 // loaded prior to the module system being initialized to be created with their 208 // PackageEntry node's correctly pointing at java.base's ModuleEntry. No class 209 // outside of java.base is allowed to be loaded pre-module system initialization. 210 // 253 // Only lookup module within loader's module entry table. The table read is lock-free. 254 ModuleEntry* lookup_only(Symbol* name); 255 256 // purge dead weak references out of reads list 257 void purge_all_module_reads(); 258 259 // Special handling for java.base 260 static ModuleEntry* javabase_moduleEntry() { return _javabase_module; } 261 static void set_javabase_moduleEntry(ModuleEntry* java_base) { 262 assert(_javabase_module == NULL, "_javabase_module is already defined"); 263 _javabase_module = java_base; 264 } 265 266 static bool javabase_defined() { return ((_javabase_module != NULL) && 267 (_javabase_module->module() != NULL)); } 268 static void finalize_javabase(Handle module_handle, Symbol* version, Symbol* location); 269 static void patch_javabase_entries(Handle module_handle); 270 271 void print(outputStream* st = tty); 272 void verify(); 273 }; 274 275 #endif // SHARE_CLASSFILE_MODULEENTRY_HPP | 30 #include "classfile/vmSymbols.hpp" 31 #include "oops/oopHandle.hpp" 32 #include "oops/symbol.hpp" 33 #include "runtime/jniHandles.hpp" 34 #include "runtime/mutexLocker.hpp" 35 #include "utilities/growableArray.hpp" 36 #include "utilities/hashtable.hpp" 37 #include "utilities/macros.hpp" 38 #include "utilities/ostream.hpp" 39 #if INCLUDE_JFR 40 #include "jfr/support/jfrTraceIdExtension.hpp" 41 #endif 42 43 #define UNNAMED_MODULE "unnamed module" 44 #define UNNAMED_MODULE_LEN 14 45 #define JAVAPKG "java" 46 #define JAVAPKG_LEN 4 47 #define JAVA_BASE_NAME "java.base" 48 #define JAVA_BASE_NAME_LEN 9 49 50 template <class T> class Array; 51 class ModuleClosure; 52 53 // A ModuleEntry describes a module that has been defined by a call to JVM_DefineModule. 54 // It contains: 55 // - Symbol* containing the module's name. 56 // - pointer to the java.lang.Module for this module. 57 // - pointer to the java.security.ProtectionDomain shared by classes defined to this module. 58 // - ClassLoaderData*, class loader of this module. 59 // - a growable array containg other module entries that this module can read. 60 // - a flag indicating if this module can read all unnamed modules. 61 // 62 // The Mutex Module_lock is shared between ModuleEntry and PackageEntry, to lock either 63 // data structure. 64 class ModuleEntry : public HashtableEntry<Symbol*, mtModule> { 65 private: 66 OopHandle _module; // java.lang.Module 67 OopHandle _shared_pd; // java.security.ProtectionDomain, cached 68 // for shared classes from this module 69 ClassLoaderData* _loader_data; 70 GrowableArray<ModuleEntry*>* _reads; // list of modules that are readable by this module 71 Symbol* _version; // module version number 72 Symbol* _location; // module location 73 CDS_ONLY(int _shared_path_index;) // >=0 if classes in this module are in CDS archive 74 bool _can_read_all_unnamed; 75 bool _has_default_read_edges; // JVMTI redefine/retransform support 76 bool _must_walk_reads; // walk module's reads list at GC safepoints to purge out dead modules 77 bool _is_open; // whether the packages in the module are all unqualifiedly exported 78 bool _is_patched; // whether the module is patched via --patch-module 79 CDS_JAVA_HEAP_ONLY(narrowOop _archived_module_narrow_oop;) 80 81 JFR_ONLY(DEFINE_TRACE_ID_FIELD;) 82 enum {MODULE_READS_SIZE = 101}; // Initial size of list of modules that the module can read. 83 84 public: 85 void init() { 86 _module = OopHandle(); 87 _shared_pd = OopHandle(); 88 _loader_data = NULL; 89 _reads = NULL; 90 _version = NULL; 91 _location = NULL; 92 _can_read_all_unnamed = false; 93 _has_default_read_edges = false; 94 _must_walk_reads = false; 95 _is_patched = false; 96 _is_open = false; 97 CDS_ONLY(_shared_path_index = -1); 98 } 99 100 Symbol* name() const { return literal(); } 101 void set_name(Symbol* n) { set_literal(n); } 102 103 oop module() const; 104 OopHandle module_handle() const { return _module; } 105 void set_module(OopHandle j) { _module = j; } 106 107 // The shared ProtectionDomain reference is set once the VM loads a shared class 174 175 // iteration support for readability 176 void module_reads_do(ModuleClosure* const f); 177 178 // Purge dead weak references out of reads list when any given class loader is unloaded. 179 void purge_reads(); 180 void delete_reads(); 181 182 // Special handling for unnamed module, one per class loader 183 static ModuleEntry* create_unnamed_module(ClassLoaderData* cld); 184 static ModuleEntry* create_boot_unnamed_module(ClassLoaderData* cld); 185 static ModuleEntry* new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld); 186 void delete_unnamed_module(); 187 188 void print(outputStream* st = tty); 189 void verify(); 190 191 CDS_ONLY(int shared_path_index() { return _shared_path_index;}) 192 193 JFR_ONLY(DEFINE_TRACE_ID_METHODS;) 194 195 #if INCLUDE_CDS_JAVA_HEAP 196 ModuleEntry* allocate_archived_entry() const; 197 void init_as_archived_entry(); 198 void init_archived_oops(); 199 static ModuleEntry* get_archived_entry(ModuleEntry* orig_entry); 200 static Array<ModuleEntry*>* write_archived_entry_array(GrowableArray<ModuleEntry*>* array); 201 static GrowableArray<ModuleEntry*>* read_archived_entry_array(Array<ModuleEntry*>* archived_array); 202 void load_from_archive(ClassLoaderData* loader_data); 203 void restore_archive_oops(ClassLoaderData* loader_data); 204 #endif 205 }; 206 207 // Iterator interface 208 class ModuleClosure: public StackObj { 209 public: 210 virtual void do_module(ModuleEntry* module) = 0; 211 }; 212 213 214 // The ModuleEntryTable is a Hashtable containing a list of all modules defined 215 // by a particular class loader. Each module is represented as a ModuleEntry node. 216 // 217 // Each ModuleEntryTable contains a _javabase_module field which allows for the 218 // creation of java.base's ModuleEntry very early in bootstrapping before the 219 // corresponding JVM_DefineModule call for java.base occurs during module system 220 // initialization. Setting up java.base's ModuleEntry early enables classes, 221 // loaded prior to the module system being initialized to be created with their 222 // PackageEntry node's correctly pointing at java.base's ModuleEntry. No class 223 // outside of java.base is allowed to be loaded pre-module system initialization. 224 // 267 // Only lookup module within loader's module entry table. The table read is lock-free. 268 ModuleEntry* lookup_only(Symbol* name); 269 270 // purge dead weak references out of reads list 271 void purge_all_module_reads(); 272 273 // Special handling for java.base 274 static ModuleEntry* javabase_moduleEntry() { return _javabase_module; } 275 static void set_javabase_moduleEntry(ModuleEntry* java_base) { 276 assert(_javabase_module == NULL, "_javabase_module is already defined"); 277 _javabase_module = java_base; 278 } 279 280 static bool javabase_defined() { return ((_javabase_module != NULL) && 281 (_javabase_module->module() != NULL)); } 282 static void finalize_javabase(Handle module_handle, Symbol* version, Symbol* location); 283 static void patch_javabase_entries(Handle module_handle); 284 285 void print(outputStream* st = tty); 286 void verify(); 287 288 #if INCLUDE_CDS_JAVA_HEAP 289 Array<ModuleEntry*>* allocate_archived_entries(); 290 void init_archived_entries(Array<ModuleEntry*>* archived_modules); 291 void init_archived_oops(Array<ModuleEntry*>* archived_modules); 292 void load_archived_entries(ClassLoaderData* loader_data, 293 Array<ModuleEntry*>* archived_modules); 294 void restore_archived_oops(ClassLoaderData* loader_data, 295 Array<ModuleEntry*>* archived_modules); 296 #endif 297 }; 298 299 #endif // SHARE_CLASSFILE_MODULEENTRY_HPP |