52 #include "jvmtifiles/jvmti.h"
53 #include "logging/log.hpp"
54 #include "klass.inline.hpp"
55 #include "logging/logMessage.hpp"
56 #include "logging/logStream.hpp"
57 #include "memory/allocation.inline.hpp"
58 #include "memory/iterator.inline.hpp"
59 #include "memory/metadataFactory.hpp"
60 #include "memory/metaspaceClosure.hpp"
61 #include "memory/oopFactory.hpp"
62 #include "memory/resourceArea.hpp"
63 #include "memory/universe.hpp"
64 #include "oops/fieldStreams.inline.hpp"
65 #include "oops/constantPool.hpp"
66 #include "oops/instanceClassLoaderKlass.hpp"
67 #include "oops/instanceKlass.inline.hpp"
68 #include "oops/instanceMirrorKlass.hpp"
69 #include "oops/instanceOop.hpp"
70 #include "oops/instanceStackChunkKlass.hpp"
71 #include "oops/klass.inline.hpp"
72 #include "oops/method.hpp"
73 #include "oops/oop.inline.hpp"
74 #include "oops/recordComponent.hpp"
75 #include "oops/symbol.hpp"
76 #include "prims/jvmtiExport.hpp"
77 #include "prims/jvmtiRedefineClasses.hpp"
78 #include "prims/jvmtiThreadState.hpp"
79 #include "prims/methodComparator.hpp"
80 #include "runtime/arguments.hpp"
81 #include "runtime/deoptimization.hpp"
82 #include "runtime/atomic.hpp"
83 #include "runtime/fieldDescriptor.inline.hpp"
84 #include "runtime/handles.inline.hpp"
85 #include "runtime/javaCalls.hpp"
86 #include "runtime/javaThread.inline.hpp"
87 #include "runtime/mutexLocker.hpp"
88 #include "runtime/orderAccess.hpp"
89 #include "runtime/os.inline.hpp"
90 #include "runtime/reflection.hpp"
91 #include "runtime/synchronizer.hpp"
92 #include "runtime/threads.hpp"
93 #include "services/classLoadingService.hpp"
94 #include "services/finalizerService.hpp"
95 #include "services/threadService.hpp"
133 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait) \
134 { \
135 char* data = nullptr; \
136 int len = 0; \
137 Symbol* clss_name = name(); \
138 if (clss_name != nullptr) { \
139 data = (char*)clss_name->bytes(); \
140 len = clss_name->utf8_length(); \
141 } \
142 HOTSPOT_CLASS_INITIALIZATION_##type( \
143 data, len, (void*)class_loader(), thread_type, wait); \
144 }
145
146 #else // ndef DTRACE_ENABLED
147
148 #define DTRACE_CLASSINIT_PROBE(type, thread_type)
149 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait)
150
151 #endif // ndef DTRACE_ENABLED
152
153 bool InstanceKlass::_finalization_enabled = true;
154
155 static inline bool is_class_loader(const Symbol* class_name,
156 const ClassFileParser& parser) {
157 assert(class_name != nullptr, "invariant");
158
159 if (class_name == vmSymbols::java_lang_ClassLoader()) {
160 return true;
161 }
162
163 if (vmClasses::ClassLoader_klass_loaded()) {
164 const Klass* const super_klass = parser.super_klass();
165 if (super_klass != nullptr) {
166 if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
167 return true;
168 }
169 }
170 }
171 return false;
172 }
173
174 static inline bool is_stack_chunk_class(const Symbol* class_name,
175 const ClassLoaderData* loader_data) {
176 return (class_name == vmSymbols::jdk_internal_vm_StackChunk() &&
177 loader_data->is_the_null_class_loader_data());
178 }
179
180 // private: called to verify that k is a static member of this nest.
181 // We know that k is an instance class in the same package and hence the
182 // same classloader.
183 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
184 assert(!is_hidden(), "unexpected hidden class");
185 if (_nest_members == nullptr || _nest_members == Universe::the_empty_short_array()) {
186 if (log_is_enabled(Trace, class, nestmates)) {
187 ResourceMark rm(current);
188 log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
189 k->external_name(), this->external_name());
190 }
191 return false;
192 }
193
448 }
449
450 const char* InstanceKlass::nest_host_error() {
451 if (_nest_host_index == 0) {
452 return nullptr;
453 } else {
454 constantPoolHandle cph(Thread::current(), constants());
455 return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
456 }
457 }
458
459 void* InstanceKlass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size,
460 bool use_class_space, TRAPS) throw() {
461 return Metaspace::allocate(loader_data, word_size, ClassType, use_class_space, THREAD);
462 }
463
464 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
465 const int size = InstanceKlass::size(parser.vtable_size(),
466 parser.itable_size(),
467 nonstatic_oop_map_size(parser.total_oop_map_count()),
468 parser.is_interface());
469
470 const Symbol* const class_name = parser.class_name();
471 assert(class_name != nullptr, "invariant");
472 ClassLoaderData* loader_data = parser.loader_data();
473 assert(loader_data != nullptr, "invariant");
474
475 InstanceKlass* ik;
476 const bool use_class_space = parser.klass_needs_narrow_id();
477
478 // Allocation
479 if (parser.is_instance_ref_klass()) {
480 // java.lang.ref.Reference
481 ik = new (loader_data, size, use_class_space, THREAD) InstanceRefKlass(parser);
482 } else if (class_name == vmSymbols::java_lang_Class()) {
483 // mirror - java.lang.Class
484 ik = new (loader_data, size, use_class_space, THREAD) InstanceMirrorKlass(parser);
485 } else if (is_stack_chunk_class(class_name, loader_data)) {
486 // stack chunk
487 ik = new (loader_data, size, use_class_space, THREAD) InstanceStackChunkKlass(parser);
488 } else if (is_class_loader(class_name, parser)) {
489 // class loader - java.lang.ClassLoader
490 ik = new (loader_data, size, use_class_space, THREAD) InstanceClassLoaderKlass(parser);
491 } else {
492 // normal
493 ik = new (loader_data, size, use_class_space, THREAD) InstanceKlass(parser);
494 }
495
496 if (ik != nullptr && UseCompressedClassPointers && use_class_space) {
497 assert(CompressedKlassPointers::is_encodable(ik),
498 "Klass " PTR_FORMAT "needs a narrow Klass ID, but is not encodable", p2i(ik));
499 }
500
501 // Check for pending exception before adding to the loader data and incrementing
502 // class count. Can get OOM here.
503 if (HAS_PENDING_EXCEPTION) {
504 return nullptr;
505 }
506
507 return ik;
508 }
509
510
511 // copy method ordering from resource area to Metaspace
512 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
513 if (m != nullptr) {
514 // allocate a new array and copy contents (memcpy?)
515 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
516 for (int i = 0; i < m->length(); i++) {
517 _method_ordering->at_put(i, m->at(i));
518 }
519 } else {
520 _method_ordering = Universe::the_empty_int_array();
521 }
522 }
523
524 // create a new array of vtable_indices for default methods
525 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
526 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
527 assert(default_vtable_indices() == nullptr, "only create once");
528 set_default_vtable_indices(vtable_indices);
529 return vtable_indices;
530 }
531
532
533 InstanceKlass::InstanceKlass() {
534 assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
535 }
536
537 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) :
538 Klass(kind),
539 _nest_members(nullptr),
540 _nest_host(nullptr),
541 _permitted_subclasses(nullptr),
542 _record_components(nullptr),
543 _static_field_size(parser.static_field_size()),
544 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
545 _itable_len(parser.itable_size()),
546 _nest_host_index(0),
547 _init_state(allocated),
548 _reference_type(reference_type),
549 _init_thread(nullptr)
550 {
551 set_vtable_length(parser.vtable_size());
552 set_access_flags(parser.access_flags());
553 if (parser.is_hidden()) set_is_hidden();
554 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
555 false));
556
557 assert(nullptr == _methods, "underlying memory not zeroed?");
558 assert(is_instance_klass(), "is layout incorrect?");
559 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
560 }
561
562 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
563 Array<Method*>* methods) {
564 if (methods != nullptr && methods != Universe::the_empty_method_array() &&
565 !methods->is_shared()) {
566 for (int i = 0; i < methods->length(); i++) {
567 Method* method = methods->at(i);
568 if (method == nullptr) continue; // maybe null if error processing
569 // Only want to delete methods that are not executing for RedefineClasses.
570 // The previous version will point to them so they're not totally dangling
571 assert (!method->on_stack(), "shouldn't be called with methods on stack");
572 MetadataFactory::free_metadata(loader_data, method);
573 }
574 MetadataFactory::free_array<Method*>(loader_data, methods);
575 }
675 (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
676 !secondary_supers()->is_shared()) {
677 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
678 }
679 set_secondary_supers(nullptr, SECONDARY_SUPERS_BITMAP_EMPTY);
680
681 deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
682 set_transitive_interfaces(nullptr);
683 set_local_interfaces(nullptr);
684
685 if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->is_shared()) {
686 MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
687 }
688 set_fieldinfo_stream(nullptr);
689
690 if (fields_status() != nullptr && !fields_status()->is_shared()) {
691 MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
692 }
693 set_fields_status(nullptr);
694
695 // If a method from a redefined class is using this constant pool, don't
696 // delete it, yet. The new class's previous version will point to this.
697 if (constants() != nullptr) {
698 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
699 if (!constants()->is_shared()) {
700 MetadataFactory::free_metadata(loader_data, constants());
701 }
702 // Delete any cached resolution errors for the constant pool
703 SystemDictionary::delete_resolution_error(constants());
704
705 set_constants(nullptr);
706 }
707
708 if (inner_classes() != nullptr &&
709 inner_classes() != Universe::the_empty_short_array() &&
710 !inner_classes()->is_shared()) {
711 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
712 }
713 set_inner_classes(nullptr);
714
715 if (nest_members() != nullptr &&
716 nest_members() != Universe::the_empty_short_array() &&
717 !nest_members()->is_shared()) {
718 MetadataFactory::free_array<jushort>(loader_data, nest_members());
719 }
720 set_nest_members(nullptr);
721
722 if (permitted_subclasses() != nullptr &&
723 permitted_subclasses() != Universe::the_empty_short_array() &&
724 !permitted_subclasses()->is_shared()) {
725 MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
726 }
727 set_permitted_subclasses(nullptr);
728
729 // We should deallocate the Annotations instance if it's not in shared spaces.
730 if (annotations() != nullptr && !annotations()->is_shared()) {
731 MetadataFactory::free_metadata(loader_data, annotations());
732 }
733 set_annotations(nullptr);
734
735 SystemDictionaryShared::handle_class_unloading(this);
736
737 #if INCLUDE_CDS_JAVA_HEAP
738 if (CDSConfig::is_dumping_heap()) {
739 HeapShared::remove_scratch_objects(this);
740 }
741 #endif
742 }
743
744 bool InstanceKlass::is_record() const {
745 return _record_components != nullptr &&
746 is_final() &&
747 java_super() == vmClasses::Record_klass();
748 }
943 vmSymbols::java_lang_IncompatibleClassChangeError(),
944 "class %s has interface %s as super class",
945 external_name(),
946 super_klass->external_name()
947 );
948 return false;
949 }
950
951 InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
952 ik_super->link_class_impl(CHECK_false);
953 }
954
955 // link all interfaces implemented by this class before linking this class
956 Array<InstanceKlass*>* interfaces = local_interfaces();
957 int num_interfaces = interfaces->length();
958 for (int index = 0; index < num_interfaces; index++) {
959 InstanceKlass* interk = interfaces->at(index);
960 interk->link_class_impl(CHECK_false);
961 }
962
963 // in case the class is linked in the process of linking its superclasses
964 if (is_linked()) {
965 return true;
966 }
967
968 // trace only the link time for this klass that includes
969 // the verification time
970 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
971 ClassLoader::perf_class_link_selftime(),
972 ClassLoader::perf_classes_linked(),
973 jt->get_thread_stat()->perf_recursion_counts_addr(),
974 jt->get_thread_stat()->perf_timers_addr(),
975 PerfClassTraceTime::CLASS_LINK);
976
977 // verification & rewriting
978 {
979 HandleMark hm(THREAD);
980 Handle h_init_lock(THREAD, init_lock());
981 ObjectLocker ol(h_init_lock, jt);
982 // rewritten will have been set if loader constraint error found
1247 ss.print("Could not initialize class %s", external_name());
1248 if (cause.is_null()) {
1249 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1250 } else {
1251 THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1252 ss.as_string(), cause);
1253 }
1254 } else {
1255
1256 // Step 6
1257 set_init_state(being_initialized);
1258 set_init_thread(jt);
1259 if (debug_logging_enabled) {
1260 ResourceMark rm(jt);
1261 log_debug(class, init)("Thread \"%s\" is initializing %s",
1262 jt->name(), external_name());
1263 }
1264 }
1265 }
1266
1267 // Step 7
1268 // Next, if C is a class rather than an interface, initialize it's super class and super
1269 // interfaces.
1270 if (!is_interface()) {
1271 Klass* super_klass = super();
1272 if (super_klass != nullptr && super_klass->should_be_initialized()) {
1273 super_klass->initialize(THREAD);
1274 }
1275 // If C implements any interface that declares a non-static, concrete method,
1276 // the initialization of C triggers initialization of its super interfaces.
1277 // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1278 // having a superinterface that declares, non-static, concrete methods
1279 if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1280 initialize_super_interfaces(THREAD);
1281 }
1282
1283 // If any exceptions, complete abruptly, throwing the same exception as above.
1284 if (HAS_PENDING_EXCEPTION) {
1285 Handle e(THREAD, PENDING_EXCEPTION);
1286 CLEAR_PENDING_EXCEPTION;
1287 {
1288 EXCEPTION_MARK;
1289 add_initialization_error(THREAD, e);
1290 // Locks object, set state, and notify all waiting threads
1291 set_initialization_state_and_notify(initialization_error, THREAD);
1292 CLEAR_PENDING_EXCEPTION;
1293 }
1294 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1295 THROW_OOP(e());
1296 }
1297 }
1298
1299
1300 // Step 8
1301 {
1302 DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1303 if (class_initializer() != nullptr) {
1304 // Timer includes any side effects of class initialization (resolution,
1305 // etc), but not recursive entry into call_class_initializer().
1306 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1307 ClassLoader::perf_class_init_selftime(),
1308 ClassLoader::perf_classes_inited(),
1309 jt->get_thread_stat()->perf_recursion_counts_addr(),
1310 jt->get_thread_stat()->perf_timers_addr(),
1311 PerfClassTraceTime::CLASS_CLINIT);
1312 call_class_initializer(THREAD);
1313 } else {
1314 // The elapsed time is so small it's not worth counting.
1315 if (UsePerfData) {
1316 ClassLoader::perf_classes_inited()->inc();
1317 }
1318 call_class_initializer(THREAD);
1319 }
1604 ResourceMark rm(THREAD);
1605 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1606 : vmSymbols::java_lang_InstantiationException(), external_name());
1607 }
1608 if (this == vmClasses::Class_klass()) {
1609 ResourceMark rm(THREAD);
1610 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1611 : vmSymbols::java_lang_IllegalAccessException(), external_name());
1612 }
1613 }
1614
1615 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1616 // Need load-acquire for lock-free read
1617 if (array_klasses_acquire() == nullptr) {
1618
1619 // Recursively lock array allocation
1620 RecursiveLocker rl(MultiArray_lock, THREAD);
1621
1622 // Check if another thread created the array klass while we were waiting for the lock.
1623 if (array_klasses() == nullptr) {
1624 ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);
1625 // use 'release' to pair with lock-free load
1626 release_set_array_klasses(k);
1627 }
1628 }
1629
1630 // array_klasses() will always be set at this point
1631 ObjArrayKlass* ak = array_klasses();
1632 assert(ak != nullptr, "should be set");
1633 return ak->array_klass(n, THREAD);
1634 }
1635
1636 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1637 // Need load-acquire for lock-free read
1638 ObjArrayKlass* oak = array_klasses_acquire();
1639 if (oak == nullptr) {
1640 return nullptr;
1641 } else {
1642 return oak->array_klass_or_null(n);
1643 }
1644 }
1645
1646 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1647 return array_klass(1, THREAD);
1648 }
1649
1650 ArrayKlass* InstanceKlass::array_klass_or_null() {
1651 return array_klass_or_null(1);
1652 }
1653
1654 static int call_class_initializer_counter = 0; // for debugging
1655
1656 Method* InstanceKlass::class_initializer() const {
1657 Method* clinit = find_method(
1658 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1659 if (clinit != nullptr && clinit->has_valid_initializer_flags()) {
1660 return clinit;
1661 }
1662 return nullptr;
1663 }
1664
1665 void InstanceKlass::call_class_initializer(TRAPS) {
1666 if (ReplayCompiles &&
1667 (ReplaySuppressInitializers == 1 ||
1668 (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1669 // Hide the existence of the initializer for the purpose of replaying the compile
1670 return;
1671 }
1672
1673 #if INCLUDE_CDS
1674 // This is needed to ensure the consistency of the archived heap objects.
1675 if (has_aot_initialized_mirror() && CDSConfig::is_loading_heap()) {
1676 AOTClassInitializer::call_runtime_setup(THREAD, this);
1677 return;
1678 } else if (has_archived_enum_objs()) {
1679 assert(is_shared(), "must be");
1748
1749 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1750 InterpreterOopMap* entry_for) {
1751 // Lazily create the _oop_map_cache at first request.
1752 // Load_acquire is needed to safely get instance published with CAS by another thread.
1753 OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1754 if (oop_map_cache == nullptr) {
1755 // Try to install new instance atomically.
1756 oop_map_cache = new OopMapCache();
1757 OopMapCache* other = Atomic::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
1758 if (other != nullptr) {
1759 // Someone else managed to install before us, ditch local copy and use the existing one.
1760 delete oop_map_cache;
1761 oop_map_cache = other;
1762 }
1763 }
1764 // _oop_map_cache is constant after init; lookup below does its own locking.
1765 oop_map_cache->lookup(method, bci, entry_for);
1766 }
1767
1768 bool InstanceKlass::contains_field_offset(int offset) {
1769 fieldDescriptor fd;
1770 return find_field_from_offset(offset, false, &fd);
1771 }
1772
1773 FieldInfo InstanceKlass::field(int index) const {
1774 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1775 if (fs.index() == index) {
1776 return fs.to_FieldInfo();
1777 }
1778 }
1779 fatal("Field not found");
1780 return FieldInfo();
1781 }
1782
1783 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1784 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1785 Symbol* f_name = fs.name();
1786 Symbol* f_sig = fs.signature();
1787 if (f_name == name && f_sig == sig) {
1788 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1789 return true;
1790 }
1791 }
1833
1834 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1835 // search order according to newest JVM spec (5.4.3.2, p.167).
1836 // 1) search for field in current klass
1837 if (find_local_field(name, sig, fd)) {
1838 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1839 }
1840 // 2) search for field recursively in direct superinterfaces
1841 if (is_static) {
1842 Klass* intf = find_interface_field(name, sig, fd);
1843 if (intf != nullptr) return intf;
1844 }
1845 // 3) apply field lookup recursively if superclass exists
1846 { Klass* supr = super();
1847 if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1848 }
1849 // 4) otherwise field lookup fails
1850 return nullptr;
1851 }
1852
1853
1854 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1855 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1856 if (fs.offset() == offset) {
1857 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1858 if (fd->is_static() == is_static) return true;
1859 }
1860 }
1861 return false;
1862 }
1863
1864
1865 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1866 Klass* klass = const_cast<InstanceKlass*>(this);
1867 while (klass != nullptr) {
1868 if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1869 return true;
1870 }
1871 klass = klass->super();
1872 }
2224 }
2225
2226 // uncached_lookup_method searches both the local class methods array and all
2227 // superclasses methods arrays, skipping any overpass methods in superclasses,
2228 // and possibly skipping private methods.
2229 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2230 const Symbol* signature,
2231 OverpassLookupMode overpass_mode,
2232 PrivateLookupMode private_mode) const {
2233 OverpassLookupMode overpass_local_mode = overpass_mode;
2234 const Klass* klass = this;
2235 while (klass != nullptr) {
2236 Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2237 signature,
2238 overpass_local_mode,
2239 StaticLookupMode::find,
2240 private_mode);
2241 if (method != nullptr) {
2242 return method;
2243 }
2244 klass = klass->super();
2245 overpass_local_mode = OverpassLookupMode::skip; // Always ignore overpass methods in superclasses
2246 }
2247 return nullptr;
2248 }
2249
2250 #ifdef ASSERT
2251 // search through class hierarchy and return true if this class or
2252 // one of the superclasses was redefined
2253 bool InstanceKlass::has_redefined_this_or_super() const {
2254 const Klass* klass = this;
2255 while (klass != nullptr) {
2256 if (InstanceKlass::cast(klass)->has_been_redefined()) {
2257 return true;
2258 }
2259 klass = klass->super();
2260 }
2261 return false;
2262 }
2263 #endif
2621 int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2622
2623 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2624 / itableOffsetEntry::size();
2625
2626 for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2627 if (ioe->interface_klass() != nullptr) {
2628 it->push(ioe->interface_klass_addr());
2629 itableMethodEntry* ime = ioe->first_method_entry(this);
2630 int n = klassItable::method_count_for_interface(ioe->interface_klass());
2631 for (int index = 0; index < n; index ++) {
2632 it->push(ime[index].method_addr());
2633 }
2634 }
2635 }
2636 }
2637
2638 it->push(&_nest_host);
2639 it->push(&_nest_members);
2640 it->push(&_permitted_subclasses);
2641 it->push(&_record_components);
2642 }
2643
2644 #if INCLUDE_CDS
2645 void InstanceKlass::remove_unshareable_info() {
2646
2647 if (is_linked()) {
2648 assert(can_be_verified_at_dumptime(), "must be");
2649 // Remember this so we can avoid walking the hierarchy at runtime.
2650 set_verified_at_dump_time();
2651 }
2652
2653 Klass::remove_unshareable_info();
2654
2655 if (SystemDictionaryShared::has_class_failed_verification(this)) {
2656 // Classes are attempted to link during dumping and may fail,
2657 // but these classes are still in the dictionary and class list in CLD.
2658 // If the class has failed verification, there is nothing else to remove.
2659 return;
2660 }
2661
2667
2668 { // Otherwise this needs to take out the Compile_lock.
2669 assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2670 init_implementor();
2671 }
2672
2673 // Call remove_unshareable_info() on other objects that belong to this class, except
2674 // for constants()->remove_unshareable_info(), which is called in a separate pass in
2675 // ArchiveBuilder::make_klasses_shareable(),
2676
2677 for (int i = 0; i < methods()->length(); i++) {
2678 Method* m = methods()->at(i);
2679 m->remove_unshareable_info();
2680 }
2681
2682 // do array classes also.
2683 if (array_klasses() != nullptr) {
2684 array_klasses()->remove_unshareable_info();
2685 }
2686
2687 // These are not allocated from metaspace. They are safe to set to null.
2688 _source_debug_extension = nullptr;
2689 _dep_context = nullptr;
2690 _osr_nmethods_head = nullptr;
2691 #if INCLUDE_JVMTI
2692 _breakpoints = nullptr;
2693 _previous_versions = nullptr;
2694 _cached_class_file = nullptr;
2695 _jvmti_cached_class_field_map = nullptr;
2696 #endif
2697
2698 _init_thread = nullptr;
2699 _methods_jmethod_ids = nullptr;
2700 _jni_ids = nullptr;
2701 _oop_map_cache = nullptr;
2702 if (CDSConfig::is_dumping_method_handles() && HeapShared::is_lambda_proxy_klass(this)) {
2703 // keep _nest_host
2704 } else {
2705 // clear _nest_host to ensure re-load at runtime
2706 _nest_host = nullptr;
2707 }
2756 void InstanceKlass::compute_has_loops_flag_for_methods() {
2757 Array<Method*>* methods = this->methods();
2758 for (int index = 0; index < methods->length(); ++index) {
2759 Method* m = methods->at(index);
2760 if (!m->is_overpass()) { // work around JDK-8305771
2761 m->compute_has_loops_flag();
2762 }
2763 }
2764 }
2765
2766 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2767 PackageEntry* pkg_entry, TRAPS) {
2768 // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2769 // before the InstanceKlass is added to the SystemDictionary. Make
2770 // sure the current state is <loaded.
2771 assert(!is_loaded(), "invalid init state");
2772 assert(!shared_loading_failed(), "Must not try to load failed class again");
2773 set_package(loader_data, pkg_entry, CHECK);
2774 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2775
2776 Array<Method*>* methods = this->methods();
2777 int num_methods = methods->length();
2778 for (int index = 0; index < num_methods; ++index) {
2779 methods->at(index)->restore_unshareable_info(CHECK);
2780 }
2781 #if INCLUDE_JVMTI
2782 if (JvmtiExport::has_redefined_a_class()) {
2783 // Reinitialize vtable because RedefineClasses may have changed some
2784 // entries in this vtable for super classes so the CDS vtable might
2785 // point to old or obsolete entries. RedefineClasses doesn't fix up
2786 // vtables in the shared system dictionary, only the main one.
2787 // It also redefines the itable too so fix that too.
2788 // First fix any default methods that point to a super class that may
2789 // have been redefined.
2790 bool trace_name_printed = false;
2791 adjust_default_methods(&trace_name_printed);
2792 if (verified_at_dump_time()) {
2793 // Initialize vtable and itable for classes which can be verified at dump time.
2794 // Unlinked classes such as old classes with major version < 50 cannot be verified
2795 // at dump time.
2796 vtable().initialize_vtable();
2797 itable().initialize_itable();
2798 }
2799 }
2800 #endif // INCLUDE_JVMTI
2801
2802 // restore constant pool resolved references
2803 constants()->restore_unshareable_info(CHECK);
2804
2805 if (array_klasses() != nullptr) {
2806 // To get a consistent list of classes we need MultiArray_lock to ensure
2807 // array classes aren't observed while they are being restored.
2808 RecursiveLocker rl(MultiArray_lock, THREAD);
2809 assert(this == array_klasses()->bottom_klass(), "sanity");
2810 // Array classes have null protection domain.
2811 // --> see ArrayKlass::complete_create_array_klass()
2812 array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2813 }
2814
2815 // Initialize @ValueBased class annotation if not already set in the archived klass.
2816 if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
2817 set_is_value_based();
2818 }
2819 }
2820
2821 // Check if a class or any of its supertypes has a version older than 50.
2822 // CDS will not perform verification of old classes during dump time because
2823 // without changing the old verifier, the verification constraint cannot be
2824 // retrieved during dump time.
2825 // Verification of archived old classes will be performed during run time.
2826 bool InstanceKlass::can_be_verified_at_dumptime() const {
2827 if (MetaspaceShared::is_in_shared_metaspace(this)) {
2828 // This is a class that was dumped into the base archive, so we know
2829 // it was verified at dump time.
2986 } else {
2987 // Adding one to the attribute length in order to store a null terminator
2988 // character could cause an overflow because the attribute length is
2989 // already coded with an u4 in the classfile, but in practice, it's
2990 // unlikely to happen.
2991 assert((length+1) > length, "Overflow checking");
2992 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
2993 for (int i = 0; i < length; i++) {
2994 sde[i] = array[i];
2995 }
2996 sde[length] = '\0';
2997 _source_debug_extension = sde;
2998 }
2999 }
3000
3001 Symbol* InstanceKlass::generic_signature() const { return _constants->generic_signature(); }
3002 u2 InstanceKlass::generic_signature_index() const { return _constants->generic_signature_index(); }
3003 void InstanceKlass::set_generic_signature_index(u2 sig_index) { _constants->set_generic_signature_index(sig_index); }
3004
3005 const char* InstanceKlass::signature_name() const {
3006
3007 // Get the internal name as a c string
3008 const char* src = (const char*) (name()->as_C_string());
3009 const int src_length = (int)strlen(src);
3010
3011 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
3012
3013 // Add L as type indicator
3014 int dest_index = 0;
3015 dest[dest_index++] = JVM_SIGNATURE_CLASS;
3016
3017 // Add the actual class name
3018 for (int src_index = 0; src_index < src_length; ) {
3019 dest[dest_index++] = src[src_index++];
3020 }
3021
3022 if (is_hidden()) { // Replace the last '+' with a '.'.
3023 for (int index = (int)src_length; index > 0; index--) {
3024 if (dest[index] == '+') {
3025 dest[index] = JVM_SIGNATURE_DOT;
3026 break;
3027 }
3028 }
3029 }
3030
3031 // Add the semicolon and the null
3032 dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
3033 dest[dest_index] = '\0';
3034 return dest;
3035 }
3342 u2 InstanceKlass::compute_modifier_flags() const {
3343 u2 access = access_flags().as_unsigned_short();
3344
3345 // But check if it happens to be member class.
3346 InnerClassesIterator iter(this);
3347 for (; !iter.done(); iter.next()) {
3348 int ioff = iter.inner_class_info_index();
3349 // Inner class attribute can be zero, skip it.
3350 // Strange but true: JVM spec. allows null inner class refs.
3351 if (ioff == 0) continue;
3352
3353 // only look at classes that are already loaded
3354 // since we are looking for the flags for our self.
3355 Symbol* inner_name = constants()->klass_name_at(ioff);
3356 if (name() == inner_name) {
3357 // This is really a member class.
3358 access = iter.inner_access_flags();
3359 break;
3360 }
3361 }
3362 // Remember to strip ACC_SUPER bit
3363 return (access & (~JVM_ACC_SUPER));
3364 }
3365
3366 jint InstanceKlass::jvmti_class_status() const {
3367 jint result = 0;
3368
3369 if (is_linked()) {
3370 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3371 }
3372
3373 if (is_initialized()) {
3374 assert(is_linked(), "Class status is not consistent");
3375 result |= JVMTI_CLASS_STATUS_INITIALIZED;
3376 }
3377 if (is_in_error_state()) {
3378 result |= JVMTI_CLASS_STATUS_ERROR;
3379 }
3380 return result;
3381 }
3382
3383 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {
3597 }
3598 osr = osr->osr_link();
3599 }
3600
3601 assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3602 if (best != nullptr && best->comp_level() >= comp_level) {
3603 return best;
3604 }
3605 return nullptr;
3606 }
3607
3608 // -----------------------------------------------------------------------------------------------------
3609 // Printing
3610
3611 #define BULLET " - "
3612
3613 static const char* state_names[] = {
3614 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3615 };
3616
3617 static void print_vtable(intptr_t* start, int len, outputStream* st) {
3618 for (int i = 0; i < len; i++) {
3619 intptr_t e = start[i];
3620 st->print("%d : " INTPTR_FORMAT, i, e);
3621 if (MetaspaceObj::is_valid((Metadata*)e)) {
3622 st->print(" ");
3623 ((Metadata*)e)->print_value_on(st);
3624 }
3625 st->cr();
3626 }
3627 }
3628
3629 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3630 return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
3631 }
3632
3633 const char* InstanceKlass::init_state_name() const {
3634 return state_names[init_state()];
3635 }
3636
3637 void InstanceKlass::print_on(outputStream* st) const {
3638 assert(is_klass(), "must be klass");
3639 Klass::print_on(st);
3640
3641 st->print(BULLET"instance size: %d", size_helper()); st->cr();
3642 st->print(BULLET"klass size: %d", size()); st->cr();
3643 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
3644 st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
3645 st->print(BULLET"state: "); st->print_cr("%s", init_state_name());
3646 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3647 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3648 st->print(BULLET"sub: ");
3649 Klass* sub = subklass();
3650 int n;
3651 for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3652 if (n < MaxSubklassPrintSize) {
3653 sub->print_value_on(st);
3654 st->print(" ");
3655 }
3656 }
3657 if (n >= MaxSubklassPrintSize) st->print("(%zd more klasses...)", n - MaxSubklassPrintSize);
3658 st->cr();
3659
3660 if (is_interface()) {
3661 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
3662 if (nof_implementors() == 1) {
3663 st->print_cr(BULLET"implementor: ");
3664 st->print(" ");
3665 implementor()->print_value_on(st);
3666 st->cr();
3667 }
3668 }
3669
3670 st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3671 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr();
3672 if (Verbose || WizardMode) {
3673 Array<Method*>* method_array = methods();
3674 for (int i = 0; i < method_array->length(); i++) {
3675 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3676 }
3677 }
3678 st->print(BULLET"method ordering: "); method_ordering()->print_value_on(st); st->cr();
3679 if (default_methods() != nullptr) {
3680 st->print(BULLET"default_methods: "); default_methods()->print_value_on(st); st->cr();
3681 if (Verbose) {
3682 Array<Method*>* method_array = default_methods();
3683 for (int i = 0; i < method_array->length(); i++) {
3684 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3685 }
3686 }
3687 }
3688 print_on_maybe_null(st, BULLET"default vtable indices: ", default_vtable_indices());
3689 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr();
3690 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3691
3692 st->print(BULLET"secondary supers: "); secondary_supers()->print_value_on(st); st->cr();
3693
3694 st->print(BULLET"hash_slot: %d", hash_slot()); st->cr();
3695 st->print(BULLET"secondary bitmap: " UINTX_FORMAT_X_0, _secondary_supers_bitmap); st->cr();
3696
3697 if (secondary_supers() != nullptr) {
3698 if (Verbose) {
3699 bool is_hashed = (_secondary_supers_bitmap != SECONDARY_SUPERS_BITMAP_FULL);
3700 st->print_cr(BULLET"---- secondary supers (%d words):", _secondary_supers->length());
3701 for (int i = 0; i < _secondary_supers->length(); i++) {
3702 ResourceMark rm; // for external_name()
3703 Klass* secondary_super = _secondary_supers->at(i);
3704 st->print(BULLET"%2d:", i);
3705 if (is_hashed) {
3706 int home_slot = compute_home_slot(secondary_super, _secondary_supers_bitmap);
3726 print_on_maybe_null(st, BULLET"field type annotations: ", fields_type_annotations());
3727 {
3728 bool have_pv = false;
3729 // previous versions are linked together through the InstanceKlass
3730 for (InstanceKlass* pv_node = previous_versions();
3731 pv_node != nullptr;
3732 pv_node = pv_node->previous_versions()) {
3733 if (!have_pv)
3734 st->print(BULLET"previous version: ");
3735 have_pv = true;
3736 pv_node->constants()->print_value_on(st);
3737 }
3738 if (have_pv) st->cr();
3739 }
3740
3741 print_on_maybe_null(st, BULLET"generic signature: ", generic_signature());
3742 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
3743 st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr();
3744 print_on_maybe_null(st, BULLET"record components: ", record_components());
3745 st->print(BULLET"permitted subclasses: "); permitted_subclasses()->print_value_on(st); st->cr();
3746 if (java_mirror() != nullptr) {
3747 st->print(BULLET"java mirror: ");
3748 java_mirror()->print_value_on(st);
3749 st->cr();
3750 } else {
3751 st->print_cr(BULLET"java mirror: null");
3752 }
3753 st->print(BULLET"vtable length %d (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3754 if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
3755 st->print(BULLET"itable length %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3756 if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_itable(), itable_length(), st);
3757 st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3758
3759 FieldPrinter print_static_field(st);
3760 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3761 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3762 FieldPrinter print_nonstatic_field(st);
3763 InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3764 ik->print_nonstatic_fields(&print_nonstatic_field);
3765
3766 st->print(BULLET"non-static oop maps: ");
3767 OopMapBlock* map = start_of_nonstatic_oop_maps();
3768 OopMapBlock* end_map = map + nonstatic_oop_map_count();
3769 while (map < end_map) {
3770 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3771 map++;
3772 }
3773 st->cr();
3774 }
3775
3776 void InstanceKlass::print_value_on(outputStream* st) const {
3777 assert(is_klass(), "must be klass");
3778 if (Verbose || WizardMode) access_flags().print_on(st);
3779 name()->print_value_on(st);
3780 }
3781
3782 void FieldPrinter::do_field(fieldDescriptor* fd) {
3783 _st->print(BULLET);
3784 if (_obj == nullptr) {
3785 fd->print_on(_st);
3786 _st->cr();
3787 } else {
3788 fd->print_on_for(_st, _obj);
3789 _st->cr();
3790 }
3791 }
3792
3793
3794 void InstanceKlass::oop_print_on(oop obj, outputStream* st) {
3795 Klass::oop_print_on(obj, st);
3796
3797 if (this == vmClasses::String_klass()) {
3798 typeArrayOop value = java_lang_String::value(obj);
3799 juint length = java_lang_String::length(obj);
3800 if (value != nullptr &&
3801 value->is_typeArray() &&
3802 length <= (juint) value->length()) {
3803 st->print(BULLET"string: ");
3804 java_lang_String::print(obj, st);
3805 st->cr();
3806 }
3807 }
3808
3809 st->print_cr(BULLET"---- fields (total size %zu words):", oop_size(obj));
3810 FieldPrinter print_field(st, obj);
3811 print_nonstatic_fields(&print_field);
3812
3813 if (this == vmClasses::Class_klass()) {
3814 st->print(BULLET"signature: ");
3815 java_lang_Class::print_signature(obj, st);
3816 st->cr();
3817 Klass* real_klass = java_lang_Class::as_Klass(obj);
3818 if (real_klass != nullptr && real_klass->is_instance_klass()) {
3819 st->print_cr(BULLET"---- static fields (%d):", java_lang_Class::static_oop_field_count(obj));
3820 InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field);
3821 }
3822 } else if (this == vmClasses::MethodType_klass()) {
3823 st->print(BULLET"signature: ");
3824 java_lang_invoke_MethodType::print_signature(obj, st);
3825 st->cr();
3826 }
3827 }
3828
3829 #ifndef PRODUCT
3830
|
52 #include "jvmtifiles/jvmti.h"
53 #include "logging/log.hpp"
54 #include "klass.inline.hpp"
55 #include "logging/logMessage.hpp"
56 #include "logging/logStream.hpp"
57 #include "memory/allocation.inline.hpp"
58 #include "memory/iterator.inline.hpp"
59 #include "memory/metadataFactory.hpp"
60 #include "memory/metaspaceClosure.hpp"
61 #include "memory/oopFactory.hpp"
62 #include "memory/resourceArea.hpp"
63 #include "memory/universe.hpp"
64 #include "oops/fieldStreams.inline.hpp"
65 #include "oops/constantPool.hpp"
66 #include "oops/instanceClassLoaderKlass.hpp"
67 #include "oops/instanceKlass.inline.hpp"
68 #include "oops/instanceMirrorKlass.hpp"
69 #include "oops/instanceOop.hpp"
70 #include "oops/instanceStackChunkKlass.hpp"
71 #include "oops/klass.inline.hpp"
72 #include "oops/markWord.hpp"
73 #include "oops/method.hpp"
74 #include "oops/oop.inline.hpp"
75 #include "oops/recordComponent.hpp"
76 #include "oops/symbol.hpp"
77 #include "oops/inlineKlass.hpp"
78 #include "prims/jvmtiExport.hpp"
79 #include "prims/jvmtiRedefineClasses.hpp"
80 #include "prims/jvmtiThreadState.hpp"
81 #include "prims/methodComparator.hpp"
82 #include "runtime/arguments.hpp"
83 #include "runtime/deoptimization.hpp"
84 #include "runtime/atomic.hpp"
85 #include "runtime/fieldDescriptor.inline.hpp"
86 #include "runtime/handles.inline.hpp"
87 #include "runtime/javaCalls.hpp"
88 #include "runtime/javaThread.inline.hpp"
89 #include "runtime/mutexLocker.hpp"
90 #include "runtime/orderAccess.hpp"
91 #include "runtime/os.inline.hpp"
92 #include "runtime/reflection.hpp"
93 #include "runtime/synchronizer.hpp"
94 #include "runtime/threads.hpp"
95 #include "services/classLoadingService.hpp"
96 #include "services/finalizerService.hpp"
97 #include "services/threadService.hpp"
135 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait) \
136 { \
137 char* data = nullptr; \
138 int len = 0; \
139 Symbol* clss_name = name(); \
140 if (clss_name != nullptr) { \
141 data = (char*)clss_name->bytes(); \
142 len = clss_name->utf8_length(); \
143 } \
144 HOTSPOT_CLASS_INITIALIZATION_##type( \
145 data, len, (void*)class_loader(), thread_type, wait); \
146 }
147
148 #else // ndef DTRACE_ENABLED
149
150 #define DTRACE_CLASSINIT_PROBE(type, thread_type)
151 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait)
152
153 #endif // ndef DTRACE_ENABLED
154
155 void InlineLayoutInfo::metaspace_pointers_do(MetaspaceClosure* it) {
156 log_trace(cds)("Iter(InlineFieldInfo): %p", this);
157 it->push(&_klass);
158 }
159
160 bool InstanceKlass::_finalization_enabled = true;
161
162 static inline bool is_class_loader(const Symbol* class_name,
163 const ClassFileParser& parser) {
164 assert(class_name != nullptr, "invariant");
165
166 if (class_name == vmSymbols::java_lang_ClassLoader()) {
167 return true;
168 }
169
170 if (vmClasses::ClassLoader_klass_loaded()) {
171 const Klass* const super_klass = parser.super_klass();
172 if (super_klass != nullptr) {
173 if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
174 return true;
175 }
176 }
177 }
178 return false;
179 }
180
181 bool InstanceKlass::field_is_null_free_inline_type(int index) const {
182 return field(index).field_flags().is_null_free_inline_type();
183 }
184
185 bool InstanceKlass::is_class_in_loadable_descriptors_attribute(Symbol* name) const {
186 if (_loadable_descriptors == nullptr) return false;
187 for (int i = 0; i < _loadable_descriptors->length(); i++) {
188 Symbol* class_name = _constants->symbol_at(_loadable_descriptors->at(i));
189 if (class_name == name) return true;
190 }
191 return false;
192 }
193
194 static inline bool is_stack_chunk_class(const Symbol* class_name,
195 const ClassLoaderData* loader_data) {
196 return (class_name == vmSymbols::jdk_internal_vm_StackChunk() &&
197 loader_data->is_the_null_class_loader_data());
198 }
199
200 // private: called to verify that k is a static member of this nest.
201 // We know that k is an instance class in the same package and hence the
202 // same classloader.
203 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
204 assert(!is_hidden(), "unexpected hidden class");
205 if (_nest_members == nullptr || _nest_members == Universe::the_empty_short_array()) {
206 if (log_is_enabled(Trace, class, nestmates)) {
207 ResourceMark rm(current);
208 log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
209 k->external_name(), this->external_name());
210 }
211 return false;
212 }
213
468 }
469
470 const char* InstanceKlass::nest_host_error() {
471 if (_nest_host_index == 0) {
472 return nullptr;
473 } else {
474 constantPoolHandle cph(Thread::current(), constants());
475 return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
476 }
477 }
478
479 void* InstanceKlass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size,
480 bool use_class_space, TRAPS) throw() {
481 return Metaspace::allocate(loader_data, word_size, ClassType, use_class_space, THREAD);
482 }
483
484 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
485 const int size = InstanceKlass::size(parser.vtable_size(),
486 parser.itable_size(),
487 nonstatic_oop_map_size(parser.total_oop_map_count()),
488 parser.is_interface(),
489 parser.is_inline_type());
490
491 const Symbol* const class_name = parser.class_name();
492 assert(class_name != nullptr, "invariant");
493 ClassLoaderData* loader_data = parser.loader_data();
494 assert(loader_data != nullptr, "invariant");
495
496 InstanceKlass* ik;
497 const bool use_class_space = parser.klass_needs_narrow_id();
498
499 // Allocation
500 if (parser.is_instance_ref_klass()) {
501 // java.lang.ref.Reference
502 ik = new (loader_data, size, use_class_space, THREAD) InstanceRefKlass(parser);
503 } else if (class_name == vmSymbols::java_lang_Class()) {
504 // mirror - java.lang.Class
505 ik = new (loader_data, size, use_class_space, THREAD) InstanceMirrorKlass(parser);
506 } else if (is_stack_chunk_class(class_name, loader_data)) {
507 // stack chunk
508 ik = new (loader_data, size, use_class_space, THREAD) InstanceStackChunkKlass(parser);
509 } else if (is_class_loader(class_name, parser)) {
510 // class loader - java.lang.ClassLoader
511 ik = new (loader_data, size, use_class_space, THREAD) InstanceClassLoaderKlass(parser);
512 } else if (parser.is_inline_type()) {
513 // inline type
514 ik = new (loader_data, size, use_class_space, THREAD) InlineKlass(parser);
515 } else {
516 // normal
517 ik = new (loader_data, size, use_class_space, THREAD) InstanceKlass(parser);
518 }
519
520 if (ik != nullptr && UseCompressedClassPointers && use_class_space) {
521 assert(CompressedKlassPointers::is_encodable(ik),
522 "Klass " PTR_FORMAT "needs a narrow Klass ID, but is not encodable", p2i(ik));
523 }
524
525 // Check for pending exception before adding to the loader data and incrementing
526 // class count. Can get OOM here.
527 if (HAS_PENDING_EXCEPTION) {
528 return nullptr;
529 }
530
531 #ifdef ASSERT
532 ik->bounds_check((address) ik->start_of_vtable(), false, size);
533 ik->bounds_check((address) ik->start_of_itable(), false, size);
534 ik->bounds_check((address) ik->end_of_itable(), true, size);
535 ik->bounds_check((address) ik->end_of_nonstatic_oop_maps(), true, size);
536 #endif //ASSERT
537 return ik;
538 }
539
540 #ifndef PRODUCT
541 bool InstanceKlass::bounds_check(address addr, bool edge_ok, intptr_t size_in_bytes) const {
542 const char* bad = nullptr;
543 address end = nullptr;
544 if (addr < (address)this) {
545 bad = "before";
546 } else if (addr == (address)this) {
547 if (edge_ok) return true;
548 bad = "just before";
549 } else if (addr == (end = (address)this + sizeof(intptr_t) * (size_in_bytes < 0 ? size() : size_in_bytes))) {
550 if (edge_ok) return true;
551 bad = "just after";
552 } else if (addr > end) {
553 bad = "after";
554 } else {
555 return true;
556 }
557 tty->print_cr("%s object bounds: " INTPTR_FORMAT " [" INTPTR_FORMAT ".." INTPTR_FORMAT "]",
558 bad, (intptr_t)addr, (intptr_t)this, (intptr_t)end);
559 Verbose = WizardMode = true; this->print(); //@@
560 return false;
561 }
562 #endif //PRODUCT
563
564 // copy method ordering from resource area to Metaspace
565 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
566 if (m != nullptr) {
567 // allocate a new array and copy contents (memcpy?)
568 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
569 for (int i = 0; i < m->length(); i++) {
570 _method_ordering->at_put(i, m->at(i));
571 }
572 } else {
573 _method_ordering = Universe::the_empty_int_array();
574 }
575 }
576
577 // create a new array of vtable_indices for default methods
578 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
579 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
580 assert(default_vtable_indices() == nullptr, "only create once");
581 set_default_vtable_indices(vtable_indices);
582 return vtable_indices;
583 }
584
585
586 InstanceKlass::InstanceKlass() {
587 assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
588 }
589
590 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, markWord prototype_header, ReferenceType reference_type) :
591 Klass(kind, prototype_header),
592 _nest_members(nullptr),
593 _nest_host(nullptr),
594 _permitted_subclasses(nullptr),
595 _record_components(nullptr),
596 _static_field_size(parser.static_field_size()),
597 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
598 _itable_len(parser.itable_size()),
599 _nest_host_index(0),
600 _init_state(allocated),
601 _reference_type(reference_type),
602 _init_thread(nullptr),
603 _inline_layout_info_array(nullptr),
604 _loadable_descriptors(nullptr),
605 _adr_inlineklass_fixed_block(nullptr)
606 {
607 set_vtable_length(parser.vtable_size());
608 set_access_flags(parser.access_flags());
609 if (parser.is_hidden()) set_is_hidden();
610 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
611 false));
612 if (parser.has_inline_fields()) {
613 set_has_inline_type_fields();
614 }
615
616 assert(nullptr == _methods, "underlying memory not zeroed?");
617 assert(is_instance_klass(), "is layout incorrect?");
618 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
619 }
620
621 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
622 Array<Method*>* methods) {
623 if (methods != nullptr && methods != Universe::the_empty_method_array() &&
624 !methods->is_shared()) {
625 for (int i = 0; i < methods->length(); i++) {
626 Method* method = methods->at(i);
627 if (method == nullptr) continue; // maybe null if error processing
628 // Only want to delete methods that are not executing for RedefineClasses.
629 // The previous version will point to them so they're not totally dangling
630 assert (!method->on_stack(), "shouldn't be called with methods on stack");
631 MetadataFactory::free_metadata(loader_data, method);
632 }
633 MetadataFactory::free_array<Method*>(loader_data, methods);
634 }
734 (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
735 !secondary_supers()->is_shared()) {
736 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
737 }
738 set_secondary_supers(nullptr, SECONDARY_SUPERS_BITMAP_EMPTY);
739
740 deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
741 set_transitive_interfaces(nullptr);
742 set_local_interfaces(nullptr);
743
744 if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->is_shared()) {
745 MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
746 }
747 set_fieldinfo_stream(nullptr);
748
749 if (fields_status() != nullptr && !fields_status()->is_shared()) {
750 MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
751 }
752 set_fields_status(nullptr);
753
754 if (inline_layout_info_array() != nullptr) {
755 MetadataFactory::free_array<InlineLayoutInfo>(loader_data, inline_layout_info_array());
756 }
757 set_inline_layout_info_array(nullptr);
758
759 // If a method from a redefined class is using this constant pool, don't
760 // delete it, yet. The new class's previous version will point to this.
761 if (constants() != nullptr) {
762 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
763 if (!constants()->is_shared()) {
764 MetadataFactory::free_metadata(loader_data, constants());
765 }
766 // Delete any cached resolution errors for the constant pool
767 SystemDictionary::delete_resolution_error(constants());
768
769 set_constants(nullptr);
770 }
771
772 if (inner_classes() != nullptr &&
773 inner_classes() != Universe::the_empty_short_array() &&
774 !inner_classes()->is_shared()) {
775 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
776 }
777 set_inner_classes(nullptr);
778
779 if (nest_members() != nullptr &&
780 nest_members() != Universe::the_empty_short_array() &&
781 !nest_members()->is_shared()) {
782 MetadataFactory::free_array<jushort>(loader_data, nest_members());
783 }
784 set_nest_members(nullptr);
785
786 if (permitted_subclasses() != nullptr &&
787 permitted_subclasses() != Universe::the_empty_short_array() &&
788 !permitted_subclasses()->is_shared()) {
789 MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
790 }
791 set_permitted_subclasses(nullptr);
792
793 if (loadable_descriptors() != nullptr &&
794 loadable_descriptors() != Universe::the_empty_short_array() &&
795 !loadable_descriptors()->is_shared()) {
796 MetadataFactory::free_array<jushort>(loader_data, loadable_descriptors());
797 }
798 set_loadable_descriptors(nullptr);
799
800 // We should deallocate the Annotations instance if it's not in shared spaces.
801 if (annotations() != nullptr && !annotations()->is_shared()) {
802 MetadataFactory::free_metadata(loader_data, annotations());
803 }
804 set_annotations(nullptr);
805
806 SystemDictionaryShared::handle_class_unloading(this);
807
808 #if INCLUDE_CDS_JAVA_HEAP
809 if (CDSConfig::is_dumping_heap()) {
810 HeapShared::remove_scratch_objects(this);
811 }
812 #endif
813 }
814
815 bool InstanceKlass::is_record() const {
816 return _record_components != nullptr &&
817 is_final() &&
818 java_super() == vmClasses::Record_klass();
819 }
1014 vmSymbols::java_lang_IncompatibleClassChangeError(),
1015 "class %s has interface %s as super class",
1016 external_name(),
1017 super_klass->external_name()
1018 );
1019 return false;
1020 }
1021
1022 InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
1023 ik_super->link_class_impl(CHECK_false);
1024 }
1025
1026 // link all interfaces implemented by this class before linking this class
1027 Array<InstanceKlass*>* interfaces = local_interfaces();
1028 int num_interfaces = interfaces->length();
1029 for (int index = 0; index < num_interfaces; index++) {
1030 InstanceKlass* interk = interfaces->at(index);
1031 interk->link_class_impl(CHECK_false);
1032 }
1033
1034
1035 // If a class declares a method that uses an inline class as an argument
1036 // type or return inline type, this inline class must be loaded during the
1037 // linking of this class because size and properties of the inline class
1038 // must be known in order to be able to perform inline type optimizations.
1039 // The implementation below is an approximation of this rule, the code
1040 // iterates over all methods of the current class (including overridden
1041 // methods), not only the methods declared by this class. This
1042 // approximation makes the code simpler, and doesn't change the semantic
1043 // because classes declaring methods overridden by the current class are
1044 // linked (and have performed their own pre-loading) before the linking
1045 // of the current class.
1046
1047
1048 // Note:
1049 // Inline class types are loaded during
1050 // the loading phase (see ClassFileParser::post_process_parsed_stream()).
1051 // Inline class types used as element types for array creation
1052 // are not pre-loaded. Their loading is triggered by either anewarray
1053 // or multianewarray bytecodes.
1054
1055 // Could it be possible to do the following processing only if the
1056 // class uses inline types?
1057 if (EnableValhalla) {
1058 ResourceMark rm(THREAD);
1059 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1060 if (fs.is_null_free_inline_type() && fs.access_flags().is_static()) {
1061 assert(fs.access_flags().is_strict(), "null-free fields must be strict");
1062 Symbol* sig = fs.signature();
1063 TempNewSymbol s = Signature::strip_envelope(sig);
1064 if (s != name()) {
1065 log_info(class, preload)("Preloading class %s during linking of class %s. Cause: a null-free static field is declared with this type", s->as_C_string(), name()->as_C_string());
1066 Klass* klass = SystemDictionary::resolve_or_fail(s,
1067 Handle(THREAD, class_loader()), true,
1068 CHECK_false);
1069 if (HAS_PENDING_EXCEPTION) {
1070 log_warning(class, preload)("Preloading of class %s during linking of class %s (cause: null-free static field) failed: %s",
1071 s->as_C_string(), name()->as_C_string(), PENDING_EXCEPTION->klass()->name()->as_C_string());
1072 return false; // Exception is still pending
1073 }
1074 log_info(class, preload)("Preloading of class %s during linking of class %s (cause: null-free static field) succeeded",
1075 s->as_C_string(), name()->as_C_string());
1076 assert(klass != nullptr, "Sanity check");
1077 if (klass->is_abstract()) {
1078 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
1079 err_msg("Class %s expects class %s to be concrete value class, but it is an abstract class",
1080 name()->as_C_string(),
1081 InstanceKlass::cast(klass)->external_name()), false);
1082 }
1083 if (!klass->is_inline_klass()) {
1084 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
1085 err_msg("class %s expects class %s to be a value class but it is an identity class",
1086 name()->as_C_string(), klass->external_name()), false);
1087 }
1088 InlineKlass* vk = InlineKlass::cast(klass);
1089 // the inline_type_field_klasses_array might have been loaded with CDS, so update only if not already set and check consistency
1090 InlineLayoutInfo* li = inline_layout_info_adr(fs.index());
1091 if (li->klass() == nullptr) {
1092 li->set_klass(InlineKlass::cast(vk));
1093 li->set_kind(LayoutKind::REFERENCE);
1094 }
1095 assert(get_inline_type_field_klass(fs.index()) == vk, "Must match");
1096 } else {
1097 InlineLayoutInfo* li = inline_layout_info_adr(fs.index());
1098 if (li->klass() == nullptr) {
1099 li->set_klass(InlineKlass::cast(this));
1100 li->set_kind(LayoutKind::REFERENCE);
1101 }
1102 assert(get_inline_type_field_klass(fs.index()) == this, "Must match");
1103 }
1104 }
1105 }
1106
1107 // Aggressively preloading all classes from the LoadableDescriptors attribute
1108 if (loadable_descriptors() != nullptr) {
1109 HandleMark hm(THREAD);
1110 for (int i = 0; i < loadable_descriptors()->length(); i++) {
1111 Symbol* sig = constants()->symbol_at(loadable_descriptors()->at(i));
1112 if (!Signature::has_envelope(sig)) continue;
1113 TempNewSymbol class_name = Signature::strip_envelope(sig);
1114 if (class_name == name()) continue;
1115 log_info(class, preload)("Preloading class %s during linking of class %s because of the class is listed in the LoadableDescriptors attribute", sig->as_C_string(), name()->as_C_string());
1116 oop loader = class_loader();
1117 Klass* klass = SystemDictionary::resolve_or_null(class_name,
1118 Handle(THREAD, loader), THREAD);
1119 if (HAS_PENDING_EXCEPTION) {
1120 CLEAR_PENDING_EXCEPTION;
1121 }
1122 if (klass != nullptr) {
1123 log_info(class, preload)("Preloading of class %s during linking of class %s (cause: LoadableDescriptors attribute) succeeded", class_name->as_C_string(), name()->as_C_string());
1124 if (!klass->is_inline_klass()) {
1125 // Non value class are allowed by the current spec, but it could be an indication of an issue so let's log a warning
1126 log_warning(class, preload)("Preloading class %s during linking of class %s (cause: LoadableDescriptors attribute) but loaded class is not a value class", class_name->as_C_string(), name()->as_C_string());
1127 }
1128 } else {
1129 log_warning(class, preload)("Preloading of class %s during linking of class %s (cause: LoadableDescriptors attribute) failed", class_name->as_C_string(), name()->as_C_string());
1130 }
1131 }
1132 }
1133 }
1134
1135 // in case the class is linked in the process of linking its superclasses
1136 if (is_linked()) {
1137 return true;
1138 }
1139
1140 // trace only the link time for this klass that includes
1141 // the verification time
1142 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
1143 ClassLoader::perf_class_link_selftime(),
1144 ClassLoader::perf_classes_linked(),
1145 jt->get_thread_stat()->perf_recursion_counts_addr(),
1146 jt->get_thread_stat()->perf_timers_addr(),
1147 PerfClassTraceTime::CLASS_LINK);
1148
1149 // verification & rewriting
1150 {
1151 HandleMark hm(THREAD);
1152 Handle h_init_lock(THREAD, init_lock());
1153 ObjectLocker ol(h_init_lock, jt);
1154 // rewritten will have been set if loader constraint error found
1419 ss.print("Could not initialize class %s", external_name());
1420 if (cause.is_null()) {
1421 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1422 } else {
1423 THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1424 ss.as_string(), cause);
1425 }
1426 } else {
1427
1428 // Step 6
1429 set_init_state(being_initialized);
1430 set_init_thread(jt);
1431 if (debug_logging_enabled) {
1432 ResourceMark rm(jt);
1433 log_debug(class, init)("Thread \"%s\" is initializing %s",
1434 jt->name(), external_name());
1435 }
1436 }
1437 }
1438
1439 // Pre-allocating an all-zero value to be used to reset nullable flat storages
1440 if (is_inline_klass()) {
1441 InlineKlass* vk = InlineKlass::cast(this);
1442 if (vk->has_nullable_atomic_layout()) {
1443 oop val = vk->allocate_instance(THREAD);
1444 if (HAS_PENDING_EXCEPTION) {
1445 Handle e(THREAD, PENDING_EXCEPTION);
1446 CLEAR_PENDING_EXCEPTION;
1447 {
1448 EXCEPTION_MARK;
1449 add_initialization_error(THREAD, e);
1450 // Locks object, set state, and notify all waiting threads
1451 set_initialization_state_and_notify(initialization_error, THREAD);
1452 CLEAR_PENDING_EXCEPTION;
1453 }
1454 THROW_OOP(e());
1455 }
1456 vk->set_null_reset_value(val);
1457 }
1458 }
1459
1460 // Step 7
1461 // Next, if C is a class rather than an interface, initialize it's super class and super
1462 // interfaces.
1463 if (!is_interface()) {
1464 Klass* super_klass = super();
1465 if (super_klass != nullptr && super_klass->should_be_initialized()) {
1466 super_klass->initialize(THREAD);
1467 }
1468 // If C implements any interface that declares a non-static, concrete method,
1469 // the initialization of C triggers initialization of its super interfaces.
1470 // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1471 // having a superinterface that declares, non-static, concrete methods
1472 if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1473 initialize_super_interfaces(THREAD);
1474 }
1475
1476 // If any exceptions, complete abruptly, throwing the same exception as above.
1477 if (HAS_PENDING_EXCEPTION) {
1478 Handle e(THREAD, PENDING_EXCEPTION);
1479 CLEAR_PENDING_EXCEPTION;
1480 {
1481 EXCEPTION_MARK;
1482 add_initialization_error(THREAD, e);
1483 // Locks object, set state, and notify all waiting threads
1484 set_initialization_state_and_notify(initialization_error, THREAD);
1485 CLEAR_PENDING_EXCEPTION;
1486 }
1487 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1488 THROW_OOP(e());
1489 }
1490 }
1491
1492 // Step 8
1493 {
1494 DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1495 if (class_initializer() != nullptr) {
1496 // Timer includes any side effects of class initialization (resolution,
1497 // etc), but not recursive entry into call_class_initializer().
1498 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1499 ClassLoader::perf_class_init_selftime(),
1500 ClassLoader::perf_classes_inited(),
1501 jt->get_thread_stat()->perf_recursion_counts_addr(),
1502 jt->get_thread_stat()->perf_timers_addr(),
1503 PerfClassTraceTime::CLASS_CLINIT);
1504 call_class_initializer(THREAD);
1505 } else {
1506 // The elapsed time is so small it's not worth counting.
1507 if (UsePerfData) {
1508 ClassLoader::perf_classes_inited()->inc();
1509 }
1510 call_class_initializer(THREAD);
1511 }
1796 ResourceMark rm(THREAD);
1797 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1798 : vmSymbols::java_lang_InstantiationException(), external_name());
1799 }
1800 if (this == vmClasses::Class_klass()) {
1801 ResourceMark rm(THREAD);
1802 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1803 : vmSymbols::java_lang_IllegalAccessException(), external_name());
1804 }
1805 }
1806
1807 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1808 // Need load-acquire for lock-free read
1809 if (array_klasses_acquire() == nullptr) {
1810
1811 // Recursively lock array allocation
1812 RecursiveLocker rl(MultiArray_lock, THREAD);
1813
1814 // Check if another thread created the array klass while we were waiting for the lock.
1815 if (array_klasses() == nullptr) {
1816 ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, false, CHECK_NULL);
1817 // use 'release' to pair with lock-free load
1818 release_set_array_klasses(k);
1819 }
1820 }
1821
1822 // array_klasses() will always be set at this point
1823 ArrayKlass* ak = array_klasses();
1824 assert(ak != nullptr, "should be set");
1825 return ak->array_klass(n, THREAD);
1826 }
1827
1828 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1829 // Need load-acquire for lock-free read
1830 ArrayKlass* ak = array_klasses_acquire();
1831 if (ak == nullptr) {
1832 return nullptr;
1833 } else {
1834 return ak->array_klass_or_null(n);
1835 }
1836 }
1837
1838 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1839 return array_klass(1, THREAD);
1840 }
1841
1842 ArrayKlass* InstanceKlass::array_klass_or_null() {
1843 return array_klass_or_null(1);
1844 }
1845
1846 static int call_class_initializer_counter = 0; // for debugging
1847
1848 Method* InstanceKlass::class_initializer() const {
1849 Method* clinit = find_method(
1850 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1851 if (clinit != nullptr && clinit->is_class_initializer()) {
1852 return clinit;
1853 }
1854 return nullptr;
1855 }
1856
1857 void InstanceKlass::call_class_initializer(TRAPS) {
1858 if (ReplayCompiles &&
1859 (ReplaySuppressInitializers == 1 ||
1860 (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1861 // Hide the existence of the initializer for the purpose of replaying the compile
1862 return;
1863 }
1864
1865 #if INCLUDE_CDS
1866 // This is needed to ensure the consistency of the archived heap objects.
1867 if (has_aot_initialized_mirror() && CDSConfig::is_loading_heap()) {
1868 AOTClassInitializer::call_runtime_setup(THREAD, this);
1869 return;
1870 } else if (has_archived_enum_objs()) {
1871 assert(is_shared(), "must be");
1940
1941 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1942 InterpreterOopMap* entry_for) {
1943 // Lazily create the _oop_map_cache at first request.
1944 // Load_acquire is needed to safely get instance published with CAS by another thread.
1945 OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1946 if (oop_map_cache == nullptr) {
1947 // Try to install new instance atomically.
1948 oop_map_cache = new OopMapCache();
1949 OopMapCache* other = Atomic::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
1950 if (other != nullptr) {
1951 // Someone else managed to install before us, ditch local copy and use the existing one.
1952 delete oop_map_cache;
1953 oop_map_cache = other;
1954 }
1955 }
1956 // _oop_map_cache is constant after init; lookup below does its own locking.
1957 oop_map_cache->lookup(method, bci, entry_for);
1958 }
1959
1960
1961 FieldInfo InstanceKlass::field(int index) const {
1962 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1963 if (fs.index() == index) {
1964 return fs.to_FieldInfo();
1965 }
1966 }
1967 fatal("Field not found");
1968 return FieldInfo();
1969 }
1970
1971 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1972 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1973 Symbol* f_name = fs.name();
1974 Symbol* f_sig = fs.signature();
1975 if (f_name == name && f_sig == sig) {
1976 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1977 return true;
1978 }
1979 }
2021
2022 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
2023 // search order according to newest JVM spec (5.4.3.2, p.167).
2024 // 1) search for field in current klass
2025 if (find_local_field(name, sig, fd)) {
2026 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
2027 }
2028 // 2) search for field recursively in direct superinterfaces
2029 if (is_static) {
2030 Klass* intf = find_interface_field(name, sig, fd);
2031 if (intf != nullptr) return intf;
2032 }
2033 // 3) apply field lookup recursively if superclass exists
2034 { Klass* supr = super();
2035 if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
2036 }
2037 // 4) otherwise field lookup fails
2038 return nullptr;
2039 }
2040
2041 bool InstanceKlass::contains_field_offset(int offset) {
2042 if (this->is_inline_klass()) {
2043 InlineKlass* vk = InlineKlass::cast(this);
2044 return offset >= vk->payload_offset() && offset < (vk->payload_offset() + vk->payload_size_in_bytes());
2045 } else {
2046 fieldDescriptor fd;
2047 return find_field_from_offset(offset, false, &fd);
2048 }
2049 }
2050
2051 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
2052 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
2053 if (fs.offset() == offset) {
2054 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
2055 if (fd->is_static() == is_static) return true;
2056 }
2057 }
2058 return false;
2059 }
2060
2061
2062 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
2063 Klass* klass = const_cast<InstanceKlass*>(this);
2064 while (klass != nullptr) {
2065 if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
2066 return true;
2067 }
2068 klass = klass->super();
2069 }
2421 }
2422
2423 // uncached_lookup_method searches both the local class methods array and all
2424 // superclasses methods arrays, skipping any overpass methods in superclasses,
2425 // and possibly skipping private methods.
2426 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2427 const Symbol* signature,
2428 OverpassLookupMode overpass_mode,
2429 PrivateLookupMode private_mode) const {
2430 OverpassLookupMode overpass_local_mode = overpass_mode;
2431 const Klass* klass = this;
2432 while (klass != nullptr) {
2433 Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2434 signature,
2435 overpass_local_mode,
2436 StaticLookupMode::find,
2437 private_mode);
2438 if (method != nullptr) {
2439 return method;
2440 }
2441 if (name == vmSymbols::object_initializer_name()) {
2442 break; // <init> is never inherited
2443 }
2444 klass = klass->super();
2445 overpass_local_mode = OverpassLookupMode::skip; // Always ignore overpass methods in superclasses
2446 }
2447 return nullptr;
2448 }
2449
2450 #ifdef ASSERT
2451 // search through class hierarchy and return true if this class or
2452 // one of the superclasses was redefined
2453 bool InstanceKlass::has_redefined_this_or_super() const {
2454 const Klass* klass = this;
2455 while (klass != nullptr) {
2456 if (InstanceKlass::cast(klass)->has_been_redefined()) {
2457 return true;
2458 }
2459 klass = klass->super();
2460 }
2461 return false;
2462 }
2463 #endif
2821 int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2822
2823 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2824 / itableOffsetEntry::size();
2825
2826 for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2827 if (ioe->interface_klass() != nullptr) {
2828 it->push(ioe->interface_klass_addr());
2829 itableMethodEntry* ime = ioe->first_method_entry(this);
2830 int n = klassItable::method_count_for_interface(ioe->interface_klass());
2831 for (int index = 0; index < n; index ++) {
2832 it->push(ime[index].method_addr());
2833 }
2834 }
2835 }
2836 }
2837
2838 it->push(&_nest_host);
2839 it->push(&_nest_members);
2840 it->push(&_permitted_subclasses);
2841 it->push(&_loadable_descriptors);
2842 it->push(&_record_components);
2843 it->push(&_inline_layout_info_array, MetaspaceClosure::_writable);
2844 }
2845
2846 #if INCLUDE_CDS
2847 void InstanceKlass::remove_unshareable_info() {
2848
2849 if (is_linked()) {
2850 assert(can_be_verified_at_dumptime(), "must be");
2851 // Remember this so we can avoid walking the hierarchy at runtime.
2852 set_verified_at_dump_time();
2853 }
2854
2855 Klass::remove_unshareable_info();
2856
2857 if (SystemDictionaryShared::has_class_failed_verification(this)) {
2858 // Classes are attempted to link during dumping and may fail,
2859 // but these classes are still in the dictionary and class list in CLD.
2860 // If the class has failed verification, there is nothing else to remove.
2861 return;
2862 }
2863
2869
2870 { // Otherwise this needs to take out the Compile_lock.
2871 assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2872 init_implementor();
2873 }
2874
2875 // Call remove_unshareable_info() on other objects that belong to this class, except
2876 // for constants()->remove_unshareable_info(), which is called in a separate pass in
2877 // ArchiveBuilder::make_klasses_shareable(),
2878
2879 for (int i = 0; i < methods()->length(); i++) {
2880 Method* m = methods()->at(i);
2881 m->remove_unshareable_info();
2882 }
2883
2884 // do array classes also.
2885 if (array_klasses() != nullptr) {
2886 array_klasses()->remove_unshareable_info();
2887 }
2888
2889 // These are not allocated from metaspace. They are safe to set to nullptr.
2890 _source_debug_extension = nullptr;
2891 _dep_context = nullptr;
2892 _osr_nmethods_head = nullptr;
2893 #if INCLUDE_JVMTI
2894 _breakpoints = nullptr;
2895 _previous_versions = nullptr;
2896 _cached_class_file = nullptr;
2897 _jvmti_cached_class_field_map = nullptr;
2898 #endif
2899
2900 _init_thread = nullptr;
2901 _methods_jmethod_ids = nullptr;
2902 _jni_ids = nullptr;
2903 _oop_map_cache = nullptr;
2904 if (CDSConfig::is_dumping_method_handles() && HeapShared::is_lambda_proxy_klass(this)) {
2905 // keep _nest_host
2906 } else {
2907 // clear _nest_host to ensure re-load at runtime
2908 _nest_host = nullptr;
2909 }
2958 void InstanceKlass::compute_has_loops_flag_for_methods() {
2959 Array<Method*>* methods = this->methods();
2960 for (int index = 0; index < methods->length(); ++index) {
2961 Method* m = methods->at(index);
2962 if (!m->is_overpass()) { // work around JDK-8305771
2963 m->compute_has_loops_flag();
2964 }
2965 }
2966 }
2967
2968 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2969 PackageEntry* pkg_entry, TRAPS) {
2970 // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2971 // before the InstanceKlass is added to the SystemDictionary. Make
2972 // sure the current state is <loaded.
2973 assert(!is_loaded(), "invalid init state");
2974 assert(!shared_loading_failed(), "Must not try to load failed class again");
2975 set_package(loader_data, pkg_entry, CHECK);
2976 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2977
2978 if (is_inline_klass()) {
2979 InlineKlass::cast(this)->initialize_calling_convention(CHECK);
2980 }
2981
2982 Array<Method*>* methods = this->methods();
2983 int num_methods = methods->length();
2984 for (int index = 0; index < num_methods; ++index) {
2985 methods->at(index)->restore_unshareable_info(CHECK);
2986 }
2987 #if INCLUDE_JVMTI
2988 if (JvmtiExport::has_redefined_a_class()) {
2989 // Reinitialize vtable because RedefineClasses may have changed some
2990 // entries in this vtable for super classes so the CDS vtable might
2991 // point to old or obsolete entries. RedefineClasses doesn't fix up
2992 // vtables in the shared system dictionary, only the main one.
2993 // It also redefines the itable too so fix that too.
2994 // First fix any default methods that point to a super class that may
2995 // have been redefined.
2996 bool trace_name_printed = false;
2997 adjust_default_methods(&trace_name_printed);
2998 if (verified_at_dump_time()) {
2999 // Initialize vtable and itable for classes which can be verified at dump time.
3000 // Unlinked classes such as old classes with major version < 50 cannot be verified
3001 // at dump time.
3002 vtable().initialize_vtable();
3003 itable().initialize_itable();
3004 }
3005 }
3006 #endif // INCLUDE_JVMTI
3007
3008 // restore constant pool resolved references
3009 constants()->restore_unshareable_info(CHECK);
3010
3011 if (array_klasses() != nullptr) {
3012 // To get a consistent list of classes we need MultiArray_lock to ensure
3013 // array classes aren't observed while they are being restored.
3014 RecursiveLocker rl(MultiArray_lock, THREAD);
3015 assert(this == ObjArrayKlass::cast(array_klasses())->bottom_klass(), "sanity");
3016 // Array classes have null protection domain.
3017 // --> see ArrayKlass::complete_create_array_klass()
3018 array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
3019 }
3020
3021 // Initialize @ValueBased class annotation if not already set in the archived klass.
3022 if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
3023 set_is_value_based();
3024 }
3025 }
3026
3027 // Check if a class or any of its supertypes has a version older than 50.
3028 // CDS will not perform verification of old classes during dump time because
3029 // without changing the old verifier, the verification constraint cannot be
3030 // retrieved during dump time.
3031 // Verification of archived old classes will be performed during run time.
3032 bool InstanceKlass::can_be_verified_at_dumptime() const {
3033 if (MetaspaceShared::is_in_shared_metaspace(this)) {
3034 // This is a class that was dumped into the base archive, so we know
3035 // it was verified at dump time.
3192 } else {
3193 // Adding one to the attribute length in order to store a null terminator
3194 // character could cause an overflow because the attribute length is
3195 // already coded with an u4 in the classfile, but in practice, it's
3196 // unlikely to happen.
3197 assert((length+1) > length, "Overflow checking");
3198 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
3199 for (int i = 0; i < length; i++) {
3200 sde[i] = array[i];
3201 }
3202 sde[length] = '\0';
3203 _source_debug_extension = sde;
3204 }
3205 }
3206
3207 Symbol* InstanceKlass::generic_signature() const { return _constants->generic_signature(); }
3208 u2 InstanceKlass::generic_signature_index() const { return _constants->generic_signature_index(); }
3209 void InstanceKlass::set_generic_signature_index(u2 sig_index) { _constants->set_generic_signature_index(sig_index); }
3210
3211 const char* InstanceKlass::signature_name() const {
3212 return signature_name_of_carrier(JVM_SIGNATURE_CLASS);
3213 }
3214
3215 const char* InstanceKlass::signature_name_of_carrier(char c) const {
3216 // Get the internal name as a c string
3217 const char* src = (const char*) (name()->as_C_string());
3218 const int src_length = (int)strlen(src);
3219
3220 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
3221
3222 // Add L or Q as type indicator
3223 int dest_index = 0;
3224 dest[dest_index++] = c;
3225
3226 // Add the actual class name
3227 for (int src_index = 0; src_index < src_length; ) {
3228 dest[dest_index++] = src[src_index++];
3229 }
3230
3231 if (is_hidden()) { // Replace the last '+' with a '.'.
3232 for (int index = (int)src_length; index > 0; index--) {
3233 if (dest[index] == '+') {
3234 dest[index] = JVM_SIGNATURE_DOT;
3235 break;
3236 }
3237 }
3238 }
3239
3240 // Add the semicolon and the null
3241 dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
3242 dest[dest_index] = '\0';
3243 return dest;
3244 }
3551 u2 InstanceKlass::compute_modifier_flags() const {
3552 u2 access = access_flags().as_unsigned_short();
3553
3554 // But check if it happens to be member class.
3555 InnerClassesIterator iter(this);
3556 for (; !iter.done(); iter.next()) {
3557 int ioff = iter.inner_class_info_index();
3558 // Inner class attribute can be zero, skip it.
3559 // Strange but true: JVM spec. allows null inner class refs.
3560 if (ioff == 0) continue;
3561
3562 // only look at classes that are already loaded
3563 // since we are looking for the flags for our self.
3564 Symbol* inner_name = constants()->klass_name_at(ioff);
3565 if (name() == inner_name) {
3566 // This is really a member class.
3567 access = iter.inner_access_flags();
3568 break;
3569 }
3570 }
3571 return access;
3572 }
3573
3574 jint InstanceKlass::jvmti_class_status() const {
3575 jint result = 0;
3576
3577 if (is_linked()) {
3578 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3579 }
3580
3581 if (is_initialized()) {
3582 assert(is_linked(), "Class status is not consistent");
3583 result |= JVMTI_CLASS_STATUS_INITIALIZED;
3584 }
3585 if (is_in_error_state()) {
3586 result |= JVMTI_CLASS_STATUS_ERROR;
3587 }
3588 return result;
3589 }
3590
3591 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {
3805 }
3806 osr = osr->osr_link();
3807 }
3808
3809 assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3810 if (best != nullptr && best->comp_level() >= comp_level) {
3811 return best;
3812 }
3813 return nullptr;
3814 }
3815
3816 // -----------------------------------------------------------------------------------------------------
3817 // Printing
3818
3819 #define BULLET " - "
3820
3821 static const char* state_names[] = {
3822 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3823 };
3824
3825 static void print_vtable(address self, intptr_t* start, int len, outputStream* st) {
3826 ResourceMark rm;
3827 int* forward_refs = NEW_RESOURCE_ARRAY(int, len);
3828 for (int i = 0; i < len; i++) forward_refs[i] = 0;
3829 for (int i = 0; i < len; i++) {
3830 intptr_t e = start[i];
3831 st->print("%d : " INTPTR_FORMAT, i, e);
3832 if (forward_refs[i] != 0) {
3833 int from = forward_refs[i];
3834 int off = (int) start[from];
3835 st->print(" (offset %d <= [%d])", off, from);
3836 }
3837 if (MetaspaceObj::is_valid((Metadata*)e)) {
3838 st->print(" ");
3839 ((Metadata*)e)->print_value_on(st);
3840 } else if (self != nullptr && e > 0 && e < 0x10000) {
3841 address location = self + e;
3842 int index = (int)((intptr_t*)location - start);
3843 st->print(" (offset %d => [%d])", (int)e, index);
3844 if (index >= 0 && index < len)
3845 forward_refs[index] = i;
3846 }
3847 st->cr();
3848 }
3849 }
3850
3851 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3852 return print_vtable(nullptr, reinterpret_cast<intptr_t*>(start), len, st);
3853 }
3854
3855 template<typename T>
3856 static void print_array_on(outputStream* st, Array<T>* array) {
3857 if (array == nullptr) { st->print_cr("nullptr"); return; }
3858 array->print_value_on(st); st->cr();
3859 if (Verbose || WizardMode) {
3860 for (int i = 0; i < array->length(); i++) {
3861 st->print("%d : ", i); array->at(i)->print_value_on(st); st->cr();
3862 }
3863 }
3864 }
3865
3866 static void print_array_on(outputStream* st, Array<int>* array) {
3867 if (array == nullptr) { st->print_cr("nullptr"); return; }
3868 array->print_value_on(st); st->cr();
3869 if (Verbose || WizardMode) {
3870 for (int i = 0; i < array->length(); i++) {
3871 st->print("%d : %d", i, array->at(i)); st->cr();
3872 }
3873 }
3874 }
3875
3876 const char* InstanceKlass::init_state_name() const {
3877 return state_names[init_state()];
3878 }
3879
3880 void InstanceKlass::print_on(outputStream* st) const {
3881 assert(is_klass(), "must be klass");
3882 Klass::print_on(st);
3883
3884 st->print(BULLET"instance size: %d", size_helper()); st->cr();
3885 st->print(BULLET"klass size: %d", size()); st->cr();
3886 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
3887 st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
3888 st->print(BULLET"state: "); st->print_cr("%s", init_state_name());
3889 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3890 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3891 st->print(BULLET"sub: ");
3892 Klass* sub = subklass();
3893 int n;
3894 for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3895 if (n < MaxSubklassPrintSize) {
3896 sub->print_value_on(st);
3897 st->print(" ");
3898 }
3899 }
3900 if (n >= MaxSubklassPrintSize) st->print("(%zd more klasses...)", n - MaxSubklassPrintSize);
3901 st->cr();
3902
3903 if (is_interface()) {
3904 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
3905 if (nof_implementors() == 1) {
3906 st->print_cr(BULLET"implementor: ");
3907 st->print(" ");
3908 implementor()->print_value_on(st);
3909 st->cr();
3910 }
3911 }
3912
3913 st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3914 st->print(BULLET"methods: "); print_array_on(st, methods());
3915 st->print(BULLET"method ordering: "); print_array_on(st, method_ordering());
3916 if (default_methods() != nullptr) {
3917 st->print(BULLET"default_methods: "); print_array_on(st, default_methods());
3918 }
3919 print_on_maybe_null(st, BULLET"default vtable indices: ", default_vtable_indices());
3920 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr();
3921 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3922
3923 st->print(BULLET"secondary supers: "); secondary_supers()->print_value_on(st); st->cr();
3924
3925 st->print(BULLET"hash_slot: %d", hash_slot()); st->cr();
3926 st->print(BULLET"secondary bitmap: " UINTX_FORMAT_X_0, _secondary_supers_bitmap); st->cr();
3927
3928 if (secondary_supers() != nullptr) {
3929 if (Verbose) {
3930 bool is_hashed = (_secondary_supers_bitmap != SECONDARY_SUPERS_BITMAP_FULL);
3931 st->print_cr(BULLET"---- secondary supers (%d words):", _secondary_supers->length());
3932 for (int i = 0; i < _secondary_supers->length(); i++) {
3933 ResourceMark rm; // for external_name()
3934 Klass* secondary_super = _secondary_supers->at(i);
3935 st->print(BULLET"%2d:", i);
3936 if (is_hashed) {
3937 int home_slot = compute_home_slot(secondary_super, _secondary_supers_bitmap);
3957 print_on_maybe_null(st, BULLET"field type annotations: ", fields_type_annotations());
3958 {
3959 bool have_pv = false;
3960 // previous versions are linked together through the InstanceKlass
3961 for (InstanceKlass* pv_node = previous_versions();
3962 pv_node != nullptr;
3963 pv_node = pv_node->previous_versions()) {
3964 if (!have_pv)
3965 st->print(BULLET"previous version: ");
3966 have_pv = true;
3967 pv_node->constants()->print_value_on(st);
3968 }
3969 if (have_pv) st->cr();
3970 }
3971
3972 print_on_maybe_null(st, BULLET"generic signature: ", generic_signature());
3973 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
3974 st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr();
3975 print_on_maybe_null(st, BULLET"record components: ", record_components());
3976 st->print(BULLET"permitted subclasses: "); permitted_subclasses()->print_value_on(st); st->cr();
3977 st->print(BULLET"loadable descriptors: "); loadable_descriptors()->print_value_on(st); st->cr();
3978 if (java_mirror() != nullptr) {
3979 st->print(BULLET"java mirror: ");
3980 java_mirror()->print_value_on(st);
3981 st->cr();
3982 } else {
3983 st->print_cr(BULLET"java mirror: null");
3984 }
3985 st->print(BULLET"vtable length %d (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3986 if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
3987 st->print(BULLET"itable length %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3988 if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(nullptr, start_of_itable(), itable_length(), st);
3989 st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3990
3991 FieldPrinter print_static_field(st);
3992 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3993 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3994 FieldPrinter print_nonstatic_field(st);
3995 InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3996 ik->print_nonstatic_fields(&print_nonstatic_field);
3997
3998 st->print(BULLET"non-static oop maps: ");
3999 OopMapBlock* map = start_of_nonstatic_oop_maps();
4000 OopMapBlock* end_map = map + nonstatic_oop_map_count();
4001 while (map < end_map) {
4002 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
4003 map++;
4004 }
4005 st->cr();
4006 }
4007
4008 void InstanceKlass::print_value_on(outputStream* st) const {
4009 assert(is_klass(), "must be klass");
4010 if (Verbose || WizardMode) access_flags().print_on(st);
4011 name()->print_value_on(st);
4012 }
4013
4014 void FieldPrinter::do_field(fieldDescriptor* fd) {
4015 for (int i = 0; i < _indent; i++) _st->print(" ");
4016 _st->print(BULLET);
4017 if (_obj == nullptr) {
4018 fd->print_on(_st, _base_offset);
4019 _st->cr();
4020 } else {
4021 fd->print_on_for(_st, _obj, _indent, _base_offset);
4022 if (!fd->field_flags().is_flat()) _st->cr();
4023 }
4024 }
4025
4026
4027 void InstanceKlass::oop_print_on(oop obj, outputStream* st, int indent, int base_offset) {
4028 Klass::oop_print_on(obj, st);
4029
4030 if (this == vmClasses::String_klass()) {
4031 typeArrayOop value = java_lang_String::value(obj);
4032 juint length = java_lang_String::length(obj);
4033 if (value != nullptr &&
4034 value->is_typeArray() &&
4035 length <= (juint) value->length()) {
4036 st->print(BULLET"string: ");
4037 java_lang_String::print(obj, st);
4038 st->cr();
4039 }
4040 }
4041
4042 st->print_cr(BULLET"---- fields (total size %zu words):", oop_size(obj));
4043 FieldPrinter print_field(st, obj, indent, base_offset);
4044 print_nonstatic_fields(&print_field);
4045
4046 if (this == vmClasses::Class_klass()) {
4047 st->print(BULLET"signature: ");
4048 java_lang_Class::print_signature(obj, st);
4049 st->cr();
4050 Klass* real_klass = java_lang_Class::as_Klass(obj);
4051 if (real_klass != nullptr && real_klass->is_instance_klass()) {
4052 st->print_cr(BULLET"---- static fields (%d):", java_lang_Class::static_oop_field_count(obj));
4053 InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field);
4054 }
4055 } else if (this == vmClasses::MethodType_klass()) {
4056 st->print(BULLET"signature: ");
4057 java_lang_invoke_MethodType::print_signature(obj, st);
4058 st->cr();
4059 }
4060 }
4061
4062 #ifndef PRODUCT
4063
|