91
92 // The shared ProtectionDomain reference is set once the VM loads a shared class
93 // originated from the current Module. The referenced ProtectionDomain object is
94 // created by the ClassLoader when loading a class (shared or non-shared) from the
95 // Module for the first time. This ProtectionDomain object is used for all
96 // classes from the Module loaded by the same ClassLoader.
97 Handle shared_protection_domain();
98 void set_shared_protection_domain(ClassLoaderData *loader_data, Handle pd);
99
100 ClassLoaderData* loader_data() const { return _loader_data; }
101 void set_loader_data(ClassLoaderData* l) { _loader_data = l; }
102
103 Symbol* version() const { return _version; }
104 void set_version(Symbol* version);
105
106 Symbol* location() const { return _location; }
107 void set_location(Symbol* location);
108 bool is_non_jdk_module();
109
110 bool can_read(ModuleEntry* m) const;
111 bool has_reads() const;
112 void add_read(ModuleEntry* m);
113 void set_read_walk_required(ClassLoaderData* m_loader_data);
114
115 bool is_named() const { return (name() != NULL); }
116
117 bool can_read_all_unnamed() const {
118 assert(is_named() || _can_read_all_unnamed == true,
119 "unnamed modules can always read all unnamed modules");
120 return _can_read_all_unnamed;
121 }
122
123 // Modules can only go from strict to loose.
124 void set_can_read_all_unnamed() { _can_read_all_unnamed = true; }
125
126 bool has_default_read_edges() const {
127 return _has_default_read_edges;
128 }
129
130 // Sets true and returns the previous value.
131 bool set_has_default_read_edges() {
141 bool is_patched() {
142 return _is_patched;
143 }
144
145 ModuleEntry* next() const {
146 return (ModuleEntry*)HashtableEntry<Symbol*, mtModule>::next();
147 }
148 ModuleEntry** next_addr() {
149 return (ModuleEntry**)HashtableEntry<Symbol*, mtModule>::next_addr();
150 }
151
152 // iteration support for readability
153 void module_reads_do(ModuleClosure* const f);
154
155 TRACE_DEFINE_TRACE_ID_METHODS;
156
157 // Purge dead weak references out of reads list when any given class loader is unloaded.
158 void purge_reads();
159 void delete_reads();
160
161 void print(outputStream* st = tty);
162 void verify();
163 };
164
165 // Iterator interface
166 class ModuleClosure: public StackObj {
167 public:
168 virtual void do_module(ModuleEntry* const module) = 0;
169 };
170
171
172 // The ModuleEntryTable is a Hashtable containing a list of all modules defined
173 // by a particular class loader. Each module is represented as a ModuleEntry node.
174 //
175 // Each ModuleEntryTable contains a _javabase_module field which allows for the
176 // creation of java.base's ModuleEntry very early in bootstrapping before the
177 // corresponding JVM_DefineModule call for java.base occurs during module system
178 // initialization. Setting up java.base's ModuleEntry early enables classes,
179 // loaded prior to the module system being initialized to be created with their
180 // PackageEntry node's correctly pointing at java.base's ModuleEntry. No class
181 // outside of java.base is allowed to be loaded pre-module system initialization.
182 //
183 // The ModuleEntryTable's lookup is lock free.
184 //
185 class ModuleEntryTable : public Hashtable<Symbol*, mtModule> {
186 friend class VMStructs;
187 public:
188 enum Constants {
189 _moduletable_entry_size = 109 // number of entries in module entry table
190 };
191
192 private:
193 static ModuleEntry* _javabase_module;
194 ModuleEntry* _unnamed_module;
195
196 ModuleEntry* new_entry(unsigned int hash, Handle module_handle, Symbol* name, Symbol* version,
197 Symbol* location, ClassLoaderData* loader_data);
198 void add_entry(int index, ModuleEntry* new_entry);
199
200 int entry_size() const { return BasicHashtable<mtModule>::entry_size(); }
201
202 ModuleEntry** bucket_addr(int i) {
203 return (ModuleEntry**)Hashtable<Symbol*, mtModule>::bucket_addr(i);
204 }
205
206 static unsigned int compute_hash(Symbol* name) { return ((name == NULL) ? 0 : (unsigned int)(name->identity_hash())); }
207 int index_for(Symbol* name) const { return hash_to_index(compute_hash(name)); }
208
209 public:
210 ModuleEntryTable(int table_size);
211 ~ModuleEntryTable();
212
213 ModuleEntry* bucket(int i) {
214 return (ModuleEntry*)Hashtable<Symbol*, mtModule>::bucket(i);
215 }
216
217 // Create module in loader's module entry table, if already exists then
218 // return null. Assume Module_lock has been locked by caller.
219 ModuleEntry* locked_create_entry_or_null(Handle module_handle,
220 Symbol* module_name,
221 Symbol* module_version,
222 Symbol* module_location,
223 ClassLoaderData* loader_data);
224
225 // Only lookup module within loader's module entry table. The table read is lock-free.
226 ModuleEntry* lookup_only(Symbol* name);
227
228 // purge dead weak references out of reads list
229 void purge_all_module_reads();
230
231 // Special handling for unnamed module, one per class loader's ModuleEntryTable
232 void create_unnamed_module(ClassLoaderData* loader_data);
233 ModuleEntry* unnamed_module() { return _unnamed_module; }
234
235 // Special handling for java.base
236 static ModuleEntry* javabase_moduleEntry() { return _javabase_module; }
237 static void set_javabase_moduleEntry(ModuleEntry* java_base) { _javabase_module = java_base; }
238 static bool javabase_defined() { return ((_javabase_module != NULL) &&
239 (_javabase_module->module() != NULL)); }
240 static void finalize_javabase(Handle module_handle, Symbol* version, Symbol* location);
241 static void patch_javabase_entries(Handle module_handle);
242
243 void print(outputStream* st = tty);
244 void verify();
245 };
246
247 #endif // SHARE_VM_CLASSFILE_MODULEENTRY_HPP
|
91
92 // The shared ProtectionDomain reference is set once the VM loads a shared class
93 // originated from the current Module. The referenced ProtectionDomain object is
94 // created by the ClassLoader when loading a class (shared or non-shared) from the
95 // Module for the first time. This ProtectionDomain object is used for all
96 // classes from the Module loaded by the same ClassLoader.
97 Handle shared_protection_domain();
98 void set_shared_protection_domain(ClassLoaderData *loader_data, Handle pd);
99
100 ClassLoaderData* loader_data() const { return _loader_data; }
101 void set_loader_data(ClassLoaderData* l) { _loader_data = l; }
102
103 Symbol* version() const { return _version; }
104 void set_version(Symbol* version);
105
106 Symbol* location() const { return _location; }
107 void set_location(Symbol* location);
108 bool is_non_jdk_module();
109
110 bool can_read(ModuleEntry* m) const;
111 bool has_reads() const; // Whether the module has a non-empty reads list
112 void add_read(ModuleEntry* m);
113 void set_read_walk_required(ClassLoaderData* m_loader_data);
114
115 bool is_named() const { return (name() != NULL); }
116
117 bool can_read_all_unnamed() const {
118 assert(is_named() || _can_read_all_unnamed == true,
119 "unnamed modules can always read all unnamed modules");
120 return _can_read_all_unnamed;
121 }
122
123 // Modules can only go from strict to loose.
124 void set_can_read_all_unnamed() { _can_read_all_unnamed = true; }
125
126 bool has_default_read_edges() const {
127 return _has_default_read_edges;
128 }
129
130 // Sets true and returns the previous value.
131 bool set_has_default_read_edges() {
141 bool is_patched() {
142 return _is_patched;
143 }
144
145 ModuleEntry* next() const {
146 return (ModuleEntry*)HashtableEntry<Symbol*, mtModule>::next();
147 }
148 ModuleEntry** next_addr() {
149 return (ModuleEntry**)HashtableEntry<Symbol*, mtModule>::next_addr();
150 }
151
152 // iteration support for readability
153 void module_reads_do(ModuleClosure* const f);
154
155 TRACE_DEFINE_TRACE_ID_METHODS;
156
157 // Purge dead weak references out of reads list when any given class loader is unloaded.
158 void purge_reads();
159 void delete_reads();
160
161 // Special handling for unnamed module, one per class loader
162 static ModuleEntry* create_unnamed_module(ClassLoaderData* cld);
163 static ModuleEntry* create_boot_unnamed_module(ClassLoaderData* cld);
164 static ModuleEntry* new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld);
165
166 void print(outputStream* st = tty);
167 void verify();
168 };
169
170 // Iterator interface
171 class ModuleClosure: public StackObj {
172 public:
173 virtual void do_module(ModuleEntry* const module) = 0;
174 };
175
176
177 // The ModuleEntryTable is a Hashtable containing a list of all modules defined
178 // by a particular class loader. Each module is represented as a ModuleEntry node.
179 //
180 // Each ModuleEntryTable contains a _javabase_module field which allows for the
181 // creation of java.base's ModuleEntry very early in bootstrapping before the
182 // corresponding JVM_DefineModule call for java.base occurs during module system
183 // initialization. Setting up java.base's ModuleEntry early enables classes,
184 // loaded prior to the module system being initialized to be created with their
185 // PackageEntry node's correctly pointing at java.base's ModuleEntry. No class
186 // outside of java.base is allowed to be loaded pre-module system initialization.
187 //
188 // The ModuleEntryTable's lookup is lock free.
189 //
190 class ModuleEntryTable : public Hashtable<Symbol*, mtModule> {
191 friend class VMStructs;
192 public:
193 enum Constants {
194 _moduletable_entry_size = 109 // number of entries in module entry table
195 };
196
197 private:
198 static ModuleEntry* _javabase_module;
199
200 ModuleEntry* new_entry(unsigned int hash, Handle module_handle, Symbol* name, Symbol* version,
201 Symbol* location, ClassLoaderData* loader_data);
202 void add_entry(int index, ModuleEntry* new_entry);
203
204 int entry_size() const { return BasicHashtable<mtModule>::entry_size(); }
205
206 ModuleEntry** bucket_addr(int i) {
207 return (ModuleEntry**)Hashtable<Symbol*, mtModule>::bucket_addr(i);
208 }
209
210 static unsigned int compute_hash(Symbol* name) { return ((name == NULL) ? 0 : (unsigned int)(name->identity_hash())); }
211 int index_for(Symbol* name) const { return hash_to_index(compute_hash(name)); }
212
213 public:
214 ModuleEntryTable(int table_size);
215 ~ModuleEntryTable();
216
217 ModuleEntry* bucket(int i) {
218 return (ModuleEntry*)Hashtable<Symbol*, mtModule>::bucket(i);
219 }
220
221 // Create module in loader's module entry table, if already exists then
222 // return null. Assume Module_lock has been locked by caller.
223 ModuleEntry* locked_create_entry_or_null(Handle module_handle,
224 Symbol* module_name,
225 Symbol* module_version,
226 Symbol* module_location,
227 ClassLoaderData* loader_data);
228
229 // Only lookup module within loader's module entry table. The table read is lock-free.
230 ModuleEntry* lookup_only(Symbol* name);
231
232 // purge dead weak references out of reads list
233 void purge_all_module_reads();
234
235 // Special handling for java.base
236 static ModuleEntry* javabase_moduleEntry() { return _javabase_module; }
237 static void set_javabase_moduleEntry(ModuleEntry* java_base) { _javabase_module = java_base; }
238 static bool javabase_defined() { return ((_javabase_module != NULL) &&
239 (_javabase_module->module() != NULL)); }
240 static void finalize_javabase(Handle module_handle, Symbol* version, Symbol* location);
241 static void patch_javabase_entries(Handle module_handle);
242
243 void print(outputStream* st = tty);
244 void verify();
245 };
246
247 #endif // SHARE_VM_CLASSFILE_MODULEENTRY_HPP
|