12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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 "cds/aotGrowableArray.inline.hpp"
26 #include "cds/aotMetaspace.hpp"
27 #include "cds/archiveBuilder.hpp"
28 #include "cds/archiveUtils.hpp"
29 #include "cds/cdsConfig.hpp"
30 #include "classfile/classLoaderData.hpp"
31 #include "classfile/moduleEntry.hpp"
32 #include "classfile/packageEntry.hpp"
33 #include "classfile/vmSymbols.hpp"
34 #include "logging/log.hpp"
35 #include "logging/logStream.hpp"
36 #include "memory/metadataFactory.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/array.hpp"
39 #include "oops/symbol.hpp"
40 #include "runtime/handles.inline.hpp"
41 #include "runtime/java.hpp"
42 #include "utilities/events.hpp"
43 #include "utilities/hashTable.hpp"
44 #include "utilities/ostream.hpp"
45 #include "utilities/quickSort.hpp"
46
47 PackageEntry::PackageEntry(Symbol* name, ModuleEntry* module) :
48 _name(name),
49 _module(module),
50 _export_flags(0),
51 _classpath_index(-1),
183 }
184 }
185 }
186
187 void PackageEntry::delete_qualified_exports() {
188 if (_qualified_exports != nullptr && !AOTMetaspace::in_aot_cache(_qualified_exports)) {
189 delete _qualified_exports;
190 }
191 _qualified_exports = nullptr;
192 }
193
194 void PackageEntry::pack_qualified_exports() {
195 if (_qualified_exports != nullptr) {
196 _qualified_exports->shrink_to_fit();
197 }
198 }
199
200 void PackageEntry::metaspace_pointers_do(MetaspaceClosure* it) {
201 it->push(&_name);
202 it->push(&_module);
203 it->push(&_qualified_exports);
204 }
205
206 PackageEntryTable::PackageEntryTable() { }
207
208 PackageEntryTable::~PackageEntryTable() {
209 class PackageEntryTableDeleter : public StackObj {
210 public:
211 bool do_entry(const SymbolHandle& name, PackageEntry*& entry) {
212 if (log_is_enabled(Info, module, unload) || log_is_enabled(Debug, module)) {
213 ResourceMark rm;
214 const char* str = name->as_C_string();
215 log_info(module, unload)("unloading package %s", str);
216 log_debug(module)("PackageEntry: deleting package: %s", str);
217 }
218 delete entry;
219 return true;
220 }
221 };
222
223 PackageEntryTableDeleter deleter;
224 _table.unlink(&deleter);
225 assert(_table.number_of_entries() == 0, "should have removed all entries");
226 }
227
228 #if INCLUDE_CDS_JAVA_HEAP
229 bool PackageEntry::should_be_archived() const {
230 return module()->should_be_archived();
231 }
232
233 void PackageEntry::remove_unshareable_info() {
234 if (_qualified_exports != nullptr) {
235 _qualified_exports->set_in_aot_cache();
236 }
237 _defined_by_cds_in_class_path = 0;
238 JFR_ONLY(set_trace_id(0);) // re-init at runtime
239 }
240
241 void PackageEntry::load_from_archive() {
242 JFR_ONLY(INIT_ID(this);)
243 }
244
245 static int compare_package_by_name(PackageEntry* a, PackageEntry* b) {
246 assert(a == b || a->name() != b->name(), "no duplicated names");
247 return a->name()->fast_compare(b->name());
248 }
249
250 Array<PackageEntry*>* PackageEntryTable::build_aot_table(ClassLoaderData* loader_data, TRAPS) {
251 // First count the packages in named modules
252 int n = 0;
253 auto count = [&] (const SymbolHandle& key, PackageEntry*& p) {
|
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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 "cds/aotGrowableArray.inline.hpp"
26 #include "cds/aotMetaspace.hpp"
27 #include "cds/archiveBuilder.hpp"
28 #include "cds/archiveUtils.hpp"
29 #include "cds/cdsConfig.hpp"
30 #include "classfile/classLoaderData.hpp"
31 #include "classfile/moduleEntry.hpp"
32 #include "classfile/modules.hpp"
33 #include "classfile/packageEntry.hpp"
34 #include "classfile/vmSymbols.hpp"
35 #include "logging/log.hpp"
36 #include "logging/logStream.hpp"
37 #include "memory/metadataFactory.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "oops/array.hpp"
40 #include "oops/symbol.hpp"
41 #include "runtime/handles.inline.hpp"
42 #include "runtime/java.hpp"
43 #include "utilities/events.hpp"
44 #include "utilities/hashTable.hpp"
45 #include "utilities/ostream.hpp"
46 #include "utilities/quickSort.hpp"
47
48 PackageEntry::PackageEntry(Symbol* name, ModuleEntry* module) :
49 _name(name),
50 _module(module),
51 _export_flags(0),
52 _classpath_index(-1),
184 }
185 }
186 }
187
188 void PackageEntry::delete_qualified_exports() {
189 if (_qualified_exports != nullptr && !AOTMetaspace::in_aot_cache(_qualified_exports)) {
190 delete _qualified_exports;
191 }
192 _qualified_exports = nullptr;
193 }
194
195 void PackageEntry::pack_qualified_exports() {
196 if (_qualified_exports != nullptr) {
197 _qualified_exports->shrink_to_fit();
198 }
199 }
200
201 void PackageEntry::metaspace_pointers_do(MetaspaceClosure* it) {
202 it->push(&_name);
203 it->push(&_module);
204
205 ModuleEntry* module_entry = module();
206 if (!(module_entry->is_named() && Modules::is_dynamic_proxy_module(module_entry))) {
207 // This is a dynamically generated module. Its _qualified_exports will be
208 // restored at runtime in the Java code. See comments in ArchivedData::restore().
209 it->push(&_qualified_exports);
210 }
211 }
212
213 PackageEntryTable::PackageEntryTable() { }
214
215 PackageEntryTable::~PackageEntryTable() {
216 class PackageEntryTableDeleter : public StackObj {
217 public:
218 bool do_entry(const SymbolHandle& name, PackageEntry*& entry) {
219 if (log_is_enabled(Info, module, unload) || log_is_enabled(Debug, module)) {
220 ResourceMark rm;
221 const char* str = name->as_C_string();
222 log_info(module, unload)("unloading package %s", str);
223 log_debug(module)("PackageEntry: deleting package: %s", str);
224 }
225 delete entry;
226 return true;
227 }
228 };
229
230 PackageEntryTableDeleter deleter;
231 _table.unlink(&deleter);
232 assert(_table.number_of_entries() == 0, "should have removed all entries");
233 }
234
235 #if INCLUDE_CDS_JAVA_HEAP
236 bool PackageEntry::should_be_archived() const {
237 return module()->should_be_archived();
238 }
239
240 void PackageEntry::remove_unshareable_info() {
241 ModuleEntry* module_entry = ArchiveBuilder::current()->get_source_addr(module());
242 if (module_entry->is_named() && Modules::is_dynamic_proxy_module(module_entry)) {
243 // See comments in PackageEntry::metaspace_pointers_do()
244 _qualified_exports = nullptr;
245 }
246 if (_qualified_exports != nullptr) {
247 _qualified_exports->set_in_aot_cache();
248 }
249 _defined_by_cds_in_class_path = 0;
250 JFR_ONLY(set_trace_id(0);) // re-init at runtime
251 }
252
253 void PackageEntry::load_from_archive() {
254 JFR_ONLY(INIT_ID(this);)
255 }
256
257 static int compare_package_by_name(PackageEntry* a, PackageEntry* b) {
258 assert(a == b || a->name() != b->name(), "no duplicated names");
259 return a->name()->fast_compare(b->name());
260 }
261
262 Array<PackageEntry*>* PackageEntryTable::build_aot_table(ClassLoaderData* loader_data, TRAPS) {
263 // First count the packages in named modules
264 int n = 0;
265 auto count = [&] (const SymbolHandle& key, PackageEntry*& p) {
|