1 /* |
1 /* |
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
35 #include "utilities/hashtable.inline.hpp" |
35 #include "utilities/hashtable.inline.hpp" |
36 #include "utilities/ostream.hpp" |
36 #include "utilities/ostream.hpp" |
37 |
37 |
38 // Returns true if this package specifies m as a qualified export, including through an unnamed export |
38 // Returns true if this package specifies m as a qualified export, including through an unnamed export |
39 bool PackageEntry::is_qexported_to(ModuleEntry* m) const { |
39 bool PackageEntry::is_qexported_to(ModuleEntry* m) const { |
|
40 assert(Module_lock->owned_by_self(), "should have the Module_lock"); |
40 assert(m != NULL, "No module to lookup in this package's qualified exports list"); |
41 assert(m != NULL, "No module to lookup in this package's qualified exports list"); |
41 MutexLocker m1(Module_lock); |
|
42 if (is_exported_allUnnamed() && !m->is_named()) { |
42 if (is_exported_allUnnamed() && !m->is_named()) { |
43 return true; |
43 return true; |
44 } else if (!has_qual_exports_list()) { |
44 } else if (!has_qual_exports_list()) { |
45 return false; |
45 return false; |
46 } else { |
46 } else { |
96 // Illegal to convert an unqualified exported package to be qualifiedly exported |
96 // Illegal to convert an unqualified exported package to be qualifiedly exported |
97 return; |
97 return; |
98 } |
98 } |
99 |
99 |
100 if (m == NULL) { |
100 if (m == NULL) { |
101 // NULL indicates the package is being unqualifiedly exported |
101 // NULL indicates the package is being unqualifiedly exported. Clean up |
102 if (has_qual_exports_list()) { |
102 // the qualified list at the next safepoint. |
103 // Legit to transition a package from being qualifiedly exported |
|
104 // to unqualified. Clean up the qualified lists at the next |
|
105 // safepoint. |
|
106 _exported_pending_delete = _qualified_exports; |
|
107 } |
|
108 |
|
109 // Mark package as unqualifiedly exported |
|
110 set_unqual_exported(); |
103 set_unqual_exported(); |
111 |
104 |
112 } else { |
105 } else { |
113 // Add the exported module |
106 // Add the exported module |
114 add_qexport(m); |
107 add_qexport(m); |
115 } |
108 } |
116 } |
109 } |
117 |
110 |
|
111 // Set the package as exported to all unnamed modules unless the package is |
|
112 // already unqualifiedly exported. |
118 void PackageEntry::set_is_exported_allUnnamed() { |
113 void PackageEntry::set_is_exported_allUnnamed() { |
119 MutexLocker m1(Module_lock); |
114 MutexLocker m1(Module_lock); |
120 if (!is_unqual_exported()) { |
115 if (!is_unqual_exported()) { |
121 _is_exported_allUnnamed = true; |
116 _export_flags = PKG_EXP_ALLUNNAMED; |
122 } |
117 } |
123 } |
118 } |
124 |
119 |
125 // Remove dead module entries within the package's exported list. |
120 // Remove dead module entries within the package's exported list. Note that |
|
121 // if all of the modules on the _qualified_exports get purged the list does not |
|
122 // get deleted. This prevents the package from illegally transitioning from |
|
123 // exported to non-exported. |
126 void PackageEntry::purge_qualified_exports() { |
124 void PackageEntry::purge_qualified_exports() { |
127 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
125 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
128 if (_must_walk_exports && |
126 if (_must_walk_exports && |
129 _qualified_exports != NULL && |
127 _qualified_exports != NULL && |
130 !_qualified_exports->is_empty()) { |
128 !_qualified_exports->is_empty()) { |
158 } |
156 } |
159 } |
157 } |
160 |
158 |
161 void PackageEntry::delete_qualified_exports() { |
159 void PackageEntry::delete_qualified_exports() { |
162 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
160 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
163 if (_exported_pending_delete != NULL) { |
|
164 // If a transition occurred from qualified to unqualified, the _qualified_exports |
|
165 // field should have been NULL'ed out. |
|
166 assert(_qualified_exports == NULL, "Package's exported pending delete, exported list should not be active"); |
|
167 delete _exported_pending_delete; |
|
168 } |
|
169 |
|
170 if (_qualified_exports != NULL) { |
161 if (_qualified_exports != NULL) { |
171 delete _qualified_exports; |
162 delete _qualified_exports; |
172 } |
163 } |
173 |
|
174 _exported_pending_delete = NULL; |
|
175 _qualified_exports = NULL; |
164 _qualified_exports = NULL; |
176 } |
165 } |
177 |
166 |
178 PackageEntryTable::PackageEntryTable(int table_size) |
167 PackageEntryTable::PackageEntryTable(int table_size) |
179 : Hashtable<Symbol*, mtModule>(table_size, sizeof(PackageEntry)) |
168 : Hashtable<Symbol*, mtModule>(table_size, sizeof(PackageEntry)) |
312 f->do_module(_qualified_exports->at(i)); |
301 f->do_module(_qualified_exports->at(i)); |
313 } |
302 } |
314 } |
303 } |
315 } |
304 } |
316 |
305 |
|
306 bool PackageEntry::exported_pending_delete() const { |
|
307 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
|
308 return (is_unqual_exported() && _qualified_exports != NULL); |
|
309 } |
|
310 |
317 // Remove dead entries from all packages' exported list |
311 // Remove dead entries from all packages' exported list |
318 void PackageEntryTable::purge_all_package_exports() { |
312 void PackageEntryTable::purge_all_package_exports() { |
319 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
313 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
320 for (int i = 0; i < table_size(); i++) { |
314 for (int i = 0; i < table_size(); i++) { |
321 for (PackageEntry* entry = bucket(i); |
315 for (PackageEntry* entry = bucket(i); |
342 probe->print(st); |
336 probe->print(st); |
343 } |
337 } |
344 } |
338 } |
345 } |
339 } |
346 |
340 |
|
341 // This function may be called from debuggers so access private fields directly |
|
342 // to prevent triggering locking-related asserts that could result from calling |
|
343 // getter methods. |
347 void PackageEntry::print(outputStream* st) { |
344 void PackageEntry::print(outputStream* st) { |
348 ResourceMark rm; |
345 ResourceMark rm; |
349 st->print_cr("package entry " PTR_FORMAT " name %s module %s classpath_index " |
346 st->print_cr("package entry " PTR_FORMAT " name %s module %s classpath_index " |
350 INT32_FORMAT " is_exported_unqualified %d is_exported_allUnnamed %d " "next " PTR_FORMAT, |
347 INT32_FORMAT " is_exported_unqualified %d is_exported_allUnnamed %d " "next " PTR_FORMAT, |
351 p2i(this), name()->as_C_string(), |
348 p2i(this), name()->as_C_string(), |
352 (module()->is_named() ? module()->name()->as_C_string() : UNNAMED_MODULE), |
349 (module()->is_named() ? module()->name()->as_C_string() : UNNAMED_MODULE), |
353 _classpath_index, _is_exported_unqualified, _is_exported_allUnnamed, p2i(next())); |
350 _classpath_index, _export_flags == PKG_EXP_UNQUALIFIED, |
|
351 _export_flags == PKG_EXP_ALLUNNAMED, p2i(next())); |
354 } |
352 } |
355 |
353 |
356 void PackageEntryTable::verify() { |
354 void PackageEntryTable::verify() { |
357 int element_count = 0; |
355 int element_count = 0; |
358 for (int index = 0; index < table_size(); index++) { |
356 for (int index = 0; index < table_size(); index++) { |