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/classFileStream.hpp"
27 #include "classfile/classListParser.hpp"
28 #include "classfile/classLoader.hpp"
29 #include "classfile/classLoaderData.inline.hpp"
30 #include "classfile/classLoaderDataGraph.hpp"
31 #include "classfile/classLoaderExt.hpp"
32 #include "classfile/dictionary.hpp"
33 #include "classfile/javaClasses.hpp"
34 #include "classfile/symbolTable.hpp"
35 #include "classfile/systemDictionary.hpp"
36 #include "classfile/systemDictionaryShared.hpp"
37 #include "classfile/verificationType.hpp"
38 #include "classfile/vmSymbols.hpp"
39 #include "logging/log.hpp"
40 #include "memory/allocation.hpp"
41 #include "memory/archiveUtils.hpp"
42 #include "memory/filemap.hpp"
43 #include "memory/heapShared.hpp"
44 #include "memory/metadataFactory.hpp"
45 #include "memory/metaspaceClosure.hpp"
46 #include "memory/oopFactory.hpp"
47 #include "memory/resourceArea.hpp"
48 #include "memory/universe.hpp"
49 #include "memory/dynamicArchive.hpp"
50 #include "oops/instanceKlass.hpp"
51 #include "oops/klass.inline.hpp"
52 #include "oops/objArrayOop.inline.hpp"
53 #include "oops/oop.inline.hpp"
54 #include "oops/typeArrayOop.inline.hpp"
55 #include "runtime/handles.inline.hpp"
56 #include "runtime/java.hpp"
57 #include "runtime/javaCalls.hpp"
58 #include "runtime/mutexLocker.hpp"
59 #include "utilities/hashtable.inline.hpp"
60 #include "utilities/resourceHash.hpp"
61 #include "utilities/stringUtils.hpp"
62
63
64 OopHandle SystemDictionaryShared::_shared_protection_domains = NULL;
65 OopHandle SystemDictionaryShared::_shared_jar_urls = NULL;
66 OopHandle SystemDictionaryShared::_shared_jar_manifests = NULL;
67 DEBUG_ONLY(bool SystemDictionaryShared::_no_class_loading_should_happen = false;)
68
69 class DumpTimeSharedClassInfo: public CHeapObj<mtClass> {
79 DTLoaderConstraint() : _name(NULL), _loader_type1('0'), _loader_type2('0') {}
80 bool equals(const DTLoaderConstraint& t) {
81 return t._name == _name &&
82 ((t._loader_type1 == _loader_type1 && t._loader_type2 == _loader_type2) ||
83 (t._loader_type2 == _loader_type1 && t._loader_type1 == _loader_type2));
84 }
85 };
86
87 struct DTVerifierConstraint {
88 Symbol* _name;
89 Symbol* _from_name;
90 DTVerifierConstraint() : _name(NULL), _from_name(NULL) {}
91 DTVerifierConstraint(Symbol* n, Symbol* fn) : _name(n), _from_name(fn) {
92 _name->increment_refcount();
93 _from_name->increment_refcount();
94 }
95 };
96
97 InstanceKlass* _klass;
98 bool _failed_verification;
99 int _id;
100 int _clsfile_size;
101 int _clsfile_crc32;
102 GrowableArray<DTVerifierConstraint>* _verifier_constraints;
103 GrowableArray<char>* _verifier_constraint_flags;
104 GrowableArray<DTLoaderConstraint>* _loader_constraints;
105
106 DumpTimeSharedClassInfo() {
107 _klass = NULL;
108 _failed_verification = false;
109 _id = -1;
110 _clsfile_size = -1;
111 _clsfile_crc32 = -1;
112 _excluded = false;
113 _verifier_constraints = NULL;
114 _verifier_constraint_flags = NULL;
115 _loader_constraints = NULL;
116 }
117
118 void add_verification_constraint(InstanceKlass* k, Symbol* name,
119 Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object);
120 void record_linking_constraint(Symbol* name, Handle loader1, Handle loader2);
121
122 bool is_builtin() {
123 return SystemDictionaryShared::is_builtin(_klass);
124 }
125
126 int num_verifier_constraints() {
127 if (_verifier_constraint_flags != NULL) {
128 return _verifier_constraint_flags->length();
225 return true; // keep on iterating
226 }
227 };
228
229 void update_counts() {
230 _builtin_count = 0;
231 _unregistered_count = 0;
232 CountClassByCategory counter(this);
233 iterate(&counter);
234 }
235
236 int count_of(bool is_builtin) const {
237 if (is_builtin) {
238 return _builtin_count;
239 } else {
240 return _unregistered_count;
241 }
242 }
243 };
244
245 class RunTimeSharedClassInfo {
246 public:
247 struct CrcInfo {
248 int _clsfile_size;
249 int _clsfile_crc32;
250 };
251
252 // This is different than DumpTimeSharedClassInfo::DTVerifierConstraint. We use
253 // u4 instead of Symbol* to save space on 64-bit CPU.
254 struct RTVerifierConstraint {
255 u4 _name;
256 u4 _from_name;
257 Symbol* name() { return (Symbol*)(SharedBaseAddress + _name);}
258 Symbol* from_name() { return (Symbol*)(SharedBaseAddress + _from_name); }
259 };
260
261 struct RTLoaderConstraint {
262 u4 _name;
263 char _loader_type1;
264 char _loader_type2;
265 Symbol* constraint_name() {
266 return (Symbol*)(SharedBaseAddress + _name);
267 }
268 };
269
270 InstanceKlass* _klass;
271 int _num_verifier_constraints;
272 int _num_loader_constraints;
273
274 // optional CrcInfo _crc; (only for UNREGISTERED classes)
275 // optional RTLoaderConstraint _loader_constraint_types[_num_loader_constraints]
276 // optional RTVerifierConstraint _verifier_constraints[_num_verifier_constraints]
277 // optional char _verifier_constraint_flags[_num_verifier_constraints]
278
279 private:
280 static size_t header_size_size() {
281 return sizeof(RunTimeSharedClassInfo);
282 }
283 static size_t crc_size(InstanceKlass* klass) {
284 if (!SystemDictionaryShared::is_builtin(klass)) {
285 return sizeof(CrcInfo);
286 } else {
287 return 0;
288 }
289 }
290 static size_t verifier_constraints_size(int num_verifier_constraints) {
291 return sizeof(RTVerifierConstraint) * num_verifier_constraints;
292 }
293 static size_t verifier_constraint_flags_size(int num_verifier_constraints) {
294 return sizeof(char) * num_verifier_constraints;
295 }
296 static size_t loader_constraints_size(int num_loader_constraints) {
297 return sizeof(RTLoaderConstraint) * num_loader_constraints;
298 }
299
300 public:
301 static size_t byte_size(InstanceKlass* klass, int num_verifier_constraints, int num_loader_constraints) {
302 return header_size_size() +
303 crc_size(klass) +
304 loader_constraints_size(num_loader_constraints) +
305 verifier_constraints_size(num_verifier_constraints) +
306 verifier_constraint_flags_size(num_verifier_constraints);
307 }
308
309 private:
310 size_t crc_offset() const {
311 return header_size_size();
312 }
313
314 size_t loader_constraints_offset() const {
315 return crc_offset() + crc_size(_klass);
316 }
317 size_t verifier_constraints_offset() const {
318 return loader_constraints_offset() + loader_constraints_size(_num_loader_constraints);
319 }
320 size_t verifier_constraint_flags_offset() const {
321 return verifier_constraints_offset() + verifier_constraints_size(_num_verifier_constraints);
322 }
323
324 void check_verifier_constraint_offset(int i) const {
325 assert(0 <= i && i < _num_verifier_constraints, "sanity");
326 }
327
328 void check_loader_constraint_offset(int i) const {
329 assert(0 <= i && i < _num_loader_constraints, "sanity");
330 }
331
332 public:
333 CrcInfo* crc() const {
334 assert(crc_size(_klass) > 0, "must be");
335 return (CrcInfo*)(address(this) + crc_offset());
336 }
337 RTVerifierConstraint* verifier_constraints() {
338 assert(_num_verifier_constraints > 0, "sanity");
339 return (RTVerifierConstraint*)(address(this) + verifier_constraints_offset());
340 }
341 RTVerifierConstraint* verifier_constraint_at(int i) {
342 check_verifier_constraint_offset(i);
343 return verifier_constraints() + i;
344 }
345
346 char* verifier_constraint_flags() {
347 assert(_num_verifier_constraints > 0, "sanity");
348 return (char*)(address(this) + verifier_constraint_flags_offset());
349 }
350
351 RTLoaderConstraint* loader_constraints() {
352 assert(_num_loader_constraints > 0, "sanity");
353 return (RTLoaderConstraint*)(address(this) + loader_constraints_offset());
354 }
355
356 RTLoaderConstraint* loader_constraint_at(int i) {
357 check_loader_constraint_offset(i);
358 return loader_constraints() + i;
359 }
360
361 static u4 object_delta_u4(Symbol* sym) {
362 if (DynamicDumpSharedSpaces) {
363 sym = DynamicArchive::original_to_target(sym);
364 }
365 return MetaspaceShared::object_delta_u4(sym);
366 }
367
368 void init(DumpTimeSharedClassInfo& info) {
369 _klass = info._klass;
370 if (!SystemDictionaryShared::is_builtin(_klass)) {
379 RTVerifierConstraint* vf_constraints = verifier_constraints();
380 char* flags = verifier_constraint_flags();
381 for (i = 0; i < _num_verifier_constraints; i++) {
382 vf_constraints[i]._name = object_delta_u4(info._verifier_constraints->at(i)._name);
383 vf_constraints[i]._from_name = object_delta_u4(info._verifier_constraints->at(i)._from_name);
384 }
385 for (i = 0; i < _num_verifier_constraints; i++) {
386 flags[i] = info._verifier_constraint_flags->at(i);
387 }
388 }
389
390 if (_num_loader_constraints > 0) {
391 RTLoaderConstraint* ld_constraints = loader_constraints();
392 for (i = 0; i < _num_loader_constraints; i++) {
393 ld_constraints[i]._name = object_delta_u4(info._loader_constraints->at(i)._name);
394 ld_constraints[i]._loader_type1 = info._loader_constraints->at(i)._loader_type1;
395 ld_constraints[i]._loader_type2 = info._loader_constraints->at(i)._loader_type2;
396 }
397 }
398 if (DynamicDumpSharedSpaces) {
399 _klass = DynamicArchive::original_to_target(info._klass);
400 }
401 ArchivePtrMarker::mark_pointer(&_klass);
402 }
403
404 bool matches(int clsfile_size, int clsfile_crc32) const {
405 return crc()->_clsfile_size == clsfile_size &&
406 crc()->_clsfile_crc32 == clsfile_crc32;
407 }
408
409 char verifier_constraint_flag(int i) {
410 check_verifier_constraint_offset(i);
411 return verifier_constraint_flags()[i];
412 }
413
414 private:
415 // ArchiveCompactor::allocate() has reserved a pointer immediately before
416 // archived InstanceKlasses. We can use this slot to do a quick
417 // lookup of InstanceKlass* -> RunTimeSharedClassInfo* without
418 // building a new hashtable.
419 //
420 // info_pointer_addr(klass) --> 0x0100 RunTimeSharedClassInfo*
421 // InstanceKlass* klass --> 0x0108 <C++ vtbl>
422 // 0x0110 fields from Klass ...
423 static RunTimeSharedClassInfo** info_pointer_addr(InstanceKlass* klass) {
424 return &((RunTimeSharedClassInfo**)klass)[-1];
425 }
426
427 public:
428 static RunTimeSharedClassInfo* get_for(InstanceKlass* klass) {
429 return *info_pointer_addr(klass);
430 }
431 static void set_for(InstanceKlass* klass, RunTimeSharedClassInfo* record) {
432 if (DynamicDumpSharedSpaces) {
433 klass = DynamicArchive::original_to_buffer(klass);
434 *info_pointer_addr(klass) = DynamicArchive::buffer_to_target(record);
435 } else {
436 *info_pointer_addr(klass) = record;
437 }
438
439 ArchivePtrMarker::mark_pointer(info_pointer_addr(klass));
440 }
441
442 // Used by RunTimeSharedDictionary to implement OffsetCompactHashtable::EQUALS
443 static inline bool EQUALS(
444 const RunTimeSharedClassInfo* value, Symbol* key, int len_unused) {
445 return (value->_klass->name() == key);
446 }
447 };
448
1131 if (ld._name != NULL) {
1132 ld._name->decrement_refcount();
1133 }
1134 }
1135 FREE_C_HEAP_ARRAY(DumpTimeSharedClassInfo::DTLoaderConstraint, p->_loader_constraints);
1136 p->_loader_constraints = NULL;
1137 }
1138 _dumptime_table->remove(k);
1139 }
1140
1141 bool SystemDictionaryShared::is_jfr_event_class(InstanceKlass *k) {
1142 while (k) {
1143 if (k->name()->equals("jdk/internal/event/Event")) {
1144 return true;
1145 }
1146 k = k->java_super();
1147 }
1148 return false;
1149 }
1150
1151 void SystemDictionaryShared::warn_excluded(InstanceKlass* k, const char* reason) {
1152 ResourceMark rm;
1153 log_warning(cds)("Skipping %s: %s", k->name()->as_C_string(), reason);
1154 }
1155
1156 bool SystemDictionaryShared::should_be_excluded(InstanceKlass* k) {
1157 if (k->is_hidden() || k->is_unsafe_anonymous()) {
1158 warn_excluded(k, "Hidden or Unsafe anonymous class");
1159 return true; // hidden and unsafe anonymous classes are not archived, skip
1160 }
1161 if (k->is_in_error_state()) {
1162 warn_excluded(k, "In error state");
1163 return true;
1164 }
1165 if (k->has_been_redefined()) {
1166 warn_excluded(k, "Has been redefined");
1167 return true;
1168 }
1169 if (k->shared_classpath_index() < 0 && is_builtin(k)) {
1170 // These are classes loaded from unsupported locations (such as those loaded by JVMTI native
1171 // agent during dump time).
1172 warn_excluded(k, "Unsupported location");
1173 return true;
1174 }
1175 if (k->signers() != NULL) {
1176 // We cannot include signed classes in the archive because the certificates
1177 // used during dump time may be different than those used during
1178 // runtime (due to expiration, etc).
1179 warn_excluded(k, "Signed JAR");
1180 return true;
1181 }
1182 if (is_jfr_event_class(k)) {
1183 // We cannot include JFR event classes because they need runtime-specific
1184 // instrumentation in order to work with -XX:FlightRecorderOptions=retransform=false.
1185 // There are only a small number of these classes, so it's not worthwhile to
1186 // support them and make CDS more complicated.
1187 warn_excluded(k, "JFR event class");
1188 return true;
1189 }
1202 warn_excluded(k, "Failed verification");
1203 } else {
1204 warn_excluded(k, "Not linked");
1205 }
1206 return true;
1207 }
1208 if (k->major_version() < 50 /*JAVA_6_VERSION*/) {
1209 ResourceMark rm;
1210 log_warning(cds)("Pre JDK 6 class not supported by CDS: %u.%u %s",
1211 k->major_version(), k->minor_version(), k->name()->as_C_string());
1212 return true;
1213 }
1214
1215 InstanceKlass* super = k->java_super();
1216 if (super != NULL && should_be_excluded(super)) {
1217 ResourceMark rm;
1218 log_warning(cds)("Skipping %s: super class %s is excluded", k->name()->as_C_string(), super->name()->as_C_string());
1219 return true;
1220 }
1221
1222 Array<InstanceKlass*>* interfaces = k->local_interfaces();
1223 int len = interfaces->length();
1224 for (int i = 0; i < len; i++) {
1225 InstanceKlass* intf = interfaces->at(i);
1226 if (should_be_excluded(intf)) {
1227 log_warning(cds)("Skipping %s: interface %s is excluded", k->name()->as_C_string(), intf->name()->as_C_string());
1228 return true;
1229 }
1230 }
1231
1232 return false;
1233 }
1234
1235 // k is a class before relocating by ArchiveCompactor
1236 void SystemDictionaryShared::validate_before_archiving(InstanceKlass* k) {
1237 ResourceMark rm;
1238 const char* name = k->name()->as_C_string();
1239 DumpTimeSharedClassInfo* info = _dumptime_table->get(k);
1240 assert(_no_class_loading_should_happen, "class loading must be disabled");
1241 guarantee(info != NULL, "Class %s must be entered into _dumptime_table", name);
1242 guarantee(!info->is_excluded(), "Should not attempt to archive excluded class %s", name);
1243 if (is_builtin(k)) {
1244 guarantee(!k->is_shared_unregistered_class(),
1245 "Class loader type must be set for BUILTIN class %s", name);
1246 } else {
1247 guarantee(k->is_shared_unregistered_class(),
1248 "Class loader type must not be set for UNREGISTERED class %s", name);
1249 }
1250 }
1251
1252 class ExcludeDumpTimeSharedClasses : StackObj {
1253 public:
1254 bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) {
1255 if (SystemDictionaryShared::should_be_excluded(k)) {
1256 info.set_excluded();
1257 }
1258 return true; // keep on iterating
1259 }
1260 };
1261
1262 void SystemDictionaryShared::check_excluded_classes() {
1263 ExcludeDumpTimeSharedClasses excl;
1264 _dumptime_table->iterate(&excl);
1265 _dumptime_table->update_counts();
1341 }
1342 GrowableArray<DTVerifierConstraint>* vc_array = _verifier_constraints;
1343 for (int i = 0; i < vc_array->length(); i++) {
1344 DTVerifierConstraint* p = vc_array->adr_at(i);
1345 if (name == p->_name && from_name == p->_from_name) {
1346 return;
1347 }
1348 }
1349 DTVerifierConstraint cons(name, from_name);
1350 vc_array->append(cons);
1351
1352 GrowableArray<char>* vcflags_array = _verifier_constraint_flags;
1353 char c = 0;
1354 c |= from_field_is_protected ? SystemDictionaryShared::FROM_FIELD_IS_PROTECTED : 0;
1355 c |= from_is_array ? SystemDictionaryShared::FROM_IS_ARRAY : 0;
1356 c |= from_is_object ? SystemDictionaryShared::FROM_IS_OBJECT : 0;
1357 vcflags_array->append(c);
1358
1359 if (log_is_enabled(Trace, cds, verification)) {
1360 ResourceMark rm;
1361 log_trace(cds, verification)("add_verification_constraint: %s: %s must be subclass of %s [0x%x]",
1362 k->external_name(), from_name->as_klass_external_name(),
1363 name->as_klass_external_name(), c);
1364 }
1365 }
1366
1367 static char get_loader_type_by(oop loader) {
1368 assert(SystemDictionary::is_builtin_class_loader(loader), "Must be built-in loader");
1369 if (SystemDictionary::is_boot_class_loader(loader)) {
1370 return (char)ClassLoader::BOOT_LOADER;
1371 } else if (SystemDictionary::is_platform_class_loader(loader)) {
1372 return (char)ClassLoader::PLATFORM_LOADER;
1373 } else {
1374 assert(SystemDictionary::is_system_class_loader(loader), "Class loader mismatch");
1375 return (char)ClassLoader::APP_LOADER;
1376 }
1377 }
1378
1379 static oop get_class_loader_by(char type) {
1380 if (type == (char)ClassLoader::BOOT_LOADER) {
1381 return (oop)NULL;
1382 } else if (type == (char)ClassLoader::PLATFORM_LOADER) {
1383 return SystemDictionary::java_platform_loader();
1384 } else {
1577 _num_builtin_klasses = 0;
1578 _num_unregistered_klasses = 0;
1579 }
1580
1581 bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) {
1582 if (!info.is_excluded()) {
1583 size_t byte_size = RunTimeSharedClassInfo::byte_size(info._klass, info.num_verifier_constraints(), info.num_loader_constraints());
1584 _shared_class_info_size += align_up(byte_size, BytesPerWord);
1585 }
1586 return true; // keep on iterating
1587 }
1588
1589 size_t total() {
1590 return _shared_class_info_size;
1591 }
1592 };
1593
1594 size_t SystemDictionaryShared::estimate_size_for_archive() {
1595 EstimateSizeForArchive est;
1596 _dumptime_table->iterate(&est);
1597 return est.total() +
1598 CompactHashtableWriter::estimate_size(_dumptime_table->count_of(true)) +
1599 CompactHashtableWriter::estimate_size(_dumptime_table->count_of(false));
1600 }
1601
1602 class CopySharedClassInfoToArchive : StackObj {
1603 CompactHashtableWriter* _writer;
1604 bool _is_builtin;
1605 public:
1606 CopySharedClassInfoToArchive(CompactHashtableWriter* writer,
1607 bool is_builtin,
1608 bool is_static_archive)
1609 : _writer(writer), _is_builtin(is_builtin) {}
1610
1611 bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) {
1612 if (!info.is_excluded() && info.is_builtin() == _is_builtin) {
1613 size_t byte_size = RunTimeSharedClassInfo::byte_size(info._klass, info.num_verifier_constraints(), info.num_loader_constraints());
1614 RunTimeSharedClassInfo* record;
1615 record = (RunTimeSharedClassInfo*)MetaspaceShared::read_only_space_alloc(byte_size);
1616 record->init(info);
1617
1618 unsigned int hash;
1619 Symbol* name = info._klass->name();
1620 if (DynamicDumpSharedSpaces) {
1621 name = DynamicArchive::original_to_target(name);
1622 }
1623 hash = SystemDictionaryShared::hash_for_shared_dictionary(name);
1624 u4 delta;
1625 if (DynamicDumpSharedSpaces) {
1626 delta = MetaspaceShared::object_delta_u4(DynamicArchive::buffer_to_target(record));
1627 } else {
1628 delta = MetaspaceShared::object_delta_u4(record);
1629 }
1630 _writer->add(hash, delta);
1631 if (log_is_enabled(Trace, cds, hashtables)) {
1632 ResourceMark rm;
1633 log_trace(cds,hashtables)("%s dictionary: %s", (_is_builtin ? "builtin" : "unregistered"), info._klass->external_name());
1634 }
1635
1636 // Save this for quick runtime lookup of InstanceKlass* -> RunTimeSharedClassInfo*
1637 RunTimeSharedClassInfo::set_for(info._klass, record);
1638 }
1639 return true; // keep on iterating
1640 }
1641 };
1642
1643 void SystemDictionaryShared::write_dictionary(RunTimeSharedDictionary* dictionary,
1644 bool is_builtin,
1645 bool is_static_archive) {
1646 CompactHashtableStats stats;
1647 dictionary->reset();
1648 CompactHashtableWriter writer(_dumptime_table->count_of(is_builtin), &stats);
1649 CopySharedClassInfoToArchive copy(&writer, is_builtin, is_static_archive);
1650 _dumptime_table->iterate(©);
1651 writer.dump(dictionary, is_builtin ? "builtin dictionary" : "unregistered dictionary");
1652 }
1653
1654 void SystemDictionaryShared::write_to_archive(bool is_static_archive) {
1655 if (is_static_archive) {
1656 write_dictionary(&_builtin_dictionary, true);
1657 write_dictionary(&_unregistered_dictionary, false);
1658 } else {
1659 write_dictionary(&_dynamic_builtin_dictionary, true);
1660 write_dictionary(&_dynamic_unregistered_dictionary, false);
1661 }
1662 }
1663
1664 void SystemDictionaryShared::serialize_dictionary_headers(SerializeClosure* soc,
1665 bool is_static_archive) {
1666 if (is_static_archive) {
1667 _builtin_dictionary.serialize_header(soc);
1668 _unregistered_dictionary.serialize_header(soc);
1669 } else {
1670 _dynamic_builtin_dictionary.serialize_header(soc);
1671 _dynamic_unregistered_dictionary.serialize_header(soc);
1672 }
1673 }
1674
1675 void SystemDictionaryShared::serialize_well_known_klasses(SerializeClosure* soc) {
1676 for (int i = FIRST_WKID; i < WKID_LIMIT; i++) {
1677 soc->do_ptr((void**)&_well_known_klasses[i]);
1678 }
1679 }
1680
1681 const RunTimeSharedClassInfo*
1682 SystemDictionaryShared::find_record(RunTimeSharedDictionary* static_dict, RunTimeSharedDictionary* dynamic_dict, Symbol* name) {
1683 if (!UseSharedSpaces || !name->is_shared()) {
1684 // The names of all shared classes must also be a shared Symbol.
1685 return NULL;
1686 }
1687
1688 unsigned int hash = SystemDictionaryShared::hash_for_shared_dictionary(name);
1689 const RunTimeSharedClassInfo* record = NULL;
1690 if (!MetaspaceShared::is_shared_dynamic(name)) {
1691 // The names of all shared classes in the static dict must also be in the
1692 // static archive
1693 record = static_dict->lookup(name, hash, 0);
1694 }
1695
1696 if (record == NULL && DynamicArchive::is_mapped()) {
1697 record = dynamic_dict->lookup(name, hash, 0);
1698 }
1699
1700 return record;
1701 }
1702
1703 InstanceKlass* SystemDictionaryShared::find_builtin_class(Symbol* name) {
1704 const RunTimeSharedClassInfo* record = find_record(&_builtin_dictionary, &_dynamic_builtin_dictionary, name);
1705 if (record != NULL) {
1706 return record->_klass;
1707 } else {
1708 return NULL;
1709 }
1710 }
1711
1712 void SystemDictionaryShared::update_shared_entry(InstanceKlass* k, int id) {
1713 assert(DumpSharedSpaces, "supported only when dumping");
1714 DumpTimeSharedClassInfo* info = find_or_allocate_info_for(k);
1715 info->_id = id;
1716 }
1717
1718 class SharedDictionaryPrinter : StackObj {
1719 outputStream* _st;
1720 int _index;
1721 public:
1722 SharedDictionaryPrinter(outputStream* st) : _st(st), _index(0) {}
1723
1724 void do_value(const RunTimeSharedClassInfo* record) {
1725 ResourceMark rm;
1726 _st->print_cr("%4d: %s", (_index++), record->_klass->external_name());
1727 }
1728 };
1729
1730 void SystemDictionaryShared::print_on(outputStream* st) {
1731 if (UseSharedSpaces) {
1732 st->print_cr("Shared Dictionary");
1733 SharedDictionaryPrinter p(st);
1734 _builtin_dictionary.iterate(&p);
1735 _unregistered_dictionary.iterate(&p);
1736 if (DynamicArchive::is_mapped()) {
1737 _dynamic_builtin_dictionary.iterate(&p);
1738 _unregistered_dictionary.iterate(&p);
1739 }
1740 }
1741 }
1742
1743 void SystemDictionaryShared::print_table_statistics(outputStream* st) {
1744 if (UseSharedSpaces) {
1745 _builtin_dictionary.print_table_statistics(st, "Builtin Shared Dictionary");
1746 _unregistered_dictionary.print_table_statistics(st, "Unregistered Shared Dictionary");
1747 if (DynamicArchive::is_mapped()) {
1748 _dynamic_builtin_dictionary.print_table_statistics(st, "Dynamic Builtin Shared Dictionary");
1749 _dynamic_unregistered_dictionary.print_table_statistics(st, "Unregistered Shared Dictionary");
1750 }
1751 }
1752 }
1753
1754 bool SystemDictionaryShared::empty_dumptime_table() {
1755 if (_dumptime_table == NULL) {
1756 return true;
1757 }
1758 _dumptime_table->update_counts();
1759 if (_dumptime_table->count_of(true) == 0 && _dumptime_table->count_of(false) == 0){
1760 return true;
1761 }
1762 return false;
1763 }
1764
1765 #if INCLUDE_CDS_JAVA_HEAP
1766
1767 class ArchivedMirrorPatcher {
1768 static void update(Klass* k) {
1769 if (k->has_raw_archived_mirror()) {
|
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/classFileStream.hpp"
27 #include "classfile/classListParser.hpp"
28 #include "classfile/classLoader.hpp"
29 #include "classfile/classLoaderData.inline.hpp"
30 #include "classfile/classLoaderDataGraph.hpp"
31 #include "classfile/classLoaderExt.hpp"
32 #include "classfile/dictionary.hpp"
33 #include "classfile/javaClasses.hpp"
34 #include "classfile/symbolTable.hpp"
35 #include "classfile/systemDictionary.hpp"
36 #include "classfile/systemDictionaryShared.hpp"
37 #include "classfile/verificationType.hpp"
38 #include "classfile/vmSymbols.hpp"
39 #include "jfr/jfrEvents.hpp"
40 #include "logging/log.hpp"
41 #include "memory/allocation.hpp"
42 #include "memory/archiveUtils.hpp"
43 #include "memory/dynamicArchive.hpp"
44 #include "memory/filemap.hpp"
45 #include "memory/heapShared.hpp"
46 #include "memory/metadataFactory.hpp"
47 #include "memory/metaspaceClosure.hpp"
48 #include "memory/oopFactory.hpp"
49 #include "memory/resourceArea.hpp"
50 #include "memory/universe.hpp"
51 #include "oops/instanceKlass.hpp"
52 #include "oops/klass.inline.hpp"
53 #include "oops/objArrayOop.inline.hpp"
54 #include "oops/oop.inline.hpp"
55 #include "oops/typeArrayOop.inline.hpp"
56 #include "runtime/handles.inline.hpp"
57 #include "runtime/java.hpp"
58 #include "runtime/javaCalls.hpp"
59 #include "runtime/mutexLocker.hpp"
60 #include "utilities/hashtable.inline.hpp"
61 #include "utilities/resourceHash.hpp"
62 #include "utilities/stringUtils.hpp"
63
64
65 OopHandle SystemDictionaryShared::_shared_protection_domains = NULL;
66 OopHandle SystemDictionaryShared::_shared_jar_urls = NULL;
67 OopHandle SystemDictionaryShared::_shared_jar_manifests = NULL;
68 DEBUG_ONLY(bool SystemDictionaryShared::_no_class_loading_should_happen = false;)
69
70 class DumpTimeSharedClassInfo: public CHeapObj<mtClass> {
80 DTLoaderConstraint() : _name(NULL), _loader_type1('0'), _loader_type2('0') {}
81 bool equals(const DTLoaderConstraint& t) {
82 return t._name == _name &&
83 ((t._loader_type1 == _loader_type1 && t._loader_type2 == _loader_type2) ||
84 (t._loader_type2 == _loader_type1 && t._loader_type1 == _loader_type2));
85 }
86 };
87
88 struct DTVerifierConstraint {
89 Symbol* _name;
90 Symbol* _from_name;
91 DTVerifierConstraint() : _name(NULL), _from_name(NULL) {}
92 DTVerifierConstraint(Symbol* n, Symbol* fn) : _name(n), _from_name(fn) {
93 _name->increment_refcount();
94 _from_name->increment_refcount();
95 }
96 };
97
98 InstanceKlass* _klass;
99 bool _failed_verification;
100 bool _is_archived_lambda_proxy;
101 int _id;
102 int _clsfile_size;
103 int _clsfile_crc32;
104 GrowableArray<DTVerifierConstraint>* _verifier_constraints;
105 GrowableArray<char>* _verifier_constraint_flags;
106 GrowableArray<DTLoaderConstraint>* _loader_constraints;
107
108 DumpTimeSharedClassInfo() {
109 _klass = NULL;
110 _failed_verification = false;
111 _is_archived_lambda_proxy = false;
112 _id = -1;
113 _clsfile_size = -1;
114 _clsfile_crc32 = -1;
115 _excluded = false;
116 _verifier_constraints = NULL;
117 _verifier_constraint_flags = NULL;
118 _loader_constraints = NULL;
119 }
120
121 void add_verification_constraint(InstanceKlass* k, Symbol* name,
122 Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object);
123 void record_linking_constraint(Symbol* name, Handle loader1, Handle loader2);
124
125 bool is_builtin() {
126 return SystemDictionaryShared::is_builtin(_klass);
127 }
128
129 int num_verifier_constraints() {
130 if (_verifier_constraint_flags != NULL) {
131 return _verifier_constraint_flags->length();
228 return true; // keep on iterating
229 }
230 };
231
232 void update_counts() {
233 _builtin_count = 0;
234 _unregistered_count = 0;
235 CountClassByCategory counter(this);
236 iterate(&counter);
237 }
238
239 int count_of(bool is_builtin) const {
240 if (is_builtin) {
241 return _builtin_count;
242 } else {
243 return _unregistered_count;
244 }
245 }
246 };
247
248 class LambdaProxyClassKey {
249 template <typename T> static void original_to_target(T& field) {
250 if (field != NULL) {
251 field = DynamicArchive::original_to_target(field);
252 ArchivePtrMarker::mark_pointer(&field);
253 }
254 }
255
256 InstanceKlass* _caller_ik;
257 Symbol* _invoked_name;
258 Symbol* _invoked_type;
259 Symbol* _method_type;
260 Method* _member_method;
261 Symbol* _instantiated_method_type;
262
263 public:
264 LambdaProxyClassKey(InstanceKlass* caller_ik,
265 Symbol* invoked_name,
266 Symbol* invoked_type,
267 Symbol* method_type,
268 Method* member_method,
269 Symbol* instantiated_method_type) :
270 _caller_ik(caller_ik),
271 _invoked_name(invoked_name),
272 _invoked_type(invoked_type),
273 _method_type(method_type),
274 _member_method(member_method),
275 _instantiated_method_type(instantiated_method_type) {}
276
277 void original_to_target() {
278 original_to_target(_caller_ik);
279 original_to_target(_instantiated_method_type);
280 original_to_target(_invoked_name);
281 original_to_target(_invoked_type);
282 original_to_target(_member_method);
283 original_to_target(_method_type);
284 }
285
286 bool equals(LambdaProxyClassKey const& other) const {
287 return _caller_ik == other._caller_ik &&
288 _invoked_name == other._invoked_name &&
289 _invoked_type == other._invoked_type &&
290 _method_type == other._method_type &&
291 _member_method == other._member_method &&
292 _instantiated_method_type == other._instantiated_method_type;
293 }
294
295 unsigned int hash() const {
296 return SystemDictionaryShared::hash_for_shared_dictionary(_caller_ik) +
297 SystemDictionaryShared::hash_for_shared_dictionary(_invoked_name) +
298 SystemDictionaryShared::hash_for_shared_dictionary(_invoked_type) +
299 SystemDictionaryShared::hash_for_shared_dictionary(_method_type) +
300 SystemDictionaryShared::hash_for_shared_dictionary(_instantiated_method_type);
301 }
302
303 unsigned int dumptime_hash() const {
304 return primitive_hash<InstanceKlass*>(_caller_ik) +
305 primitive_hash<Symbol*>(_invoked_name) +
306 primitive_hash<Symbol*>(_invoked_type) +
307 primitive_hash<Symbol*>(_method_type) +
308 primitive_hash<Symbol*>(_instantiated_method_type);
309 }
310
311 static inline unsigned int DUMPTIME_HASH(LambdaProxyClassKey const& key) {
312 return (key.dumptime_hash());
313 }
314
315 static inline bool DUMPTIME_EQUALS(
316 LambdaProxyClassKey const& k1, LambdaProxyClassKey const& k2) {
317 return (k1.equals(k2));
318 }
319 };
320
321
322 class DumpTimeLambdaProxyClassInfo {
323 public:
324 GrowableArray<InstanceKlass*>* _proxy_klasses;
325 DumpTimeLambdaProxyClassInfo() : _proxy_klasses(NULL) {}
326 void add_proxy_klass(InstanceKlass* proxy_klass) {
327 if (_proxy_klasses == NULL) {
328 _proxy_klasses = new (ResourceObj::C_HEAP, mtInternal)GrowableArray<InstanceKlass*>(5, true);
329 }
330 assert(_proxy_klasses != NULL, "sanity");
331 _proxy_klasses->append(proxy_klass);
332 }
333 };
334
335 class RunTimeLambdaProxyClassInfo {
336 LambdaProxyClassKey _key;
337 InstanceKlass* _proxy_klass_head;
338 public:
339 RunTimeLambdaProxyClassInfo(LambdaProxyClassKey key, InstanceKlass* proxy_klass) :
340 _key(key), _proxy_klass_head(proxy_klass) {}
341
342 InstanceKlass* proxy_klass_head() const { return _proxy_klass_head; }
343
344 // Used by LambdaProxyClassDictionary to implement OffsetCompactHashtable::EQUALS
345 static inline bool EQUALS(
346 const RunTimeLambdaProxyClassInfo* value, LambdaProxyClassKey* key, int len_unused) {
347 return (value->_key.equals(*key));
348 }
349 void init(LambdaProxyClassKey& key, DumpTimeLambdaProxyClassInfo& info) {
350 _key = key;
351 _key.original_to_target();
352 _proxy_klass_head = DynamicArchive::original_to_target(info._proxy_klasses->at(0));
353 ArchivePtrMarker::mark_pointer(&_proxy_klass_head);
354 }
355
356 unsigned int hash() const {
357 return _key.hash();
358 }
359 };
360
361 class LambdaProxyClassDictionary : public OffsetCompactHashtable<
362 LambdaProxyClassKey*,
363 const RunTimeLambdaProxyClassInfo*,
364 RunTimeLambdaProxyClassInfo::EQUALS> {};
365
366 LambdaProxyClassDictionary _lambda_proxy_class_dictionary;
367
368 class DumpTimeLambdaProxyClassDictionary
369 : public ResourceHashtable<LambdaProxyClassKey,
370 DumpTimeLambdaProxyClassInfo,
371 LambdaProxyClassKey::DUMPTIME_HASH,
372 LambdaProxyClassKey::DUMPTIME_EQUALS,
373 137, // prime number
374 ResourceObj::C_HEAP> {
375 public:
376 int _count;
377 };
378
379 DumpTimeLambdaProxyClassDictionary* _dumptime_lambda_proxy_class_dictionary = NULL;
380
381 static void add_to_dump_time_lambda_proxy_class_dictionary(LambdaProxyClassKey key,
382 InstanceKlass* proxy_klass) {
383 assert(DumpTimeTable_lock->owned_by_self(), "sanity");
384 if (_dumptime_lambda_proxy_class_dictionary == NULL) {
385 _dumptime_lambda_proxy_class_dictionary =
386 new (ResourceObj::C_HEAP, mtClass)DumpTimeLambdaProxyClassDictionary();
387 }
388 DumpTimeLambdaProxyClassInfo* lambda_info = _dumptime_lambda_proxy_class_dictionary->get(key);
389 if (lambda_info == NULL) {
390 DumpTimeLambdaProxyClassInfo info;
391 info.add_proxy_klass(proxy_klass);
392 _dumptime_lambda_proxy_class_dictionary->put(key, info);
393 //lambda_info = _dumptime_lambda_proxy_class_dictionary->get(key);
394 //assert(lambda_info->_proxy_klass == proxy_klass, "must be"); // debug only -- remove
395 ++_dumptime_lambda_proxy_class_dictionary->_count;
396 } else {
397 lambda_info->add_proxy_klass(proxy_klass);
398 }
399 }
400
401 class RunTimeSharedClassInfo {
402 public:
403 struct CrcInfo {
404 int _clsfile_size;
405 int _clsfile_crc32;
406 };
407
408 // This is different than DumpTimeSharedClassInfo::DTVerifierConstraint. We use
409 // u4 instead of Symbol* to save space on 64-bit CPU.
410 struct RTVerifierConstraint {
411 u4 _name;
412 u4 _from_name;
413 Symbol* name() { return (Symbol*)(SharedBaseAddress + _name);}
414 Symbol* from_name() { return (Symbol*)(SharedBaseAddress + _from_name); }
415 };
416
417 struct RTLoaderConstraint {
418 u4 _name;
419 char _loader_type1;
420 char _loader_type2;
421 Symbol* constraint_name() {
422 return (Symbol*)(SharedBaseAddress + _name);
423 }
424 };
425
426 InstanceKlass* _klass;
427 int _num_verifier_constraints;
428 int _num_loader_constraints;
429
430 // optional CrcInfo _crc; (only for UNREGISTERED classes)
431 // optional InstanceKlass* _nest_host
432 // optional RTLoaderConstraint _loader_constraint_types[_num_loader_constraints]
433 // optional RTVerifierConstraint _verifier_constraints[_num_verifier_constraints]
434 // optional char _verifier_constraint_flags[_num_verifier_constraints]
435
436 private:
437 static size_t header_size_size() {
438 return sizeof(RunTimeSharedClassInfo);
439 }
440 static size_t crc_size(InstanceKlass* klass) {
441 if (!SystemDictionaryShared::is_builtin(klass)) {
442 return sizeof(CrcInfo);
443 } else {
444 return 0;
445 }
446 }
447 static size_t verifier_constraints_size(int num_verifier_constraints) {
448 return sizeof(RTVerifierConstraint) * num_verifier_constraints;
449 }
450 static size_t verifier_constraint_flags_size(int num_verifier_constraints) {
451 return sizeof(char) * num_verifier_constraints;
452 }
453 static size_t loader_constraints_size(int num_loader_constraints) {
454 return sizeof(RTLoaderConstraint) * num_loader_constraints;
455 }
456 static size_t nest_host_size(InstanceKlass* klass) {
457 if (klass->is_hidden()) {
458 return sizeof(InstanceKlass*);
459 } else {
460 return 0;
461 }
462 }
463
464 public:
465 static size_t byte_size(InstanceKlass* klass, int num_verifier_constraints, int num_loader_constraints) {
466 return header_size_size() +
467 crc_size(klass) +
468 nest_host_size(klass) +
469 loader_constraints_size(num_loader_constraints) +
470 verifier_constraints_size(num_verifier_constraints) +
471 verifier_constraint_flags_size(num_verifier_constraints);
472 }
473
474 private:
475 size_t crc_offset() const {
476 return header_size_size();
477 }
478
479 size_t nest_host_offset() const {
480 return crc_offset() + crc_size(_klass);
481 }
482
483 size_t loader_constraints_offset() const {
484 return nest_host_offset() + nest_host_size(_klass);
485 }
486 size_t verifier_constraints_offset() const {
487 return loader_constraints_offset() + loader_constraints_size(_num_loader_constraints);
488 }
489 size_t verifier_constraint_flags_offset() const {
490 return verifier_constraints_offset() + verifier_constraints_size(_num_verifier_constraints);
491 }
492
493 void check_verifier_constraint_offset(int i) const {
494 assert(0 <= i && i < _num_verifier_constraints, "sanity");
495 }
496
497 void check_loader_constraint_offset(int i) const {
498 assert(0 <= i && i < _num_loader_constraints, "sanity");
499 }
500
501 public:
502 CrcInfo* crc() const {
503 assert(crc_size(_klass) > 0, "must be");
504 return (CrcInfo*)(address(this) + crc_offset());
505 }
506 RTVerifierConstraint* verifier_constraints() {
507 assert(_num_verifier_constraints > 0, "sanity");
508 return (RTVerifierConstraint*)(address(this) + verifier_constraints_offset());
509 }
510 RTVerifierConstraint* verifier_constraint_at(int i) {
511 check_verifier_constraint_offset(i);
512 return verifier_constraints() + i;
513 }
514
515 char* verifier_constraint_flags() {
516 assert(_num_verifier_constraints > 0, "sanity");
517 return (char*)(address(this) + verifier_constraint_flags_offset());
518 }
519
520 InstanceKlass** nest_host_addr() {
521 assert(_klass->is_hidden(), "sanity");
522 return (InstanceKlass**)(address(this) + nest_host_offset());
523 }
524 InstanceKlass* nest_host() {
525 return *nest_host_addr();
526 }
527 void set_nest_host(InstanceKlass* k) {
528 *nest_host_addr() = k;
529 ArchivePtrMarker::mark_pointer((address*)nest_host_addr());
530 }
531
532 RTLoaderConstraint* loader_constraints() {
533 assert(_num_loader_constraints > 0, "sanity");
534 return (RTLoaderConstraint*)(address(this) + loader_constraints_offset());
535 }
536
537 RTLoaderConstraint* loader_constraint_at(int i) {
538 check_loader_constraint_offset(i);
539 return loader_constraints() + i;
540 }
541
542 static u4 object_delta_u4(Symbol* sym) {
543 if (DynamicDumpSharedSpaces) {
544 sym = DynamicArchive::original_to_target(sym);
545 }
546 return MetaspaceShared::object_delta_u4(sym);
547 }
548
549 void init(DumpTimeSharedClassInfo& info) {
550 _klass = info._klass;
551 if (!SystemDictionaryShared::is_builtin(_klass)) {
560 RTVerifierConstraint* vf_constraints = verifier_constraints();
561 char* flags = verifier_constraint_flags();
562 for (i = 0; i < _num_verifier_constraints; i++) {
563 vf_constraints[i]._name = object_delta_u4(info._verifier_constraints->at(i)._name);
564 vf_constraints[i]._from_name = object_delta_u4(info._verifier_constraints->at(i)._from_name);
565 }
566 for (i = 0; i < _num_verifier_constraints; i++) {
567 flags[i] = info._verifier_constraint_flags->at(i);
568 }
569 }
570
571 if (_num_loader_constraints > 0) {
572 RTLoaderConstraint* ld_constraints = loader_constraints();
573 for (i = 0; i < _num_loader_constraints; i++) {
574 ld_constraints[i]._name = object_delta_u4(info._loader_constraints->at(i)._name);
575 ld_constraints[i]._loader_type1 = info._loader_constraints->at(i)._loader_type1;
576 ld_constraints[i]._loader_type2 = info._loader_constraints->at(i)._loader_type2;
577 }
578 }
579 if (DynamicDumpSharedSpaces) {
580 if (_klass->is_hidden()) {
581 Thread* THREAD = Thread::current();
582 InstanceKlass* n_h = _klass->nest_host(THREAD);
583 n_h = DynamicArchive::original_to_target(n_h);
584 set_nest_host(n_h);
585 }
586 _klass = DynamicArchive::original_to_target(info._klass);
587 }
588 ArchivePtrMarker::mark_pointer(&_klass);
589 }
590
591 bool matches(int clsfile_size, int clsfile_crc32) const {
592 return crc()->_clsfile_size == clsfile_size &&
593 crc()->_clsfile_crc32 == clsfile_crc32;
594 }
595
596 char verifier_constraint_flag(int i) {
597 check_verifier_constraint_offset(i);
598 return verifier_constraint_flags()[i];
599 }
600
601 private:
602 // ArchiveCompactor::allocate() has reserved a pointer immediately before
603 // archived InstanceKlasses. We can use this slot to do a quick
604 // lookup of InstanceKlass* -> RunTimeSharedClassInfo* without
605 // building a new hashtable.
606 //
607 // info_pointer_addr(klass) --> 0x0100 RunTimeSharedClassInfo*
608 // InstanceKlass* klass --> 0x0108 <C++ vtbl>
609 // 0x0110 fields from Klass ...
610 static RunTimeSharedClassInfo** info_pointer_addr(InstanceKlass* klass) {
611 return &((RunTimeSharedClassInfo**)klass)[-1];
612 }
613
614 public:
615 static RunTimeSharedClassInfo* get_for(InstanceKlass* klass) {
616 assert(klass->is_shared(), "don't call for non-shared class");
617 return *info_pointer_addr(klass);
618 }
619 static void set_for(InstanceKlass* klass, RunTimeSharedClassInfo* record) {
620 if (DynamicDumpSharedSpaces) {
621 klass = DynamicArchive::original_to_buffer(klass);
622 *info_pointer_addr(klass) = DynamicArchive::buffer_to_target(record);
623 } else {
624 *info_pointer_addr(klass) = record;
625 }
626
627 ArchivePtrMarker::mark_pointer(info_pointer_addr(klass));
628 }
629
630 // Used by RunTimeSharedDictionary to implement OffsetCompactHashtable::EQUALS
631 static inline bool EQUALS(
632 const RunTimeSharedClassInfo* value, Symbol* key, int len_unused) {
633 return (value->_klass->name() == key);
634 }
635 };
636
1319 if (ld._name != NULL) {
1320 ld._name->decrement_refcount();
1321 }
1322 }
1323 FREE_C_HEAP_ARRAY(DumpTimeSharedClassInfo::DTLoaderConstraint, p->_loader_constraints);
1324 p->_loader_constraints = NULL;
1325 }
1326 _dumptime_table->remove(k);
1327 }
1328
1329 bool SystemDictionaryShared::is_jfr_event_class(InstanceKlass *k) {
1330 while (k) {
1331 if (k->name()->equals("jdk/internal/event/Event")) {
1332 return true;
1333 }
1334 k = k->java_super();
1335 }
1336 return false;
1337 }
1338
1339 bool SystemDictionaryShared::is_registered_lambda_proxy_class(InstanceKlass* ik) {
1340 DumpTimeSharedClassInfo* info = _dumptime_table->get(ik);
1341 return (info != NULL) ? info->_is_archived_lambda_proxy : false;
1342 }
1343
1344 bool SystemDictionaryShared::is_in_shared_lambda_proxy_table(InstanceKlass* ik) {
1345 assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only");
1346 RunTimeSharedClassInfo* record = RunTimeSharedClassInfo::get_for(ik);
1347 if (record != NULL && record->nest_host() != NULL) {
1348 return true;
1349 } else {
1350 return false;
1351 }
1352 }
1353
1354 bool SystemDictionaryShared::is_hidden_lambda_proxy(InstanceKlass* ik) {
1355 assert(ik->is_shared(), "applicable to only a shared class");
1356 if (ik->is_hidden()) {
1357 return true;
1358 } else {
1359 return false;
1360 }
1361 }
1362
1363 void SystemDictionaryShared::warn_excluded(InstanceKlass* k, const char* reason) {
1364 ResourceMark rm;
1365 log_warning(cds)("Skipping %s: %s", k->name()->as_C_string(), reason);
1366 }
1367
1368 bool SystemDictionaryShared::should_be_excluded(InstanceKlass* k) {
1369
1370 if (k->is_unsafe_anonymous()) {
1371 warn_excluded(k, "Unsafe anonymous class");
1372 return true; // unsafe anonymous classes are not archived, skip
1373 }
1374
1375 if (k->is_in_error_state()) {
1376 warn_excluded(k, "In error state");
1377 return true;
1378 }
1379 if (k->has_been_redefined()) {
1380 warn_excluded(k, "Has been redefined");
1381 return true;
1382 }
1383 if (!k->is_hidden() && k->shared_classpath_index() < 0 && is_builtin(k)) {
1384 // These are classes loaded from unsupported locations (such as those loaded by JVMTI native
1385 // agent during dump time).
1386 warn_excluded(k, "Unsupported location");
1387 return true;
1388 }
1389 if (k->signers() != NULL) {
1390 // We cannot include signed classes in the archive because the certificates
1391 // used during dump time may be different than those used during
1392 // runtime (due to expiration, etc).
1393 warn_excluded(k, "Signed JAR");
1394 return true;
1395 }
1396 if (is_jfr_event_class(k)) {
1397 // We cannot include JFR event classes because they need runtime-specific
1398 // instrumentation in order to work with -XX:FlightRecorderOptions=retransform=false.
1399 // There are only a small number of these classes, so it's not worthwhile to
1400 // support them and make CDS more complicated.
1401 warn_excluded(k, "JFR event class");
1402 return true;
1403 }
1416 warn_excluded(k, "Failed verification");
1417 } else {
1418 warn_excluded(k, "Not linked");
1419 }
1420 return true;
1421 }
1422 if (k->major_version() < 50 /*JAVA_6_VERSION*/) {
1423 ResourceMark rm;
1424 log_warning(cds)("Pre JDK 6 class not supported by CDS: %u.%u %s",
1425 k->major_version(), k->minor_version(), k->name()->as_C_string());
1426 return true;
1427 }
1428
1429 InstanceKlass* super = k->java_super();
1430 if (super != NULL && should_be_excluded(super)) {
1431 ResourceMark rm;
1432 log_warning(cds)("Skipping %s: super class %s is excluded", k->name()->as_C_string(), super->name()->as_C_string());
1433 return true;
1434 }
1435
1436 if (k->is_hidden() && !is_registered_lambda_proxy_class(k)) {
1437 warn_excluded(k, "Hidden class");
1438 return true;
1439 }
1440
1441 Array<InstanceKlass*>* interfaces = k->local_interfaces();
1442 int len = interfaces->length();
1443 for (int i = 0; i < len; i++) {
1444 InstanceKlass* intf = interfaces->at(i);
1445 if (should_be_excluded(intf)) {
1446 log_warning(cds)("Skipping %s: interface %s is excluded", k->name()->as_C_string(), intf->name()->as_C_string());
1447 return true;
1448 }
1449 }
1450
1451 return false;
1452 }
1453
1454 // k is a class before relocating by ArchiveCompactor
1455 void SystemDictionaryShared::validate_before_archiving(InstanceKlass* k) {
1456 ResourceMark rm;
1457 const char* name = k->name()->as_C_string();
1458 DumpTimeSharedClassInfo* info = _dumptime_table->get(k);
1459 assert(_no_class_loading_should_happen, "class loading must be disabled");
1460 guarantee(info != NULL, "Class %s must be entered into _dumptime_table", name);
1461 guarantee(!info->is_excluded(), "Should not attempt to archive excluded class %s", name);
1462 if (is_builtin(k)) {
1463 if (k->is_hidden()) {
1464 assert(is_registered_lambda_proxy_class(k), "unexpected hidden class %s", name);
1465 }
1466 guarantee(!k->is_shared_unregistered_class(),
1467 "Class loader type must be set for BUILTIN class %s", name);
1468
1469 } else {
1470 guarantee(k->is_shared_unregistered_class(),
1471 "Class loader type must not be set for UNREGISTERED class %s", name);
1472 }
1473 }
1474
1475 class ExcludeDumpTimeSharedClasses : StackObj {
1476 public:
1477 bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) {
1478 if (SystemDictionaryShared::should_be_excluded(k)) {
1479 info.set_excluded();
1480 }
1481 return true; // keep on iterating
1482 }
1483 };
1484
1485 void SystemDictionaryShared::check_excluded_classes() {
1486 ExcludeDumpTimeSharedClasses excl;
1487 _dumptime_table->iterate(&excl);
1488 _dumptime_table->update_counts();
1564 }
1565 GrowableArray<DTVerifierConstraint>* vc_array = _verifier_constraints;
1566 for (int i = 0; i < vc_array->length(); i++) {
1567 DTVerifierConstraint* p = vc_array->adr_at(i);
1568 if (name == p->_name && from_name == p->_from_name) {
1569 return;
1570 }
1571 }
1572 DTVerifierConstraint cons(name, from_name);
1573 vc_array->append(cons);
1574
1575 GrowableArray<char>* vcflags_array = _verifier_constraint_flags;
1576 char c = 0;
1577 c |= from_field_is_protected ? SystemDictionaryShared::FROM_FIELD_IS_PROTECTED : 0;
1578 c |= from_is_array ? SystemDictionaryShared::FROM_IS_ARRAY : 0;
1579 c |= from_is_object ? SystemDictionaryShared::FROM_IS_OBJECT : 0;
1580 vcflags_array->append(c);
1581
1582 if (log_is_enabled(Trace, cds, verification)) {
1583 ResourceMark rm;
1584 log_trace(cds, verification)("add_verification_constraint: %s: %s must be subclass of %s [0x%x] array len %d flags len %d",
1585 k->external_name(), from_name->as_klass_external_name(),
1586 name->as_klass_external_name(), c, vc_array->length(), vcflags_array->length());
1587 }
1588 }
1589
1590 void SystemDictionaryShared::add_lambda_proxy_class(InstanceKlass* caller_ik,
1591 InstanceKlass* lambda_ik,
1592 Symbol* invoked_name,
1593 Symbol* invoked_type,
1594 Symbol* method_type,
1595 Method* member_method,
1596 Symbol* instantiated_method_type) {
1597
1598 assert(caller_ik->class_loader() == lambda_ik->class_loader(), "mismatched class loader");
1599 assert(caller_ik->class_loader_data() == lambda_ik->class_loader_data(), "mismatched class loader data");
1600
1601 MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag);
1602
1603 lambda_ik->assign_class_loader_type();
1604
1605 DumpTimeSharedClassInfo* info = _dumptime_table->get(lambda_ik);
1606 if (info != NULL && !lambda_ik->is_non_strong_hidden()) {
1607 // Set _is_archived_lambda_proxy in DumpTimeSharedClassInfo so that the lambda_ik
1608 // won't be excluded during dumping of shared archive. See ExcludeDumpTimeSharedClasses.
1609 info->_is_archived_lambda_proxy = true;
1610 }
1611
1612 LambdaProxyClassKey key(caller_ik,
1613 invoked_name,
1614 invoked_type,
1615 method_type,
1616 member_method,
1617 instantiated_method_type);
1618 add_to_dump_time_lambda_proxy_class_dictionary(key, lambda_ik);
1619 }
1620
1621 InstanceKlass* SystemDictionaryShared::get_shared_lambda_proxy_class(InstanceKlass* caller_ik,
1622 Symbol* invoked_name,
1623 Symbol* invoked_type,
1624 Symbol* method_type,
1625 Method* member_method,
1626 Symbol* instantiated_method_type) {
1627 MutexLocker ml(CDSLambda_lock, Mutex::_no_safepoint_check_flag);
1628 LambdaProxyClassKey key(caller_ik, invoked_name, invoked_type,
1629 method_type, member_method, instantiated_method_type);
1630 const RunTimeLambdaProxyClassInfo* info = _lambda_proxy_class_dictionary.lookup(&key, key.hash(), 0);
1631 InstanceKlass* proxy_klass = NULL;
1632 if (info != NULL) {
1633 InstanceKlass* curr_klass = info->proxy_klass_head();
1634 InstanceKlass* prev_klass = curr_klass;
1635 if (curr_klass->lambda_proxy_is_available()) {
1636 while (curr_klass->next_link() != NULL) {
1637 prev_klass = curr_klass;
1638 curr_klass = InstanceKlass::cast(curr_klass->next_link());
1639 }
1640 assert(curr_klass->is_hidden(), "must be");
1641 assert(curr_klass->lambda_proxy_is_available(), "must be");
1642
1643 prev_klass->set_next_link(NULL);
1644 proxy_klass = curr_klass;
1645 proxy_klass->clear_lambda_proxy_is_available();
1646 if (log_is_enabled(Debug, cds)) {
1647 ResourceMark rm;
1648 log_debug(cds)("Loaded lambda proxy: %s", proxy_klass->external_name());
1649 }
1650 } else {
1651 if (log_is_enabled(Debug, cds)) {
1652 ResourceMark rm;
1653 log_debug(cds)("Used all archived lambda proxy classes for: %s %s%s",
1654 caller_ik->external_name(), invoked_name->as_C_string(), invoked_type->as_C_string());
1655 }
1656 }
1657 }
1658 return proxy_klass;
1659 }
1660
1661 InstanceKlass* SystemDictionaryShared::get_shared_nest_host(InstanceKlass* lambda_ik) {
1662 assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only");
1663 RunTimeSharedClassInfo* record = RunTimeSharedClassInfo::get_for(lambda_ik);
1664 return record->nest_host();
1665 }
1666
1667 InstanceKlass* SystemDictionaryShared::prepare_shared_lambda_proxy_class(InstanceKlass* lambda_ik,
1668 InstanceKlass* caller_ik,
1669 bool initialize, TRAPS) {
1670 Handle class_loader(THREAD, caller_ik->class_loader());
1671 Handle protection_domain;
1672 PackageEntry* pkg_entry = get_package_entry_from_class_name(class_loader, caller_ik->name());
1673 if (caller_ik->class_loader() != NULL) {
1674 protection_domain = SystemDictionaryShared::init_security_info(class_loader, caller_ik, pkg_entry, CHECK_NULL);
1675 }
1676
1677 InstanceKlass* shared_nest_host = get_shared_nest_host(lambda_ik);
1678 assert(shared_nest_host != NULL, "unexpected NULL _nest_host");
1679
1680 InstanceKlass* loaded_lambda =
1681 SystemDictionary::load_shared_lambda_proxy_class(lambda_ik, class_loader, protection_domain, pkg_entry, CHECK_NULL);
1682
1683 // Ensures the nest host is the same as the lambda proxy's
1684 // nest host recorded at dump time.
1685 InstanceKlass* nest_host = caller_ik->nest_host(THREAD);
1686 assert(nest_host == shared_nest_host, "mismatched nest host");
1687
1688 EventClassLoad class_load_start_event;
1689 {
1690 MutexLocker mu_r(THREAD, Compile_lock);
1691
1692 // Add to class hierarchy, initialize vtables, and do possible
1693 // deoptimizations.
1694 SystemDictionary::add_to_hierarchy(loaded_lambda, CHECK_NULL); // No exception, but can block
1695 // But, do not add to dictionary.
1696 }
1697 loaded_lambda->link_class(CHECK_NULL);
1698 // notify jvmti
1699 if (JvmtiExport::should_post_class_load()) {
1700 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
1701 JvmtiExport::post_class_load((JavaThread *) THREAD, loaded_lambda);
1702 }
1703 if (class_load_start_event.should_commit()) {
1704 SystemDictionary::post_class_load_event(&class_load_start_event, loaded_lambda, ClassLoaderData::class_loader_data(class_loader()));
1705 }
1706
1707 if (initialize) {
1708 loaded_lambda->initialize(CHECK_NULL);
1709 }
1710
1711 return loaded_lambda;
1712 }
1713
1714 static char get_loader_type_by(oop loader) {
1715 assert(SystemDictionary::is_builtin_class_loader(loader), "Must be built-in loader");
1716 if (SystemDictionary::is_boot_class_loader(loader)) {
1717 return (char)ClassLoader::BOOT_LOADER;
1718 } else if (SystemDictionary::is_platform_class_loader(loader)) {
1719 return (char)ClassLoader::PLATFORM_LOADER;
1720 } else {
1721 assert(SystemDictionary::is_system_class_loader(loader), "Class loader mismatch");
1722 return (char)ClassLoader::APP_LOADER;
1723 }
1724 }
1725
1726 static oop get_class_loader_by(char type) {
1727 if (type == (char)ClassLoader::BOOT_LOADER) {
1728 return (oop)NULL;
1729 } else if (type == (char)ClassLoader::PLATFORM_LOADER) {
1730 return SystemDictionary::java_platform_loader();
1731 } else {
1924 _num_builtin_klasses = 0;
1925 _num_unregistered_klasses = 0;
1926 }
1927
1928 bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) {
1929 if (!info.is_excluded()) {
1930 size_t byte_size = RunTimeSharedClassInfo::byte_size(info._klass, info.num_verifier_constraints(), info.num_loader_constraints());
1931 _shared_class_info_size += align_up(byte_size, BytesPerWord);
1932 }
1933 return true; // keep on iterating
1934 }
1935
1936 size_t total() {
1937 return _shared_class_info_size;
1938 }
1939 };
1940
1941 size_t SystemDictionaryShared::estimate_size_for_archive() {
1942 EstimateSizeForArchive est;
1943 _dumptime_table->iterate(&est);
1944 size_t total_size = est.total() +
1945 CompactHashtableWriter::estimate_size(_dumptime_table->count_of(true)) +
1946 CompactHashtableWriter::estimate_size(_dumptime_table->count_of(false));
1947 if (_dumptime_lambda_proxy_class_dictionary != NULL) {
1948 total_size +=
1949 (sizeof(RunTimeLambdaProxyClassInfo) * _dumptime_lambda_proxy_class_dictionary->_count) +
1950 CompactHashtableWriter::estimate_size(_dumptime_lambda_proxy_class_dictionary->_count);
1951 } else {
1952 total_size += CompactHashtableWriter::estimate_size(0);
1953 }
1954 return total_size;
1955 }
1956
1957 class CopyLambdaProxyClassInfoToArchive : StackObj {
1958 CompactHashtableWriter* _writer;
1959 public:
1960 CopyLambdaProxyClassInfoToArchive(CompactHashtableWriter* writer)
1961 : _writer(writer) {}
1962 bool do_entry(LambdaProxyClassKey& key, DumpTimeLambdaProxyClassInfo& info) {
1963 if (SystemDictionaryShared::is_excluded_class(info._proxy_klasses->at(0))) {
1964 return true;
1965 }
1966 ResourceMark rm;
1967 log_info(cds,dynamic)("Archiving hidden %s", info._proxy_klasses->at(0)->external_name());
1968 size_t byte_size = sizeof(RunTimeLambdaProxyClassInfo);
1969 RunTimeLambdaProxyClassInfo* runtime_info =
1970 (RunTimeLambdaProxyClassInfo*)MetaspaceShared::read_only_space_alloc(byte_size);
1971 runtime_info->init(key, info);
1972 unsigned int hash = runtime_info->hash(); // Fields in runtime_info->_key already point to target space.
1973 u4 delta = MetaspaceShared::object_delta_u4(DynamicArchive::buffer_to_target(runtime_info));
1974 _writer->add(hash, delta);
1975 return true;
1976 }
1977 };
1978
1979 class AdjustLambdaProxyClassInfo : StackObj {
1980 public:
1981 AdjustLambdaProxyClassInfo() {}
1982 bool do_entry(LambdaProxyClassKey& key, DumpTimeLambdaProxyClassInfo& info) {
1983 if (SystemDictionaryShared::is_excluded_class(info._proxy_klasses->at(0))) {
1984 return true;
1985 }
1986 int len = info._proxy_klasses->length();
1987 if (len > 1) {
1988 for (int i = 0; i < len-1; i++) {
1989 InstanceKlass* ok0 = info._proxy_klasses->at(i+0); // this is original klass
1990 InstanceKlass* ok1 = info._proxy_klasses->at(i+1); // this is original klass
1991 InstanceKlass* bk0 = DynamicArchive::original_to_buffer(ok0);
1992 InstanceKlass* bk1 = DynamicArchive::original_to_buffer(ok1);
1993 assert(bk0->next_link() == 0, "must be called after Klass::remove_unshareable_info()");
1994 assert(bk1->next_link() == 0, "must be called after Klass::remove_unshareable_info()");
1995 bk0->set_next_link(bk1);
1996 bk1->set_lambda_proxy_is_available();
1997 ArchivePtrMarker::mark_pointer(bk0->next_link_addr());
1998 }
1999 }
2000 DynamicArchive::original_to_buffer(info._proxy_klasses->at(0))->set_lambda_proxy_is_available();
2001 return true;
2002 }
2003 };
2004
2005 class CopySharedClassInfoToArchive : StackObj {
2006 CompactHashtableWriter* _writer;
2007 bool _is_builtin;
2008 public:
2009 CopySharedClassInfoToArchive(CompactHashtableWriter* writer,
2010 bool is_builtin,
2011 bool is_static_archive)
2012 : _writer(writer), _is_builtin(is_builtin) {}
2013
2014 bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) {
2015 if (!info.is_excluded() && info.is_builtin() == _is_builtin) {
2016 size_t byte_size = RunTimeSharedClassInfo::byte_size(info._klass, info.num_verifier_constraints(), info.num_loader_constraints());
2017 RunTimeSharedClassInfo* record;
2018 record = (RunTimeSharedClassInfo*)MetaspaceShared::read_only_space_alloc(byte_size);
2019 record->init(info);
2020
2021 unsigned int hash;
2022 Symbol* name = info._klass->name();
2023 if (DynamicDumpSharedSpaces) {
2024 name = DynamicArchive::original_to_target(name);
2025 }
2026 hash = SystemDictionaryShared::hash_for_shared_dictionary(name);
2027 u4 delta;
2028 if (DynamicDumpSharedSpaces) {
2029 delta = MetaspaceShared::object_delta_u4(DynamicArchive::buffer_to_target(record));
2030 } else {
2031 delta = MetaspaceShared::object_delta_u4(record);
2032 }
2033 if (_is_builtin && info._klass->is_hidden()) {
2034 // skip
2035 } else {
2036 _writer->add(hash, delta);
2037 }
2038 if (log_is_enabled(Trace, cds, hashtables)) {
2039 ResourceMark rm;
2040 log_trace(cds,hashtables)("%s dictionary: %s", (_is_builtin ? "builtin" : "unregistered"), info._klass->external_name());
2041 }
2042
2043 // Save this for quick runtime lookup of InstanceKlass* -> RunTimeSharedClassInfo*
2044 RunTimeSharedClassInfo::set_for(info._klass, record);
2045 }
2046 return true; // keep on iterating
2047 }
2048 };
2049
2050 void SystemDictionaryShared::write_lambda_proxy_class_dictionary(LambdaProxyClassDictionary *dictionary) {
2051 CompactHashtableStats stats;
2052 dictionary->reset();
2053 CompactHashtableWriter writer(_dumptime_lambda_proxy_class_dictionary->_count, &stats);
2054 CopyLambdaProxyClassInfoToArchive copy(&writer);
2055 _dumptime_lambda_proxy_class_dictionary->iterate(©);
2056 writer.dump(dictionary, "lambda proxy class dictionary");
2057 }
2058
2059 void SystemDictionaryShared::write_dictionary(RunTimeSharedDictionary* dictionary,
2060 bool is_builtin,
2061 bool is_static_archive) {
2062 CompactHashtableStats stats;
2063 dictionary->reset();
2064 CompactHashtableWriter writer(_dumptime_table->count_of(is_builtin), &stats);
2065 CopySharedClassInfoToArchive copy(&writer, is_builtin, is_static_archive);
2066 _dumptime_table->iterate(©);
2067 writer.dump(dictionary, is_builtin ? "builtin dictionary" : "unregistered dictionary");
2068 }
2069
2070 void SystemDictionaryShared::write_to_archive(bool is_static_archive) {
2071 if (is_static_archive) {
2072 write_dictionary(&_builtin_dictionary, true);
2073 write_dictionary(&_unregistered_dictionary, false);
2074 } else {
2075 write_dictionary(&_dynamic_builtin_dictionary, true);
2076 write_dictionary(&_dynamic_unregistered_dictionary, false);
2077 }
2078 if (_dumptime_lambda_proxy_class_dictionary != NULL) {
2079 write_lambda_proxy_class_dictionary(&_lambda_proxy_class_dictionary);
2080 }
2081 }
2082
2083 void SystemDictionaryShared::adjust_lambda_proxy_class_dictionary() {
2084 if (_dumptime_lambda_proxy_class_dictionary != NULL) {
2085 AdjustLambdaProxyClassInfo adjuster;
2086 _dumptime_lambda_proxy_class_dictionary->iterate(&adjuster);
2087 }
2088 }
2089
2090 void SystemDictionaryShared::serialize_dictionary_headers(SerializeClosure* soc,
2091 bool is_static_archive) {
2092 if (is_static_archive) {
2093 _builtin_dictionary.serialize_header(soc);
2094 _unregistered_dictionary.serialize_header(soc);
2095 } else {
2096 _dynamic_builtin_dictionary.serialize_header(soc);
2097 _dynamic_unregistered_dictionary.serialize_header(soc);
2098 _lambda_proxy_class_dictionary.serialize_header(soc);
2099 }
2100 }
2101
2102 void SystemDictionaryShared::serialize_well_known_klasses(SerializeClosure* soc) {
2103 for (int i = FIRST_WKID; i < WKID_LIMIT; i++) {
2104 soc->do_ptr((void**)&_well_known_klasses[i]);
2105 }
2106 }
2107
2108 const RunTimeSharedClassInfo*
2109 SystemDictionaryShared::find_record(RunTimeSharedDictionary* static_dict, RunTimeSharedDictionary* dynamic_dict, Symbol* name) {
2110 if (!UseSharedSpaces || !name->is_shared()) {
2111 // The names of all shared classes must also be a shared Symbol.
2112 return NULL;
2113 }
2114
2115 unsigned int hash = SystemDictionaryShared::hash_for_shared_dictionary(name);
2116 const RunTimeSharedClassInfo* record = NULL;
2117 if (!MetaspaceShared::is_shared_dynamic(name)) {
2118 // The names of all shared classes in the static dict must also be in the
2119 // static archive
2120 record = static_dict->lookup(name, hash, 0);
2121 }
2122
2123 if (record == NULL && DynamicArchive::is_mapped()) {
2124 record = dynamic_dict->lookup(name, hash, 0);
2125 }
2126
2127 return record;
2128 }
2129
2130 InstanceKlass* SystemDictionaryShared::find_builtin_class(Symbol* name) {
2131 const RunTimeSharedClassInfo* record = find_record(&_builtin_dictionary, &_dynamic_builtin_dictionary, name);
2132 if (record != NULL) {
2133 assert(!record->_klass->is_hidden(), "hidden class cannot be looked up by name");
2134 return record->_klass;
2135 } else {
2136 return NULL;
2137 }
2138 }
2139
2140 void SystemDictionaryShared::update_shared_entry(InstanceKlass* k, int id) {
2141 assert(DumpSharedSpaces, "supported only when dumping");
2142 DumpTimeSharedClassInfo* info = find_or_allocate_info_for(k);
2143 info->_id = id;
2144 }
2145
2146 class SharedDictionaryPrinter : StackObj {
2147 outputStream* _st;
2148 int _index;
2149 public:
2150 SharedDictionaryPrinter(outputStream* st) : _st(st), _index(0) {}
2151
2152 void do_value(const RunTimeSharedClassInfo* record) {
2153 ResourceMark rm;
2154 _st->print_cr("%4d: %s", (_index++), record->_klass->external_name());
2155 }
2156 };
2157
2158 class SharedLambdaDictionaryPrinter : StackObj {
2159 outputStream* _st;
2160 int _index;
2161 public:
2162 SharedLambdaDictionaryPrinter(outputStream* st) : _st(st), _index(0) {}
2163
2164 void do_value(const RunTimeLambdaProxyClassInfo* record) {
2165 ResourceMark rm;
2166 _st->print_cr("%4d: %s", (_index++), record->proxy_klass_head()->external_name());
2167 Klass* k = record->proxy_klass_head()->next_link();
2168 while (k != NULL) {
2169 _st->print_cr("%4d: %s", (_index++), k->external_name());
2170 k = k->next_link();
2171 }
2172 }
2173 };
2174
2175 void SystemDictionaryShared::print_on(outputStream* st) {
2176 if (UseSharedSpaces) {
2177 st->print_cr("Shared Dictionary");
2178 SharedDictionaryPrinter p(st);
2179 _builtin_dictionary.iterate(&p);
2180 _unregistered_dictionary.iterate(&p);
2181 if (DynamicArchive::is_mapped()) {
2182 _dynamic_builtin_dictionary.iterate(&p);
2183 _unregistered_dictionary.iterate(&p);
2184 if (!_lambda_proxy_class_dictionary.empty()) {
2185 st->print_cr("Shared Lambda Dictionary");
2186 SharedLambdaDictionaryPrinter ldp(st);
2187 _lambda_proxy_class_dictionary.iterate(&ldp);
2188 }
2189 }
2190 }
2191 }
2192
2193 void SystemDictionaryShared::print_table_statistics(outputStream* st) {
2194 if (UseSharedSpaces) {
2195 _builtin_dictionary.print_table_statistics(st, "Builtin Shared Dictionary");
2196 _unregistered_dictionary.print_table_statistics(st, "Unregistered Shared Dictionary");
2197 if (DynamicArchive::is_mapped()) {
2198 _dynamic_builtin_dictionary.print_table_statistics(st, "Dynamic Builtin Shared Dictionary");
2199 _dynamic_unregistered_dictionary.print_table_statistics(st, "Unregistered Shared Dictionary");
2200 _lambda_proxy_class_dictionary.print_table_statistics(st, "Lambda Shared Dictionary");
2201 }
2202 }
2203 }
2204
2205 bool SystemDictionaryShared::empty_dumptime_table() {
2206 if (_dumptime_table == NULL) {
2207 return true;
2208 }
2209 _dumptime_table->update_counts();
2210 if (_dumptime_table->count_of(true) == 0 && _dumptime_table->count_of(false) == 0){
2211 return true;
2212 }
2213 return false;
2214 }
2215
2216 #if INCLUDE_CDS_JAVA_HEAP
2217
2218 class ArchivedMirrorPatcher {
2219 static void update(Klass* k) {
2220 if (k->has_raw_archived_mirror()) {
|