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"
132 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait) \
133 { \
134 char* data = nullptr; \
135 int len = 0; \
136 Symbol* clss_name = name(); \
137 if (clss_name != nullptr) { \
138 data = (char*)clss_name->bytes(); \
139 len = clss_name->utf8_length(); \
140 } \
141 HOTSPOT_CLASS_INITIALIZATION_##type( \
142 data, len, (void*)class_loader(), thread_type, wait); \
143 }
144
145 #else // ndef DTRACE_ENABLED
146
147 #define DTRACE_CLASSINIT_PROBE(type, thread_type)
148 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait)
149
150 #endif // ndef DTRACE_ENABLED
151
152 bool InstanceKlass::_finalization_enabled = true;
153
154 static inline bool is_class_loader(const Symbol* class_name,
155 const ClassFileParser& parser) {
156 assert(class_name != nullptr, "invariant");
157
158 if (class_name == vmSymbols::java_lang_ClassLoader()) {
159 return true;
160 }
161
162 if (vmClasses::ClassLoader_klass_loaded()) {
163 const Klass* const super_klass = parser.super_klass();
164 if (super_klass != nullptr) {
165 if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
166 return true;
167 }
168 }
169 }
170 return false;
171 }
172
173 static inline bool is_stack_chunk_class(const Symbol* class_name,
174 const ClassLoaderData* loader_data) {
175 return (class_name == vmSymbols::jdk_internal_vm_StackChunk() &&
176 loader_data->is_the_null_class_loader_data());
177 }
178
179 // private: called to verify that k is a static member of this nest.
180 // We know that k is an instance class in the same package and hence the
181 // same classloader.
182 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
183 assert(!is_hidden(), "unexpected hidden class");
184 if (_nest_members == nullptr || _nest_members == Universe::the_empty_short_array()) {
185 if (log_is_enabled(Trace, class, nestmates)) {
186 ResourceMark rm(current);
187 log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
188 k->external_name(), this->external_name());
189 }
190 return false;
191 }
192
430 }
431
432 const char* InstanceKlass::nest_host_error() {
433 if (_nest_host_index == 0) {
434 return nullptr;
435 } else {
436 constantPoolHandle cph(Thread::current(), constants());
437 return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
438 }
439 }
440
441 void* InstanceKlass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size,
442 bool use_class_space, TRAPS) throw() {
443 return Metaspace::allocate(loader_data, word_size, ClassType, use_class_space, THREAD);
444 }
445
446 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
447 const int size = InstanceKlass::size(parser.vtable_size(),
448 parser.itable_size(),
449 nonstatic_oop_map_size(parser.total_oop_map_count()),
450 parser.is_interface());
451
452 const Symbol* const class_name = parser.class_name();
453 assert(class_name != nullptr, "invariant");
454 ClassLoaderData* loader_data = parser.loader_data();
455 assert(loader_data != nullptr, "invariant");
456
457 InstanceKlass* ik;
458 const bool use_class_space = !parser.is_interface() && !parser.is_abstract();
459
460 // Allocation
461 if (parser.is_instance_ref_klass()) {
462 // java.lang.ref.Reference
463 ik = new (loader_data, size, use_class_space, THREAD) InstanceRefKlass(parser);
464 } else if (class_name == vmSymbols::java_lang_Class()) {
465 // mirror - java.lang.Class
466 ik = new (loader_data, size, use_class_space, THREAD) InstanceMirrorKlass(parser);
467 } else if (is_stack_chunk_class(class_name, loader_data)) {
468 // stack chunk
469 ik = new (loader_data, size, use_class_space, THREAD) InstanceStackChunkKlass(parser);
470 } else if (is_class_loader(class_name, parser)) {
471 // class loader - java.lang.ClassLoader
472 ik = new (loader_data, size, use_class_space, THREAD) InstanceClassLoaderKlass(parser);
473 } else {
474 // normal
475 ik = new (loader_data, size, use_class_space, THREAD) InstanceKlass(parser);
476 }
477
478 // Check for pending exception before adding to the loader data and incrementing
479 // class count. Can get OOM here.
480 if (HAS_PENDING_EXCEPTION) {
481 return nullptr;
482 }
483
484 return ik;
485 }
486
487
488 // copy method ordering from resource area to Metaspace
489 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
490 if (m != nullptr) {
491 // allocate a new array and copy contents (memcpy?)
492 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
493 for (int i = 0; i < m->length(); i++) {
494 _method_ordering->at_put(i, m->at(i));
495 }
496 } else {
497 _method_ordering = Universe::the_empty_int_array();
498 }
499 }
500
501 // create a new array of vtable_indices for default methods
502 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
503 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
504 assert(default_vtable_indices() == nullptr, "only create once");
505 set_default_vtable_indices(vtable_indices);
506 return vtable_indices;
507 }
508
509
510 InstanceKlass::InstanceKlass() {
511 assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
512 }
513
514 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) :
515 Klass(kind),
516 _nest_members(nullptr),
517 _nest_host(nullptr),
518 _permitted_subclasses(nullptr),
519 _record_components(nullptr),
520 _static_field_size(parser.static_field_size()),
521 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
522 _itable_len(parser.itable_size()),
523 _nest_host_index(0),
524 _init_state(allocated),
525 _reference_type(reference_type),
526 _init_thread(nullptr)
527 {
528 set_vtable_length(parser.vtable_size());
529 set_access_flags(parser.access_flags());
530 if (parser.is_hidden()) set_is_hidden();
531 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
532 false));
533
534 assert(nullptr == _methods, "underlying memory not zeroed?");
535 assert(is_instance_klass(), "is layout incorrect?");
536 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
537 }
538
539 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
540 Array<Method*>* methods) {
541 if (methods != nullptr && methods != Universe::the_empty_method_array() &&
542 !methods->is_shared()) {
543 for (int i = 0; i < methods->length(); i++) {
544 Method* method = methods->at(i);
545 if (method == nullptr) continue; // maybe null if error processing
546 // Only want to delete methods that are not executing for RedefineClasses.
547 // The previous version will point to them so they're not totally dangling
548 assert (!method->on_stack(), "shouldn't be called with methods on stack");
549 MetadataFactory::free_metadata(loader_data, method);
550 }
551 MetadataFactory::free_array<Method*>(loader_data, methods);
552 }
652 (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
653 !secondary_supers()->is_shared()) {
654 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
655 }
656 set_secondary_supers(nullptr, SECONDARY_SUPERS_BITMAP_EMPTY);
657
658 deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
659 set_transitive_interfaces(nullptr);
660 set_local_interfaces(nullptr);
661
662 if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->is_shared()) {
663 MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
664 }
665 set_fieldinfo_stream(nullptr);
666
667 if (fields_status() != nullptr && !fields_status()->is_shared()) {
668 MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
669 }
670 set_fields_status(nullptr);
671
672 // If a method from a redefined class is using this constant pool, don't
673 // delete it, yet. The new class's previous version will point to this.
674 if (constants() != nullptr) {
675 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
676 if (!constants()->is_shared()) {
677 MetadataFactory::free_metadata(loader_data, constants());
678 }
679 // Delete any cached resolution errors for the constant pool
680 SystemDictionary::delete_resolution_error(constants());
681
682 set_constants(nullptr);
683 }
684
685 if (inner_classes() != nullptr &&
686 inner_classes() != Universe::the_empty_short_array() &&
687 !inner_classes()->is_shared()) {
688 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
689 }
690 set_inner_classes(nullptr);
691
692 if (nest_members() != nullptr &&
693 nest_members() != Universe::the_empty_short_array() &&
694 !nest_members()->is_shared()) {
695 MetadataFactory::free_array<jushort>(loader_data, nest_members());
696 }
697 set_nest_members(nullptr);
698
699 if (permitted_subclasses() != nullptr &&
700 permitted_subclasses() != Universe::the_empty_short_array() &&
701 !permitted_subclasses()->is_shared()) {
702 MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
703 }
704 set_permitted_subclasses(nullptr);
705
706 // We should deallocate the Annotations instance if it's not in shared spaces.
707 if (annotations() != nullptr && !annotations()->is_shared()) {
708 MetadataFactory::free_metadata(loader_data, annotations());
709 }
710 set_annotations(nullptr);
711
712 SystemDictionaryShared::handle_class_unloading(this);
713
714 #if INCLUDE_CDS_JAVA_HEAP
715 if (CDSConfig::is_dumping_heap()) {
716 HeapShared::remove_scratch_objects(this);
717 }
718 #endif
719 }
720
721 bool InstanceKlass::is_record() const {
722 return _record_components != nullptr &&
723 is_final() &&
724 java_super() == vmClasses::Record_klass();
725 }
844 vmSymbols::java_lang_IncompatibleClassChangeError(),
845 "class %s has interface %s as super class",
846 external_name(),
847 super_klass->external_name()
848 );
849 return false;
850 }
851
852 InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
853 ik_super->link_class_impl(CHECK_false);
854 }
855
856 // link all interfaces implemented by this class before linking this class
857 Array<InstanceKlass*>* interfaces = local_interfaces();
858 int num_interfaces = interfaces->length();
859 for (int index = 0; index < num_interfaces; index++) {
860 InstanceKlass* interk = interfaces->at(index);
861 interk->link_class_impl(CHECK_false);
862 }
863
864 // in case the class is linked in the process of linking its superclasses
865 if (is_linked()) {
866 return true;
867 }
868
869 // trace only the link time for this klass that includes
870 // the verification time
871 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
872 ClassLoader::perf_class_link_selftime(),
873 ClassLoader::perf_classes_linked(),
874 jt->get_thread_stat()->perf_recursion_counts_addr(),
875 jt->get_thread_stat()->perf_timers_addr(),
876 PerfClassTraceTime::CLASS_LINK);
877
878 // verification & rewriting
879 {
880 HandleMark hm(THREAD);
881 Handle h_init_lock(THREAD, init_lock());
882 ObjectLocker ol(h_init_lock, jt);
883 // rewritten will have been set if loader constraint error found
1148 ss.print("Could not initialize class %s", external_name());
1149 if (cause.is_null()) {
1150 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1151 } else {
1152 THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1153 ss.as_string(), cause);
1154 }
1155 } else {
1156
1157 // Step 6
1158 set_init_state(being_initialized);
1159 set_init_thread(jt);
1160 if (debug_logging_enabled) {
1161 ResourceMark rm(jt);
1162 log_debug(class, init)("Thread \"%s\" is initializing %s",
1163 jt->name(), external_name());
1164 }
1165 }
1166 }
1167
1168 // Step 7
1169 // Next, if C is a class rather than an interface, initialize it's super class and super
1170 // interfaces.
1171 if (!is_interface()) {
1172 Klass* super_klass = super();
1173 if (super_klass != nullptr && super_klass->should_be_initialized()) {
1174 super_klass->initialize(THREAD);
1175 }
1176 // If C implements any interface that declares a non-static, concrete method,
1177 // the initialization of C triggers initialization of its super interfaces.
1178 // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1179 // having a superinterface that declares, non-static, concrete methods
1180 if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1181 initialize_super_interfaces(THREAD);
1182 }
1183
1184 // If any exceptions, complete abruptly, throwing the same exception as above.
1185 if (HAS_PENDING_EXCEPTION) {
1186 Handle e(THREAD, PENDING_EXCEPTION);
1187 CLEAR_PENDING_EXCEPTION;
1188 {
1189 EXCEPTION_MARK;
1190 add_initialization_error(THREAD, e);
1191 // Locks object, set state, and notify all waiting threads
1192 set_initialization_state_and_notify(initialization_error, THREAD);
1193 CLEAR_PENDING_EXCEPTION;
1194 }
1195 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1196 THROW_OOP(e());
1197 }
1198 }
1199
1200
1201 // Step 8
1202 {
1203 DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1204 if (class_initializer() != nullptr) {
1205 // Timer includes any side effects of class initialization (resolution,
1206 // etc), but not recursive entry into call_class_initializer().
1207 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1208 ClassLoader::perf_class_init_selftime(),
1209 ClassLoader::perf_classes_inited(),
1210 jt->get_thread_stat()->perf_recursion_counts_addr(),
1211 jt->get_thread_stat()->perf_timers_addr(),
1212 PerfClassTraceTime::CLASS_CLINIT);
1213 call_class_initializer(THREAD);
1214 } else {
1215 // The elapsed time is so small it's not worth counting.
1216 if (UsePerfData) {
1217 ClassLoader::perf_classes_inited()->inc();
1218 }
1219 call_class_initializer(THREAD);
1220 }
1221 }
1222
1223 // Step 9
1224 if (!HAS_PENDING_EXCEPTION) {
1225 set_initialization_state_and_notify(fully_initialized, CHECK);
1226 debug_only(vtable().verify(tty, true);)
1227 }
1228 else {
1229 // Step 10 and 11
1230 Handle e(THREAD, PENDING_EXCEPTION);
1231 CLEAR_PENDING_EXCEPTION;
1232 // JVMTI has already reported the pending exception
1233 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1234 JvmtiExport::clear_detected_exception(jt);
1235 {
1236 EXCEPTION_MARK;
1237 add_initialization_error(THREAD, e);
1238 set_initialization_state_and_notify(initialization_error, THREAD);
1239 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
1240 // JVMTI has already reported the pending exception
1241 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1242 JvmtiExport::clear_detected_exception(jt);
1243 }
1244 DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1245 if (e->is_a(vmClasses::Error_klass())) {
1246 THROW_OOP(e());
1247 } else {
1248 JavaCallArguments args(e);
1249 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1505 ResourceMark rm(THREAD);
1506 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1507 : vmSymbols::java_lang_InstantiationException(), external_name());
1508 }
1509 if (this == vmClasses::Class_klass()) {
1510 ResourceMark rm(THREAD);
1511 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1512 : vmSymbols::java_lang_IllegalAccessException(), external_name());
1513 }
1514 }
1515
1516 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1517 // Need load-acquire for lock-free read
1518 if (array_klasses_acquire() == nullptr) {
1519
1520 // Recursively lock array allocation
1521 RecursiveLocker rl(MultiArray_lock, THREAD);
1522
1523 // Check if another thread created the array klass while we were waiting for the lock.
1524 if (array_klasses() == nullptr) {
1525 ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);
1526 // use 'release' to pair with lock-free load
1527 release_set_array_klasses(k);
1528 }
1529 }
1530
1531 // array_klasses() will always be set at this point
1532 ObjArrayKlass* ak = array_klasses();
1533 assert(ak != nullptr, "should be set");
1534 return ak->array_klass(n, THREAD);
1535 }
1536
1537 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1538 // Need load-acquire for lock-free read
1539 ObjArrayKlass* oak = array_klasses_acquire();
1540 if (oak == nullptr) {
1541 return nullptr;
1542 } else {
1543 return oak->array_klass_or_null(n);
1544 }
1545 }
1546
1547 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1548 return array_klass(1, THREAD);
1549 }
1550
1551 ArrayKlass* InstanceKlass::array_klass_or_null() {
1552 return array_klass_or_null(1);
1553 }
1554
1555 static int call_class_initializer_counter = 0; // for debugging
1556
1557 Method* InstanceKlass::class_initializer() const {
1558 Method* clinit = find_method(
1559 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1560 if (clinit != nullptr && clinit->has_valid_initializer_flags()) {
1561 return clinit;
1562 }
1563 return nullptr;
1564 }
1565
1566 void InstanceKlass::call_class_initializer(TRAPS) {
1567 if (ReplayCompiles &&
1568 (ReplaySuppressInitializers == 1 ||
1569 (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1570 // Hide the existence of the initializer for the purpose of replaying the compile
1571 return;
1572 }
1573
1574 #if INCLUDE_CDS
1575 // This is needed to ensure the consistency of the archived heap objects.
1576 if (has_archived_enum_objs()) {
1577 assert(is_shared(), "must be");
1578 bool initialized = CDSEnumKlass::initialize_enum_klass(this, CHECK);
1579 if (initialized) {
1580 return;
1604
1605 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1606 InterpreterOopMap* entry_for) {
1607 // Lazily create the _oop_map_cache at first request.
1608 // Load_acquire is needed to safely get instance published with CAS by another thread.
1609 OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1610 if (oop_map_cache == nullptr) {
1611 // Try to install new instance atomically.
1612 oop_map_cache = new OopMapCache();
1613 OopMapCache* other = Atomic::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
1614 if (other != nullptr) {
1615 // Someone else managed to install before us, ditch local copy and use the existing one.
1616 delete oop_map_cache;
1617 oop_map_cache = other;
1618 }
1619 }
1620 // _oop_map_cache is constant after init; lookup below does its own locking.
1621 oop_map_cache->lookup(method, bci, entry_for);
1622 }
1623
1624 bool InstanceKlass::contains_field_offset(int offset) {
1625 fieldDescriptor fd;
1626 return find_field_from_offset(offset, false, &fd);
1627 }
1628
1629 FieldInfo InstanceKlass::field(int index) const {
1630 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1631 if (fs.index() == index) {
1632 return fs.to_FieldInfo();
1633 }
1634 }
1635 fatal("Field not found");
1636 return FieldInfo();
1637 }
1638
1639 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1640 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1641 Symbol* f_name = fs.name();
1642 Symbol* f_sig = fs.signature();
1643 if (f_name == name && f_sig == sig) {
1644 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1645 return true;
1646 }
1647 }
1689
1690 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1691 // search order according to newest JVM spec (5.4.3.2, p.167).
1692 // 1) search for field in current klass
1693 if (find_local_field(name, sig, fd)) {
1694 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1695 }
1696 // 2) search for field recursively in direct superinterfaces
1697 if (is_static) {
1698 Klass* intf = find_interface_field(name, sig, fd);
1699 if (intf != nullptr) return intf;
1700 }
1701 // 3) apply field lookup recursively if superclass exists
1702 { Klass* supr = super();
1703 if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1704 }
1705 // 4) otherwise field lookup fails
1706 return nullptr;
1707 }
1708
1709
1710 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1711 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1712 if (fs.offset() == offset) {
1713 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1714 if (fd->is_static() == is_static) return true;
1715 }
1716 }
1717 return false;
1718 }
1719
1720
1721 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1722 Klass* klass = const_cast<InstanceKlass*>(this);
1723 while (klass != nullptr) {
1724 if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1725 return true;
1726 }
1727 klass = klass->super();
1728 }
2080 }
2081
2082 // uncached_lookup_method searches both the local class methods array and all
2083 // superclasses methods arrays, skipping any overpass methods in superclasses,
2084 // and possibly skipping private methods.
2085 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2086 const Symbol* signature,
2087 OverpassLookupMode overpass_mode,
2088 PrivateLookupMode private_mode) const {
2089 OverpassLookupMode overpass_local_mode = overpass_mode;
2090 const Klass* klass = this;
2091 while (klass != nullptr) {
2092 Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2093 signature,
2094 overpass_local_mode,
2095 StaticLookupMode::find,
2096 private_mode);
2097 if (method != nullptr) {
2098 return method;
2099 }
2100 klass = klass->super();
2101 overpass_local_mode = OverpassLookupMode::skip; // Always ignore overpass methods in superclasses
2102 }
2103 return nullptr;
2104 }
2105
2106 #ifdef ASSERT
2107 // search through class hierarchy and return true if this class or
2108 // one of the superclasses was redefined
2109 bool InstanceKlass::has_redefined_this_or_super() const {
2110 const Klass* klass = this;
2111 while (klass != nullptr) {
2112 if (InstanceKlass::cast(klass)->has_been_redefined()) {
2113 return true;
2114 }
2115 klass = klass->super();
2116 }
2117 return false;
2118 }
2119 #endif
2476 int method_table_offset_in_words = ioe->offset()/wordSize;
2477 int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2478
2479 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2480 / itableOffsetEntry::size();
2481
2482 for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2483 if (ioe->interface_klass() != nullptr) {
2484 it->push(ioe->interface_klass_addr());
2485 itableMethodEntry* ime = ioe->first_method_entry(this);
2486 int n = klassItable::method_count_for_interface(ioe->interface_klass());
2487 for (int index = 0; index < n; index ++) {
2488 it->push(ime[index].method_addr());
2489 }
2490 }
2491 }
2492 }
2493
2494 it->push(&_nest_members);
2495 it->push(&_permitted_subclasses);
2496 it->push(&_record_components);
2497 }
2498
2499 #if INCLUDE_CDS
2500 void InstanceKlass::remove_unshareable_info() {
2501
2502 if (is_linked()) {
2503 assert(can_be_verified_at_dumptime(), "must be");
2504 // Remember this so we can avoid walking the hierarchy at runtime.
2505 set_verified_at_dump_time();
2506 }
2507
2508 Klass::remove_unshareable_info();
2509
2510 if (SystemDictionaryShared::has_class_failed_verification(this)) {
2511 // Classes are attempted to link during dumping and may fail,
2512 // but these classes are still in the dictionary and class list in CLD.
2513 // If the class has failed verification, there is nothing else to remove.
2514 return;
2515 }
2516
2522
2523 { // Otherwise this needs to take out the Compile_lock.
2524 assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2525 init_implementor();
2526 }
2527
2528 // Call remove_unshareable_info() on other objects that belong to this class, except
2529 // for constants()->remove_unshareable_info(), which is called in a separate pass in
2530 // ArchiveBuilder::make_klasses_shareable(),
2531
2532 for (int i = 0; i < methods()->length(); i++) {
2533 Method* m = methods()->at(i);
2534 m->remove_unshareable_info();
2535 }
2536
2537 // do array classes also.
2538 if (array_klasses() != nullptr) {
2539 array_klasses()->remove_unshareable_info();
2540 }
2541
2542 // These are not allocated from metaspace. They are safe to set to null.
2543 _source_debug_extension = nullptr;
2544 _dep_context = nullptr;
2545 _osr_nmethods_head = nullptr;
2546 #if INCLUDE_JVMTI
2547 _breakpoints = nullptr;
2548 _previous_versions = nullptr;
2549 _cached_class_file = nullptr;
2550 _jvmti_cached_class_field_map = nullptr;
2551 #endif
2552
2553 _init_thread = nullptr;
2554 _methods_jmethod_ids = nullptr;
2555 _jni_ids = nullptr;
2556 _oop_map_cache = nullptr;
2557 // clear _nest_host to ensure re-load at runtime
2558 _nest_host = nullptr;
2559 init_shared_package_entry();
2560 _dep_context_last_cleaned = 0;
2561
2562 remove_unshareable_flags();
2606 void InstanceKlass::compute_has_loops_flag_for_methods() {
2607 Array<Method*>* methods = this->methods();
2608 for (int index = 0; index < methods->length(); ++index) {
2609 Method* m = methods->at(index);
2610 if (!m->is_overpass()) { // work around JDK-8305771
2611 m->compute_has_loops_flag();
2612 }
2613 }
2614 }
2615
2616 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2617 PackageEntry* pkg_entry, TRAPS) {
2618 // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2619 // before the InstanceKlass is added to the SystemDictionary. Make
2620 // sure the current state is <loaded.
2621 assert(!is_loaded(), "invalid init state");
2622 assert(!shared_loading_failed(), "Must not try to load failed class again");
2623 set_package(loader_data, pkg_entry, CHECK);
2624 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2625
2626 Array<Method*>* methods = this->methods();
2627 int num_methods = methods->length();
2628 for (int index = 0; index < num_methods; ++index) {
2629 methods->at(index)->restore_unshareable_info(CHECK);
2630 }
2631 #if INCLUDE_JVMTI
2632 if (JvmtiExport::has_redefined_a_class()) {
2633 // Reinitialize vtable because RedefineClasses may have changed some
2634 // entries in this vtable for super classes so the CDS vtable might
2635 // point to old or obsolete entries. RedefineClasses doesn't fix up
2636 // vtables in the shared system dictionary, only the main one.
2637 // It also redefines the itable too so fix that too.
2638 // First fix any default methods that point to a super class that may
2639 // have been redefined.
2640 bool trace_name_printed = false;
2641 adjust_default_methods(&trace_name_printed);
2642 vtable().initialize_vtable();
2643 itable().initialize_itable();
2644 }
2645 #endif
2646
2647 // restore constant pool resolved references
2648 constants()->restore_unshareable_info(CHECK);
2649
2650 if (array_klasses() != nullptr) {
2651 // To get a consistent list of classes we need MultiArray_lock to ensure
2652 // array classes aren't observed while they are being restored.
2653 RecursiveLocker rl(MultiArray_lock, THREAD);
2654 assert(this == array_klasses()->bottom_klass(), "sanity");
2655 // Array classes have null protection domain.
2656 // --> see ArrayKlass::complete_create_array_klass()
2657 array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2658 }
2659
2660 // Initialize @ValueBased class annotation if not already set in the archived klass.
2661 if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
2662 set_is_value_based();
2663 }
2664 }
2665
2666 // Check if a class or any of its supertypes has a version older than 50.
2667 // CDS will not perform verification of old classes during dump time because
2668 // without changing the old verifier, the verification constraint cannot be
2669 // retrieved during dump time.
2670 // Verification of archived old classes will be performed during run time.
2671 bool InstanceKlass::can_be_verified_at_dumptime() const {
2672 if (MetaspaceShared::is_in_shared_metaspace(this)) {
2673 // This is a class that was dumped into the base archive, so we know
2674 // it was verified at dump time.
2819 } else {
2820 // Adding one to the attribute length in order to store a null terminator
2821 // character could cause an overflow because the attribute length is
2822 // already coded with an u4 in the classfile, but in practice, it's
2823 // unlikely to happen.
2824 assert((length+1) > length, "Overflow checking");
2825 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
2826 for (int i = 0; i < length; i++) {
2827 sde[i] = array[i];
2828 }
2829 sde[length] = '\0';
2830 _source_debug_extension = sde;
2831 }
2832 }
2833
2834 Symbol* InstanceKlass::generic_signature() const { return _constants->generic_signature(); }
2835 u2 InstanceKlass::generic_signature_index() const { return _constants->generic_signature_index(); }
2836 void InstanceKlass::set_generic_signature_index(u2 sig_index) { _constants->set_generic_signature_index(sig_index); }
2837
2838 const char* InstanceKlass::signature_name() const {
2839
2840 // Get the internal name as a c string
2841 const char* src = (const char*) (name()->as_C_string());
2842 const int src_length = (int)strlen(src);
2843
2844 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
2845
2846 // Add L as type indicator
2847 int dest_index = 0;
2848 dest[dest_index++] = JVM_SIGNATURE_CLASS;
2849
2850 // Add the actual class name
2851 for (int src_index = 0; src_index < src_length; ) {
2852 dest[dest_index++] = src[src_index++];
2853 }
2854
2855 if (is_hidden()) { // Replace the last '+' with a '.'.
2856 for (int index = (int)src_length; index > 0; index--) {
2857 if (dest[index] == '+') {
2858 dest[index] = JVM_SIGNATURE_DOT;
2859 break;
2860 }
2861 }
2862 }
2863
2864 // Add the semicolon and the null
2865 dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
2866 dest[dest_index] = '\0';
2867 return dest;
2868 }
3170 jint InstanceKlass::compute_modifier_flags() const {
3171 jint access = access_flags().as_int();
3172
3173 // But check if it happens to be member class.
3174 InnerClassesIterator iter(this);
3175 for (; !iter.done(); iter.next()) {
3176 int ioff = iter.inner_class_info_index();
3177 // Inner class attribute can be zero, skip it.
3178 // Strange but true: JVM spec. allows null inner class refs.
3179 if (ioff == 0) continue;
3180
3181 // only look at classes that are already loaded
3182 // since we are looking for the flags for our self.
3183 Symbol* inner_name = constants()->klass_name_at(ioff);
3184 if (name() == inner_name) {
3185 // This is really a member class.
3186 access = iter.inner_access_flags();
3187 break;
3188 }
3189 }
3190 // Remember to strip ACC_SUPER bit
3191 return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
3192 }
3193
3194 jint InstanceKlass::jvmti_class_status() const {
3195 jint result = 0;
3196
3197 if (is_linked()) {
3198 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3199 }
3200
3201 if (is_initialized()) {
3202 assert(is_linked(), "Class status is not consistent");
3203 result |= JVMTI_CLASS_STATUS_INITIALIZED;
3204 }
3205 if (is_in_error_state()) {
3206 result |= JVMTI_CLASS_STATUS_ERROR;
3207 }
3208 return result;
3209 }
3210
3211 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {
3425 }
3426 osr = osr->osr_link();
3427 }
3428
3429 assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3430 if (best != nullptr && best->comp_level() >= comp_level) {
3431 return best;
3432 }
3433 return nullptr;
3434 }
3435
3436 // -----------------------------------------------------------------------------------------------------
3437 // Printing
3438
3439 #define BULLET " - "
3440
3441 static const char* state_names[] = {
3442 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3443 };
3444
3445 static void print_vtable(intptr_t* start, int len, outputStream* st) {
3446 for (int i = 0; i < len; i++) {
3447 intptr_t e = start[i];
3448 st->print("%d : " INTPTR_FORMAT, i, e);
3449 if (MetaspaceObj::is_valid((Metadata*)e)) {
3450 st->print(" ");
3451 ((Metadata*)e)->print_value_on(st);
3452 }
3453 st->cr();
3454 }
3455 }
3456
3457 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3458 return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
3459 }
3460
3461 const char* InstanceKlass::init_state_name() const {
3462 return state_names[init_state()];
3463 }
3464
3465 void InstanceKlass::print_on(outputStream* st) const {
3466 assert(is_klass(), "must be klass");
3467 Klass::print_on(st);
3468
3469 st->print(BULLET"instance size: %d", size_helper()); st->cr();
3470 st->print(BULLET"klass size: %d", size()); st->cr();
3471 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
3472 st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
3473 st->print(BULLET"state: "); st->print_cr("%s", init_state_name());
3474 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3475 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3476 st->print(BULLET"sub: ");
3477 Klass* sub = subklass();
3478 int n;
3479 for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3480 if (n < MaxSubklassPrintSize) {
3481 sub->print_value_on(st);
3482 st->print(" ");
3483 }
3484 }
3485 if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3486 st->cr();
3487
3488 if (is_interface()) {
3489 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
3490 if (nof_implementors() == 1) {
3491 st->print_cr(BULLET"implementor: ");
3492 st->print(" ");
3493 implementor()->print_value_on(st);
3494 st->cr();
3495 }
3496 }
3497
3498 st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3499 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr();
3500 if (Verbose || WizardMode) {
3501 Array<Method*>* method_array = methods();
3502 for (int i = 0; i < method_array->length(); i++) {
3503 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3504 }
3505 }
3506 st->print(BULLET"method ordering: "); method_ordering()->print_value_on(st); st->cr();
3507 if (default_methods() != nullptr) {
3508 st->print(BULLET"default_methods: "); default_methods()->print_value_on(st); st->cr();
3509 if (Verbose) {
3510 Array<Method*>* method_array = default_methods();
3511 for (int i = 0; i < method_array->length(); i++) {
3512 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3513 }
3514 }
3515 }
3516 print_on_maybe_null(st, BULLET"default vtable indices: ", default_vtable_indices());
3517 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr();
3518 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3519
3520 st->print(BULLET"secondary supers: "); secondary_supers()->print_value_on(st); st->cr();
3521
3522 st->print(BULLET"hash_slot: %d", hash_slot()); st->cr();
3523 st->print(BULLET"secondary bitmap: " UINTX_FORMAT_X_0, _secondary_supers_bitmap); st->cr();
3524
3525 if (secondary_supers() != nullptr) {
3526 if (Verbose) {
3527 bool is_hashed = (_secondary_supers_bitmap != SECONDARY_SUPERS_BITMAP_FULL);
3528 st->print_cr(BULLET"---- secondary supers (%d words):", _secondary_supers->length());
3529 for (int i = 0; i < _secondary_supers->length(); i++) {
3530 ResourceMark rm; // for external_name()
3531 Klass* secondary_super = _secondary_supers->at(i);
3532 st->print(BULLET"%2d:", i);
3533 if (is_hashed) {
3534 int home_slot = compute_home_slot(secondary_super, _secondary_supers_bitmap);
3554 print_on_maybe_null(st, BULLET"field type annotations: ", fields_type_annotations());
3555 {
3556 bool have_pv = false;
3557 // previous versions are linked together through the InstanceKlass
3558 for (InstanceKlass* pv_node = previous_versions();
3559 pv_node != nullptr;
3560 pv_node = pv_node->previous_versions()) {
3561 if (!have_pv)
3562 st->print(BULLET"previous version: ");
3563 have_pv = true;
3564 pv_node->constants()->print_value_on(st);
3565 }
3566 if (have_pv) st->cr();
3567 }
3568
3569 print_on_maybe_null(st, BULLET"generic signature: ", generic_signature());
3570 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
3571 st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr();
3572 print_on_maybe_null(st, BULLET"record components: ", record_components());
3573 st->print(BULLET"permitted subclasses: "); permitted_subclasses()->print_value_on(st); st->cr();
3574 if (java_mirror() != nullptr) {
3575 st->print(BULLET"java mirror: ");
3576 java_mirror()->print_value_on(st);
3577 st->cr();
3578 } else {
3579 st->print_cr(BULLET"java mirror: null");
3580 }
3581 st->print(BULLET"vtable length %d (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3582 if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
3583 st->print(BULLET"itable length %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3584 if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_itable(), itable_length(), st);
3585 st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3586
3587 FieldPrinter print_static_field(st);
3588 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3589 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3590 FieldPrinter print_nonstatic_field(st);
3591 InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3592 ik->print_nonstatic_fields(&print_nonstatic_field);
3593
3594 st->print(BULLET"non-static oop maps: ");
3595 OopMapBlock* map = start_of_nonstatic_oop_maps();
3596 OopMapBlock* end_map = map + nonstatic_oop_map_count();
3597 while (map < end_map) {
3598 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3599 map++;
3600 }
3601 st->cr();
3602 }
3603
3604 void InstanceKlass::print_value_on(outputStream* st) const {
|
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 "oops/inlineKlass.hpp"
77 #include "prims/jvmtiExport.hpp"
78 #include "prims/jvmtiRedefineClasses.hpp"
79 #include "prims/jvmtiThreadState.hpp"
80 #include "prims/methodComparator.hpp"
81 #include "runtime/arguments.hpp"
82 #include "runtime/deoptimization.hpp"
83 #include "runtime/atomic.hpp"
84 #include "runtime/fieldDescriptor.inline.hpp"
85 #include "runtime/handles.inline.hpp"
86 #include "runtime/javaCalls.hpp"
87 #include "runtime/javaThread.inline.hpp"
88 #include "runtime/mutexLocker.hpp"
89 #include "runtime/orderAccess.hpp"
90 #include "runtime/os.inline.hpp"
91 #include "runtime/reflection.hpp"
92 #include "runtime/synchronizer.hpp"
93 #include "runtime/threads.hpp"
94 #include "services/classLoadingService.hpp"
95 #include "services/finalizerService.hpp"
96 #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 void InlineLayoutInfo::metaspace_pointers_do(MetaspaceClosure* it) {
154 log_trace(cds)("Iter(InlineFieldInfo): %p", this);
155 it->push(&_klass);
156 }
157
158 bool InstanceKlass::_finalization_enabled = true;
159
160 static inline bool is_class_loader(const Symbol* class_name,
161 const ClassFileParser& parser) {
162 assert(class_name != nullptr, "invariant");
163
164 if (class_name == vmSymbols::java_lang_ClassLoader()) {
165 return true;
166 }
167
168 if (vmClasses::ClassLoader_klass_loaded()) {
169 const Klass* const super_klass = parser.super_klass();
170 if (super_klass != nullptr) {
171 if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
172 return true;
173 }
174 }
175 }
176 return false;
177 }
178
179 bool InstanceKlass::field_is_null_free_inline_type(int index) const {
180 return field(index).field_flags().is_null_free_inline_type();
181 }
182
183 bool InstanceKlass::is_class_in_loadable_descriptors_attribute(Symbol* name) const {
184 if (_loadable_descriptors == nullptr) return false;
185 for (int i = 0; i < _loadable_descriptors->length(); i++) {
186 Symbol* class_name = _constants->symbol_at(_loadable_descriptors->at(i));
187 if (class_name == name) return true;
188 }
189 return false;
190 }
191
192 static inline bool is_stack_chunk_class(const Symbol* class_name,
193 const ClassLoaderData* loader_data) {
194 return (class_name == vmSymbols::jdk_internal_vm_StackChunk() &&
195 loader_data->is_the_null_class_loader_data());
196 }
197
198 // private: called to verify that k is a static member of this nest.
199 // We know that k is an instance class in the same package and hence the
200 // same classloader.
201 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
202 assert(!is_hidden(), "unexpected hidden class");
203 if (_nest_members == nullptr || _nest_members == Universe::the_empty_short_array()) {
204 if (log_is_enabled(Trace, class, nestmates)) {
205 ResourceMark rm(current);
206 log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
207 k->external_name(), this->external_name());
208 }
209 return false;
210 }
211
449 }
450
451 const char* InstanceKlass::nest_host_error() {
452 if (_nest_host_index == 0) {
453 return nullptr;
454 } else {
455 constantPoolHandle cph(Thread::current(), constants());
456 return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
457 }
458 }
459
460 void* InstanceKlass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size,
461 bool use_class_space, TRAPS) throw() {
462 return Metaspace::allocate(loader_data, word_size, ClassType, use_class_space, THREAD);
463 }
464
465 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
466 const int size = InstanceKlass::size(parser.vtable_size(),
467 parser.itable_size(),
468 nonstatic_oop_map_size(parser.total_oop_map_count()),
469 parser.is_interface(),
470 parser.is_inline_type());
471
472 const Symbol* const class_name = parser.class_name();
473 assert(class_name != nullptr, "invariant");
474 ClassLoaderData* loader_data = parser.loader_data();
475 assert(loader_data != nullptr, "invariant");
476
477 InstanceKlass* ik;
478 const bool use_class_space = !parser.is_interface() && !parser.is_abstract();
479
480 // Allocation
481 if (parser.is_instance_ref_klass()) {
482 // java.lang.ref.Reference
483 ik = new (loader_data, size, use_class_space, THREAD) InstanceRefKlass(parser);
484 } else if (class_name == vmSymbols::java_lang_Class()) {
485 // mirror - java.lang.Class
486 ik = new (loader_data, size, use_class_space, THREAD) InstanceMirrorKlass(parser);
487 } else if (is_stack_chunk_class(class_name, loader_data)) {
488 // stack chunk
489 ik = new (loader_data, size, use_class_space, THREAD) InstanceStackChunkKlass(parser);
490 } else if (is_class_loader(class_name, parser)) {
491 // class loader - java.lang.ClassLoader
492 ik = new (loader_data, size, use_class_space, THREAD) InstanceClassLoaderKlass(parser);
493 } else if (parser.is_inline_type()) {
494 // inline type
495 ik = new (loader_data, size, use_class_space, THREAD) InlineKlass(parser);
496 } else {
497 // normal
498 ik = new (loader_data, size, use_class_space, THREAD) InstanceKlass(parser);
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 #ifdef ASSERT
508 ik->bounds_check((address) ik->start_of_vtable(), false, size);
509 ik->bounds_check((address) ik->start_of_itable(), false, size);
510 ik->bounds_check((address) ik->end_of_itable(), true, size);
511 ik->bounds_check((address) ik->end_of_nonstatic_oop_maps(), true, size);
512 #endif //ASSERT
513 return ik;
514 }
515
516 #ifndef PRODUCT
517 bool InstanceKlass::bounds_check(address addr, bool edge_ok, intptr_t size_in_bytes) const {
518 const char* bad = nullptr;
519 address end = nullptr;
520 if (addr < (address)this) {
521 bad = "before";
522 } else if (addr == (address)this) {
523 if (edge_ok) return true;
524 bad = "just before";
525 } else if (addr == (end = (address)this + sizeof(intptr_t) * (size_in_bytes < 0 ? size() : size_in_bytes))) {
526 if (edge_ok) return true;
527 bad = "just after";
528 } else if (addr > end) {
529 bad = "after";
530 } else {
531 return true;
532 }
533 tty->print_cr("%s object bounds: " INTPTR_FORMAT " [" INTPTR_FORMAT ".." INTPTR_FORMAT "]",
534 bad, (intptr_t)addr, (intptr_t)this, (intptr_t)end);
535 Verbose = WizardMode = true; this->print(); //@@
536 return false;
537 }
538 #endif //PRODUCT
539
540 // copy method ordering from resource area to Metaspace
541 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
542 if (m != nullptr) {
543 // allocate a new array and copy contents (memcpy?)
544 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
545 for (int i = 0; i < m->length(); i++) {
546 _method_ordering->at_put(i, m->at(i));
547 }
548 } else {
549 _method_ordering = Universe::the_empty_int_array();
550 }
551 }
552
553 // create a new array of vtable_indices for default methods
554 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
555 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
556 assert(default_vtable_indices() == nullptr, "only create once");
557 set_default_vtable_indices(vtable_indices);
558 return vtable_indices;
559 }
560
561
562 InstanceKlass::InstanceKlass() {
563 assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
564 }
565
566 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) :
567 Klass(kind),
568 _nest_members(nullptr),
569 _nest_host(nullptr),
570 _permitted_subclasses(nullptr),
571 _record_components(nullptr),
572 _static_field_size(parser.static_field_size()),
573 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
574 _itable_len(parser.itable_size()),
575 _nest_host_index(0),
576 _init_state(allocated),
577 _reference_type(reference_type),
578 _init_thread(nullptr),
579 _inline_layout_info_array(nullptr),
580 _loadable_descriptors(nullptr),
581 _adr_inlineklass_fixed_block(nullptr)
582 {
583 set_vtable_length(parser.vtable_size());
584 set_access_flags(parser.access_flags());
585 if (parser.is_hidden()) set_is_hidden();
586 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
587 false));
588 if (parser.has_inline_fields()) {
589 set_has_inline_type_fields();
590 }
591
592 assert(nullptr == _methods, "underlying memory not zeroed?");
593 assert(is_instance_klass(), "is layout incorrect?");
594 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
595 }
596
597 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
598 Array<Method*>* methods) {
599 if (methods != nullptr && methods != Universe::the_empty_method_array() &&
600 !methods->is_shared()) {
601 for (int i = 0; i < methods->length(); i++) {
602 Method* method = methods->at(i);
603 if (method == nullptr) continue; // maybe null if error processing
604 // Only want to delete methods that are not executing for RedefineClasses.
605 // The previous version will point to them so they're not totally dangling
606 assert (!method->on_stack(), "shouldn't be called with methods on stack");
607 MetadataFactory::free_metadata(loader_data, method);
608 }
609 MetadataFactory::free_array<Method*>(loader_data, methods);
610 }
710 (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
711 !secondary_supers()->is_shared()) {
712 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
713 }
714 set_secondary_supers(nullptr, SECONDARY_SUPERS_BITMAP_EMPTY);
715
716 deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
717 set_transitive_interfaces(nullptr);
718 set_local_interfaces(nullptr);
719
720 if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->is_shared()) {
721 MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
722 }
723 set_fieldinfo_stream(nullptr);
724
725 if (fields_status() != nullptr && !fields_status()->is_shared()) {
726 MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
727 }
728 set_fields_status(nullptr);
729
730 if (inline_layout_info_array() != nullptr) {
731 MetadataFactory::free_array<InlineLayoutInfo>(loader_data, inline_layout_info_array());
732 }
733 set_inline_layout_info_array(nullptr);
734
735 // If a method from a redefined class is using this constant pool, don't
736 // delete it, yet. The new class's previous version will point to this.
737 if (constants() != nullptr) {
738 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
739 if (!constants()->is_shared()) {
740 MetadataFactory::free_metadata(loader_data, constants());
741 }
742 // Delete any cached resolution errors for the constant pool
743 SystemDictionary::delete_resolution_error(constants());
744
745 set_constants(nullptr);
746 }
747
748 if (inner_classes() != nullptr &&
749 inner_classes() != Universe::the_empty_short_array() &&
750 !inner_classes()->is_shared()) {
751 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
752 }
753 set_inner_classes(nullptr);
754
755 if (nest_members() != nullptr &&
756 nest_members() != Universe::the_empty_short_array() &&
757 !nest_members()->is_shared()) {
758 MetadataFactory::free_array<jushort>(loader_data, nest_members());
759 }
760 set_nest_members(nullptr);
761
762 if (permitted_subclasses() != nullptr &&
763 permitted_subclasses() != Universe::the_empty_short_array() &&
764 !permitted_subclasses()->is_shared()) {
765 MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
766 }
767 set_permitted_subclasses(nullptr);
768
769 if (loadable_descriptors() != nullptr &&
770 loadable_descriptors() != Universe::the_empty_short_array() &&
771 !loadable_descriptors()->is_shared()) {
772 MetadataFactory::free_array<jushort>(loader_data, loadable_descriptors());
773 }
774 set_loadable_descriptors(nullptr);
775
776 // We should deallocate the Annotations instance if it's not in shared spaces.
777 if (annotations() != nullptr && !annotations()->is_shared()) {
778 MetadataFactory::free_metadata(loader_data, annotations());
779 }
780 set_annotations(nullptr);
781
782 SystemDictionaryShared::handle_class_unloading(this);
783
784 #if INCLUDE_CDS_JAVA_HEAP
785 if (CDSConfig::is_dumping_heap()) {
786 HeapShared::remove_scratch_objects(this);
787 }
788 #endif
789 }
790
791 bool InstanceKlass::is_record() const {
792 return _record_components != nullptr &&
793 is_final() &&
794 java_super() == vmClasses::Record_klass();
795 }
914 vmSymbols::java_lang_IncompatibleClassChangeError(),
915 "class %s has interface %s as super class",
916 external_name(),
917 super_klass->external_name()
918 );
919 return false;
920 }
921
922 InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
923 ik_super->link_class_impl(CHECK_false);
924 }
925
926 // link all interfaces implemented by this class before linking this class
927 Array<InstanceKlass*>* interfaces = local_interfaces();
928 int num_interfaces = interfaces->length();
929 for (int index = 0; index < num_interfaces; index++) {
930 InstanceKlass* interk = interfaces->at(index);
931 interk->link_class_impl(CHECK_false);
932 }
933
934
935 // If a class declares a method that uses an inline class as an argument
936 // type or return inline type, this inline class must be loaded during the
937 // linking of this class because size and properties of the inline class
938 // must be known in order to be able to perform inline type optimizations.
939 // The implementation below is an approximation of this rule, the code
940 // iterates over all methods of the current class (including overridden
941 // methods), not only the methods declared by this class. This
942 // approximation makes the code simpler, and doesn't change the semantic
943 // because classes declaring methods overridden by the current class are
944 // linked (and have performed their own pre-loading) before the linking
945 // of the current class.
946
947
948 // Note:
949 // Inline class types are loaded during
950 // the loading phase (see ClassFileParser::post_process_parsed_stream()).
951 // Inline class types used as element types for array creation
952 // are not pre-loaded. Their loading is triggered by either anewarray
953 // or multianewarray bytecodes.
954
955 // Could it be possible to do the following processing only if the
956 // class uses inline types?
957 if (EnableValhalla) {
958 ResourceMark rm(THREAD);
959 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
960 if (fs.is_null_free_inline_type() && fs.access_flags().is_static()) {
961 Symbol* sig = fs.signature();
962 TempNewSymbol s = Signature::strip_envelope(sig);
963 if (s != name()) {
964 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());
965 Klass* klass = SystemDictionary::resolve_or_fail(s,
966 Handle(THREAD, class_loader()), Handle(THREAD, protection_domain()), true,
967 CHECK_false);
968 if (HAS_PENDING_EXCEPTION) {
969 log_warning(class, preload)("Preloading of class %s during linking of class %s (cause: null-free static field) failed: %s",
970 s->as_C_string(), name()->as_C_string(), PENDING_EXCEPTION->klass()->name()->as_C_string());
971 return false; // Exception is still pending
972 }
973 log_info(class, preload)("Preloading of class %s during linking of class %s (cause: null-free static field) succeeded",
974 s->as_C_string(), name()->as_C_string());
975 assert(klass != nullptr, "Sanity check");
976 if (klass->is_abstract()) {
977 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
978 err_msg("Class %s expects class %s to be concrete value class, but it is an abstract class",
979 name()->as_C_string(),
980 InstanceKlass::cast(klass)->external_name()), false);
981 }
982 if (!klass->is_inline_klass()) {
983 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
984 err_msg("class %s expects class %s to be a value class but it is an identity class",
985 name()->as_C_string(), klass->external_name()), false);
986 }
987 InlineKlass* vk = InlineKlass::cast(klass);
988 if (!vk->is_implicitly_constructible()) {
989 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
990 err_msg("class %s is not implicitly constructible and it is used in a null restricted static field (not supported)",
991 klass->external_name()), false);
992 }
993 // the inline_type_field_klasses_array might have been loaded with CDS, so update only if not already set and check consistency
994 InlineLayoutInfo* li = inline_layout_info_adr(fs.index());
995 if (li->klass() == nullptr) {
996 li->set_klass(InlineKlass::cast(vk));
997 li->set_kind(LayoutKind::REFERENCE);
998 }
999 assert(get_inline_type_field_klass(fs.index()) == vk, "Must match");
1000 } else {
1001 InlineLayoutInfo* li = inline_layout_info_adr(fs.index());
1002 if (li->klass() == nullptr) {
1003 li->set_klass(InlineKlass::cast(this));
1004 li->set_kind(LayoutKind::REFERENCE);
1005 }
1006 assert(get_inline_type_field_klass(fs.index()) == this, "Must match");
1007 }
1008 }
1009 }
1010
1011 // Aggressively preloading all classes from the LoadableDescriptors attribute
1012 if (loadable_descriptors() != nullptr) {
1013 HandleMark hm(THREAD);
1014 for (int i = 0; i < loadable_descriptors()->length(); i++) {
1015 Symbol* sig = constants()->symbol_at(loadable_descriptors()->at(i));
1016 if (!Signature::has_envelope(sig)) continue;
1017 TempNewSymbol class_name = Signature::strip_envelope(sig);
1018 if (class_name == name()) continue;
1019 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());
1020 oop loader = class_loader();
1021 oop protection_domain = this->protection_domain();
1022 Klass* klass = SystemDictionary::resolve_or_null(class_name,
1023 Handle(THREAD, loader), Handle(THREAD, protection_domain), THREAD);
1024 if (HAS_PENDING_EXCEPTION) {
1025 CLEAR_PENDING_EXCEPTION;
1026 }
1027 if (klass != nullptr) {
1028 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());
1029 if (!klass->is_inline_klass()) {
1030 // Non value class are allowed by the current spec, but it could be an indication of an issue so let's log a warning
1031 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());
1032 }
1033 } else {
1034 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());
1035 }
1036 }
1037 }
1038 }
1039
1040 // in case the class is linked in the process of linking its superclasses
1041 if (is_linked()) {
1042 return true;
1043 }
1044
1045 // trace only the link time for this klass that includes
1046 // the verification time
1047 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
1048 ClassLoader::perf_class_link_selftime(),
1049 ClassLoader::perf_classes_linked(),
1050 jt->get_thread_stat()->perf_recursion_counts_addr(),
1051 jt->get_thread_stat()->perf_timers_addr(),
1052 PerfClassTraceTime::CLASS_LINK);
1053
1054 // verification & rewriting
1055 {
1056 HandleMark hm(THREAD);
1057 Handle h_init_lock(THREAD, init_lock());
1058 ObjectLocker ol(h_init_lock, jt);
1059 // rewritten will have been set if loader constraint error found
1324 ss.print("Could not initialize class %s", external_name());
1325 if (cause.is_null()) {
1326 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1327 } else {
1328 THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1329 ss.as_string(), cause);
1330 }
1331 } else {
1332
1333 // Step 6
1334 set_init_state(being_initialized);
1335 set_init_thread(jt);
1336 if (debug_logging_enabled) {
1337 ResourceMark rm(jt);
1338 log_debug(class, init)("Thread \"%s\" is initializing %s",
1339 jt->name(), external_name());
1340 }
1341 }
1342 }
1343
1344 // Pre-allocating an instance of the default value
1345 if (is_inline_klass()) {
1346 InlineKlass* vk = InlineKlass::cast(this);
1347 oop val = vk->allocate_instance(THREAD);
1348 if (HAS_PENDING_EXCEPTION) {
1349 Handle e(THREAD, PENDING_EXCEPTION);
1350 CLEAR_PENDING_EXCEPTION;
1351 {
1352 EXCEPTION_MARK;
1353 add_initialization_error(THREAD, e);
1354 // Locks object, set state, and notify all waiting threads
1355 set_initialization_state_and_notify(initialization_error, THREAD);
1356 CLEAR_PENDING_EXCEPTION;
1357 }
1358 THROW_OOP(e());
1359 }
1360 vk->set_default_value(val);
1361 if (vk->has_nullable_layout()) {
1362 val = vk->allocate_instance(THREAD);
1363 if (HAS_PENDING_EXCEPTION) {
1364 Handle e(THREAD, PENDING_EXCEPTION);
1365 CLEAR_PENDING_EXCEPTION;
1366 {
1367 EXCEPTION_MARK;
1368 add_initialization_error(THREAD, e);
1369 // Locks object, set state, and notify all waiting threads
1370 set_initialization_state_and_notify(initialization_error, THREAD);
1371 CLEAR_PENDING_EXCEPTION;
1372 }
1373 THROW_OOP(e());
1374 }
1375 vk->set_null_reset_value(val);
1376 }
1377 }
1378
1379 // Step 7
1380 // Next, if C is a class rather than an interface, initialize it's super class and super
1381 // interfaces.
1382 if (!is_interface()) {
1383 Klass* super_klass = super();
1384 if (super_klass != nullptr && super_klass->should_be_initialized()) {
1385 super_klass->initialize(THREAD);
1386 }
1387 // If C implements any interface that declares a non-static, concrete method,
1388 // the initialization of C triggers initialization of its super interfaces.
1389 // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1390 // having a superinterface that declares, non-static, concrete methods
1391 if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1392 initialize_super_interfaces(THREAD);
1393 }
1394
1395 // If any exceptions, complete abruptly, throwing the same exception as above.
1396 if (HAS_PENDING_EXCEPTION) {
1397 Handle e(THREAD, PENDING_EXCEPTION);
1398 CLEAR_PENDING_EXCEPTION;
1399 {
1400 EXCEPTION_MARK;
1401 add_initialization_error(THREAD, e);
1402 // Locks object, set state, and notify all waiting threads
1403 set_initialization_state_and_notify(initialization_error, THREAD);
1404 CLEAR_PENDING_EXCEPTION;
1405 }
1406 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1407 THROW_OOP(e());
1408 }
1409 }
1410
1411 // Step 8
1412 // Initialize classes of inline fields
1413 if (EnableValhalla) {
1414 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1415 if (fs.is_null_free_inline_type()) {
1416
1417 // inline type field klass array entries must have alreadyt been filed at load time or link time
1418 Klass* klass = get_inline_type_field_klass(fs.index());
1419
1420 InstanceKlass::cast(klass)->initialize(THREAD);
1421 if (fs.access_flags().is_static()) {
1422 if (java_mirror()->obj_field(fs.offset()) == nullptr) {
1423 java_mirror()->obj_field_put(fs.offset(), InlineKlass::cast(klass)->default_value());
1424 }
1425 }
1426
1427 if (HAS_PENDING_EXCEPTION) {
1428 Handle e(THREAD, PENDING_EXCEPTION);
1429 CLEAR_PENDING_EXCEPTION;
1430 {
1431 EXCEPTION_MARK;
1432 add_initialization_error(THREAD, e);
1433 // Locks object, set state, and notify all waiting threads
1434 set_initialization_state_and_notify(initialization_error, THREAD);
1435 CLEAR_PENDING_EXCEPTION;
1436 }
1437 THROW_OOP(e());
1438 }
1439 }
1440 }
1441 }
1442
1443
1444 // Step 9
1445 {
1446 DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1447 if (class_initializer() != nullptr) {
1448 // Timer includes any side effects of class initialization (resolution,
1449 // etc), but not recursive entry into call_class_initializer().
1450 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1451 ClassLoader::perf_class_init_selftime(),
1452 ClassLoader::perf_classes_inited(),
1453 jt->get_thread_stat()->perf_recursion_counts_addr(),
1454 jt->get_thread_stat()->perf_timers_addr(),
1455 PerfClassTraceTime::CLASS_CLINIT);
1456 call_class_initializer(THREAD);
1457 } else {
1458 // The elapsed time is so small it's not worth counting.
1459 if (UsePerfData) {
1460 ClassLoader::perf_classes_inited()->inc();
1461 }
1462 call_class_initializer(THREAD);
1463 }
1464 }
1465
1466 // Step 10
1467 if (!HAS_PENDING_EXCEPTION) {
1468 set_initialization_state_and_notify(fully_initialized, CHECK);
1469 debug_only(vtable().verify(tty, true);)
1470 }
1471 else {
1472 // Step 11 and 12
1473 Handle e(THREAD, PENDING_EXCEPTION);
1474 CLEAR_PENDING_EXCEPTION;
1475 // JVMTI has already reported the pending exception
1476 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1477 JvmtiExport::clear_detected_exception(jt);
1478 {
1479 EXCEPTION_MARK;
1480 add_initialization_error(THREAD, e);
1481 set_initialization_state_and_notify(initialization_error, THREAD);
1482 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
1483 // JVMTI has already reported the pending exception
1484 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1485 JvmtiExport::clear_detected_exception(jt);
1486 }
1487 DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1488 if (e->is_a(vmClasses::Error_klass())) {
1489 THROW_OOP(e());
1490 } else {
1491 JavaCallArguments args(e);
1492 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1748 ResourceMark rm(THREAD);
1749 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1750 : vmSymbols::java_lang_InstantiationException(), external_name());
1751 }
1752 if (this == vmClasses::Class_klass()) {
1753 ResourceMark rm(THREAD);
1754 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1755 : vmSymbols::java_lang_IllegalAccessException(), external_name());
1756 }
1757 }
1758
1759 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1760 // Need load-acquire for lock-free read
1761 if (array_klasses_acquire() == nullptr) {
1762
1763 // Recursively lock array allocation
1764 RecursiveLocker rl(MultiArray_lock, THREAD);
1765
1766 // Check if another thread created the array klass while we were waiting for the lock.
1767 if (array_klasses() == nullptr) {
1768 ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, false, CHECK_NULL);
1769 // use 'release' to pair with lock-free load
1770 release_set_array_klasses(k);
1771 }
1772 }
1773
1774 // array_klasses() will always be set at this point
1775 ArrayKlass* ak = array_klasses();
1776 assert(ak != nullptr, "should be set");
1777 return ak->array_klass(n, THREAD);
1778 }
1779
1780 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1781 // Need load-acquire for lock-free read
1782 ArrayKlass* ak = array_klasses_acquire();
1783 if (ak == nullptr) {
1784 return nullptr;
1785 } else {
1786 return ak->array_klass_or_null(n);
1787 }
1788 }
1789
1790 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1791 return array_klass(1, THREAD);
1792 }
1793
1794 ArrayKlass* InstanceKlass::array_klass_or_null() {
1795 return array_klass_or_null(1);
1796 }
1797
1798 static int call_class_initializer_counter = 0; // for debugging
1799
1800 Method* InstanceKlass::class_initializer() const {
1801 Method* clinit = find_method(
1802 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1803 if (clinit != nullptr && clinit->is_class_initializer()) {
1804 return clinit;
1805 }
1806 return nullptr;
1807 }
1808
1809 void InstanceKlass::call_class_initializer(TRAPS) {
1810 if (ReplayCompiles &&
1811 (ReplaySuppressInitializers == 1 ||
1812 (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1813 // Hide the existence of the initializer for the purpose of replaying the compile
1814 return;
1815 }
1816
1817 #if INCLUDE_CDS
1818 // This is needed to ensure the consistency of the archived heap objects.
1819 if (has_archived_enum_objs()) {
1820 assert(is_shared(), "must be");
1821 bool initialized = CDSEnumKlass::initialize_enum_klass(this, CHECK);
1822 if (initialized) {
1823 return;
1847
1848 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1849 InterpreterOopMap* entry_for) {
1850 // Lazily create the _oop_map_cache at first request.
1851 // Load_acquire is needed to safely get instance published with CAS by another thread.
1852 OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1853 if (oop_map_cache == nullptr) {
1854 // Try to install new instance atomically.
1855 oop_map_cache = new OopMapCache();
1856 OopMapCache* other = Atomic::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
1857 if (other != nullptr) {
1858 // Someone else managed to install before us, ditch local copy and use the existing one.
1859 delete oop_map_cache;
1860 oop_map_cache = other;
1861 }
1862 }
1863 // _oop_map_cache is constant after init; lookup below does its own locking.
1864 oop_map_cache->lookup(method, bci, entry_for);
1865 }
1866
1867
1868 FieldInfo InstanceKlass::field(int index) const {
1869 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1870 if (fs.index() == index) {
1871 return fs.to_FieldInfo();
1872 }
1873 }
1874 fatal("Field not found");
1875 return FieldInfo();
1876 }
1877
1878 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1879 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1880 Symbol* f_name = fs.name();
1881 Symbol* f_sig = fs.signature();
1882 if (f_name == name && f_sig == sig) {
1883 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1884 return true;
1885 }
1886 }
1928
1929 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1930 // search order according to newest JVM spec (5.4.3.2, p.167).
1931 // 1) search for field in current klass
1932 if (find_local_field(name, sig, fd)) {
1933 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1934 }
1935 // 2) search for field recursively in direct superinterfaces
1936 if (is_static) {
1937 Klass* intf = find_interface_field(name, sig, fd);
1938 if (intf != nullptr) return intf;
1939 }
1940 // 3) apply field lookup recursively if superclass exists
1941 { Klass* supr = super();
1942 if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1943 }
1944 // 4) otherwise field lookup fails
1945 return nullptr;
1946 }
1947
1948 bool InstanceKlass::contains_field_offset(int offset) {
1949 if (this->is_inline_klass()) {
1950 InlineKlass* vk = InlineKlass::cast(this);
1951 return offset >= vk->first_field_offset() && offset < (vk->first_field_offset() + vk->payload_size_in_bytes());
1952 } else {
1953 fieldDescriptor fd;
1954 return find_field_from_offset(offset, false, &fd);
1955 }
1956 }
1957
1958 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1959 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1960 if (fs.offset() == offset) {
1961 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1962 if (fd->is_static() == is_static) return true;
1963 }
1964 }
1965 return false;
1966 }
1967
1968
1969 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1970 Klass* klass = const_cast<InstanceKlass*>(this);
1971 while (klass != nullptr) {
1972 if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1973 return true;
1974 }
1975 klass = klass->super();
1976 }
2328 }
2329
2330 // uncached_lookup_method searches both the local class methods array and all
2331 // superclasses methods arrays, skipping any overpass methods in superclasses,
2332 // and possibly skipping private methods.
2333 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2334 const Symbol* signature,
2335 OverpassLookupMode overpass_mode,
2336 PrivateLookupMode private_mode) const {
2337 OverpassLookupMode overpass_local_mode = overpass_mode;
2338 const Klass* klass = this;
2339 while (klass != nullptr) {
2340 Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2341 signature,
2342 overpass_local_mode,
2343 StaticLookupMode::find,
2344 private_mode);
2345 if (method != nullptr) {
2346 return method;
2347 }
2348 if (name == vmSymbols::object_initializer_name()) {
2349 break; // <init> is never inherited
2350 }
2351 klass = klass->super();
2352 overpass_local_mode = OverpassLookupMode::skip; // Always ignore overpass methods in superclasses
2353 }
2354 return nullptr;
2355 }
2356
2357 #ifdef ASSERT
2358 // search through class hierarchy and return true if this class or
2359 // one of the superclasses was redefined
2360 bool InstanceKlass::has_redefined_this_or_super() const {
2361 const Klass* klass = this;
2362 while (klass != nullptr) {
2363 if (InstanceKlass::cast(klass)->has_been_redefined()) {
2364 return true;
2365 }
2366 klass = klass->super();
2367 }
2368 return false;
2369 }
2370 #endif
2727 int method_table_offset_in_words = ioe->offset()/wordSize;
2728 int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2729
2730 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2731 / itableOffsetEntry::size();
2732
2733 for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2734 if (ioe->interface_klass() != nullptr) {
2735 it->push(ioe->interface_klass_addr());
2736 itableMethodEntry* ime = ioe->first_method_entry(this);
2737 int n = klassItable::method_count_for_interface(ioe->interface_klass());
2738 for (int index = 0; index < n; index ++) {
2739 it->push(ime[index].method_addr());
2740 }
2741 }
2742 }
2743 }
2744
2745 it->push(&_nest_members);
2746 it->push(&_permitted_subclasses);
2747 it->push(&_loadable_descriptors);
2748 it->push(&_record_components);
2749 it->push(&_inline_layout_info_array, MetaspaceClosure::_writable);
2750 }
2751
2752 #if INCLUDE_CDS
2753 void InstanceKlass::remove_unshareable_info() {
2754
2755 if (is_linked()) {
2756 assert(can_be_verified_at_dumptime(), "must be");
2757 // Remember this so we can avoid walking the hierarchy at runtime.
2758 set_verified_at_dump_time();
2759 }
2760
2761 Klass::remove_unshareable_info();
2762
2763 if (SystemDictionaryShared::has_class_failed_verification(this)) {
2764 // Classes are attempted to link during dumping and may fail,
2765 // but these classes are still in the dictionary and class list in CLD.
2766 // If the class has failed verification, there is nothing else to remove.
2767 return;
2768 }
2769
2775
2776 { // Otherwise this needs to take out the Compile_lock.
2777 assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2778 init_implementor();
2779 }
2780
2781 // Call remove_unshareable_info() on other objects that belong to this class, except
2782 // for constants()->remove_unshareable_info(), which is called in a separate pass in
2783 // ArchiveBuilder::make_klasses_shareable(),
2784
2785 for (int i = 0; i < methods()->length(); i++) {
2786 Method* m = methods()->at(i);
2787 m->remove_unshareable_info();
2788 }
2789
2790 // do array classes also.
2791 if (array_klasses() != nullptr) {
2792 array_klasses()->remove_unshareable_info();
2793 }
2794
2795 // These are not allocated from metaspace. They are safe to set to nullptr.
2796 _source_debug_extension = nullptr;
2797 _dep_context = nullptr;
2798 _osr_nmethods_head = nullptr;
2799 #if INCLUDE_JVMTI
2800 _breakpoints = nullptr;
2801 _previous_versions = nullptr;
2802 _cached_class_file = nullptr;
2803 _jvmti_cached_class_field_map = nullptr;
2804 #endif
2805
2806 _init_thread = nullptr;
2807 _methods_jmethod_ids = nullptr;
2808 _jni_ids = nullptr;
2809 _oop_map_cache = nullptr;
2810 // clear _nest_host to ensure re-load at runtime
2811 _nest_host = nullptr;
2812 init_shared_package_entry();
2813 _dep_context_last_cleaned = 0;
2814
2815 remove_unshareable_flags();
2859 void InstanceKlass::compute_has_loops_flag_for_methods() {
2860 Array<Method*>* methods = this->methods();
2861 for (int index = 0; index < methods->length(); ++index) {
2862 Method* m = methods->at(index);
2863 if (!m->is_overpass()) { // work around JDK-8305771
2864 m->compute_has_loops_flag();
2865 }
2866 }
2867 }
2868
2869 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2870 PackageEntry* pkg_entry, TRAPS) {
2871 // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2872 // before the InstanceKlass is added to the SystemDictionary. Make
2873 // sure the current state is <loaded.
2874 assert(!is_loaded(), "invalid init state");
2875 assert(!shared_loading_failed(), "Must not try to load failed class again");
2876 set_package(loader_data, pkg_entry, CHECK);
2877 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2878
2879 if (is_inline_klass()) {
2880 InlineKlass::cast(this)->initialize_calling_convention(CHECK);
2881 }
2882
2883 Array<Method*>* methods = this->methods();
2884 int num_methods = methods->length();
2885 for (int index = 0; index < num_methods; ++index) {
2886 methods->at(index)->restore_unshareable_info(CHECK);
2887 }
2888 #if INCLUDE_JVMTI
2889 if (JvmtiExport::has_redefined_a_class()) {
2890 // Reinitialize vtable because RedefineClasses may have changed some
2891 // entries in this vtable for super classes so the CDS vtable might
2892 // point to old or obsolete entries. RedefineClasses doesn't fix up
2893 // vtables in the shared system dictionary, only the main one.
2894 // It also redefines the itable too so fix that too.
2895 // First fix any default methods that point to a super class that may
2896 // have been redefined.
2897 bool trace_name_printed = false;
2898 adjust_default_methods(&trace_name_printed);
2899 vtable().initialize_vtable();
2900 itable().initialize_itable();
2901 }
2902 #endif
2903
2904 // restore constant pool resolved references
2905 constants()->restore_unshareable_info(CHECK);
2906
2907 if (array_klasses() != nullptr) {
2908 // To get a consistent list of classes we need MultiArray_lock to ensure
2909 // array classes aren't observed while they are being restored.
2910 RecursiveLocker rl(MultiArray_lock, THREAD);
2911 assert(this == ObjArrayKlass::cast(array_klasses())->bottom_klass(), "sanity");
2912 // Array classes have null protection domain.
2913 // --> see ArrayKlass::complete_create_array_klass()
2914 array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2915 }
2916
2917 // Initialize @ValueBased class annotation if not already set in the archived klass.
2918 if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
2919 set_is_value_based();
2920 }
2921 }
2922
2923 // Check if a class or any of its supertypes has a version older than 50.
2924 // CDS will not perform verification of old classes during dump time because
2925 // without changing the old verifier, the verification constraint cannot be
2926 // retrieved during dump time.
2927 // Verification of archived old classes will be performed during run time.
2928 bool InstanceKlass::can_be_verified_at_dumptime() const {
2929 if (MetaspaceShared::is_in_shared_metaspace(this)) {
2930 // This is a class that was dumped into the base archive, so we know
2931 // it was verified at dump time.
3076 } else {
3077 // Adding one to the attribute length in order to store a null terminator
3078 // character could cause an overflow because the attribute length is
3079 // already coded with an u4 in the classfile, but in practice, it's
3080 // unlikely to happen.
3081 assert((length+1) > length, "Overflow checking");
3082 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
3083 for (int i = 0; i < length; i++) {
3084 sde[i] = array[i];
3085 }
3086 sde[length] = '\0';
3087 _source_debug_extension = sde;
3088 }
3089 }
3090
3091 Symbol* InstanceKlass::generic_signature() const { return _constants->generic_signature(); }
3092 u2 InstanceKlass::generic_signature_index() const { return _constants->generic_signature_index(); }
3093 void InstanceKlass::set_generic_signature_index(u2 sig_index) { _constants->set_generic_signature_index(sig_index); }
3094
3095 const char* InstanceKlass::signature_name() const {
3096 return signature_name_of_carrier(JVM_SIGNATURE_CLASS);
3097 }
3098
3099 const char* InstanceKlass::signature_name_of_carrier(char c) const {
3100 // Get the internal name as a c string
3101 const char* src = (const char*) (name()->as_C_string());
3102 const int src_length = (int)strlen(src);
3103
3104 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
3105
3106 // Add L or Q as type indicator
3107 int dest_index = 0;
3108 dest[dest_index++] = c;
3109
3110 // Add the actual class name
3111 for (int src_index = 0; src_index < src_length; ) {
3112 dest[dest_index++] = src[src_index++];
3113 }
3114
3115 if (is_hidden()) { // Replace the last '+' with a '.'.
3116 for (int index = (int)src_length; index > 0; index--) {
3117 if (dest[index] == '+') {
3118 dest[index] = JVM_SIGNATURE_DOT;
3119 break;
3120 }
3121 }
3122 }
3123
3124 // Add the semicolon and the null
3125 dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
3126 dest[dest_index] = '\0';
3127 return dest;
3128 }
3430 jint InstanceKlass::compute_modifier_flags() const {
3431 jint access = access_flags().as_int();
3432
3433 // But check if it happens to be member class.
3434 InnerClassesIterator iter(this);
3435 for (; !iter.done(); iter.next()) {
3436 int ioff = iter.inner_class_info_index();
3437 // Inner class attribute can be zero, skip it.
3438 // Strange but true: JVM spec. allows null inner class refs.
3439 if (ioff == 0) continue;
3440
3441 // only look at classes that are already loaded
3442 // since we are looking for the flags for our self.
3443 Symbol* inner_name = constants()->klass_name_at(ioff);
3444 if (name() == inner_name) {
3445 // This is really a member class.
3446 access = iter.inner_access_flags();
3447 break;
3448 }
3449 }
3450 return (access & JVM_ACC_WRITTEN_FLAGS);
3451 }
3452
3453 jint InstanceKlass::jvmti_class_status() const {
3454 jint result = 0;
3455
3456 if (is_linked()) {
3457 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3458 }
3459
3460 if (is_initialized()) {
3461 assert(is_linked(), "Class status is not consistent");
3462 result |= JVMTI_CLASS_STATUS_INITIALIZED;
3463 }
3464 if (is_in_error_state()) {
3465 result |= JVMTI_CLASS_STATUS_ERROR;
3466 }
3467 return result;
3468 }
3469
3470 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {
3684 }
3685 osr = osr->osr_link();
3686 }
3687
3688 assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3689 if (best != nullptr && best->comp_level() >= comp_level) {
3690 return best;
3691 }
3692 return nullptr;
3693 }
3694
3695 // -----------------------------------------------------------------------------------------------------
3696 // Printing
3697
3698 #define BULLET " - "
3699
3700 static const char* state_names[] = {
3701 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3702 };
3703
3704 static void print_vtable(address self, intptr_t* start, int len, outputStream* st) {
3705 ResourceMark rm;
3706 int* forward_refs = NEW_RESOURCE_ARRAY(int, len);
3707 for (int i = 0; i < len; i++) forward_refs[i] = 0;
3708 for (int i = 0; i < len; i++) {
3709 intptr_t e = start[i];
3710 st->print("%d : " INTPTR_FORMAT, i, e);
3711 if (forward_refs[i] != 0) {
3712 int from = forward_refs[i];
3713 int off = (int) start[from];
3714 st->print(" (offset %d <= [%d])", off, from);
3715 }
3716 if (MetaspaceObj::is_valid((Metadata*)e)) {
3717 st->print(" ");
3718 ((Metadata*)e)->print_value_on(st);
3719 } else if (self != nullptr && e > 0 && e < 0x10000) {
3720 address location = self + e;
3721 int index = (int)((intptr_t*)location - start);
3722 st->print(" (offset %d => [%d])", (int)e, index);
3723 if (index >= 0 && index < len)
3724 forward_refs[index] = i;
3725 }
3726 st->cr();
3727 }
3728 }
3729
3730 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3731 return print_vtable(nullptr, reinterpret_cast<intptr_t*>(start), len, st);
3732 }
3733
3734 template<typename T>
3735 static void print_array_on(outputStream* st, Array<T>* array) {
3736 if (array == nullptr) { st->print_cr("nullptr"); return; }
3737 array->print_value_on(st); st->cr();
3738 if (Verbose || WizardMode) {
3739 for (int i = 0; i < array->length(); i++) {
3740 st->print("%d : ", i); array->at(i)->print_value_on(st); st->cr();
3741 }
3742 }
3743 }
3744
3745 static void print_array_on(outputStream* st, Array<int>* array) {
3746 if (array == nullptr) { st->print_cr("nullptr"); return; }
3747 array->print_value_on(st); st->cr();
3748 if (Verbose || WizardMode) {
3749 for (int i = 0; i < array->length(); i++) {
3750 st->print("%d : %d", i, array->at(i)); st->cr();
3751 }
3752 }
3753 }
3754
3755 const char* InstanceKlass::init_state_name() const {
3756 return state_names[init_state()];
3757 }
3758
3759 void InstanceKlass::print_on(outputStream* st) const {
3760 assert(is_klass(), "must be klass");
3761 Klass::print_on(st);
3762
3763 st->print(BULLET"instance size: %d", size_helper()); st->cr();
3764 st->print(BULLET"klass size: %d", size()); st->cr();
3765 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
3766 st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
3767 st->print(BULLET"state: "); st->print_cr("%s", init_state_name());
3768 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3769 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3770 st->print(BULLET"sub: ");
3771 Klass* sub = subklass();
3772 int n;
3773 for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3774 if (n < MaxSubklassPrintSize) {
3775 sub->print_value_on(st);
3776 st->print(" ");
3777 }
3778 }
3779 if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3780 st->cr();
3781
3782 if (is_interface()) {
3783 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
3784 if (nof_implementors() == 1) {
3785 st->print_cr(BULLET"implementor: ");
3786 st->print(" ");
3787 implementor()->print_value_on(st);
3788 st->cr();
3789 }
3790 }
3791
3792 st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3793 st->print(BULLET"methods: "); print_array_on(st, methods());
3794 st->print(BULLET"method ordering: "); print_array_on(st, method_ordering());
3795 if (default_methods() != nullptr) {
3796 st->print(BULLET"default_methods: "); print_array_on(st, default_methods());
3797 }
3798 print_on_maybe_null(st, BULLET"default vtable indices: ", default_vtable_indices());
3799 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr();
3800 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3801
3802 st->print(BULLET"secondary supers: "); secondary_supers()->print_value_on(st); st->cr();
3803
3804 st->print(BULLET"hash_slot: %d", hash_slot()); st->cr();
3805 st->print(BULLET"secondary bitmap: " UINTX_FORMAT_X_0, _secondary_supers_bitmap); st->cr();
3806
3807 if (secondary_supers() != nullptr) {
3808 if (Verbose) {
3809 bool is_hashed = (_secondary_supers_bitmap != SECONDARY_SUPERS_BITMAP_FULL);
3810 st->print_cr(BULLET"---- secondary supers (%d words):", _secondary_supers->length());
3811 for (int i = 0; i < _secondary_supers->length(); i++) {
3812 ResourceMark rm; // for external_name()
3813 Klass* secondary_super = _secondary_supers->at(i);
3814 st->print(BULLET"%2d:", i);
3815 if (is_hashed) {
3816 int home_slot = compute_home_slot(secondary_super, _secondary_supers_bitmap);
3836 print_on_maybe_null(st, BULLET"field type annotations: ", fields_type_annotations());
3837 {
3838 bool have_pv = false;
3839 // previous versions are linked together through the InstanceKlass
3840 for (InstanceKlass* pv_node = previous_versions();
3841 pv_node != nullptr;
3842 pv_node = pv_node->previous_versions()) {
3843 if (!have_pv)
3844 st->print(BULLET"previous version: ");
3845 have_pv = true;
3846 pv_node->constants()->print_value_on(st);
3847 }
3848 if (have_pv) st->cr();
3849 }
3850
3851 print_on_maybe_null(st, BULLET"generic signature: ", generic_signature());
3852 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
3853 st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr();
3854 print_on_maybe_null(st, BULLET"record components: ", record_components());
3855 st->print(BULLET"permitted subclasses: "); permitted_subclasses()->print_value_on(st); st->cr();
3856 st->print(BULLET"loadable descriptors: "); loadable_descriptors()->print_value_on(st); st->cr();
3857 if (java_mirror() != nullptr) {
3858 st->print(BULLET"java mirror: ");
3859 java_mirror()->print_value_on(st);
3860 st->cr();
3861 } else {
3862 st->print_cr(BULLET"java mirror: null");
3863 }
3864 st->print(BULLET"vtable length %d (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3865 if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
3866 st->print(BULLET"itable length %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3867 if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(nullptr, start_of_itable(), itable_length(), st);
3868 st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3869
3870 FieldPrinter print_static_field(st);
3871 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3872 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3873 FieldPrinter print_nonstatic_field(st);
3874 InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3875 ik->print_nonstatic_fields(&print_nonstatic_field);
3876
3877 st->print(BULLET"non-static oop maps: ");
3878 OopMapBlock* map = start_of_nonstatic_oop_maps();
3879 OopMapBlock* end_map = map + nonstatic_oop_map_count();
3880 while (map < end_map) {
3881 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3882 map++;
3883 }
3884 st->cr();
3885 }
3886
3887 void InstanceKlass::print_value_on(outputStream* st) const {
|