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 "precompiled.hpp"
26 #include "classfile/moduleEntry.hpp"
27 #include "classfile/packageEntry.hpp"
28 #include "logging/log.hpp"
29 #include "memory/archiveUtils.hpp"
30 #include "memory/metaspaceShared.hpp"
31 #include "memory/resourceArea.hpp"
32 #include "oops/array.hpp"
33 #include "oops/symbol.hpp"
34 #include "runtime/handles.inline.hpp"
35 #include "utilities/events.hpp"
36 #include "utilities/growableArray.hpp"
37 #include "utilities/hashtable.inline.hpp"
38 #include "utilities/ostream.hpp"
39 #include "utilities/resourceHash.hpp"
40
41 // Returns true if this package specifies m as a qualified export, including through an unnamed export
42 bool PackageEntry::is_qexported_to(ModuleEntry* m) const {
43 assert(Module_lock->owned_by_self(), "should have the Module_lock");
44 assert(m != NULL, "No module to lookup in this package's qualified exports list");
45 if (is_exported_allUnnamed() && !m->is_named()) {
46 return true;
47 } else if (!has_qual_exports_list()) {
48 return false;
49 } else {
50 return _qualified_exports->contains(m);
51 }
52 }
53
54 // Add a module to the package's qualified export list.
55 void PackageEntry::add_qexport(ModuleEntry* m) {
56 assert(Module_lock->owned_by_self(), "should have the Module_lock");
57 if (!has_qual_exports_list()) {
58 // Lazily create a package's qualified exports list.
225 void PackageEntry::init_as_archived_entry() {
226 Array<ModuleEntry*>* archived_qualified_exports = ModuleEntry::write_archived_entry_array(_qualified_exports);
227
228 set_next(NULL);
229 set_literal(MetaspaceShared::get_relocated_symbol(literal()));
230 set_hash(0x0); // re-init at runtime
231 _module = ModuleEntry::get_archived_entry(_module);
232 _qualified_exports = (GrowableArray<ModuleEntry*>*)archived_qualified_exports;
233 _defined_by_cds_in_class_path = 0;
234
235 ArchivePtrMarker::mark_pointer((address*)literal_addr());
236 ArchivePtrMarker::mark_pointer((address*)&_module);
237 ArchivePtrMarker::mark_pointer((address*)&_qualified_exports);
238 }
239
240 void PackageEntry::load_from_archive() {
241 _qualified_exports = ModuleEntry::read_archived_entry_array((Array<ModuleEntry*>*)_qualified_exports);
242 JFR_ONLY(INIT_ID(this);)
243 }
244
245 static int compare_package_by_name(PackageEntry** a, PackageEntry** b) {
246 return a[0]->name()->fast_compare(b[0]->name());
247 }
248
249 Array<PackageEntry*>* PackageEntryTable::allocate_archived_entries() {
250 // First count the packages in named modules
251 int n, i;
252 for (n = 0, i = 0; i < table_size(); ++i) {
253 for (PackageEntry* p = bucket(i); p != NULL; p = p->next()) {
254 if (p->module()->name() != NULL) {
255 n++;
256 }
257 }
258 }
259
260 Array<PackageEntry*>* archived_packages = MetaspaceShared::new_rw_array<PackageEntry*>(n);
261 for (n = 0, i = 0; i < table_size(); ++i) {
262 for (PackageEntry* p = bucket(i); p != NULL; p = p->next()) {
263 if (p->module()->name() != NULL) {
264 // We don't archive unnamed modules, or packages in unnamed modules. They will be
265 // created on-demand at runtime as classes in such packages are loaded.
266 archived_packages->at_put(n++, p);
267 }
268 }
269 }
270 if (n > 0) {
271 qsort(archived_packages->adr_at(0), n, sizeof(PackageEntry*), (_sort_Fn)compare_package_by_name);
272 for (i = 0; i < n; i++) {
273 archived_packages->at_put(i, archived_packages->at(i)->allocate_archived_entry());
274 ArchivePtrMarker::mark_pointer((address*)archived_packages->adr_at(i));
275 }
276 }
277 return archived_packages;
278 }
279
280 void PackageEntryTable::init_archived_entries(Array<PackageEntry*>* archived_packages) {
281 for (int i = 0; i < archived_packages->length(); i++) {
282 PackageEntry* archived_entry = archived_packages->at(i);
283 archived_entry->init_as_archived_entry();
284 }
285 }
286
287 void PackageEntryTable::load_archived_entries(Array<PackageEntry*>* archived_packages) {
288 assert(UseSharedSpaces, "runtime only");
289
290 MutexLocker m1(Module_lock);
291 for (int i = 0; i < archived_packages->length(); i++) {
292 PackageEntry* archived_entry = archived_packages->at(i);
293 archived_entry->load_from_archive();
294
295 unsigned int hash = compute_hash(archived_entry->name());
296 archived_entry->set_hash(hash);
297 add_entry(hash_to_index(hash), archived_entry);
298 }
299 }
300
301 #endif
302
303 PackageEntry* PackageEntryTable::new_entry(unsigned int hash, Symbol* name, ModuleEntry* module) {
304 assert(Module_lock->owned_by_self(), "should have the Module_lock");
305 PackageEntry* entry = (PackageEntry*)Hashtable<Symbol*, mtModule>::allocate_new_entry(hash, name);
306
307 JFR_ONLY(INIT_ID(entry);)
308
309 // Initialize fields specific to a PackageEntry
310 entry->init();
311 entry->name()->increment_refcount();
312 entry->set_module(module);
313 return entry;
314 }
315
316 void PackageEntryTable::add_entry(int index, PackageEntry* new_entry) {
317 assert(Module_lock->owned_by_self(), "should have the Module_lock");
318 Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);
319 }
320
321 // Create package entry in loader's package entry table. Assume Module lock
368 }
369
370 // Called when a define module for java.base is being processed.
371 // Verify the packages loaded thus far are in java.base's package list.
372 void PackageEntryTable::verify_javabase_packages(GrowableArray<Symbol*> *pkg_list) {
373 assert_lock_strong(Module_lock);
374 for (int i = 0; i < table_size(); i++) {
375 for (PackageEntry* entry = bucket(i);
376 entry != NULL;
377 entry = entry->next()) {
378 ModuleEntry* m = entry->module();
379 Symbol* module_name = (m == NULL ? NULL : m->name());
380 if (module_name != NULL &&
381 (module_name->fast_compare(vmSymbols::java_base()) == 0) &&
382 !pkg_list->contains(entry->name())) {
383 ResourceMark rm;
384 vm_exit_during_initialization("A non-" JAVA_BASE_NAME " package was loaded prior to module system initialization", entry->name()->as_C_string());
385 }
386 }
387 }
388
389 }
390
391 // iteration of qualified exports
392 void PackageEntry::package_exports_do(ModuleClosure* f) {
393 assert_locked_or_safepoint(Module_lock);
394 assert(f != NULL, "invariant");
395
396 if (has_qual_exports_list()) {
397 int qe_len = _qualified_exports->length();
398
399 for (int i = 0; i < qe_len; ++i) {
400 f->do_module(_qualified_exports->at(i));
401 }
402 }
403 }
404
405 bool PackageEntry::exported_pending_delete() const {
406 assert_locked_or_safepoint(Module_lock);
407 return (is_unqual_exported() && _qualified_exports != NULL);
408 }
|
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 "precompiled.hpp"
26 #include "classfile/moduleEntry.hpp"
27 #include "classfile/packageEntry.hpp"
28 #include "logging/log.hpp"
29 #include "memory/archiveUtils.hpp"
30 #include "memory/metaspaceShared.hpp"
31 #include "memory/resourceArea.hpp"
32 #include "oops/array.hpp"
33 #include "oops/symbol.hpp"
34 #include "runtime/handles.inline.hpp"
35 #include "utilities/events.hpp"
36 #include "utilities/growableArray.hpp"
37 #include "utilities/hashtable.inline.hpp"
38 #include "utilities/ostream.hpp"
39 #include "utilities/quickSort.hpp"
40 #include "utilities/resourceHash.hpp"
41
42 // Returns true if this package specifies m as a qualified export, including through an unnamed export
43 bool PackageEntry::is_qexported_to(ModuleEntry* m) const {
44 assert(Module_lock->owned_by_self(), "should have the Module_lock");
45 assert(m != NULL, "No module to lookup in this package's qualified exports list");
46 if (is_exported_allUnnamed() && !m->is_named()) {
47 return true;
48 } else if (!has_qual_exports_list()) {
49 return false;
50 } else {
51 return _qualified_exports->contains(m);
52 }
53 }
54
55 // Add a module to the package's qualified export list.
56 void PackageEntry::add_qexport(ModuleEntry* m) {
57 assert(Module_lock->owned_by_self(), "should have the Module_lock");
58 if (!has_qual_exports_list()) {
59 // Lazily create a package's qualified exports list.
226 void PackageEntry::init_as_archived_entry() {
227 Array<ModuleEntry*>* archived_qualified_exports = ModuleEntry::write_archived_entry_array(_qualified_exports);
228
229 set_next(NULL);
230 set_literal(MetaspaceShared::get_relocated_symbol(literal()));
231 set_hash(0x0); // re-init at runtime
232 _module = ModuleEntry::get_archived_entry(_module);
233 _qualified_exports = (GrowableArray<ModuleEntry*>*)archived_qualified_exports;
234 _defined_by_cds_in_class_path = 0;
235
236 ArchivePtrMarker::mark_pointer((address*)literal_addr());
237 ArchivePtrMarker::mark_pointer((address*)&_module);
238 ArchivePtrMarker::mark_pointer((address*)&_qualified_exports);
239 }
240
241 void PackageEntry::load_from_archive() {
242 _qualified_exports = ModuleEntry::read_archived_entry_array((Array<ModuleEntry*>*)_qualified_exports);
243 JFR_ONLY(INIT_ID(this);)
244 }
245
246 static int compare_package_by_name(PackageEntry* a, PackageEntry* b) {
247 return a->name()->fast_compare(b->name());
248 }
249
250 Array<PackageEntry*>* PackageEntryTable::allocate_archived_entries() {
251 // First count the packages in named modules
252 int n, i;
253 for (n = 0, i = 0; i < table_size(); ++i) {
254 for (PackageEntry* p = bucket(i); p != NULL; p = p->next()) {
255 if (p->module()->name() != NULL) {
256 n++;
257 }
258 }
259 }
260
261 Array<PackageEntry*>* archived_packages = MetaspaceShared::new_rw_array<PackageEntry*>(n);
262 for (n = 0, i = 0; i < table_size(); ++i) {
263 for (PackageEntry* p = bucket(i); p != NULL; p = p->next()) {
264 if (p->module()->name() != NULL) {
265 // We don't archive unnamed modules, or packages in unnamed modules. They will be
266 // created on-demand at runtime as classes in such packages are loaded.
267 archived_packages->at_put(n++, p);
268 }
269 }
270 }
271 if (n > 1) {
272 QuickSort::sort(archived_packages->data(), n, (_sort_Fn)compare_package_by_name, true);
273 }
274 for (i = 0; i < n; i++) {
275 archived_packages->at_put(i, archived_packages->at(i)->allocate_archived_entry());
276 ArchivePtrMarker::mark_pointer((address*)archived_packages->adr_at(i));
277 }
278 return archived_packages;
279 }
280
281 void PackageEntryTable::init_archived_entries(Array<PackageEntry*>* archived_packages) {
282 for (int i = 0; i < archived_packages->length(); i++) {
283 PackageEntry* archived_entry = archived_packages->at(i);
284 archived_entry->init_as_archived_entry();
285 }
286 }
287
288 void PackageEntryTable::load_archived_entries(Array<PackageEntry*>* archived_packages) {
289 assert(UseSharedSpaces, "runtime only");
290
291 for (int i = 0; i < archived_packages->length(); i++) {
292 PackageEntry* archived_entry = archived_packages->at(i);
293 archived_entry->load_from_archive();
294
295 unsigned int hash = compute_hash(archived_entry->name());
296 archived_entry->set_hash(hash);
297 add_entry(hash_to_index(hash), archived_entry);
298 }
299 }
300
301 #endif // INCLUDE_CDS_JAVA_HEAP
302
303 PackageEntry* PackageEntryTable::new_entry(unsigned int hash, Symbol* name, ModuleEntry* module) {
304 assert(Module_lock->owned_by_self(), "should have the Module_lock");
305 PackageEntry* entry = (PackageEntry*)Hashtable<Symbol*, mtModule>::allocate_new_entry(hash, name);
306
307 JFR_ONLY(INIT_ID(entry);)
308
309 // Initialize fields specific to a PackageEntry
310 entry->init();
311 entry->name()->increment_refcount();
312 entry->set_module(module);
313 return entry;
314 }
315
316 void PackageEntryTable::add_entry(int index, PackageEntry* new_entry) {
317 assert(Module_lock->owned_by_self(), "should have the Module_lock");
318 Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);
319 }
320
321 // Create package entry in loader's package entry table. Assume Module lock
368 }
369
370 // Called when a define module for java.base is being processed.
371 // Verify the packages loaded thus far are in java.base's package list.
372 void PackageEntryTable::verify_javabase_packages(GrowableArray<Symbol*> *pkg_list) {
373 assert_lock_strong(Module_lock);
374 for (int i = 0; i < table_size(); i++) {
375 for (PackageEntry* entry = bucket(i);
376 entry != NULL;
377 entry = entry->next()) {
378 ModuleEntry* m = entry->module();
379 Symbol* module_name = (m == NULL ? NULL : m->name());
380 if (module_name != NULL &&
381 (module_name->fast_compare(vmSymbols::java_base()) == 0) &&
382 !pkg_list->contains(entry->name())) {
383 ResourceMark rm;
384 vm_exit_during_initialization("A non-" JAVA_BASE_NAME " package was loaded prior to module system initialization", entry->name()->as_C_string());
385 }
386 }
387 }
388 }
389
390 // iteration of qualified exports
391 void PackageEntry::package_exports_do(ModuleClosure* f) {
392 assert_locked_or_safepoint(Module_lock);
393 assert(f != NULL, "invariant");
394
395 if (has_qual_exports_list()) {
396 int qe_len = _qualified_exports->length();
397
398 for (int i = 0; i < qe_len; ++i) {
399 f->do_module(_qualified_exports->at(i));
400 }
401 }
402 }
403
404 bool PackageEntry::exported_pending_delete() const {
405 assert_locked_or_safepoint(Module_lock);
406 return (is_unqual_exported() && _qualified_exports != NULL);
407 }
|