46 #include "compiler/compileBroker.hpp"
47 #include "gc/shared/collectedHeap.inline.hpp"
48 #include "interpreter/bytecodeStream.hpp"
49 #include "interpreter/oopMapCache.hpp"
50 #include "interpreter/rewriter.hpp"
51 #include "jvm.h"
52 #include "jvmtifiles/jvmti.h"
53 #include "klass.inline.hpp"
54 #include "logging/log.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/constantPool.hpp"
65 #include "oops/fieldStreams.inline.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/atomicAccess.hpp"
82 #include "runtime/deoptimization.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"
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_is_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
440 log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
441 this->external_name(),
442 access ? "" : "NOT ",
443 k->external_name());
444 return access;
445 }
446
447 const char* InstanceKlass::nest_host_error() {
448 if (_nest_host_index == 0) {
449 return nullptr;
450 } else {
451 constantPoolHandle cph(Thread::current(), constants());
452 return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
453 }
454 }
455
456 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
457 const int size = InstanceKlass::size(parser.vtable_size(),
458 parser.itable_size(),
459 nonstatic_oop_map_size(parser.total_oop_map_count()),
460 parser.is_interface());
461
462 const Symbol* const class_name = parser.class_name();
463 assert(class_name != nullptr, "invariant");
464 ClassLoaderData* loader_data = parser.loader_data();
465 assert(loader_data != nullptr, "invariant");
466
467 InstanceKlass* ik;
468
469 // Allocation
470 if (parser.is_instance_ref_klass()) {
471 // java.lang.ref.Reference
472 ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
473 } else if (class_name == vmSymbols::java_lang_Class()) {
474 // mirror - java.lang.Class
475 ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
476 } else if (is_stack_chunk_class(class_name, loader_data)) {
477 // stack chunk
478 ik = new (loader_data, size, THREAD) InstanceStackChunkKlass(parser);
479 } else if (is_class_loader(class_name, parser)) {
480 // class loader - java.lang.ClassLoader
481 ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
482 } else {
483 // normal
484 ik = new (loader_data, size, THREAD) InstanceKlass(parser);
485 }
486
487 if (ik != nullptr && UseCompressedClassPointers) {
488 assert(CompressedKlassPointers::is_encodable(ik),
489 "Klass " PTR_FORMAT "needs a narrow Klass ID, but is not encodable", p2i(ik));
490 }
491
492 // Check for pending exception before adding to the loader data and incrementing
493 // class count. Can get OOM here.
494 if (HAS_PENDING_EXCEPTION) {
495 return nullptr;
496 }
497
498 return ik;
499 }
500
501
502 // copy method ordering from resource area to Metaspace
503 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
504 if (m != nullptr) {
505 // allocate a new array and copy contents (memcpy?)
506 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
507 for (int i = 0; i < m->length(); i++) {
508 _method_ordering->at_put(i, m->at(i));
509 }
510 } else {
511 _method_ordering = Universe::the_empty_int_array();
512 }
513 }
514
515 // create a new array of vtable_indices for default methods
516 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
517 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
518 assert(default_vtable_indices() == nullptr, "only create once");
519 set_default_vtable_indices(vtable_indices);
520 return vtable_indices;
521 }
522
523
524 InstanceKlass::InstanceKlass() {
525 assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
526 }
527
528 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) :
529 Klass(kind),
530 _nest_members(nullptr),
531 _nest_host(nullptr),
532 _permitted_subclasses(nullptr),
533 _record_components(nullptr),
534 _static_field_size(parser.static_field_size()),
535 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
536 _itable_len(parser.itable_size()),
537 _nest_host_index(0),
538 _init_state(allocated),
539 _reference_type(reference_type),
540 _init_thread(nullptr)
541 {
542 set_vtable_length(parser.vtable_size());
543 set_access_flags(parser.access_flags());
544 if (parser.is_hidden()) set_is_hidden();
545 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
546 false));
547
548 assert(nullptr == _methods, "underlying memory not zeroed?");
549 assert(is_instance_klass(), "is layout incorrect?");
550 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
551 }
552
553 void InstanceKlass::set_is_cloneable() {
554 if (name() == vmSymbols::java_lang_invoke_MemberName()) {
555 assert(is_final(), "no subclasses allowed");
556 // MemberName cloning should not be intrinsified and always happen in JVM_Clone.
557 } else if (reference_type() != REF_NONE) {
558 // Reference cloning should not be intrinsified and always happen in JVM_Clone.
559 } else {
560 set_is_cloneable_fast();
561 }
562 }
563
564 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
565 Array<Method*>* methods) {
566 if (methods != nullptr && methods != Universe::the_empty_method_array() &&
682
683 deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
684 set_transitive_interfaces(nullptr);
685 set_local_interfaces(nullptr);
686
687 if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->in_aot_cache()) {
688 MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
689 }
690 set_fieldinfo_stream(nullptr);
691
692 if (fieldinfo_search_table() != nullptr && !fieldinfo_search_table()->in_aot_cache()) {
693 MetadataFactory::free_array<u1>(loader_data, fieldinfo_search_table());
694 }
695 set_fieldinfo_search_table(nullptr);
696
697 if (fields_status() != nullptr && !fields_status()->in_aot_cache()) {
698 MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
699 }
700 set_fields_status(nullptr);
701
702 // If a method from a redefined class is using this constant pool, don't
703 // delete it, yet. The new class's previous version will point to this.
704 if (constants() != nullptr) {
705 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
706 if (!constants()->in_aot_cache()) {
707 MetadataFactory::free_metadata(loader_data, constants());
708 }
709 // Delete any cached resolution errors for the constant pool
710 SystemDictionary::delete_resolution_error(constants());
711
712 set_constants(nullptr);
713 }
714
715 if (inner_classes() != nullptr &&
716 inner_classes() != Universe::the_empty_short_array() &&
717 !inner_classes()->in_aot_cache()) {
718 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
719 }
720 set_inner_classes(nullptr);
721
722 if (nest_members() != nullptr &&
723 nest_members() != Universe::the_empty_short_array() &&
724 !nest_members()->in_aot_cache()) {
725 MetadataFactory::free_array<jushort>(loader_data, nest_members());
726 }
727 set_nest_members(nullptr);
728
729 if (permitted_subclasses() != nullptr &&
730 permitted_subclasses() != Universe::the_empty_short_array() &&
731 !permitted_subclasses()->in_aot_cache()) {
732 MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
733 }
734 set_permitted_subclasses(nullptr);
735
736 // We should deallocate the Annotations instance if it's not in shared spaces.
737 if (annotations() != nullptr && !annotations()->in_aot_cache()) {
738 MetadataFactory::free_metadata(loader_data, annotations());
739 }
740 set_annotations(nullptr);
741
742 SystemDictionaryShared::handle_class_unloading(this);
743
744 #if INCLUDE_CDS_JAVA_HEAP
745 if (CDSConfig::is_dumping_heap()) {
746 HeapShared::remove_scratch_objects(this);
747 }
748 #endif
749 }
750
751 bool InstanceKlass::is_record() const {
752 return _record_components != nullptr &&
753 is_final() &&
754 super() == vmClasses::Record_klass();
755 }
758 return _permitted_subclasses != nullptr &&
759 _permitted_subclasses != Universe::the_empty_short_array();
760 }
761
762 // JLS 8.9: An enum class is either implicitly final and derives
763 // from java.lang.Enum, or else is implicitly sealed to its
764 // anonymous subclasses. This query detects both kinds.
765 // It does not validate the finality or
766 // sealing conditions: it merely checks for a super of Enum.
767 // This is sufficient for recognizing well-formed enums.
768 bool InstanceKlass::is_enum_subclass() const {
769 InstanceKlass* s = super();
770 return (s == vmClasses::Enum_klass() ||
771 (s != nullptr && s->super() == vmClasses::Enum_klass()));
772 }
773
774 bool InstanceKlass::should_be_initialized() const {
775 return !is_initialized();
776 }
777
778 klassItable InstanceKlass::itable() const {
779 return klassItable(const_cast<InstanceKlass*>(this));
780 }
781
782 // JVMTI spec thinks there are signers and protection domain in the
783 // instanceKlass. These accessors pretend these fields are there.
784 // The hprof specification also thinks these fields are in InstanceKlass.
785 oop InstanceKlass::protection_domain() const {
786 // return the protection_domain from the mirror
787 return java_lang_Class::protection_domain(java_mirror());
788 }
789
790 objArrayOop InstanceKlass::signers() const {
791 // return the signers from the mirror
792 return java_lang_Class::signers(java_mirror());
793 }
794
795 oop InstanceKlass::init_lock() const {
796 // return the init lock from the mirror
797 oop lock = java_lang_Class::init_lock(java_mirror());
910 #ifdef ASSERT
911 {
912 Handle h_init_lock(THREAD, init_lock());
913 ObjectLocker ol(h_init_lock, THREAD);
914 assert(!is_initialized(), "sanity");
915 assert(!is_being_initialized(), "sanity");
916 assert(!is_in_error_state(), "sanity");
917 }
918 #endif
919
920 set_init_thread(THREAD);
921 set_initialization_state_and_notify(fully_initialized, CHECK);
922 }
923 #endif
924
925 bool InstanceKlass::verify_code(TRAPS) {
926 // 1) Verify the bytecodes
927 return Verifier::verify(this, should_verify_class(), THREAD);
928 }
929
930 void InstanceKlass::link_class(TRAPS) {
931 assert(is_loaded(), "must be loaded");
932 if (!is_linked()) {
933 link_class_impl(CHECK);
934 }
935 }
936
937 // Called to verify that a class can link during initialization, without
938 // throwing a VerifyError.
939 bool InstanceKlass::link_class_or_fail(TRAPS) {
940 assert(is_loaded(), "must be loaded");
941 if (!is_linked()) {
942 link_class_impl(CHECK_false);
943 }
944 return is_linked();
945 }
946
947 bool InstanceKlass::link_class_impl(TRAPS) {
948 if (CDSConfig::is_dumping_static_archive() && SystemDictionaryShared::has_class_failed_verification(this)) {
949 // This is for CDS static dump only -- we use the in_error_state to indicate that
980 THREAD_AND_LOCATION,
981 vmSymbols::java_lang_IncompatibleClassChangeError(),
982 "class %s has interface %s as super class",
983 external_name(),
984 super_klass->external_name()
985 );
986 return false;
987 }
988
989 super_klass->link_class_impl(CHECK_false);
990 }
991
992 // link all interfaces implemented by this class before linking this class
993 Array<InstanceKlass*>* interfaces = local_interfaces();
994 int num_interfaces = interfaces->length();
995 for (int index = 0; index < num_interfaces; index++) {
996 InstanceKlass* interk = interfaces->at(index);
997 interk->link_class_impl(CHECK_false);
998 }
999
1000 // in case the class is linked in the process of linking its superclasses
1001 if (is_linked()) {
1002 return true;
1003 }
1004
1005 // trace only the link time for this klass that includes
1006 // the verification time
1007 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
1008 ClassLoader::perf_class_link_selftime(),
1009 ClassLoader::perf_classes_linked(),
1010 jt->get_thread_stat()->perf_recursion_counts_addr(),
1011 jt->get_thread_stat()->perf_timers_addr(),
1012 PerfClassTraceTime::CLASS_LINK);
1013
1014 // verification & rewriting
1015 {
1016 HandleMark hm(THREAD);
1017 Handle h_init_lock(THREAD, init_lock());
1018 ObjectLocker ol(h_init_lock, CHECK_PREEMPTABLE_false);
1019 // Don't allow preemption if we link/initialize classes below,
1303 THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1304 ss.as_string(), cause);
1305 }
1306 } else {
1307
1308 // Step 6
1309 set_init_state(being_initialized);
1310 set_init_thread(jt);
1311 if (debug_logging_enabled) {
1312 ResourceMark rm(jt);
1313 log_debug(class, init)("Thread \"%s\" is initializing %s",
1314 jt->name(), external_name());
1315 }
1316 }
1317 }
1318
1319 // Block preemption once we are the initializer thread. Unmounting now
1320 // would complicate the reentrant case (identity is platform thread).
1321 NoPreemptMark npm(THREAD);
1322
1323 // Step 7
1324 // Next, if C is a class rather than an interface, initialize it's super class and super
1325 // interfaces.
1326 if (!is_interface()) {
1327 Klass* super_klass = super();
1328 if (super_klass != nullptr && super_klass->should_be_initialized()) {
1329 super_klass->initialize(THREAD);
1330 }
1331 // If C implements any interface that declares a non-static, concrete method,
1332 // the initialization of C triggers initialization of its super interfaces.
1333 // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1334 // having a superinterface that declares, non-static, concrete methods
1335 if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1336 initialize_super_interfaces(THREAD);
1337 }
1338
1339 // If any exceptions, complete abruptly, throwing the same exception as above.
1340 if (HAS_PENDING_EXCEPTION) {
1341 Handle e(THREAD, PENDING_EXCEPTION);
1342 CLEAR_PENDING_EXCEPTION;
1343 {
1344 EXCEPTION_MARK;
1345 add_initialization_error(THREAD, e);
1346 // Locks object, set state, and notify all waiting threads
1347 set_initialization_state_and_notify(initialization_error, THREAD);
1348 CLEAR_PENDING_EXCEPTION;
1349 }
1350 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1351 THROW_OOP(e());
1352 }
1353 }
1354
1355
1356 // Step 8
1357 {
1358 DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1359 if (class_initializer() != nullptr) {
1360 // Timer includes any side effects of class initialization (resolution,
1361 // etc), but not recursive entry into call_class_initializer().
1362 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1363 ClassLoader::perf_class_init_selftime(),
1364 ClassLoader::perf_classes_inited(),
1365 jt->get_thread_stat()->perf_recursion_counts_addr(),
1366 jt->get_thread_stat()->perf_timers_addr(),
1367 PerfClassTraceTime::CLASS_CLINIT);
1368 call_class_initializer(THREAD);
1369 } else {
1370 // The elapsed time is so small it's not worth counting.
1371 if (UsePerfData) {
1372 ClassLoader::perf_classes_inited()->inc();
1373 }
1374 call_class_initializer(THREAD);
1375 }
1376 }
1377
1378 // Step 9
1379 if (!HAS_PENDING_EXCEPTION) {
1380 set_initialization_state_and_notify(fully_initialized, CHECK);
1381 DEBUG_ONLY(vtable().verify(tty, true);)
1382 CompilationPolicy::replay_training_at_init(this, THREAD);
1383 }
1384 else {
1385 // Step 10 and 11
1386 Handle e(THREAD, PENDING_EXCEPTION);
1387 CLEAR_PENDING_EXCEPTION;
1388 // JVMTI has already reported the pending exception
1389 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1390 JvmtiExport::clear_detected_exception(jt);
1391 {
1392 EXCEPTION_MARK;
1393 add_initialization_error(THREAD, e);
1394 set_initialization_state_and_notify(initialization_error, THREAD);
1395 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
1409 }
1410 DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait);
1411 }
1412
1413
1414 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
1415 Handle h_init_lock(THREAD, init_lock());
1416 if (h_init_lock() != nullptr) {
1417 ObjectLocker ol(h_init_lock, THREAD);
1418 set_init_thread(nullptr); // reset _init_thread before changing _init_state
1419 set_init_state(state);
1420 fence_and_clear_init_lock();
1421 ol.notify_all(CHECK);
1422 } else {
1423 assert(h_init_lock() != nullptr, "The initialization state should never be set twice");
1424 set_init_thread(nullptr); // reset _init_thread before changing _init_state
1425 set_init_state(state);
1426 }
1427 }
1428
1429 // Update hierarchy. This is done before the new klass has been added to the SystemDictionary. The Compile_lock
1430 // is grabbed, to ensure that the compiler is not using the class hierarchy.
1431 void InstanceKlass::add_to_hierarchy(JavaThread* current) {
1432 assert(!SafepointSynchronize::is_at_safepoint(), "must NOT be at safepoint");
1433
1434 DeoptimizationScope deopt_scope;
1435 {
1436 MutexLocker ml(current, Compile_lock);
1437
1438 set_init_state(InstanceKlass::loaded);
1439 // make sure init_state store is already done.
1440 // The compiler reads the hierarchy outside of the Compile_lock.
1441 // Access ordering is used to add to hierarchy.
1442
1443 // Link into hierarchy.
1444 append_to_sibling_list(); // add to superklass/sibling list
1445 process_interfaces(); // handle all "implements" declarations
1446
1447 // Now mark all code that depended on old class hierarchy.
1448 // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)
1659 : vmSymbols::java_lang_IllegalAccessException(), external_name());
1660 }
1661 }
1662
1663 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1664 // Need load-acquire for lock-free read
1665 if (array_klasses_acquire() == nullptr) {
1666
1667 // Recursively lock array allocation
1668 RecursiveLocker rl(MultiArray_lock, THREAD);
1669
1670 // Check if another thread created the array klass while we were waiting for the lock.
1671 if (array_klasses() == nullptr) {
1672 ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);
1673 // use 'release' to pair with lock-free load
1674 release_set_array_klasses(k);
1675 }
1676 }
1677
1678 // array_klasses() will always be set at this point
1679 ObjArrayKlass* ak = array_klasses();
1680 assert(ak != nullptr, "should be set");
1681 return ak->array_klass(n, THREAD);
1682 }
1683
1684 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1685 // Need load-acquire for lock-free read
1686 ObjArrayKlass* oak = array_klasses_acquire();
1687 if (oak == nullptr) {
1688 return nullptr;
1689 } else {
1690 return oak->array_klass_or_null(n);
1691 }
1692 }
1693
1694 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1695 return array_klass(1, THREAD);
1696 }
1697
1698 ArrayKlass* InstanceKlass::array_klass_or_null() {
1699 return array_klass_or_null(1);
1700 }
1701
1702 static int call_class_initializer_counter = 0; // for debugging
1703
1704 Method* InstanceKlass::class_initializer() const {
1705 Method* clinit = find_method(
1706 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1707 if (clinit != nullptr && clinit->has_valid_initializer_flags()) {
1708 return clinit;
1709 }
1710 return nullptr;
1711 }
1712
1713 void InstanceKlass::call_class_initializer(TRAPS) {
1714 if (ReplayCompiles &&
1715 (ReplaySuppressInitializers == 1 ||
1716 (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1717 // Hide the existence of the initializer for the purpose of replaying the compile
1718 return;
1719 }
1720
1721 #if INCLUDE_CDS
1722 // This is needed to ensure the consistency of the archived heap objects.
1723 if (has_aot_initialized_mirror() && CDSConfig::is_loading_heap()) {
1724 AOTClassInitializer::call_runtime_setup(THREAD, this);
1725 return;
1726 } else if (has_archived_enum_objs()) {
1727 assert(in_aot_cache(), "must be");
1796
1797 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1798 InterpreterOopMap* entry_for) {
1799 // Lazily create the _oop_map_cache at first request.
1800 // Load_acquire is needed to safely get instance published with CAS by another thread.
1801 OopMapCache* oop_map_cache = AtomicAccess::load_acquire(&_oop_map_cache);
1802 if (oop_map_cache == nullptr) {
1803 // Try to install new instance atomically.
1804 oop_map_cache = new OopMapCache();
1805 OopMapCache* other = AtomicAccess::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
1806 if (other != nullptr) {
1807 // Someone else managed to install before us, ditch local copy and use the existing one.
1808 delete oop_map_cache;
1809 oop_map_cache = other;
1810 }
1811 }
1812 // _oop_map_cache is constant after init; lookup below does its own locking.
1813 oop_map_cache->lookup(method, bci, entry_for);
1814 }
1815
1816 bool InstanceKlass::contains_field_offset(int offset) {
1817 fieldDescriptor fd;
1818 return find_field_from_offset(offset, false, &fd);
1819 }
1820
1821 FieldInfo InstanceKlass::field(int index) const {
1822 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1823 if (fs.index() == index) {
1824 return fs.to_FieldInfo();
1825 }
1826 }
1827 fatal("Field not found");
1828 return FieldInfo();
1829 }
1830
1831 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1832 JavaFieldStream fs(this);
1833 if (fs.lookup(name, sig)) {
1834 assert(fs.name() == name, "name must match");
1835 assert(fs.signature() == sig, "signature must match");
1836 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.to_FieldInfo());
1837 return true;
1838 }
1839 return false;
1880
1881 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1882 // search order according to newest JVM spec (5.4.3.2, p.167).
1883 // 1) search for field in current klass
1884 if (find_local_field(name, sig, fd)) {
1885 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1886 }
1887 // 2) search for field recursively in direct superinterfaces
1888 if (is_static) {
1889 Klass* intf = find_interface_field(name, sig, fd);
1890 if (intf != nullptr) return intf;
1891 }
1892 // 3) apply field lookup recursively if superclass exists
1893 { InstanceKlass* supr = super();
1894 if (supr != nullptr) return supr->find_field(name, sig, is_static, fd);
1895 }
1896 // 4) otherwise field lookup fails
1897 return nullptr;
1898 }
1899
1900
1901 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1902 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1903 if (fs.offset() == offset) {
1904 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.to_FieldInfo());
1905 if (fd->is_static() == is_static) return true;
1906 }
1907 }
1908 return false;
1909 }
1910
1911
1912 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1913 const InstanceKlass* klass = this;
1914 while (klass != nullptr) {
1915 if (klass->find_local_field_from_offset(offset, is_static, fd)) {
1916 return true;
1917 }
1918 klass = klass->super();
1919 }
2263 }
2264
2265 // uncached_lookup_method searches both the local class methods array and all
2266 // superclasses methods arrays, skipping any overpass methods in superclasses,
2267 // and possibly skipping private methods.
2268 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2269 const Symbol* signature,
2270 OverpassLookupMode overpass_mode,
2271 PrivateLookupMode private_mode) const {
2272 OverpassLookupMode overpass_local_mode = overpass_mode;
2273 const InstanceKlass* klass = this;
2274 while (klass != nullptr) {
2275 Method* const method = klass->find_method_impl(name,
2276 signature,
2277 overpass_local_mode,
2278 StaticLookupMode::find,
2279 private_mode);
2280 if (method != nullptr) {
2281 return method;
2282 }
2283 klass = klass->super();
2284 overpass_local_mode = OverpassLookupMode::skip; // Always ignore overpass methods in superclasses
2285 }
2286 return nullptr;
2287 }
2288
2289 #ifdef ASSERT
2290 // search through class hierarchy and return true if this class or
2291 // one of the superclasses was redefined
2292 bool InstanceKlass::has_redefined_this_or_super() const {
2293 const InstanceKlass* klass = this;
2294 while (klass != nullptr) {
2295 if (klass->has_been_redefined()) {
2296 return true;
2297 }
2298 klass = klass->super();
2299 }
2300 return false;
2301 }
2302 #endif
2675 int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2676
2677 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2678 / itableOffsetEntry::size();
2679
2680 for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2681 if (ioe->interface_klass() != nullptr) {
2682 it->push(ioe->interface_klass_addr());
2683 itableMethodEntry* ime = ioe->first_method_entry(this);
2684 int n = klassItable::method_count_for_interface(ioe->interface_klass());
2685 for (int index = 0; index < n; index ++) {
2686 it->push(ime[index].method_addr());
2687 }
2688 }
2689 }
2690 }
2691
2692 it->push(&_nest_host);
2693 it->push(&_nest_members);
2694 it->push(&_permitted_subclasses);
2695 it->push(&_record_components);
2696 }
2697
2698 #if INCLUDE_CDS
2699 void InstanceKlass::remove_unshareable_info() {
2700
2701 if (is_linked()) {
2702 assert(can_be_verified_at_dumptime(), "must be");
2703 // Remember this so we can avoid walking the hierarchy at runtime.
2704 set_verified_at_dump_time();
2705 }
2706
2707 _misc_flags.set_has_init_deps_processed(false);
2708
2709 Klass::remove_unshareable_info();
2710
2711 if (SystemDictionaryShared::has_class_failed_verification(this)) {
2712 // Classes are attempted to link during dumping and may fail,
2713 // but these classes are still in the dictionary and class list in CLD.
2714 // If the class has failed verification, there is nothing else to remove.
2715 return;
2723
2724 { // Otherwise this needs to take out the Compile_lock.
2725 assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2726 init_implementor();
2727 }
2728
2729 // Call remove_unshareable_info() on other objects that belong to this class, except
2730 // for constants()->remove_unshareable_info(), which is called in a separate pass in
2731 // ArchiveBuilder::make_klasses_shareable(),
2732
2733 for (int i = 0; i < methods()->length(); i++) {
2734 Method* m = methods()->at(i);
2735 m->remove_unshareable_info();
2736 }
2737
2738 // do array classes also.
2739 if (array_klasses() != nullptr) {
2740 array_klasses()->remove_unshareable_info();
2741 }
2742
2743 // These are not allocated from metaspace. They are safe to set to null.
2744 _source_debug_extension = nullptr;
2745 _dep_context = nullptr;
2746 _osr_nmethods_head = nullptr;
2747 #if INCLUDE_JVMTI
2748 _breakpoints = nullptr;
2749 _previous_versions = nullptr;
2750 _cached_class_file = nullptr;
2751 _jvmti_cached_class_field_map = nullptr;
2752 #endif
2753
2754 _init_thread = nullptr;
2755 _methods_jmethod_ids = nullptr;
2756 _jni_ids = nullptr;
2757 _oop_map_cache = nullptr;
2758 if (CDSConfig::is_dumping_method_handles() && HeapShared::is_lambda_proxy_klass(this)) {
2759 // keep _nest_host
2760 } else {
2761 // clear _nest_host to ensure re-load at runtime
2762 _nest_host = nullptr;
2763 }
2814 void InstanceKlass::compute_has_loops_flag_for_methods() {
2815 Array<Method*>* methods = this->methods();
2816 for (int index = 0; index < methods->length(); ++index) {
2817 Method* m = methods->at(index);
2818 if (!m->is_overpass()) { // work around JDK-8305771
2819 m->compute_has_loops_flag();
2820 }
2821 }
2822 }
2823
2824 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2825 PackageEntry* pkg_entry, TRAPS) {
2826 // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2827 // before the InstanceKlass is added to the SystemDictionary. Make
2828 // sure the current state is <loaded.
2829 assert(!is_loaded(), "invalid init state");
2830 assert(!shared_loading_failed(), "Must not try to load failed class again");
2831 set_package(loader_data, pkg_entry, CHECK);
2832 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2833
2834 Array<Method*>* methods = this->methods();
2835 int num_methods = methods->length();
2836 for (int index = 0; index < num_methods; ++index) {
2837 methods->at(index)->restore_unshareable_info(CHECK);
2838 }
2839 #if INCLUDE_JVMTI
2840 if (JvmtiExport::has_redefined_a_class()) {
2841 // Reinitialize vtable because RedefineClasses may have changed some
2842 // entries in this vtable for super classes so the CDS vtable might
2843 // point to old or obsolete entries. RedefineClasses doesn't fix up
2844 // vtables in the shared system dictionary, only the main one.
2845 // It also redefines the itable too so fix that too.
2846 // First fix any default methods that point to a super class that may
2847 // have been redefined.
2848 bool trace_name_printed = false;
2849 adjust_default_methods(&trace_name_printed);
2850 if (verified_at_dump_time()) {
2851 // Initialize vtable and itable for classes which can be verified at dump time.
2852 // Unlinked classes such as old classes with major version < 50 cannot be verified
2853 // at dump time.
2854 vtable().initialize_vtable();
2855 itable().initialize_itable();
2856 }
2857 }
2858 #endif // INCLUDE_JVMTI
2859
2860 // restore constant pool resolved references
2861 constants()->restore_unshareable_info(CHECK);
2862
2863 if (array_klasses() != nullptr) {
2864 // To get a consistent list of classes we need MultiArray_lock to ensure
2865 // array classes aren't observed while they are being restored.
2866 RecursiveLocker rl(MultiArray_lock, THREAD);
2867 assert(this == array_klasses()->bottom_klass(), "sanity");
2868 // Array classes have null protection domain.
2869 // --> see ArrayKlass::complete_create_array_klass()
2870 array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2871 }
2872
2873 // Initialize @ValueBased class annotation if not already set in the archived klass.
2874 if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
2875 set_is_value_based();
2876 }
2877
2878 DEBUG_ONLY(FieldInfoStream::validate_search_table(_constants, _fieldinfo_stream, _fieldinfo_search_table));
2879 }
2880
2881 bool InstanceKlass::can_be_verified_at_dumptime() const {
2882 if (CDSConfig::is_dumping_dynamic_archive() && AOTMetaspace::in_aot_cache(this)) {
2883 // This is a class that was dumped into the base archive, so we know
2884 // it was verified at dump time.
2885 return true;
2886 }
2887
2888 if (CDSConfig::is_preserving_verification_constraints()) {
2889 return true;
3005 constants()->release_C_heap_structures();
3006 }
3007 }
3008
3009 // The constant pool is on stack if any of the methods are executing or
3010 // referenced by handles.
3011 bool InstanceKlass::on_stack() const {
3012 return _constants->on_stack();
3013 }
3014
3015 Symbol* InstanceKlass::source_file_name() const { return _constants->source_file_name(); }
3016 u2 InstanceKlass::source_file_name_index() const { return _constants->source_file_name_index(); }
3017 void InstanceKlass::set_source_file_name_index(u2 sourcefile_index) { _constants->set_source_file_name_index(sourcefile_index); }
3018
3019 // minor and major version numbers of class file
3020 u2 InstanceKlass::minor_version() const { return _constants->minor_version(); }
3021 void InstanceKlass::set_minor_version(u2 minor_version) { _constants->set_minor_version(minor_version); }
3022 u2 InstanceKlass::major_version() const { return _constants->major_version(); }
3023 void InstanceKlass::set_major_version(u2 major_version) { _constants->set_major_version(major_version); }
3024
3025 const InstanceKlass* InstanceKlass::get_klass_version(int version) const {
3026 for (const InstanceKlass* ik = this; ik != nullptr; ik = ik->previous_versions()) {
3027 if (ik->constants()->version() == version) {
3028 return ik;
3029 }
3030 }
3031 return nullptr;
3032 }
3033
3034 void InstanceKlass::set_source_debug_extension(const char* array, int length) {
3035 if (array == nullptr) {
3036 _source_debug_extension = nullptr;
3037 } else {
3038 // Adding one to the attribute length in order to store a null terminator
3039 // character could cause an overflow because the attribute length is
3040 // already coded with an u4 in the classfile, but in practice, it's
3041 // unlikely to happen.
3042 assert((length+1) > length, "Overflow checking");
3043 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
3044 for (int i = 0; i < length; i++) {
3045 sde[i] = array[i];
3046 }
3047 sde[length] = '\0';
3048 _source_debug_extension = sde;
3049 }
3050 }
3051
3052 Symbol* InstanceKlass::generic_signature() const { return _constants->generic_signature(); }
3053 u2 InstanceKlass::generic_signature_index() const { return _constants->generic_signature_index(); }
3054 void InstanceKlass::set_generic_signature_index(u2 sig_index) { _constants->set_generic_signature_index(sig_index); }
3055
3056 const char* InstanceKlass::signature_name() const {
3057
3058 // Get the internal name as a c string
3059 const char* src = (const char*) (name()->as_C_string());
3060 const int src_length = (int)strlen(src);
3061
3062 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
3063
3064 // Add L as type indicator
3065 int dest_index = 0;
3066 dest[dest_index++] = JVM_SIGNATURE_CLASS;
3067
3068 // Add the actual class name
3069 for (int src_index = 0; src_index < src_length; ) {
3070 dest[dest_index++] = src[src_index++];
3071 }
3072
3073 if (is_hidden()) { // Replace the last '+' with a '.'.
3074 for (int index = (int)src_length; index > 0; index--) {
3075 if (dest[index] == '+') {
3076 dest[index] = JVM_SIGNATURE_DOT;
3077 break;
3078 }
3079 }
3080 }
3081
3082 // Add the semicolon and the null
3083 dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
3084 dest[dest_index] = '\0';
3085 return dest;
3086 }
3327 bool InstanceKlass::find_inner_classes_attr(int* ooff, int* noff, TRAPS) const {
3328 constantPoolHandle i_cp(THREAD, constants());
3329 for (InnerClassesIterator iter(this); !iter.done(); iter.next()) {
3330 int ioff = iter.inner_class_info_index();
3331 if (ioff != 0) {
3332 // Check to see if the name matches the class we're looking for
3333 // before attempting to find the class.
3334 if (i_cp->klass_name_at_matches(this, ioff)) {
3335 Klass* inner_klass = i_cp->klass_at(ioff, CHECK_false);
3336 if (this == inner_klass) {
3337 *ooff = iter.outer_class_info_index();
3338 *noff = iter.inner_name_index();
3339 return true;
3340 }
3341 }
3342 }
3343 }
3344 return false;
3345 }
3346
3347 InstanceKlass* InstanceKlass::compute_enclosing_class(bool* inner_is_member, TRAPS) const {
3348 InstanceKlass* outer_klass = nullptr;
3349 *inner_is_member = false;
3350 int ooff = 0, noff = 0;
3351 bool has_inner_classes_attr = find_inner_classes_attr(&ooff, &noff, THREAD);
3352 if (has_inner_classes_attr) {
3353 constantPoolHandle i_cp(THREAD, constants());
3354 if (ooff != 0) {
3355 Klass* ok = i_cp->klass_at(ooff, CHECK_NULL);
3356 if (!ok->is_instance_klass()) {
3357 // If the outer class is not an instance klass then it cannot have
3358 // declared any inner classes.
3359 ResourceMark rm(THREAD);
3360 // Names are all known to be < 64k so we know this formatted message is not excessively large.
3361 Exceptions::fthrow(
3362 THREAD_AND_LOCATION,
3363 vmSymbols::java_lang_IncompatibleClassChangeError(),
3364 "%s and %s disagree on InnerClasses attribute",
3365 ok->external_name(),
3366 external_name());
3393 u2 InstanceKlass::compute_modifier_flags() const {
3394 u2 access = access_flags().as_unsigned_short();
3395
3396 // But check if it happens to be member class.
3397 InnerClassesIterator iter(this);
3398 for (; !iter.done(); iter.next()) {
3399 int ioff = iter.inner_class_info_index();
3400 // Inner class attribute can be zero, skip it.
3401 // Strange but true: JVM spec. allows null inner class refs.
3402 if (ioff == 0) continue;
3403
3404 // only look at classes that are already loaded
3405 // since we are looking for the flags for our self.
3406 Symbol* inner_name = constants()->klass_name_at(ioff);
3407 if (name() == inner_name) {
3408 // This is really a member class.
3409 access = iter.inner_access_flags();
3410 break;
3411 }
3412 }
3413 // Remember to strip ACC_SUPER bit
3414 return (access & (~JVM_ACC_SUPER));
3415 }
3416
3417 jint InstanceKlass::jvmti_class_status() const {
3418 jint result = 0;
3419
3420 if (is_linked()) {
3421 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3422 }
3423
3424 if (is_initialized()) {
3425 assert(is_linked(), "Class status is not consistent");
3426 result |= JVMTI_CLASS_STATUS_INITIALIZED;
3427 }
3428 if (is_in_error_state()) {
3429 result |= JVMTI_CLASS_STATUS_ERROR;
3430 }
3431 return result;
3432 }
3433
3434 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {
3648 }
3649 osr = osr->osr_link();
3650 }
3651
3652 assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3653 if (best != nullptr && best->comp_level() >= comp_level) {
3654 return best;
3655 }
3656 return nullptr;
3657 }
3658
3659 // -----------------------------------------------------------------------------------------------------
3660 // Printing
3661
3662 #define BULLET " - "
3663
3664 static const char* state_names[] = {
3665 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3666 };
3667
3668 static void print_vtable(intptr_t* start, int len, outputStream* st) {
3669 for (int i = 0; i < len; i++) {
3670 intptr_t e = start[i];
3671 st->print("%d : " INTPTR_FORMAT, i, e);
3672 if (MetaspaceObj::is_valid((Metadata*)e)) {
3673 st->print(" ");
3674 ((Metadata*)e)->print_value_on(st);
3675 }
3676 st->cr();
3677 }
3678 }
3679
3680 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3681 return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
3682 }
3683
3684 const char* InstanceKlass::init_state_name() const {
3685 return state_names[init_state()];
3686 }
3687
3688 void InstanceKlass::print_on(outputStream* st) const {
3689 assert(is_klass(), "must be klass");
3690 Klass::print_on(st);
3691
3692 st->print(BULLET"instance size: %d", size_helper()); st->cr();
3693 st->print(BULLET"klass size: %d", size()); st->cr();
3694 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
3695 st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
3696 st->print(BULLET"state: "); st->print_cr("%s", init_state_name());
3697 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3698 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3699 st->print(BULLET"sub: ");
3700 Klass* sub = subklass();
3701 int n;
3702 for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3703 if (n < MaxSubklassPrintSize) {
3704 sub->print_value_on(st);
3705 st->print(" ");
3706 }
3707 }
3708 if (n >= MaxSubklassPrintSize) st->print("(%zd more klasses...)", n - MaxSubklassPrintSize);
3709 st->cr();
3710
3711 if (is_interface()) {
3712 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
3713 if (nof_implementors() == 1) {
3714 st->print_cr(BULLET"implementor: ");
3715 st->print(" ");
3716 implementor()->print_value_on(st);
3717 st->cr();
3718 }
3719 }
3720
3721 st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3722 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr();
3723 if (Verbose || WizardMode) {
3724 Array<Method*>* method_array = methods();
3725 for (int i = 0; i < method_array->length(); i++) {
3726 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3727 }
3728 }
3729 st->print(BULLET"method ordering: "); method_ordering()->print_value_on(st); st->cr();
3730 if (default_methods() != nullptr) {
3731 st->print(BULLET"default_methods: "); default_methods()->print_value_on(st); st->cr();
3732 if (Verbose) {
3733 Array<Method*>* method_array = default_methods();
3734 for (int i = 0; i < method_array->length(); i++) {
3735 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3736 }
3737 }
3738 }
3739 print_on_maybe_null(st, BULLET"default vtable indices: ", default_vtable_indices());
3740 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr();
3741 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3742
3743 st->print(BULLET"secondary supers: "); secondary_supers()->print_value_on(st); st->cr();
3744
3745 st->print(BULLET"hash_slot: %d", hash_slot()); st->cr();
3746 st->print(BULLET"secondary bitmap: " UINTX_FORMAT_X_0, _secondary_supers_bitmap); st->cr();
3747
3748 if (secondary_supers() != nullptr) {
3749 if (Verbose) {
3750 bool is_hashed = (_secondary_supers_bitmap != SECONDARY_SUPERS_BITMAP_FULL);
3751 st->print_cr(BULLET"---- secondary supers (%d words):", _secondary_supers->length());
3752 for (int i = 0; i < _secondary_supers->length(); i++) {
3753 ResourceMark rm; // for external_name()
3754 Klass* secondary_super = _secondary_supers->at(i);
3755 st->print(BULLET"%2d:", i);
3756 if (is_hashed) {
3757 int home_slot = compute_home_slot(secondary_super, _secondary_supers_bitmap);
3777 print_on_maybe_null(st, BULLET"field type annotations: ", fields_type_annotations());
3778 {
3779 bool have_pv = false;
3780 // previous versions are linked together through the InstanceKlass
3781 for (InstanceKlass* pv_node = previous_versions();
3782 pv_node != nullptr;
3783 pv_node = pv_node->previous_versions()) {
3784 if (!have_pv)
3785 st->print(BULLET"previous version: ");
3786 have_pv = true;
3787 pv_node->constants()->print_value_on(st);
3788 }
3789 if (have_pv) st->cr();
3790 }
3791
3792 print_on_maybe_null(st, BULLET"generic signature: ", generic_signature());
3793 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
3794 st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr();
3795 print_on_maybe_null(st, BULLET"record components: ", record_components());
3796 st->print(BULLET"permitted subclasses: "); permitted_subclasses()->print_value_on(st); st->cr();
3797 if (java_mirror() != nullptr) {
3798 st->print(BULLET"java mirror: ");
3799 java_mirror()->print_value_on(st);
3800 st->cr();
3801 } else {
3802 st->print_cr(BULLET"java mirror: null");
3803 }
3804 st->print(BULLET"vtable length %d (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3805 if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
3806 st->print(BULLET"itable length %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3807 if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_itable(), itable_length(), st);
3808 st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3809
3810 FieldPrinter print_static_field(st);
3811 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3812 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3813 FieldPrinter print_nonstatic_field(st);
3814 InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3815 ik->print_nonstatic_fields(&print_nonstatic_field);
3816
3817 st->print(BULLET"non-static oop maps (%d entries): ", nonstatic_oop_map_count());
3818 OopMapBlock* map = start_of_nonstatic_oop_maps();
3819 OopMapBlock* end_map = map + nonstatic_oop_map_count();
3820 while (map < end_map) {
3821 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3822 map++;
3823 }
3824 st->cr();
3825
3826 if (fieldinfo_search_table() != nullptr) {
3827 st->print_cr(BULLET"---- field info search table:");
3828 FieldInfoStream::print_search_table(st, _constants, _fieldinfo_stream, _fieldinfo_search_table);
3829 }
3830 }
3831
3832 void InstanceKlass::print_value_on(outputStream* st) const {
3833 assert(is_klass(), "must be klass");
3834 if (Verbose || WizardMode) access_flags().print_on(st);
3835 name()->print_value_on(st);
3836 }
3837
3838 void FieldPrinter::do_field(fieldDescriptor* fd) {
3839 _st->print(BULLET);
3840 if (_obj == nullptr) {
3841 fd->print_on(_st);
3842 _st->cr();
3843 } else {
3844 fd->print_on_for(_st, _obj);
3845 _st->cr();
3846 }
3847 }
3848
3849
3850 void InstanceKlass::oop_print_on(oop obj, outputStream* st) {
3851 Klass::oop_print_on(obj, st);
3852
3853 if (this == vmClasses::String_klass()) {
3854 typeArrayOop value = java_lang_String::value(obj);
3855 juint length = java_lang_String::length(obj);
3856 if (value != nullptr &&
3857 value->is_typeArray() &&
3858 length <= (juint) value->length()) {
3859 st->print(BULLET"string: ");
3860 java_lang_String::print(obj, st);
3861 st->cr();
3862 }
3863 }
3864
3865 st->print_cr(BULLET"---- fields (total size %zu words):", oop_size(obj));
3866 FieldPrinter print_field(st, obj);
3867 print_nonstatic_fields(&print_field);
3868
3869 if (this == vmClasses::Class_klass()) {
3870 st->print(BULLET"signature: ");
3871 java_lang_Class::print_signature(obj, st);
3872 st->cr();
3873 Klass* real_klass = java_lang_Class::as_Klass(obj);
3874 if (real_klass != nullptr && real_klass->is_instance_klass()) {
3875 st->print_cr(BULLET"---- static fields (%d):", java_lang_Class::static_oop_field_count(obj));
3876 InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field);
3877 }
3878 } else if (this == vmClasses::MethodType_klass()) {
3879 st->print(BULLET"signature: ");
3880 java_lang_invoke_MethodType::print_signature(obj, st);
3881 st->cr();
3882 }
3883 }
3884
3885 #ifndef PRODUCT
3886
|
46 #include "compiler/compileBroker.hpp"
47 #include "gc/shared/collectedHeap.inline.hpp"
48 #include "interpreter/bytecodeStream.hpp"
49 #include "interpreter/oopMapCache.hpp"
50 #include "interpreter/rewriter.hpp"
51 #include "jvm.h"
52 #include "jvmtifiles/jvmti.h"
53 #include "klass.inline.hpp"
54 #include "logging/log.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/constantPool.hpp"
65 #include "oops/fieldStreams.inline.hpp"
66 #include "oops/inlineKlass.hpp"
67 #include "oops/instanceClassLoaderKlass.hpp"
68 #include "oops/instanceKlass.inline.hpp"
69 #include "oops/instanceMirrorKlass.hpp"
70 #include "oops/instanceOop.hpp"
71 #include "oops/instanceStackChunkKlass.hpp"
72 #include "oops/klass.inline.hpp"
73 #include "oops/markWord.hpp"
74 #include "oops/method.hpp"
75 #include "oops/oop.inline.hpp"
76 #include "oops/recordComponent.hpp"
77 #include "oops/refArrayKlass.hpp"
78 #include "oops/symbol.hpp"
79 #include "prims/jvmtiExport.hpp"
80 #include "prims/jvmtiRedefineClasses.hpp"
81 #include "prims/jvmtiThreadState.hpp"
82 #include "prims/methodComparator.hpp"
83 #include "runtime/arguments.hpp"
84 #include "runtime/atomicAccess.hpp"
85 #include "runtime/deoptimization.hpp"
86 #include "runtime/fieldDescriptor.inline.hpp"
87 #include "runtime/handles.inline.hpp"
88 #include "runtime/javaCalls.hpp"
89 #include "runtime/javaThread.inline.hpp"
90 #include "runtime/mutexLocker.hpp"
91 #include "runtime/orderAccess.hpp"
92 #include "runtime/os.inline.hpp"
93 #include "runtime/reflection.hpp"
94 #include "runtime/synchronizer.hpp"
95 #include "runtime/threads.hpp"
96 #include "services/classLoadingService.hpp"
97 #include "services/finalizerService.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_is_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
461 log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
462 this->external_name(),
463 access ? "" : "NOT ",
464 k->external_name());
465 return access;
466 }
467
468 const char* InstanceKlass::nest_host_error() {
469 if (_nest_host_index == 0) {
470 return nullptr;
471 } else {
472 constantPoolHandle cph(Thread::current(), constants());
473 return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
474 }
475 }
476
477 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
478 const int size = InstanceKlass::size(parser.vtable_size(),
479 parser.itable_size(),
480 nonstatic_oop_map_size(parser.total_oop_map_count()),
481 parser.is_interface(),
482 parser.is_inline_type());
483
484 const Symbol* const class_name = parser.class_name();
485 assert(class_name != nullptr, "invariant");
486 ClassLoaderData* loader_data = parser.loader_data();
487 assert(loader_data != nullptr, "invariant");
488
489 InstanceKlass* ik;
490
491 // Allocation
492 if (parser.is_instance_ref_klass()) {
493 // java.lang.ref.Reference
494 ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
495 } else if (class_name == vmSymbols::java_lang_Class()) {
496 // mirror - java.lang.Class
497 ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
498 } else if (is_stack_chunk_class(class_name, loader_data)) {
499 // stack chunk
500 ik = new (loader_data, size, THREAD) InstanceStackChunkKlass(parser);
501 } else if (is_class_loader(class_name, parser)) {
502 // class loader - java.lang.ClassLoader
503 ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
504 } else if (parser.is_inline_type()) {
505 // inline type
506 ik = new (loader_data, size, THREAD) InlineKlass(parser);
507 } else {
508 // normal
509 ik = new (loader_data, size, THREAD) InstanceKlass(parser);
510 }
511
512 if (ik != nullptr && UseCompressedClassPointers) {
513 assert(CompressedKlassPointers::is_encodable(ik),
514 "Klass " PTR_FORMAT "needs a narrow Klass ID, but is not encodable", p2i(ik));
515 }
516
517 // Check for pending exception before adding to the loader data and incrementing
518 // class count. Can get OOM here.
519 if (HAS_PENDING_EXCEPTION) {
520 return nullptr;
521 }
522
523 #ifdef ASSERT
524 ik->bounds_check((address) ik->start_of_vtable(), false, size);
525 ik->bounds_check((address) ik->start_of_itable(), false, size);
526 ik->bounds_check((address) ik->end_of_itable(), true, size);
527 ik->bounds_check((address) ik->end_of_nonstatic_oop_maps(), true, size);
528 #endif //ASSERT
529 return ik;
530 }
531
532 #ifndef PRODUCT
533 bool InstanceKlass::bounds_check(address addr, bool edge_ok, intptr_t size_in_bytes) const {
534 const char* bad = nullptr;
535 address end = nullptr;
536 if (addr < (address)this) {
537 bad = "before";
538 } else if (addr == (address)this) {
539 if (edge_ok) return true;
540 bad = "just before";
541 } else if (addr == (end = (address)this + sizeof(intptr_t) * (size_in_bytes < 0 ? size() : size_in_bytes))) {
542 if (edge_ok) return true;
543 bad = "just after";
544 } else if (addr > end) {
545 bad = "after";
546 } else {
547 return true;
548 }
549 tty->print_cr("%s object bounds: " INTPTR_FORMAT " [" INTPTR_FORMAT ".." INTPTR_FORMAT "]",
550 bad, (intptr_t)addr, (intptr_t)this, (intptr_t)end);
551 Verbose = WizardMode = true; this->print(); //@@
552 return false;
553 }
554 #endif //PRODUCT
555
556 // copy method ordering from resource area to Metaspace
557 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
558 if (m != nullptr) {
559 // allocate a new array and copy contents (memcpy?)
560 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
561 for (int i = 0; i < m->length(); i++) {
562 _method_ordering->at_put(i, m->at(i));
563 }
564 } else {
565 _method_ordering = Universe::the_empty_int_array();
566 }
567 }
568
569 // create a new array of vtable_indices for default methods
570 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
571 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
572 assert(default_vtable_indices() == nullptr, "only create once");
573 set_default_vtable_indices(vtable_indices);
574 return vtable_indices;
575 }
576
577
578 InstanceKlass::InstanceKlass() {
579 assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
580 }
581
582 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, markWord prototype_header, ReferenceType reference_type) :
583 Klass(kind, prototype_header),
584 _nest_members(nullptr),
585 _nest_host(nullptr),
586 _permitted_subclasses(nullptr),
587 _record_components(nullptr),
588 _static_field_size(parser.static_field_size()),
589 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
590 _itable_len(parser.itable_size()),
591 _nest_host_index(0),
592 _init_state(allocated),
593 _reference_type(reference_type),
594 _acmp_maps_offset(0),
595 _init_thread(nullptr),
596 _inline_layout_info_array(nullptr),
597 _loadable_descriptors(nullptr),
598 _adr_inline_klass_members(nullptr)
599 {
600 set_vtable_length(parser.vtable_size());
601 set_access_flags(parser.access_flags());
602 if (parser.is_hidden()) set_is_hidden();
603 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
604 false));
605 if (parser.has_inline_fields()) {
606 set_has_inline_type_fields();
607 }
608
609 assert(nullptr == _methods, "underlying memory not zeroed?");
610 assert(is_instance_klass(), "is layout incorrect?");
611 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
612 }
613
614 void InstanceKlass::set_is_cloneable() {
615 if (name() == vmSymbols::java_lang_invoke_MemberName()) {
616 assert(is_final(), "no subclasses allowed");
617 // MemberName cloning should not be intrinsified and always happen in JVM_Clone.
618 } else if (reference_type() != REF_NONE) {
619 // Reference cloning should not be intrinsified and always happen in JVM_Clone.
620 } else {
621 set_is_cloneable_fast();
622 }
623 }
624
625 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
626 Array<Method*>* methods) {
627 if (methods != nullptr && methods != Universe::the_empty_method_array() &&
743
744 deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
745 set_transitive_interfaces(nullptr);
746 set_local_interfaces(nullptr);
747
748 if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->in_aot_cache()) {
749 MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
750 }
751 set_fieldinfo_stream(nullptr);
752
753 if (fieldinfo_search_table() != nullptr && !fieldinfo_search_table()->in_aot_cache()) {
754 MetadataFactory::free_array<u1>(loader_data, fieldinfo_search_table());
755 }
756 set_fieldinfo_search_table(nullptr);
757
758 if (fields_status() != nullptr && !fields_status()->in_aot_cache()) {
759 MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
760 }
761 set_fields_status(nullptr);
762
763 if (inline_layout_info_array() != nullptr) {
764 MetadataFactory::free_array<InlineLayoutInfo>(loader_data, inline_layout_info_array());
765 }
766 set_inline_layout_info_array(nullptr);
767
768 // If a method from a redefined class is using this constant pool, don't
769 // delete it, yet. The new class's previous version will point to this.
770 if (constants() != nullptr) {
771 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
772 if (!constants()->in_aot_cache()) {
773 MetadataFactory::free_metadata(loader_data, constants());
774 }
775 // Delete any cached resolution errors for the constant pool
776 SystemDictionary::delete_resolution_error(constants());
777
778 set_constants(nullptr);
779 }
780
781 if (inner_classes() != nullptr &&
782 inner_classes() != Universe::the_empty_short_array() &&
783 !inner_classes()->in_aot_cache()) {
784 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
785 }
786 set_inner_classes(nullptr);
787
788 if (nest_members() != nullptr &&
789 nest_members() != Universe::the_empty_short_array() &&
790 !nest_members()->in_aot_cache()) {
791 MetadataFactory::free_array<jushort>(loader_data, nest_members());
792 }
793 set_nest_members(nullptr);
794
795 if (permitted_subclasses() != nullptr &&
796 permitted_subclasses() != Universe::the_empty_short_array() &&
797 !permitted_subclasses()->in_aot_cache()) {
798 MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
799 }
800 set_permitted_subclasses(nullptr);
801
802 if (loadable_descriptors() != nullptr &&
803 loadable_descriptors() != Universe::the_empty_short_array() &&
804 !loadable_descriptors()->in_aot_cache()) {
805 MetadataFactory::free_array<jushort>(loader_data, loadable_descriptors());
806 }
807 set_loadable_descriptors(nullptr);
808
809 // We should deallocate the Annotations instance if it's not in shared spaces.
810 if (annotations() != nullptr && !annotations()->in_aot_cache()) {
811 MetadataFactory::free_metadata(loader_data, annotations());
812 }
813 set_annotations(nullptr);
814
815 SystemDictionaryShared::handle_class_unloading(this);
816
817 #if INCLUDE_CDS_JAVA_HEAP
818 if (CDSConfig::is_dumping_heap()) {
819 HeapShared::remove_scratch_objects(this);
820 }
821 #endif
822 }
823
824 bool InstanceKlass::is_record() const {
825 return _record_components != nullptr &&
826 is_final() &&
827 super() == vmClasses::Record_klass();
828 }
831 return _permitted_subclasses != nullptr &&
832 _permitted_subclasses != Universe::the_empty_short_array();
833 }
834
835 // JLS 8.9: An enum class is either implicitly final and derives
836 // from java.lang.Enum, or else is implicitly sealed to its
837 // anonymous subclasses. This query detects both kinds.
838 // It does not validate the finality or
839 // sealing conditions: it merely checks for a super of Enum.
840 // This is sufficient for recognizing well-formed enums.
841 bool InstanceKlass::is_enum_subclass() const {
842 InstanceKlass* s = super();
843 return (s == vmClasses::Enum_klass() ||
844 (s != nullptr && s->super() == vmClasses::Enum_klass()));
845 }
846
847 bool InstanceKlass::should_be_initialized() const {
848 return !is_initialized();
849 }
850
851 // Static size helper
852 int InstanceKlass::size(int vtable_length,
853 int itable_length,
854 int nonstatic_oop_map_size,
855 bool is_interface,
856 bool is_inline_type) {
857 return align_metadata_size(header_size() +
858 vtable_length +
859 itable_length +
860 nonstatic_oop_map_size +
861 (is_interface ? (int)sizeof(Klass*) / wordSize : 0) +
862 (is_inline_type ? (int)sizeof(InlineKlass::Members) / wordSize : 0));
863 }
864
865 int InstanceKlass::size() const {
866 return size(vtable_length(),
867 itable_length(),
868 nonstatic_oop_map_size(),
869 is_interface(),
870 is_inline_klass());
871 }
872
873 klassItable InstanceKlass::itable() const {
874 return klassItable(const_cast<InstanceKlass*>(this));
875 }
876
877 // JVMTI spec thinks there are signers and protection domain in the
878 // instanceKlass. These accessors pretend these fields are there.
879 // The hprof specification also thinks these fields are in InstanceKlass.
880 oop InstanceKlass::protection_domain() const {
881 // return the protection_domain from the mirror
882 return java_lang_Class::protection_domain(java_mirror());
883 }
884
885 objArrayOop InstanceKlass::signers() const {
886 // return the signers from the mirror
887 return java_lang_Class::signers(java_mirror());
888 }
889
890 oop InstanceKlass::init_lock() const {
891 // return the init lock from the mirror
892 oop lock = java_lang_Class::init_lock(java_mirror());
1005 #ifdef ASSERT
1006 {
1007 Handle h_init_lock(THREAD, init_lock());
1008 ObjectLocker ol(h_init_lock, THREAD);
1009 assert(!is_initialized(), "sanity");
1010 assert(!is_being_initialized(), "sanity");
1011 assert(!is_in_error_state(), "sanity");
1012 }
1013 #endif
1014
1015 set_init_thread(THREAD);
1016 set_initialization_state_and_notify(fully_initialized, CHECK);
1017 }
1018 #endif
1019
1020 bool InstanceKlass::verify_code(TRAPS) {
1021 // 1) Verify the bytecodes
1022 return Verifier::verify(this, should_verify_class(), THREAD);
1023 }
1024
1025 static void load_classes_from_loadable_descriptors_attribute(InstanceKlass *ik, TRAPS) {
1026 ResourceMark rm(THREAD);
1027 if (ik->loadable_descriptors() != nullptr && PreloadClasses) {
1028 HandleMark hm(THREAD);
1029 for (int i = 0; i < ik->loadable_descriptors()->length(); i++) {
1030 Symbol* sig = ik->constants()->symbol_at(ik->loadable_descriptors()->at(i));
1031 if (!Signature::has_envelope(sig)) continue;
1032 TempNewSymbol class_name = Signature::strip_envelope(sig);
1033 if (class_name == ik->name()) continue;
1034 log_info(class, preload)("Preloading of class %s during linking of class %s "
1035 "because of the class is listed in the LoadableDescriptors attribute",
1036 sig->as_C_string(), ik->name()->as_C_string());
1037 oop loader = ik->class_loader();
1038 Klass* klass = SystemDictionary::resolve_or_null(class_name,
1039 Handle(THREAD, loader), THREAD);
1040 if (HAS_PENDING_EXCEPTION) {
1041 CLEAR_PENDING_EXCEPTION;
1042 }
1043 if (klass != nullptr) {
1044 log_info(class, preload)("Preloading of class %s during linking of class %s "
1045 "(cause: LoadableDescriptors attribute) succeeded",
1046 class_name->as_C_string(), ik->name()->as_C_string());
1047 if (!klass->is_inline_klass()) {
1048 // Non value class are allowed by the current spec, but it could be an indication
1049 // of an issue so let's log a warning
1050 log_info(class, preload)("Preloading of class %s during linking of class %s "
1051 "(cause: LoadableDescriptors attribute) but loaded class is not a value class",
1052 class_name->as_C_string(), ik->name()->as_C_string());
1053 }
1054 } else {
1055 log_info(class, preload)("Preloading of class %s during linking of class %s "
1056 "(cause: LoadableDescriptors attribute) failed",
1057 class_name->as_C_string(), ik->name()->as_C_string());
1058 }
1059 }
1060 }
1061 }
1062
1063 void InstanceKlass::link_class(TRAPS) {
1064 assert(is_loaded(), "must be loaded");
1065 if (!is_linked()) {
1066 link_class_impl(CHECK);
1067 }
1068 }
1069
1070 // Called to verify that a class can link during initialization, without
1071 // throwing a VerifyError.
1072 bool InstanceKlass::link_class_or_fail(TRAPS) {
1073 assert(is_loaded(), "must be loaded");
1074 if (!is_linked()) {
1075 link_class_impl(CHECK_false);
1076 }
1077 return is_linked();
1078 }
1079
1080 bool InstanceKlass::link_class_impl(TRAPS) {
1081 if (CDSConfig::is_dumping_static_archive() && SystemDictionaryShared::has_class_failed_verification(this)) {
1082 // This is for CDS static dump only -- we use the in_error_state to indicate that
1113 THREAD_AND_LOCATION,
1114 vmSymbols::java_lang_IncompatibleClassChangeError(),
1115 "class %s has interface %s as super class",
1116 external_name(),
1117 super_klass->external_name()
1118 );
1119 return false;
1120 }
1121
1122 super_klass->link_class_impl(CHECK_false);
1123 }
1124
1125 // link all interfaces implemented by this class before linking this class
1126 Array<InstanceKlass*>* interfaces = local_interfaces();
1127 int num_interfaces = interfaces->length();
1128 for (int index = 0; index < num_interfaces; index++) {
1129 InstanceKlass* interk = interfaces->at(index);
1130 interk->link_class_impl(CHECK_false);
1131 }
1132
1133 if (Arguments::is_valhalla_enabled()) {
1134 // Aggressively preloading all classes from the LoadableDescriptors attribute
1135 // so inline classes can be scalarized in the calling conventions computed below
1136 load_classes_from_loadable_descriptors_attribute(this, THREAD);
1137 assert(!HAS_PENDING_EXCEPTION, "Shouldn't have pending exceptions from call above");
1138 }
1139
1140 // in case the class is linked in the process of linking its superclasses
1141 if (is_linked()) {
1142 return true;
1143 }
1144
1145 // trace only the link time for this klass that includes
1146 // the verification time
1147 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
1148 ClassLoader::perf_class_link_selftime(),
1149 ClassLoader::perf_classes_linked(),
1150 jt->get_thread_stat()->perf_recursion_counts_addr(),
1151 jt->get_thread_stat()->perf_timers_addr(),
1152 PerfClassTraceTime::CLASS_LINK);
1153
1154 // verification & rewriting
1155 {
1156 HandleMark hm(THREAD);
1157 Handle h_init_lock(THREAD, init_lock());
1158 ObjectLocker ol(h_init_lock, CHECK_PREEMPTABLE_false);
1159 // Don't allow preemption if we link/initialize classes below,
1443 THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1444 ss.as_string(), cause);
1445 }
1446 } else {
1447
1448 // Step 6
1449 set_init_state(being_initialized);
1450 set_init_thread(jt);
1451 if (debug_logging_enabled) {
1452 ResourceMark rm(jt);
1453 log_debug(class, init)("Thread \"%s\" is initializing %s",
1454 jt->name(), external_name());
1455 }
1456 }
1457 }
1458
1459 // Block preemption once we are the initializer thread. Unmounting now
1460 // would complicate the reentrant case (identity is platform thread).
1461 NoPreemptMark npm(THREAD);
1462
1463 // Pre-allocating an all-zero value to be used to reset nullable flat storages
1464 if (is_inline_klass()) {
1465 InlineKlass* vk = InlineKlass::cast(this);
1466 if (vk->has_nullable_atomic_layout()) {
1467 oop val = vk->allocate_instance(THREAD);
1468 if (HAS_PENDING_EXCEPTION) {
1469 Handle e(THREAD, PENDING_EXCEPTION);
1470 CLEAR_PENDING_EXCEPTION;
1471 {
1472 EXCEPTION_MARK;
1473 add_initialization_error(THREAD, e);
1474 // Locks object, set state, and notify all waiting threads
1475 set_initialization_state_and_notify(initialization_error, THREAD);
1476 CLEAR_PENDING_EXCEPTION;
1477 }
1478 THROW_OOP(e());
1479 }
1480 vk->set_null_reset_value(val);
1481 }
1482 }
1483
1484 // Step 7
1485 // Next, if C is a class rather than an interface, initialize it's super class and super
1486 // interfaces.
1487 if (!is_interface()) {
1488 Klass* super_klass = super();
1489 if (super_klass != nullptr && super_klass->should_be_initialized()) {
1490 super_klass->initialize(THREAD);
1491 }
1492 // If C implements any interface that declares a non-static, concrete method,
1493 // the initialization of C triggers initialization of its super interfaces.
1494 // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1495 // having a superinterface that declares, non-static, concrete methods
1496 if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1497 initialize_super_interfaces(THREAD);
1498 }
1499
1500 // If any exceptions, complete abruptly, throwing the same exception as above.
1501 if (HAS_PENDING_EXCEPTION) {
1502 Handle e(THREAD, PENDING_EXCEPTION);
1503 CLEAR_PENDING_EXCEPTION;
1504 {
1505 EXCEPTION_MARK;
1506 add_initialization_error(THREAD, e);
1507 // Locks object, set state, and notify all waiting threads
1508 set_initialization_state_and_notify(initialization_error, THREAD);
1509 CLEAR_PENDING_EXCEPTION;
1510 }
1511 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1512 THROW_OOP(e());
1513 }
1514 }
1515
1516 // Step 8
1517 {
1518 DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1519 if (class_initializer() != nullptr) {
1520 // Timer includes any side effects of class initialization (resolution,
1521 // etc), but not recursive entry into call_class_initializer().
1522 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1523 ClassLoader::perf_class_init_selftime(),
1524 ClassLoader::perf_classes_inited(),
1525 jt->get_thread_stat()->perf_recursion_counts_addr(),
1526 jt->get_thread_stat()->perf_timers_addr(),
1527 PerfClassTraceTime::CLASS_CLINIT);
1528 call_class_initializer(THREAD);
1529 } else {
1530 // The elapsed time is so small it's not worth counting.
1531 if (UsePerfData) {
1532 ClassLoader::perf_classes_inited()->inc();
1533 }
1534 call_class_initializer(THREAD);
1535 }
1536
1537 if (has_strict_static_fields() && !HAS_PENDING_EXCEPTION) {
1538 // Step 9 also verifies that strict static fields have been initialized.
1539 // Status bits were set in ClassFileParser::post_process_parsed_stream.
1540 // After <clinit>, bits must all be clear, or else we must throw an error.
1541 // This is an extremely fast check, so we won't bother with a timer.
1542 assert(fields_status() != nullptr, "");
1543 Symbol* bad_strict_static = nullptr;
1544 for (int index = 0; index < fields_status()->length(); index++) {
1545 // Very fast loop over single byte array looking for a set bit.
1546 if (fields_status()->adr_at(index)->is_strict_static_unset()) {
1547 // This strict static field has not been set by the class initializer.
1548 // Note that in the common no-error case, we read no field metadata.
1549 // We only unpack it when we need to report an error.
1550 FieldInfo fi = field(index);
1551 bad_strict_static = fi.name(constants());
1552 if (debug_logging_enabled) {
1553 ResourceMark rm(jt);
1554 const char* msg = format_strict_static_message(bad_strict_static);
1555 log_debug(class, init)("%s", msg);
1556 } else {
1557 // If we are not logging, do not bother to look for a second offense.
1558 break;
1559 }
1560 }
1561 }
1562 if (bad_strict_static != nullptr) {
1563 throw_strict_static_exception(bad_strict_static, "is unset after initialization of", THREAD);
1564 }
1565 }
1566 }
1567
1568 // Step 9
1569 if (!HAS_PENDING_EXCEPTION) {
1570 set_initialization_state_and_notify(fully_initialized, CHECK);
1571 DEBUG_ONLY(vtable().verify(tty, true);)
1572 CompilationPolicy::replay_training_at_init(this, THREAD);
1573 }
1574 else {
1575 // Step 10 and 11
1576 Handle e(THREAD, PENDING_EXCEPTION);
1577 CLEAR_PENDING_EXCEPTION;
1578 // JVMTI has already reported the pending exception
1579 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1580 JvmtiExport::clear_detected_exception(jt);
1581 {
1582 EXCEPTION_MARK;
1583 add_initialization_error(THREAD, e);
1584 set_initialization_state_and_notify(initialization_error, THREAD);
1585 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
1599 }
1600 DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait);
1601 }
1602
1603
1604 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
1605 Handle h_init_lock(THREAD, init_lock());
1606 if (h_init_lock() != nullptr) {
1607 ObjectLocker ol(h_init_lock, THREAD);
1608 set_init_thread(nullptr); // reset _init_thread before changing _init_state
1609 set_init_state(state);
1610 fence_and_clear_init_lock();
1611 ol.notify_all(CHECK);
1612 } else {
1613 assert(h_init_lock() != nullptr, "The initialization state should never be set twice");
1614 set_init_thread(nullptr); // reset _init_thread before changing _init_state
1615 set_init_state(state);
1616 }
1617 }
1618
1619 void InstanceKlass::notify_strict_static_access(int field_index, bool is_writing, TRAPS) {
1620 guarantee(field_index >= 0 && field_index < fields_status()->length(), "valid field index");
1621 DEBUG_ONLY(FieldInfo debugfi = field(field_index));
1622 assert(debugfi.access_flags().is_strict(), "");
1623 assert(debugfi.access_flags().is_static(), "");
1624 FieldStatus& fs = *fields_status()->adr_at(field_index);
1625 LogTarget(Trace, class, init) lt;
1626 if (lt.is_enabled()) {
1627 ResourceMark rm(THREAD);
1628 LogStream ls(lt);
1629 FieldInfo fi = field(field_index);
1630 ls.print("notify %s %s %s%s ",
1631 external_name(), is_writing? "Write" : "Read",
1632 fs.is_strict_static_unset() ? "Unset" : "(set)",
1633 fs.is_strict_static_unread() ? "+Unread" : "");
1634 fi.print(&ls, constants());
1635 }
1636 if (fs.is_strict_static_unset()) {
1637 assert(fs.is_strict_static_unread(), "ClassFileParser resp.");
1638 // If it is not set, there are only two reasonable things we can do here:
1639 // - mark it set if this is putstatic
1640 // - throw an error (Read-Before-Write) if this is getstatic
1641
1642 // The unset state is (or should be) transient, and observable only in one
1643 // thread during the execution of <clinit>. Something is wrong here as this
1644 // should not be possible
1645 guarantee(is_reentrant_initialization(THREAD), "unscoped access to strict static");
1646 if (is_writing) {
1647 // clear the "unset" bit, since the field is actually going to be written
1648 fs.update_strict_static_unset(false);
1649 } else {
1650 // throw an IllegalStateException, since we are reading before writing
1651 // see also InstanceKlass::initialize_impl, Step 8 (at end)
1652 Symbol* bad_strict_static = field(field_index).name(constants());
1653 throw_strict_static_exception(bad_strict_static, "is unset before first read in", CHECK);
1654 }
1655 } else {
1656 // Ensure no write after read for final strict statics
1657 FieldInfo fi = field(field_index);
1658 bool is_final = fi.access_flags().is_final();
1659 if (is_final) {
1660 // no final write after read, so observing a constant freezes it, as if <clinit> ended early
1661 // (maybe we could trust the constant a little earlier, before <clinit> ends)
1662 if (is_writing && !fs.is_strict_static_unread()) {
1663 Symbol* bad_strict_static = fi.name(constants());
1664 throw_strict_static_exception(bad_strict_static, "is set after read (as final) in", CHECK);
1665 } else if (!is_writing && fs.is_strict_static_unread()) {
1666 fs.update_strict_static_unread(false);
1667 }
1668 }
1669 }
1670 }
1671
1672 void InstanceKlass::throw_strict_static_exception(Symbol* field_name, const char* when, TRAPS) {
1673 ResourceMark rm(THREAD);
1674 const char* msg = format_strict_static_message(field_name, when);
1675 THROW_MSG(vmSymbols::java_lang_IllegalStateException(), msg);
1676 }
1677
1678 const char* InstanceKlass::format_strict_static_message(Symbol* field_name, const char* when) {
1679 stringStream ss;
1680 ss.print("Strict static \"%s\" %s %s",
1681 field_name->as_C_string(),
1682 when == nullptr ? "is unset in" : when,
1683 external_name());
1684 return ss.as_string();
1685 }
1686
1687 // Update hierarchy. This is done before the new klass has been added to the SystemDictionary. The Compile_lock
1688 // is grabbed, to ensure that the compiler is not using the class hierarchy.
1689 void InstanceKlass::add_to_hierarchy(JavaThread* current) {
1690 assert(!SafepointSynchronize::is_at_safepoint(), "must NOT be at safepoint");
1691
1692 DeoptimizationScope deopt_scope;
1693 {
1694 MutexLocker ml(current, Compile_lock);
1695
1696 set_init_state(InstanceKlass::loaded);
1697 // make sure init_state store is already done.
1698 // The compiler reads the hierarchy outside of the Compile_lock.
1699 // Access ordering is used to add to hierarchy.
1700
1701 // Link into hierarchy.
1702 append_to_sibling_list(); // add to superklass/sibling list
1703 process_interfaces(); // handle all "implements" declarations
1704
1705 // Now mark all code that depended on old class hierarchy.
1706 // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)
1917 : vmSymbols::java_lang_IllegalAccessException(), external_name());
1918 }
1919 }
1920
1921 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1922 // Need load-acquire for lock-free read
1923 if (array_klasses_acquire() == nullptr) {
1924
1925 // Recursively lock array allocation
1926 RecursiveLocker rl(MultiArray_lock, THREAD);
1927
1928 // Check if another thread created the array klass while we were waiting for the lock.
1929 if (array_klasses() == nullptr) {
1930 ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);
1931 // use 'release' to pair with lock-free load
1932 release_set_array_klasses(k);
1933 }
1934 }
1935
1936 // array_klasses() will always be set at this point
1937 ArrayKlass* ak = array_klasses();
1938 assert(ak != nullptr, "should be set");
1939 return ak->array_klass(n, THREAD);
1940 }
1941
1942 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1943 // Need load-acquire for lock-free read
1944 ArrayKlass* ak = array_klasses_acquire();
1945 if (ak == nullptr) {
1946 return nullptr;
1947 } else {
1948 return ak->array_klass_or_null(n);
1949 }
1950 }
1951
1952 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1953 return array_klass(1, THREAD);
1954 }
1955
1956 ArrayKlass* InstanceKlass::array_klass_or_null() {
1957 return array_klass_or_null(1);
1958 }
1959
1960 static int call_class_initializer_counter = 0; // for debugging
1961
1962 Method* InstanceKlass::class_initializer() const {
1963 Method* clinit = find_method(
1964 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1965 if (clinit != nullptr && clinit->is_class_initializer()) {
1966 return clinit;
1967 }
1968 return nullptr;
1969 }
1970
1971 void InstanceKlass::call_class_initializer(TRAPS) {
1972 if (ReplayCompiles &&
1973 (ReplaySuppressInitializers == 1 ||
1974 (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1975 // Hide the existence of the initializer for the purpose of replaying the compile
1976 return;
1977 }
1978
1979 #if INCLUDE_CDS
1980 // This is needed to ensure the consistency of the archived heap objects.
1981 if (has_aot_initialized_mirror() && CDSConfig::is_loading_heap()) {
1982 AOTClassInitializer::call_runtime_setup(THREAD, this);
1983 return;
1984 } else if (has_archived_enum_objs()) {
1985 assert(in_aot_cache(), "must be");
2054
2055 void InstanceKlass::mask_for(const methodHandle& method, int bci,
2056 InterpreterOopMap* entry_for) {
2057 // Lazily create the _oop_map_cache at first request.
2058 // Load_acquire is needed to safely get instance published with CAS by another thread.
2059 OopMapCache* oop_map_cache = AtomicAccess::load_acquire(&_oop_map_cache);
2060 if (oop_map_cache == nullptr) {
2061 // Try to install new instance atomically.
2062 oop_map_cache = new OopMapCache();
2063 OopMapCache* other = AtomicAccess::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
2064 if (other != nullptr) {
2065 // Someone else managed to install before us, ditch local copy and use the existing one.
2066 delete oop_map_cache;
2067 oop_map_cache = other;
2068 }
2069 }
2070 // _oop_map_cache is constant after init; lookup below does its own locking.
2071 oop_map_cache->lookup(method, bci, entry_for);
2072 }
2073
2074
2075 FieldInfo InstanceKlass::field(int index) const {
2076 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
2077 if (fs.index() == index) {
2078 return fs.to_FieldInfo();
2079 }
2080 }
2081 fatal("Field not found");
2082 return FieldInfo();
2083 }
2084
2085 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
2086 JavaFieldStream fs(this);
2087 if (fs.lookup(name, sig)) {
2088 assert(fs.name() == name, "name must match");
2089 assert(fs.signature() == sig, "signature must match");
2090 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.to_FieldInfo());
2091 return true;
2092 }
2093 return false;
2134
2135 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
2136 // search order according to newest JVM spec (5.4.3.2, p.167).
2137 // 1) search for field in current klass
2138 if (find_local_field(name, sig, fd)) {
2139 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
2140 }
2141 // 2) search for field recursively in direct superinterfaces
2142 if (is_static) {
2143 Klass* intf = find_interface_field(name, sig, fd);
2144 if (intf != nullptr) return intf;
2145 }
2146 // 3) apply field lookup recursively if superclass exists
2147 { InstanceKlass* supr = super();
2148 if (supr != nullptr) return supr->find_field(name, sig, is_static, fd);
2149 }
2150 // 4) otherwise field lookup fails
2151 return nullptr;
2152 }
2153
2154 bool InstanceKlass::contains_field_offset(int offset) {
2155 if (this->is_inline_klass()) {
2156 InlineKlass* vk = InlineKlass::cast(this);
2157 return offset >= vk->payload_offset() && offset < (vk->payload_offset() + vk->payload_size_in_bytes());
2158 } else {
2159 fieldDescriptor fd;
2160 return find_field_from_offset(offset, false, &fd);
2161 }
2162 }
2163
2164 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
2165 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
2166 if (fs.offset() == offset) {
2167 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.to_FieldInfo());
2168 if (fd->is_static() == is_static) return true;
2169 }
2170 }
2171 return false;
2172 }
2173
2174
2175 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
2176 const InstanceKlass* klass = this;
2177 while (klass != nullptr) {
2178 if (klass->find_local_field_from_offset(offset, is_static, fd)) {
2179 return true;
2180 }
2181 klass = klass->super();
2182 }
2526 }
2527
2528 // uncached_lookup_method searches both the local class methods array and all
2529 // superclasses methods arrays, skipping any overpass methods in superclasses,
2530 // and possibly skipping private methods.
2531 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2532 const Symbol* signature,
2533 OverpassLookupMode overpass_mode,
2534 PrivateLookupMode private_mode) const {
2535 OverpassLookupMode overpass_local_mode = overpass_mode;
2536 const InstanceKlass* klass = this;
2537 while (klass != nullptr) {
2538 Method* const method = klass->find_method_impl(name,
2539 signature,
2540 overpass_local_mode,
2541 StaticLookupMode::find,
2542 private_mode);
2543 if (method != nullptr) {
2544 return method;
2545 }
2546 if (name == vmSymbols::object_initializer_name()) {
2547 break; // <init> is never inherited
2548 }
2549 klass = klass->super();
2550 overpass_local_mode = OverpassLookupMode::skip; // Always ignore overpass methods in superclasses
2551 }
2552 return nullptr;
2553 }
2554
2555 #ifdef ASSERT
2556 // search through class hierarchy and return true if this class or
2557 // one of the superclasses was redefined
2558 bool InstanceKlass::has_redefined_this_or_super() const {
2559 const InstanceKlass* klass = this;
2560 while (klass != nullptr) {
2561 if (klass->has_been_redefined()) {
2562 return true;
2563 }
2564 klass = klass->super();
2565 }
2566 return false;
2567 }
2568 #endif
2941 int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2942
2943 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2944 / itableOffsetEntry::size();
2945
2946 for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2947 if (ioe->interface_klass() != nullptr) {
2948 it->push(ioe->interface_klass_addr());
2949 itableMethodEntry* ime = ioe->first_method_entry(this);
2950 int n = klassItable::method_count_for_interface(ioe->interface_klass());
2951 for (int index = 0; index < n; index ++) {
2952 it->push(ime[index].method_addr());
2953 }
2954 }
2955 }
2956 }
2957
2958 it->push(&_nest_host);
2959 it->push(&_nest_members);
2960 it->push(&_permitted_subclasses);
2961 it->push(&_loadable_descriptors);
2962 it->push(&_record_components);
2963 it->push(&_inline_layout_info_array, MetaspaceClosure::_writable);
2964 }
2965
2966 #if INCLUDE_CDS
2967 void InstanceKlass::remove_unshareable_info() {
2968
2969 if (is_linked()) {
2970 assert(can_be_verified_at_dumptime(), "must be");
2971 // Remember this so we can avoid walking the hierarchy at runtime.
2972 set_verified_at_dump_time();
2973 }
2974
2975 _misc_flags.set_has_init_deps_processed(false);
2976
2977 Klass::remove_unshareable_info();
2978
2979 if (SystemDictionaryShared::has_class_failed_verification(this)) {
2980 // Classes are attempted to link during dumping and may fail,
2981 // but these classes are still in the dictionary and class list in CLD.
2982 // If the class has failed verification, there is nothing else to remove.
2983 return;
2991
2992 { // Otherwise this needs to take out the Compile_lock.
2993 assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2994 init_implementor();
2995 }
2996
2997 // Call remove_unshareable_info() on other objects that belong to this class, except
2998 // for constants()->remove_unshareable_info(), which is called in a separate pass in
2999 // ArchiveBuilder::make_klasses_shareable(),
3000
3001 for (int i = 0; i < methods()->length(); i++) {
3002 Method* m = methods()->at(i);
3003 m->remove_unshareable_info();
3004 }
3005
3006 // do array classes also.
3007 if (array_klasses() != nullptr) {
3008 array_klasses()->remove_unshareable_info();
3009 }
3010
3011 // These are not allocated from metaspace. They are safe to set to nullptr.
3012 _source_debug_extension = nullptr;
3013 _dep_context = nullptr;
3014 _osr_nmethods_head = nullptr;
3015 #if INCLUDE_JVMTI
3016 _breakpoints = nullptr;
3017 _previous_versions = nullptr;
3018 _cached_class_file = nullptr;
3019 _jvmti_cached_class_field_map = nullptr;
3020 #endif
3021
3022 _init_thread = nullptr;
3023 _methods_jmethod_ids = nullptr;
3024 _jni_ids = nullptr;
3025 _oop_map_cache = nullptr;
3026 if (CDSConfig::is_dumping_method_handles() && HeapShared::is_lambda_proxy_klass(this)) {
3027 // keep _nest_host
3028 } else {
3029 // clear _nest_host to ensure re-load at runtime
3030 _nest_host = nullptr;
3031 }
3082 void InstanceKlass::compute_has_loops_flag_for_methods() {
3083 Array<Method*>* methods = this->methods();
3084 for (int index = 0; index < methods->length(); ++index) {
3085 Method* m = methods->at(index);
3086 if (!m->is_overpass()) { // work around JDK-8305771
3087 m->compute_has_loops_flag();
3088 }
3089 }
3090 }
3091
3092 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
3093 PackageEntry* pkg_entry, TRAPS) {
3094 // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
3095 // before the InstanceKlass is added to the SystemDictionary. Make
3096 // sure the current state is <loaded.
3097 assert(!is_loaded(), "invalid init state");
3098 assert(!shared_loading_failed(), "Must not try to load failed class again");
3099 set_package(loader_data, pkg_entry, CHECK);
3100 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
3101
3102 if (is_inline_klass()) {
3103 InlineKlass::cast(this)->initialize_calling_convention(CHECK);
3104 }
3105
3106 Array<Method*>* methods = this->methods();
3107 int num_methods = methods->length();
3108 for (int index = 0; index < num_methods; ++index) {
3109 methods->at(index)->restore_unshareable_info(CHECK);
3110 }
3111 #if INCLUDE_JVMTI
3112 if (JvmtiExport::has_redefined_a_class()) {
3113 // Reinitialize vtable because RedefineClasses may have changed some
3114 // entries in this vtable for super classes so the CDS vtable might
3115 // point to old or obsolete entries. RedefineClasses doesn't fix up
3116 // vtables in the shared system dictionary, only the main one.
3117 // It also redefines the itable too so fix that too.
3118 // First fix any default methods that point to a super class that may
3119 // have been redefined.
3120 bool trace_name_printed = false;
3121 adjust_default_methods(&trace_name_printed);
3122 if (verified_at_dump_time()) {
3123 // Initialize vtable and itable for classes which can be verified at dump time.
3124 // Unlinked classes such as old classes with major version < 50 cannot be verified
3125 // at dump time.
3126 vtable().initialize_vtable();
3127 itable().initialize_itable();
3128 }
3129 }
3130 #endif // INCLUDE_JVMTI
3131
3132 // restore constant pool resolved references
3133 constants()->restore_unshareable_info(CHECK);
3134
3135 if (array_klasses() != nullptr) {
3136 // To get a consistent list of classes we need MultiArray_lock to ensure
3137 // array classes aren't observed while they are being restored.
3138 RecursiveLocker rl(MultiArray_lock, THREAD);
3139 assert(this == ObjArrayKlass::cast(array_klasses())->bottom_klass(), "sanity");
3140 // Array classes have null protection domain.
3141 // --> see ArrayKlass::complete_create_array_klass()
3142 if (class_loader_data() == nullptr) {
3143 ResourceMark rm(THREAD);
3144 log_debug(cds)(" loader_data %s ", loader_data == nullptr ? "nullptr" : "non null");
3145 log_debug(cds)(" this %s array_klasses %s ", this->name()->as_C_string(), array_klasses()->name()->as_C_string());
3146 }
3147 assert(!array_klasses()->is_refined_objArray_klass(), "must be non-refined objarrayklass");
3148 array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
3149 }
3150
3151 // Initialize @ValueBased class annotation if not already set in the archived klass.
3152 if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
3153 set_is_value_based();
3154 }
3155
3156 DEBUG_ONLY(FieldInfoStream::validate_search_table(_constants, _fieldinfo_stream, _fieldinfo_search_table));
3157 }
3158
3159 bool InstanceKlass::can_be_verified_at_dumptime() const {
3160 if (CDSConfig::is_dumping_dynamic_archive() && AOTMetaspace::in_aot_cache(this)) {
3161 // This is a class that was dumped into the base archive, so we know
3162 // it was verified at dump time.
3163 return true;
3164 }
3165
3166 if (CDSConfig::is_preserving_verification_constraints()) {
3167 return true;
3283 constants()->release_C_heap_structures();
3284 }
3285 }
3286
3287 // The constant pool is on stack if any of the methods are executing or
3288 // referenced by handles.
3289 bool InstanceKlass::on_stack() const {
3290 return _constants->on_stack();
3291 }
3292
3293 Symbol* InstanceKlass::source_file_name() const { return _constants->source_file_name(); }
3294 u2 InstanceKlass::source_file_name_index() const { return _constants->source_file_name_index(); }
3295 void InstanceKlass::set_source_file_name_index(u2 sourcefile_index) { _constants->set_source_file_name_index(sourcefile_index); }
3296
3297 // minor and major version numbers of class file
3298 u2 InstanceKlass::minor_version() const { return _constants->minor_version(); }
3299 void InstanceKlass::set_minor_version(u2 minor_version) { _constants->set_minor_version(minor_version); }
3300 u2 InstanceKlass::major_version() const { return _constants->major_version(); }
3301 void InstanceKlass::set_major_version(u2 major_version) { _constants->set_major_version(major_version); }
3302
3303 bool InstanceKlass::supports_inline_types() const {
3304 return major_version() >= Verifier::VALUE_TYPES_MAJOR_VERSION && minor_version() == Verifier::JAVA_PREVIEW_MINOR_VERSION;
3305 }
3306
3307 const InstanceKlass* InstanceKlass::get_klass_version(int version) const {
3308 for (const InstanceKlass* ik = this; ik != nullptr; ik = ik->previous_versions()) {
3309 if (ik->constants()->version() == version) {
3310 return ik;
3311 }
3312 }
3313 return nullptr;
3314 }
3315
3316 void InstanceKlass::set_source_debug_extension(const char* array, int length) {
3317 if (array == nullptr) {
3318 _source_debug_extension = nullptr;
3319 } else {
3320 // Adding one to the attribute length in order to store a null terminator
3321 // character could cause an overflow because the attribute length is
3322 // already coded with an u4 in the classfile, but in practice, it's
3323 // unlikely to happen.
3324 assert((length+1) > length, "Overflow checking");
3325 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
3326 for (int i = 0; i < length; i++) {
3327 sde[i] = array[i];
3328 }
3329 sde[length] = '\0';
3330 _source_debug_extension = sde;
3331 }
3332 }
3333
3334 Symbol* InstanceKlass::generic_signature() const { return _constants->generic_signature(); }
3335 u2 InstanceKlass::generic_signature_index() const { return _constants->generic_signature_index(); }
3336 void InstanceKlass::set_generic_signature_index(u2 sig_index) { _constants->set_generic_signature_index(sig_index); }
3337
3338 const char* InstanceKlass::signature_name() const {
3339 return signature_name_of_carrier(JVM_SIGNATURE_CLASS);
3340 }
3341
3342 const char* InstanceKlass::signature_name_of_carrier(char c) const {
3343 // Get the internal name as a c string
3344 const char* src = (const char*) (name()->as_C_string());
3345 const int src_length = (int)strlen(src);
3346
3347 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
3348
3349 // Add L or Q as type indicator
3350 int dest_index = 0;
3351 dest[dest_index++] = c;
3352
3353 // Add the actual class name
3354 for (int src_index = 0; src_index < src_length; ) {
3355 dest[dest_index++] = src[src_index++];
3356 }
3357
3358 if (is_hidden()) { // Replace the last '+' with a '.'.
3359 for (int index = (int)src_length; index > 0; index--) {
3360 if (dest[index] == '+') {
3361 dest[index] = JVM_SIGNATURE_DOT;
3362 break;
3363 }
3364 }
3365 }
3366
3367 // Add the semicolon and the null
3368 dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
3369 dest[dest_index] = '\0';
3370 return dest;
3371 }
3612 bool InstanceKlass::find_inner_classes_attr(int* ooff, int* noff, TRAPS) const {
3613 constantPoolHandle i_cp(THREAD, constants());
3614 for (InnerClassesIterator iter(this); !iter.done(); iter.next()) {
3615 int ioff = iter.inner_class_info_index();
3616 if (ioff != 0) {
3617 // Check to see if the name matches the class we're looking for
3618 // before attempting to find the class.
3619 if (i_cp->klass_name_at_matches(this, ioff)) {
3620 Klass* inner_klass = i_cp->klass_at(ioff, CHECK_false);
3621 if (this == inner_klass) {
3622 *ooff = iter.outer_class_info_index();
3623 *noff = iter.inner_name_index();
3624 return true;
3625 }
3626 }
3627 }
3628 }
3629 return false;
3630 }
3631
3632 void InstanceKlass::check_can_be_annotated_with_NullRestricted(InstanceKlass* type, Symbol* container_klass_name, TRAPS) {
3633 assert(type->is_instance_klass(), "Sanity check");
3634 if (type->is_identity_class()) {
3635 ResourceMark rm(THREAD);
3636 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
3637 err_msg("Class %s expects class %s to be a value class, but it is an identity class",
3638 container_klass_name->as_C_string(),
3639 type->external_name()));
3640 }
3641
3642 if (type->is_abstract()) {
3643 ResourceMark rm(THREAD);
3644 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
3645 err_msg("Class %s expects class %s to be concrete value type, but it is an abstract class",
3646 container_klass_name->as_C_string(),
3647 type->external_name()));
3648 }
3649 }
3650
3651 InstanceKlass* InstanceKlass::compute_enclosing_class(bool* inner_is_member, TRAPS) const {
3652 InstanceKlass* outer_klass = nullptr;
3653 *inner_is_member = false;
3654 int ooff = 0, noff = 0;
3655 bool has_inner_classes_attr = find_inner_classes_attr(&ooff, &noff, THREAD);
3656 if (has_inner_classes_attr) {
3657 constantPoolHandle i_cp(THREAD, constants());
3658 if (ooff != 0) {
3659 Klass* ok = i_cp->klass_at(ooff, CHECK_NULL);
3660 if (!ok->is_instance_klass()) {
3661 // If the outer class is not an instance klass then it cannot have
3662 // declared any inner classes.
3663 ResourceMark rm(THREAD);
3664 // Names are all known to be < 64k so we know this formatted message is not excessively large.
3665 Exceptions::fthrow(
3666 THREAD_AND_LOCATION,
3667 vmSymbols::java_lang_IncompatibleClassChangeError(),
3668 "%s and %s disagree on InnerClasses attribute",
3669 ok->external_name(),
3670 external_name());
3697 u2 InstanceKlass::compute_modifier_flags() const {
3698 u2 access = access_flags().as_unsigned_short();
3699
3700 // But check if it happens to be member class.
3701 InnerClassesIterator iter(this);
3702 for (; !iter.done(); iter.next()) {
3703 int ioff = iter.inner_class_info_index();
3704 // Inner class attribute can be zero, skip it.
3705 // Strange but true: JVM spec. allows null inner class refs.
3706 if (ioff == 0) continue;
3707
3708 // only look at classes that are already loaded
3709 // since we are looking for the flags for our self.
3710 Symbol* inner_name = constants()->klass_name_at(ioff);
3711 if (name() == inner_name) {
3712 // This is really a member class.
3713 access = iter.inner_access_flags();
3714 break;
3715 }
3716 }
3717 return access;
3718 }
3719
3720 jint InstanceKlass::jvmti_class_status() const {
3721 jint result = 0;
3722
3723 if (is_linked()) {
3724 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3725 }
3726
3727 if (is_initialized()) {
3728 assert(is_linked(), "Class status is not consistent");
3729 result |= JVMTI_CLASS_STATUS_INITIALIZED;
3730 }
3731 if (is_in_error_state()) {
3732 result |= JVMTI_CLASS_STATUS_ERROR;
3733 }
3734 return result;
3735 }
3736
3737 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {
3951 }
3952 osr = osr->osr_link();
3953 }
3954
3955 assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3956 if (best != nullptr && best->comp_level() >= comp_level) {
3957 return best;
3958 }
3959 return nullptr;
3960 }
3961
3962 // -----------------------------------------------------------------------------------------------------
3963 // Printing
3964
3965 #define BULLET " - "
3966
3967 static const char* state_names[] = {
3968 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3969 };
3970
3971 static void print_vtable(address self, intptr_t* start, int len, outputStream* st) {
3972 ResourceMark rm;
3973 int* forward_refs = NEW_RESOURCE_ARRAY(int, len);
3974 for (int i = 0; i < len; i++) forward_refs[i] = 0;
3975 for (int i = 0; i < len; i++) {
3976 intptr_t e = start[i];
3977 st->print("%d : " INTPTR_FORMAT, i, e);
3978 if (forward_refs[i] != 0) {
3979 int from = forward_refs[i];
3980 int off = (int) start[from];
3981 st->print(" (offset %d <= [%d])", off, from);
3982 }
3983 if (MetaspaceObj::is_valid((Metadata*)e)) {
3984 st->print(" ");
3985 ((Metadata*)e)->print_value_on(st);
3986 } else if (self != nullptr && e > 0 && e < 0x10000) {
3987 address location = self + e;
3988 int index = (int)((intptr_t*)location - start);
3989 st->print(" (offset %d => [%d])", (int)e, index);
3990 if (index >= 0 && index < len)
3991 forward_refs[index] = i;
3992 }
3993 st->cr();
3994 }
3995 }
3996
3997 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3998 return print_vtable(nullptr, reinterpret_cast<intptr_t*>(start), len, st);
3999 }
4000
4001 template<typename T>
4002 static void print_array_on(outputStream* st, Array<T>* array) {
4003 if (array == nullptr) { st->print_cr("nullptr"); return; }
4004 array->print_value_on(st); st->cr();
4005 if (Verbose || WizardMode) {
4006 for (int i = 0; i < array->length(); i++) {
4007 st->print("%d : ", i); array->at(i)->print_value_on(st); st->cr();
4008 }
4009 }
4010 }
4011
4012 static void print_array_on(outputStream* st, Array<int>* array) {
4013 if (array == nullptr) { st->print_cr("nullptr"); return; }
4014 array->print_value_on(st); st->cr();
4015 if (Verbose || WizardMode) {
4016 for (int i = 0; i < array->length(); i++) {
4017 st->print("%d : %d", i, array->at(i)); st->cr();
4018 }
4019 }
4020 }
4021
4022 const char* InstanceKlass::init_state_name() const {
4023 return state_names[init_state()];
4024 }
4025
4026 void InstanceKlass::print_on(outputStream* st) const {
4027 assert(is_klass(), "must be klass");
4028 Klass::print_on(st);
4029
4030 st->print(BULLET"instance size: %d", size_helper()); st->cr();
4031 st->print(BULLET"klass size: %d", size()); st->cr();
4032 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
4033 st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
4034 st->print(BULLET"state: "); st->print_cr("%s", init_state_name());
4035 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
4036 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
4037 st->print(BULLET"sub: ");
4038 Klass* sub = subklass();
4039 int n;
4040 for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
4041 if (n < MaxSubklassPrintSize) {
4042 sub->print_value_on(st);
4043 st->print(" ");
4044 }
4045 }
4046 if (n >= MaxSubklassPrintSize) st->print("(%zd more klasses...)", n - MaxSubklassPrintSize);
4047 st->cr();
4048
4049 if (is_interface()) {
4050 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
4051 if (nof_implementors() == 1) {
4052 st->print_cr(BULLET"implementor: ");
4053 st->print(" ");
4054 implementor()->print_value_on(st);
4055 st->cr();
4056 }
4057 }
4058
4059 st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
4060 st->print(BULLET"methods: "); print_array_on(st, methods());
4061 st->print(BULLET"method ordering: "); print_array_on(st, method_ordering());
4062 if (default_methods() != nullptr) {
4063 st->print(BULLET"default_methods: "); print_array_on(st, default_methods());
4064 }
4065 print_on_maybe_null(st, BULLET"default vtable indices: ", default_vtable_indices());
4066 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr();
4067 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
4068
4069 st->print(BULLET"secondary supers: "); secondary_supers()->print_value_on(st); st->cr();
4070
4071 st->print(BULLET"hash_slot: %d", hash_slot()); st->cr();
4072 st->print(BULLET"secondary bitmap: " UINTX_FORMAT_X_0, _secondary_supers_bitmap); st->cr();
4073
4074 if (secondary_supers() != nullptr) {
4075 if (Verbose) {
4076 bool is_hashed = (_secondary_supers_bitmap != SECONDARY_SUPERS_BITMAP_FULL);
4077 st->print_cr(BULLET"---- secondary supers (%d words):", _secondary_supers->length());
4078 for (int i = 0; i < _secondary_supers->length(); i++) {
4079 ResourceMark rm; // for external_name()
4080 Klass* secondary_super = _secondary_supers->at(i);
4081 st->print(BULLET"%2d:", i);
4082 if (is_hashed) {
4083 int home_slot = compute_home_slot(secondary_super, _secondary_supers_bitmap);
4103 print_on_maybe_null(st, BULLET"field type annotations: ", fields_type_annotations());
4104 {
4105 bool have_pv = false;
4106 // previous versions are linked together through the InstanceKlass
4107 for (InstanceKlass* pv_node = previous_versions();
4108 pv_node != nullptr;
4109 pv_node = pv_node->previous_versions()) {
4110 if (!have_pv)
4111 st->print(BULLET"previous version: ");
4112 have_pv = true;
4113 pv_node->constants()->print_value_on(st);
4114 }
4115 if (have_pv) st->cr();
4116 }
4117
4118 print_on_maybe_null(st, BULLET"generic signature: ", generic_signature());
4119 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
4120 st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr();
4121 print_on_maybe_null(st, BULLET"record components: ", record_components());
4122 st->print(BULLET"permitted subclasses: "); permitted_subclasses()->print_value_on(st); st->cr();
4123 st->print(BULLET"loadable descriptors: "); loadable_descriptors()->print_value_on(st); st->cr();
4124 if (java_mirror() != nullptr) {
4125 st->print(BULLET"java mirror: ");
4126 java_mirror()->print_value_on(st);
4127 st->cr();
4128 } else {
4129 st->print_cr(BULLET"java mirror: null");
4130 }
4131 st->print(BULLET"vtable length %d (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
4132 if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
4133 st->print(BULLET"itable length %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
4134 if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(nullptr, start_of_itable(), itable_length(), st);
4135 st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
4136
4137 FieldPrinter print_static_field(st);
4138 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
4139 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
4140 FieldPrinter print_nonstatic_field(st);
4141 InstanceKlass* ik = const_cast<InstanceKlass*>(this);
4142 ik->print_nonstatic_fields(&print_nonstatic_field);
4143
4144 st->print(BULLET"non-static oop maps (%d entries): ", nonstatic_oop_map_count());
4145 OopMapBlock* map = start_of_nonstatic_oop_maps();
4146 OopMapBlock* end_map = map + nonstatic_oop_map_count();
4147 while (map < end_map) {
4148 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
4149 map++;
4150 }
4151 st->cr();
4152
4153 if (fieldinfo_search_table() != nullptr) {
4154 st->print_cr(BULLET"---- field info search table:");
4155 FieldInfoStream::print_search_table(st, _constants, _fieldinfo_stream, _fieldinfo_search_table);
4156 }
4157 }
4158
4159 void InstanceKlass::print_value_on(outputStream* st) const {
4160 assert(is_klass(), "must be klass");
4161 if (Verbose || WizardMode) access_flags().print_on(st);
4162 name()->print_value_on(st);
4163 }
4164
4165 void FieldPrinter::do_field(fieldDescriptor* fd) {
4166 for (int i = 0; i < _indent; i++) _st->print(" ");
4167 _st->print(BULLET);
4168 if (_obj == nullptr) {
4169 fd->print_on(_st, _base_offset);
4170 _st->cr();
4171 } else {
4172 fd->print_on_for(_st, _obj, _indent, _base_offset);
4173 if (!fd->field_flags().is_flat()) _st->cr();
4174 }
4175 }
4176
4177
4178 void InstanceKlass::oop_print_on(oop obj, outputStream* st, int indent, int base_offset) {
4179 Klass::oop_print_on(obj, st);
4180
4181 if (this == vmClasses::String_klass()) {
4182 typeArrayOop value = java_lang_String::value(obj);
4183 juint length = java_lang_String::length(obj);
4184 if (value != nullptr &&
4185 value->is_typeArray() &&
4186 length <= (juint) value->length()) {
4187 st->print(BULLET"string: ");
4188 java_lang_String::print(obj, st);
4189 st->cr();
4190 }
4191 }
4192
4193 st->print_cr(BULLET"---- fields (total size %zu words):", oop_size(obj));
4194 FieldPrinter print_field(st, obj, indent, base_offset);
4195 print_nonstatic_fields(&print_field);
4196
4197 if (this == vmClasses::Class_klass()) {
4198 st->print(BULLET"signature: ");
4199 java_lang_Class::print_signature(obj, st);
4200 st->cr();
4201 Klass* real_klass = java_lang_Class::as_Klass(obj);
4202 if (real_klass != nullptr && real_klass->is_instance_klass()) {
4203 st->print_cr(BULLET"---- static fields (%d):", java_lang_Class::static_oop_field_count(obj));
4204 InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field);
4205 }
4206 } else if (this == vmClasses::MethodType_klass()) {
4207 st->print(BULLET"signature: ");
4208 java_lang_invoke_MethodType::print_signature(obj, st);
4209 st->cr();
4210 }
4211 }
4212
4213 #ifndef PRODUCT
4214
|