< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page

  52 #include "jvmtifiles/jvmti.h"
  53 #include "logging/log.hpp"
  54 #include "klass.inline.hpp"
  55 #include "logging/logMessage.hpp"
  56 #include "logging/logStream.hpp"
  57 #include "memory/allocation.inline.hpp"
  58 #include "memory/iterator.inline.hpp"
  59 #include "memory/metadataFactory.hpp"
  60 #include "memory/metaspaceClosure.hpp"
  61 #include "memory/oopFactory.hpp"
  62 #include "memory/resourceArea.hpp"
  63 #include "memory/universe.hpp"
  64 #include "oops/fieldStreams.inline.hpp"
  65 #include "oops/constantPool.hpp"
  66 #include "oops/instanceClassLoaderKlass.hpp"
  67 #include "oops/instanceKlass.inline.hpp"
  68 #include "oops/instanceMirrorKlass.hpp"
  69 #include "oops/instanceOop.hpp"
  70 #include "oops/instanceStackChunkKlass.hpp"
  71 #include "oops/klass.inline.hpp"

  72 #include "oops/method.hpp"
  73 #include "oops/oop.inline.hpp"
  74 #include "oops/recordComponent.hpp"
  75 #include "oops/symbol.hpp"


  76 #include "prims/jvmtiExport.hpp"
  77 #include "prims/jvmtiRedefineClasses.hpp"
  78 #include "prims/jvmtiThreadState.hpp"
  79 #include "prims/methodComparator.hpp"
  80 #include "runtime/arguments.hpp"
  81 #include "runtime/deoptimization.hpp"
  82 #include "runtime/atomic.hpp"
  83 #include "runtime/fieldDescriptor.inline.hpp"
  84 #include "runtime/handles.inline.hpp"
  85 #include "runtime/javaCalls.hpp"
  86 #include "runtime/javaThread.inline.hpp"
  87 #include "runtime/mutexLocker.hpp"
  88 #include "runtime/orderAccess.hpp"
  89 #include "runtime/os.inline.hpp"
  90 #include "runtime/reflection.hpp"
  91 #include "runtime/synchronizer.hpp"
  92 #include "runtime/threads.hpp"
  93 #include "services/classLoadingService.hpp"
  94 #include "services/finalizerService.hpp"
  95 #include "services/threadService.hpp"

 132 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait)     \
 133   {                                                              \
 134     char* data = nullptr;                                        \
 135     int len = 0;                                                 \
 136     Symbol* clss_name = name();                                  \
 137     if (clss_name != nullptr) {                                  \
 138       data = (char*)clss_name->bytes();                          \
 139       len = clss_name->utf8_length();                            \
 140     }                                                            \
 141     HOTSPOT_CLASS_INITIALIZATION_##type(                         \
 142       data, len, (void*)class_loader(), thread_type, wait);      \
 143   }
 144 
 145 #else //  ndef DTRACE_ENABLED
 146 
 147 #define DTRACE_CLASSINIT_PROBE(type, thread_type)
 148 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait)
 149 
 150 #endif //  ndef DTRACE_ENABLED
 151 





 152 bool InstanceKlass::_finalization_enabled = true;
 153 
 154 static inline bool is_class_loader(const Symbol* class_name,
 155                                    const ClassFileParser& parser) {
 156   assert(class_name != nullptr, "invariant");
 157 
 158   if (class_name == vmSymbols::java_lang_ClassLoader()) {
 159     return true;
 160   }
 161 
 162   if (vmClasses::ClassLoader_klass_loaded()) {
 163     const Klass* const super_klass = parser.super_klass();
 164     if (super_klass != nullptr) {
 165       if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
 166         return true;
 167       }
 168     }
 169   }
 170   return false;
 171 }
 172 













 173 static inline bool is_stack_chunk_class(const Symbol* class_name,
 174                                         const ClassLoaderData* loader_data) {
 175   return (class_name == vmSymbols::jdk_internal_vm_StackChunk() &&
 176           loader_data->is_the_null_class_loader_data());
 177 }
 178 
 179 // private: called to verify that k is a static member of this nest.
 180 // We know that k is an instance class in the same package and hence the
 181 // same classloader.
 182 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
 183   assert(!is_hidden(), "unexpected hidden class");
 184   if (_nest_members == nullptr || _nest_members == Universe::the_empty_short_array()) {
 185     if (log_is_enabled(Trace, class, nestmates)) {
 186       ResourceMark rm(current);
 187       log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
 188                                   k->external_name(), this->external_name());
 189     }
 190     return false;
 191   }
 192 

 447 }
 448 
 449 const char* InstanceKlass::nest_host_error() {
 450   if (_nest_host_index == 0) {
 451     return nullptr;
 452   } else {
 453     constantPoolHandle cph(Thread::current(), constants());
 454     return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
 455   }
 456 }
 457 
 458 void* InstanceKlass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size,
 459                                   bool use_class_space, TRAPS) throw() {
 460   return Metaspace::allocate(loader_data, word_size, ClassType, use_class_space, THREAD);
 461 }
 462 
 463 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
 464   const int size = InstanceKlass::size(parser.vtable_size(),
 465                                        parser.itable_size(),
 466                                        nonstatic_oop_map_size(parser.total_oop_map_count()),
 467                                        parser.is_interface());

 468 
 469   const Symbol* const class_name = parser.class_name();
 470   assert(class_name != nullptr, "invariant");
 471   ClassLoaderData* loader_data = parser.loader_data();
 472   assert(loader_data != nullptr, "invariant");
 473 
 474   InstanceKlass* ik;
 475   const bool use_class_space = parser.klass_needs_narrow_id();
 476 
 477   // Allocation
 478   if (parser.is_instance_ref_klass()) {
 479     // java.lang.ref.Reference
 480     ik = new (loader_data, size, use_class_space, THREAD) InstanceRefKlass(parser);
 481   } else if (class_name == vmSymbols::java_lang_Class()) {
 482     // mirror - java.lang.Class
 483     ik = new (loader_data, size, use_class_space, THREAD) InstanceMirrorKlass(parser);
 484   } else if (is_stack_chunk_class(class_name, loader_data)) {
 485     // stack chunk
 486     ik = new (loader_data, size, use_class_space, THREAD) InstanceStackChunkKlass(parser);
 487   } else if (is_class_loader(class_name, parser)) {
 488     // class loader - java.lang.ClassLoader
 489     ik = new (loader_data, size, use_class_space, THREAD) InstanceClassLoaderKlass(parser);



 490   } else {
 491     // normal
 492     ik = new (loader_data, size, use_class_space, THREAD) InstanceKlass(parser);
 493   }
 494 
 495   if (ik != nullptr && UseCompressedClassPointers && use_class_space) {
 496     assert(CompressedKlassPointers::is_encodable(ik),
 497            "Klass " PTR_FORMAT "needs a narrow Klass ID, but is not encodable", p2i(ik));
 498   }
 499 
 500   // Check for pending exception before adding to the loader data and incrementing
 501   // class count.  Can get OOM here.
 502   if (HAS_PENDING_EXCEPTION) {
 503     return nullptr;
 504   }
 505 






 506   return ik;
 507 }
 508 























 509 
 510 // copy method ordering from resource area to Metaspace
 511 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
 512   if (m != nullptr) {
 513     // allocate a new array and copy contents (memcpy?)
 514     _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
 515     for (int i = 0; i < m->length(); i++) {
 516       _method_ordering->at_put(i, m->at(i));
 517     }
 518   } else {
 519     _method_ordering = Universe::the_empty_int_array();
 520   }
 521 }
 522 
 523 // create a new array of vtable_indices for default methods
 524 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
 525   Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
 526   assert(default_vtable_indices() == nullptr, "only create once");
 527   set_default_vtable_indices(vtable_indices);
 528   return vtable_indices;
 529 }
 530 
 531 
 532 InstanceKlass::InstanceKlass() {
 533   assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
 534 }
 535 
 536 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) :
 537   Klass(kind),
 538   _nest_members(nullptr),
 539   _nest_host(nullptr),
 540   _permitted_subclasses(nullptr),
 541   _record_components(nullptr),
 542   _static_field_size(parser.static_field_size()),
 543   _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
 544   _itable_len(parser.itable_size()),
 545   _nest_host_index(0),
 546   _init_state(allocated),
 547   _reference_type(reference_type),
 548   _init_thread(nullptr)



 549 {
 550   set_vtable_length(parser.vtable_size());
 551   set_access_flags(parser.access_flags());
 552   if (parser.is_hidden()) set_is_hidden();
 553   set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
 554                                                     false));



 555 
 556   assert(nullptr == _methods, "underlying memory not zeroed?");
 557   assert(is_instance_klass(), "is layout incorrect?");
 558   assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
 559 }
 560 
 561 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
 562                                        Array<Method*>* methods) {
 563   if (methods != nullptr && methods != Universe::the_empty_method_array() &&
 564       !methods->is_shared()) {
 565     for (int i = 0; i < methods->length(); i++) {
 566       Method* method = methods->at(i);
 567       if (method == nullptr) continue;  // maybe null if error processing
 568       // Only want to delete methods that are not executing for RedefineClasses.
 569       // The previous version will point to them so they're not totally dangling
 570       assert (!method->on_stack(), "shouldn't be called with methods on stack");
 571       MetadataFactory::free_metadata(loader_data, method);
 572     }
 573     MetadataFactory::free_array<Method*>(loader_data, methods);
 574   }

 679 
 680   deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
 681   set_transitive_interfaces(nullptr);
 682   set_local_interfaces(nullptr);
 683 
 684   if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->is_shared()) {
 685     MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
 686   }
 687   set_fieldinfo_stream(nullptr);
 688 
 689   if (fieldinfo_search_table() != nullptr && !fieldinfo_search_table()->is_shared()) {
 690     MetadataFactory::free_array<u1>(loader_data, fieldinfo_search_table());
 691   }
 692   set_fieldinfo_search_table(nullptr);
 693 
 694   if (fields_status() != nullptr && !fields_status()->is_shared()) {
 695     MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
 696   }
 697   set_fields_status(nullptr);
 698 





 699   // If a method from a redefined class is using this constant pool, don't
 700   // delete it, yet.  The new class's previous version will point to this.
 701   if (constants() != nullptr) {
 702     assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
 703     if (!constants()->is_shared()) {
 704       MetadataFactory::free_metadata(loader_data, constants());
 705     }
 706     // Delete any cached resolution errors for the constant pool
 707     SystemDictionary::delete_resolution_error(constants());
 708 
 709     set_constants(nullptr);
 710   }
 711 
 712   if (inner_classes() != nullptr &&
 713       inner_classes() != Universe::the_empty_short_array() &&
 714       !inner_classes()->is_shared()) {
 715     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
 716   }
 717   set_inner_classes(nullptr);
 718 
 719   if (nest_members() != nullptr &&
 720       nest_members() != Universe::the_empty_short_array() &&
 721       !nest_members()->is_shared()) {
 722     MetadataFactory::free_array<jushort>(loader_data, nest_members());
 723   }
 724   set_nest_members(nullptr);
 725 
 726   if (permitted_subclasses() != nullptr &&
 727       permitted_subclasses() != Universe::the_empty_short_array() &&
 728       !permitted_subclasses()->is_shared()) {
 729     MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
 730   }
 731   set_permitted_subclasses(nullptr);
 732 







 733   // We should deallocate the Annotations instance if it's not in shared spaces.
 734   if (annotations() != nullptr && !annotations()->is_shared()) {
 735     MetadataFactory::free_metadata(loader_data, annotations());
 736   }
 737   set_annotations(nullptr);
 738 
 739   SystemDictionaryShared::handle_class_unloading(this);
 740 
 741 #if INCLUDE_CDS_JAVA_HEAP
 742   if (CDSConfig::is_dumping_heap()) {
 743     HeapShared::remove_scratch_objects(this);
 744   }
 745 #endif
 746 }
 747 
 748 bool InstanceKlass::is_record() const {
 749   return _record_components != nullptr &&
 750          is_final() &&
 751          java_super() == vmClasses::Record_klass();
 752 }

 952         vmSymbols::java_lang_IncompatibleClassChangeError(),
 953         "class %s has interface %s as super class",
 954         external_name(),
 955         super_klass->external_name()
 956       );
 957       return false;
 958     }
 959 
 960     InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
 961     ik_super->link_class_impl(CHECK_false);
 962   }
 963 
 964   // link all interfaces implemented by this class before linking this class
 965   Array<InstanceKlass*>* interfaces = local_interfaces();
 966   int num_interfaces = interfaces->length();
 967   for (int index = 0; index < num_interfaces; index++) {
 968     InstanceKlass* interk = interfaces->at(index);
 969     interk->link_class_impl(CHECK_false);
 970   }
 971 





































































































 972   // in case the class is linked in the process of linking its superclasses
 973   if (is_linked()) {
 974     return true;
 975   }
 976 
 977   // trace only the link time for this klass that includes
 978   // the verification time
 979   PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
 980                              ClassLoader::perf_class_link_selftime(),
 981                              ClassLoader::perf_classes_linked(),
 982                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 983                              jt->get_thread_stat()->perf_timers_addr(),
 984                              PerfClassTraceTime::CLASS_LINK);
 985 
 986   // verification & rewriting
 987   {
 988     HandleMark hm(THREAD);
 989     Handle h_init_lock(THREAD, init_lock());
 990     ObjectLocker ol(h_init_lock, jt);
 991     // rewritten will have been set if loader constraint error found

1256       ss.print("Could not initialize class %s", external_name());
1257       if (cause.is_null()) {
1258         THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1259       } else {
1260         THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1261                         ss.as_string(), cause);
1262       }
1263     } else {
1264 
1265       // Step 6
1266       set_init_state(being_initialized);
1267       set_init_thread(jt);
1268       if (debug_logging_enabled) {
1269         ResourceMark rm(jt);
1270         log_debug(class, init)("Thread \"%s\" is initializing %s",
1271                                jt->name(), external_name());
1272       }
1273     }
1274   }
1275 





















1276   // Step 7
1277   // Next, if C is a class rather than an interface, initialize it's super class and super
1278   // interfaces.
1279   if (!is_interface()) {
1280     Klass* super_klass = super();
1281     if (super_klass != nullptr && super_klass->should_be_initialized()) {
1282       super_klass->initialize(THREAD);
1283     }
1284     // If C implements any interface that declares a non-static, concrete method,
1285     // the initialization of C triggers initialization of its super interfaces.
1286     // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1287     // having a superinterface that declares, non-static, concrete methods
1288     if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1289       initialize_super_interfaces(THREAD);
1290     }
1291 
1292     // If any exceptions, complete abruptly, throwing the same exception as above.
1293     if (HAS_PENDING_EXCEPTION) {
1294       Handle e(THREAD, PENDING_EXCEPTION);
1295       CLEAR_PENDING_EXCEPTION;
1296       {
1297         EXCEPTION_MARK;
1298         add_initialization_error(THREAD, e);
1299         // Locks object, set state, and notify all waiting threads
1300         set_initialization_state_and_notify(initialization_error, THREAD);
1301         CLEAR_PENDING_EXCEPTION;
1302       }
1303       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1304       THROW_OOP(e());
1305     }
1306   }
1307 
1308 
1309   // Step 8
1310   {
1311     DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1312     if (class_initializer() != nullptr) {
1313       // Timer includes any side effects of class initialization (resolution,
1314       // etc), but not recursive entry into call_class_initializer().
1315       PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1316                                ClassLoader::perf_class_init_selftime(),
1317                                ClassLoader::perf_classes_inited(),
1318                                jt->get_thread_stat()->perf_recursion_counts_addr(),
1319                                jt->get_thread_stat()->perf_timers_addr(),
1320                                PerfClassTraceTime::CLASS_CLINIT);
1321       call_class_initializer(THREAD);
1322     } else {
1323       // The elapsed time is so small it's not worth counting.
1324       if (UsePerfData) {
1325         ClassLoader::perf_classes_inited()->inc();
1326       }
1327       call_class_initializer(THREAD);
1328     }






























1329   }
1330 
1331   // Step 9
1332   if (!HAS_PENDING_EXCEPTION) {
1333     set_initialization_state_and_notify(fully_initialized, CHECK);
1334     DEBUG_ONLY(vtable().verify(tty, true);)
1335     CompilationPolicy::replay_training_at_init(this, THREAD);
1336   }
1337   else {
1338     // Step 10 and 11
1339     Handle e(THREAD, PENDING_EXCEPTION);
1340     CLEAR_PENDING_EXCEPTION;
1341     // JVMTI has already reported the pending exception
1342     // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1343     JvmtiExport::clear_detected_exception(jt);
1344     {
1345       EXCEPTION_MARK;
1346       add_initialization_error(THREAD, e);
1347       set_initialization_state_and_notify(initialization_error, THREAD);
1348       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below

1362   }
1363   DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait);
1364 }
1365 
1366 
1367 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
1368   Handle h_init_lock(THREAD, init_lock());
1369   if (h_init_lock() != nullptr) {
1370     ObjectLocker ol(h_init_lock, THREAD);
1371     set_init_thread(nullptr); // reset _init_thread before changing _init_state
1372     set_init_state(state);
1373     fence_and_clear_init_lock();
1374     ol.notify_all(CHECK);
1375   } else {
1376     assert(h_init_lock() != nullptr, "The initialization state should never be set twice");
1377     set_init_thread(nullptr); // reset _init_thread before changing _init_state
1378     set_init_state(state);
1379   }
1380 }
1381 




































































1382 // Update hierarchy. This is done before the new klass has been added to the SystemDictionary. The Compile_lock
1383 // is grabbed, to ensure that the compiler is not using the class hierarchy.
1384 void InstanceKlass::add_to_hierarchy(JavaThread* current) {
1385   assert(!SafepointSynchronize::is_at_safepoint(), "must NOT be at safepoint");
1386 
1387   DeoptimizationScope deopt_scope;
1388   {
1389     MutexLocker ml(current, Compile_lock);
1390 
1391     set_init_state(InstanceKlass::loaded);
1392     // make sure init_state store is already done.
1393     // The compiler reads the hierarchy outside of the Compile_lock.
1394     // Access ordering is used to add to hierarchy.
1395 
1396     // Link into hierarchy.
1397     append_to_sibling_list();                    // add to superklass/sibling list
1398     process_interfaces();                        // handle all "implements" declarations
1399 
1400     // Now mark all code that depended on old class hierarchy.
1401     // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)

1545   for (int i = 0; i < transitive_interfaces()->length(); i++) {
1546     if (transitive_interfaces()->at(i) == k) {
1547       return true;
1548     }
1549   }
1550   return false;
1551 }
1552 
1553 bool InstanceKlass::is_same_or_direct_interface(Klass *k) const {
1554   // Verify direct super interface
1555   if (this == k) return true;
1556   assert(k->is_interface(), "should be an interface class");
1557   for (int i = 0; i < local_interfaces()->length(); i++) {
1558     if (local_interfaces()->at(i) == k) {
1559       return true;
1560     }
1561   }
1562   return false;
1563 }
1564 
1565 objArrayOop InstanceKlass::allocate_objArray(int n, int length, TRAPS) {
1566   check_array_allocation_length(length, arrayOopDesc::max_array_length(T_OBJECT), CHECK_NULL);
1567   size_t size = objArrayOopDesc::object_size(length);
1568   ArrayKlass* ak = array_klass(n, CHECK_NULL);
1569   objArrayOop o = (objArrayOop)Universe::heap()->array_allocate(ak, size, length,
1570                                                                 /* do_zero */ true, CHECK_NULL);
1571   return o;
1572 }
1573 
1574 instanceOop InstanceKlass::register_finalizer(instanceOop i, TRAPS) {
1575   if (TraceFinalizerRegistration) {
1576     tty->print("Registered ");
1577     i->print_value_on(tty);
1578     tty->print_cr(" (" PTR_FORMAT ") as finalizable", p2i(i));
1579   }
1580   instanceHandle h_i(THREAD, i);
1581   // Pass the handle as argument, JavaCalls::call expects oop as jobjects
1582   JavaValue result(T_VOID);
1583   JavaCallArguments args(h_i);
1584   methodHandle mh(THREAD, Universe::finalizer_register_method());
1585   JavaCalls::call(&result, mh, &args, CHECK_NULL);
1586   MANAGEMENT_ONLY(FinalizerService::on_register(h_i(), THREAD);)
1587   return h_i();
1588 }
1589 
1590 instanceOop InstanceKlass::allocate_instance(TRAPS) {
1591   assert(!is_abstract() && !is_interface(), "Should not create this object");

1621               : vmSymbols::java_lang_IllegalAccessException(), external_name());
1622   }
1623 }
1624 
1625 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1626   // Need load-acquire for lock-free read
1627   if (array_klasses_acquire() == nullptr) {
1628 
1629     // Recursively lock array allocation
1630     RecursiveLocker rl(MultiArray_lock, THREAD);
1631 
1632     // Check if another thread created the array klass while we were waiting for the lock.
1633     if (array_klasses() == nullptr) {
1634       ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);
1635       // use 'release' to pair with lock-free load
1636       release_set_array_klasses(k);
1637     }
1638   }
1639 
1640   // array_klasses() will always be set at this point
1641   ObjArrayKlass* ak = array_klasses();
1642   assert(ak != nullptr, "should be set");
1643   return ak->array_klass(n, THREAD);
1644 }
1645 
1646 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1647   // Need load-acquire for lock-free read
1648   ObjArrayKlass* oak = array_klasses_acquire();
1649   if (oak == nullptr) {
1650     return nullptr;
1651   } else {
1652     return oak->array_klass_or_null(n);
1653   }
1654 }
1655 
1656 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1657   return array_klass(1, THREAD);
1658 }
1659 
1660 ArrayKlass* InstanceKlass::array_klass_or_null() {
1661   return array_klass_or_null(1);
1662 }
1663 
1664 static int call_class_initializer_counter = 0;   // for debugging
1665 
1666 Method* InstanceKlass::class_initializer() const {
1667   Method* clinit = find_method(
1668       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1669   if (clinit != nullptr && clinit->has_valid_initializer_flags()) {
1670     return clinit;
1671   }
1672   return nullptr;
1673 }
1674 
1675 void InstanceKlass::call_class_initializer(TRAPS) {
1676   if (ReplayCompiles &&
1677       (ReplaySuppressInitializers == 1 ||
1678        (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1679     // Hide the existence of the initializer for the purpose of replaying the compile
1680     return;
1681   }
1682 
1683 #if INCLUDE_CDS
1684   // This is needed to ensure the consistency of the archived heap objects.
1685   if (has_aot_initialized_mirror() && CDSConfig::is_loading_heap()) {
1686     AOTClassInitializer::call_runtime_setup(THREAD, this);
1687     return;
1688   } else if (has_archived_enum_objs()) {
1689     assert(is_shared(), "must be");

1758 
1759 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1760   InterpreterOopMap* entry_for) {
1761   // Lazily create the _oop_map_cache at first request.
1762   // Load_acquire is needed to safely get instance published with CAS by another thread.
1763   OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1764   if (oop_map_cache == nullptr) {
1765     // Try to install new instance atomically.
1766     oop_map_cache = new OopMapCache();
1767     OopMapCache* other = Atomic::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
1768     if (other != nullptr) {
1769       // Someone else managed to install before us, ditch local copy and use the existing one.
1770       delete oop_map_cache;
1771       oop_map_cache = other;
1772     }
1773   }
1774   // _oop_map_cache is constant after init; lookup below does its own locking.
1775   oop_map_cache->lookup(method, bci, entry_for);
1776 }
1777 
1778 bool InstanceKlass::contains_field_offset(int offset) {
1779   fieldDescriptor fd;
1780   return find_field_from_offset(offset, false, &fd);
1781 }
1782 
1783 FieldInfo InstanceKlass::field(int index) const {
1784   for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1785     if (fs.index() == index) {
1786       return fs.to_FieldInfo();
1787     }
1788   }
1789   fatal("Field not found");
1790   return FieldInfo();
1791 }
1792 
1793 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1794   JavaFieldStream fs(this);
1795   if (fs.lookup(name, sig)) {
1796     assert(fs.name() == name, "name must match");
1797     assert(fs.signature() == sig, "signature must match");
1798     fd->reinitialize(const_cast<InstanceKlass*>(this), fs.to_FieldInfo());
1799     return true;
1800   }
1801   return false;

1842 
1843 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1844   // search order according to newest JVM spec (5.4.3.2, p.167).
1845   // 1) search for field in current klass
1846   if (find_local_field(name, sig, fd)) {
1847     if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1848   }
1849   // 2) search for field recursively in direct superinterfaces
1850   if (is_static) {
1851     Klass* intf = find_interface_field(name, sig, fd);
1852     if (intf != nullptr) return intf;
1853   }
1854   // 3) apply field lookup recursively if superclass exists
1855   { Klass* supr = super();
1856     if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1857   }
1858   // 4) otherwise field lookup fails
1859   return nullptr;
1860 }
1861 









1862 
1863 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1864   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1865     if (fs.offset() == offset) {
1866       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.to_FieldInfo());
1867       if (fd->is_static() == is_static) return true;
1868     }
1869   }
1870   return false;
1871 }
1872 
1873 
1874 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1875   Klass* klass = const_cast<InstanceKlass*>(this);
1876   while (klass != nullptr) {
1877     if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1878       return true;
1879     }
1880     klass = klass->super();
1881   }

2225 }
2226 
2227 // uncached_lookup_method searches both the local class methods array and all
2228 // superclasses methods arrays, skipping any overpass methods in superclasses,
2229 // and possibly skipping private methods.
2230 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2231                                               const Symbol* signature,
2232                                               OverpassLookupMode overpass_mode,
2233                                               PrivateLookupMode private_mode) const {
2234   OverpassLookupMode overpass_local_mode = overpass_mode;
2235   const Klass* klass = this;
2236   while (klass != nullptr) {
2237     Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2238                                                                         signature,
2239                                                                         overpass_local_mode,
2240                                                                         StaticLookupMode::find,
2241                                                                         private_mode);
2242     if (method != nullptr) {
2243       return method;
2244     }



2245     klass = klass->super();
2246     overpass_local_mode = OverpassLookupMode::skip;   // Always ignore overpass methods in superclasses
2247   }
2248   return nullptr;
2249 }
2250 
2251 #ifdef ASSERT
2252 // search through class hierarchy and return true if this class or
2253 // one of the superclasses was redefined
2254 bool InstanceKlass::has_redefined_this_or_super() const {
2255   const Klass* klass = this;
2256   while (klass != nullptr) {
2257     if (InstanceKlass::cast(klass)->has_been_redefined()) {
2258       return true;
2259     }
2260     klass = klass->super();
2261   }
2262   return false;
2263 }
2264 #endif

2637     int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2638 
2639     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2640                          / itableOffsetEntry::size();
2641 
2642     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2643       if (ioe->interface_klass() != nullptr) {
2644         it->push(ioe->interface_klass_addr());
2645         itableMethodEntry* ime = ioe->first_method_entry(this);
2646         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2647         for (int index = 0; index < n; index ++) {
2648           it->push(ime[index].method_addr());
2649         }
2650       }
2651     }
2652   }
2653 
2654   it->push(&_nest_host);
2655   it->push(&_nest_members);
2656   it->push(&_permitted_subclasses);

2657   it->push(&_record_components);

2658 }
2659 
2660 #if INCLUDE_CDS
2661 void InstanceKlass::remove_unshareable_info() {
2662 
2663   if (is_linked()) {
2664     assert(can_be_verified_at_dumptime(), "must be");
2665     // Remember this so we can avoid walking the hierarchy at runtime.
2666     set_verified_at_dump_time();
2667   }
2668 
2669   _misc_flags.set_has_init_deps_processed(false);
2670 
2671   Klass::remove_unshareable_info();
2672 
2673   if (SystemDictionaryShared::has_class_failed_verification(this)) {
2674     // Classes are attempted to link during dumping and may fail,
2675     // but these classes are still in the dictionary and class list in CLD.
2676     // If the class has failed verification, there is nothing else to remove.
2677     return;

2685 
2686   { // Otherwise this needs to take out the Compile_lock.
2687     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2688     init_implementor();
2689   }
2690 
2691   // Call remove_unshareable_info() on other objects that belong to this class, except
2692   // for constants()->remove_unshareable_info(), which is called in a separate pass in
2693   // ArchiveBuilder::make_klasses_shareable(),
2694 
2695   for (int i = 0; i < methods()->length(); i++) {
2696     Method* m = methods()->at(i);
2697     m->remove_unshareable_info();
2698   }
2699 
2700   // do array classes also.
2701   if (array_klasses() != nullptr) {
2702     array_klasses()->remove_unshareable_info();
2703   }
2704 
2705   // These are not allocated from metaspace. They are safe to set to null.
2706   _source_debug_extension = nullptr;
2707   _dep_context = nullptr;
2708   _osr_nmethods_head = nullptr;
2709 #if INCLUDE_JVMTI
2710   _breakpoints = nullptr;
2711   _previous_versions = nullptr;
2712   _cached_class_file = nullptr;
2713   _jvmti_cached_class_field_map = nullptr;
2714 #endif
2715 
2716   _init_thread = nullptr;
2717   _methods_jmethod_ids = nullptr;
2718   _jni_ids = nullptr;
2719   _oop_map_cache = nullptr;
2720   if (CDSConfig::is_dumping_method_handles() && HeapShared::is_lambda_proxy_klass(this)) {
2721     // keep _nest_host
2722   } else {
2723     // clear _nest_host to ensure re-load at runtime
2724     _nest_host = nullptr;
2725   }

2776 void InstanceKlass::compute_has_loops_flag_for_methods() {
2777   Array<Method*>* methods = this->methods();
2778   for (int index = 0; index < methods->length(); ++index) {
2779     Method* m = methods->at(index);
2780     if (!m->is_overpass()) { // work around JDK-8305771
2781       m->compute_has_loops_flag();
2782     }
2783   }
2784 }
2785 
2786 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2787                                              PackageEntry* pkg_entry, TRAPS) {
2788   // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2789   // before the InstanceKlass is added to the SystemDictionary. Make
2790   // sure the current state is <loaded.
2791   assert(!is_loaded(), "invalid init state");
2792   assert(!shared_loading_failed(), "Must not try to load failed class again");
2793   set_package(loader_data, pkg_entry, CHECK);
2794   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2795 




2796   Array<Method*>* methods = this->methods();
2797   int num_methods = methods->length();
2798   for (int index = 0; index < num_methods; ++index) {
2799     methods->at(index)->restore_unshareable_info(CHECK);
2800   }
2801 #if INCLUDE_JVMTI
2802   if (JvmtiExport::has_redefined_a_class()) {
2803     // Reinitialize vtable because RedefineClasses may have changed some
2804     // entries in this vtable for super classes so the CDS vtable might
2805     // point to old or obsolete entries.  RedefineClasses doesn't fix up
2806     // vtables in the shared system dictionary, only the main one.
2807     // It also redefines the itable too so fix that too.
2808     // First fix any default methods that point to a super class that may
2809     // have been redefined.
2810     bool trace_name_printed = false;
2811     adjust_default_methods(&trace_name_printed);
2812     if (verified_at_dump_time()) {
2813       // Initialize vtable and itable for classes which can be verified at dump time.
2814       // Unlinked classes such as old classes with major version < 50 cannot be verified
2815       // at dump time.
2816       vtable().initialize_vtable();
2817       itable().initialize_itable();
2818     }
2819   }
2820 #endif // INCLUDE_JVMTI
2821 
2822   // restore constant pool resolved references
2823   constants()->restore_unshareable_info(CHECK);
2824 
2825   if (array_klasses() != nullptr) {
2826     // To get a consistent list of classes we need MultiArray_lock to ensure
2827     // array classes aren't observed while they are being restored.
2828     RecursiveLocker rl(MultiArray_lock, THREAD);
2829     assert(this == array_klasses()->bottom_klass(), "sanity");
2830     // Array classes have null protection domain.
2831     // --> see ArrayKlass::complete_create_array_klass()






2832     array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2833   }
2834 
2835   // Initialize @ValueBased class annotation if not already set in the archived klass.
2836   if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
2837     set_is_value_based();
2838   }
2839 
2840   DEBUG_ONLY(FieldInfoStream::validate_search_table(_constants, _fieldinfo_stream, _fieldinfo_search_table));
2841 }
2842 
2843 // Check if a class or any of its supertypes has a version older than 50.
2844 // CDS will not perform verification of old classes during dump time because
2845 // without changing the old verifier, the verification constraint cannot be
2846 // retrieved during dump time.
2847 // Verification of archived old classes will be performed during run time.
2848 bool InstanceKlass::can_be_verified_at_dumptime() const {
2849   if (MetaspaceShared::is_in_shared_metaspace(this)) {
2850     // This is a class that was dumped into the base archive, so we know
2851     // it was verified at dump time.

2965     constants()->release_C_heap_structures();
2966   }
2967 }
2968 
2969 // The constant pool is on stack if any of the methods are executing or
2970 // referenced by handles.
2971 bool InstanceKlass::on_stack() const {
2972   return _constants->on_stack();
2973 }
2974 
2975 Symbol* InstanceKlass::source_file_name() const               { return _constants->source_file_name(); }
2976 u2 InstanceKlass::source_file_name_index() const              { return _constants->source_file_name_index(); }
2977 void InstanceKlass::set_source_file_name_index(u2 sourcefile_index) { _constants->set_source_file_name_index(sourcefile_index); }
2978 
2979 // minor and major version numbers of class file
2980 u2 InstanceKlass::minor_version() const                 { return _constants->minor_version(); }
2981 void InstanceKlass::set_minor_version(u2 minor_version) { _constants->set_minor_version(minor_version); }
2982 u2 InstanceKlass::major_version() const                 { return _constants->major_version(); }
2983 void InstanceKlass::set_major_version(u2 major_version) { _constants->set_major_version(major_version); }
2984 




2985 const InstanceKlass* InstanceKlass::get_klass_version(int version) const {
2986   for (const InstanceKlass* ik = this; ik != nullptr; ik = ik->previous_versions()) {
2987     if (ik->constants()->version() == version) {
2988       return ik;
2989     }
2990   }
2991   return nullptr;
2992 }
2993 
2994 void InstanceKlass::set_source_debug_extension(const char* array, int length) {
2995   if (array == nullptr) {
2996     _source_debug_extension = nullptr;
2997   } else {
2998     // Adding one to the attribute length in order to store a null terminator
2999     // character could cause an overflow because the attribute length is
3000     // already coded with an u4 in the classfile, but in practice, it's
3001     // unlikely to happen.
3002     assert((length+1) > length, "Overflow checking");
3003     char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
3004     for (int i = 0; i < length; i++) {
3005       sde[i] = array[i];
3006     }
3007     sde[length] = '\0';
3008     _source_debug_extension = sde;
3009   }
3010 }
3011 
3012 Symbol* InstanceKlass::generic_signature() const                   { return _constants->generic_signature(); }
3013 u2 InstanceKlass::generic_signature_index() const                  { return _constants->generic_signature_index(); }
3014 void InstanceKlass::set_generic_signature_index(u2 sig_index)      { _constants->set_generic_signature_index(sig_index); }
3015 
3016 const char* InstanceKlass::signature_name() const {


3017 

3018   // Get the internal name as a c string
3019   const char* src = (const char*) (name()->as_C_string());
3020   const int src_length = (int)strlen(src);
3021 
3022   char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
3023 
3024   // Add L as type indicator
3025   int dest_index = 0;
3026   dest[dest_index++] = JVM_SIGNATURE_CLASS;
3027 
3028   // Add the actual class name
3029   for (int src_index = 0; src_index < src_length; ) {
3030     dest[dest_index++] = src[src_index++];
3031   }
3032 
3033   if (is_hidden()) { // Replace the last '+' with a '.'.
3034     for (int index = (int)src_length; index > 0; index--) {
3035       if (dest[index] == '+') {
3036         dest[index] = JVM_SIGNATURE_DOT;
3037         break;
3038       }
3039     }
3040   }
3041 
3042   // Add the semicolon and the null
3043   dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
3044   dest[dest_index] = '\0';
3045   return dest;
3046 }

3287 bool InstanceKlass::find_inner_classes_attr(int* ooff, int* noff, TRAPS) const {
3288   constantPoolHandle i_cp(THREAD, constants());
3289   for (InnerClassesIterator iter(this); !iter.done(); iter.next()) {
3290     int ioff = iter.inner_class_info_index();
3291     if (ioff != 0) {
3292       // Check to see if the name matches the class we're looking for
3293       // before attempting to find the class.
3294       if (i_cp->klass_name_at_matches(this, ioff)) {
3295         Klass* inner_klass = i_cp->klass_at(ioff, CHECK_false);
3296         if (this == inner_klass) {
3297           *ooff = iter.outer_class_info_index();
3298           *noff = iter.inner_name_index();
3299           return true;
3300         }
3301       }
3302     }
3303   }
3304   return false;
3305 }
3306 



















3307 InstanceKlass* InstanceKlass::compute_enclosing_class(bool* inner_is_member, TRAPS) const {
3308   InstanceKlass* outer_klass = nullptr;
3309   *inner_is_member = false;
3310   int ooff = 0, noff = 0;
3311   bool has_inner_classes_attr = find_inner_classes_attr(&ooff, &noff, THREAD);
3312   if (has_inner_classes_attr) {
3313     constantPoolHandle i_cp(THREAD, constants());
3314     if (ooff != 0) {
3315       Klass* ok = i_cp->klass_at(ooff, CHECK_NULL);
3316       if (!ok->is_instance_klass()) {
3317         // If the outer class is not an instance klass then it cannot have
3318         // declared any inner classes.
3319         ResourceMark rm(THREAD);
3320         // Names are all known to be < 64k so we know this formatted message is not excessively large.
3321         Exceptions::fthrow(
3322           THREAD_AND_LOCATION,
3323           vmSymbols::java_lang_IncompatibleClassChangeError(),
3324           "%s and %s disagree on InnerClasses attribute",
3325           ok->external_name(),
3326           external_name());

3353 u2 InstanceKlass::compute_modifier_flags() const {
3354   u2 access = access_flags().as_unsigned_short();
3355 
3356   // But check if it happens to be member class.
3357   InnerClassesIterator iter(this);
3358   for (; !iter.done(); iter.next()) {
3359     int ioff = iter.inner_class_info_index();
3360     // Inner class attribute can be zero, skip it.
3361     // Strange but true:  JVM spec. allows null inner class refs.
3362     if (ioff == 0) continue;
3363 
3364     // only look at classes that are already loaded
3365     // since we are looking for the flags for our self.
3366     Symbol* inner_name = constants()->klass_name_at(ioff);
3367     if (name() == inner_name) {
3368       // This is really a member class.
3369       access = iter.inner_access_flags();
3370       break;
3371     }
3372   }
3373   // Remember to strip ACC_SUPER bit
3374   return (access & (~JVM_ACC_SUPER));
3375 }
3376 
3377 jint InstanceKlass::jvmti_class_status() const {
3378   jint result = 0;
3379 
3380   if (is_linked()) {
3381     result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3382   }
3383 
3384   if (is_initialized()) {
3385     assert(is_linked(), "Class status is not consistent");
3386     result |= JVMTI_CLASS_STATUS_INITIALIZED;
3387   }
3388   if (is_in_error_state()) {
3389     result |= JVMTI_CLASS_STATUS_ERROR;
3390   }
3391   return result;
3392 }
3393 
3394 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {

3608     }
3609     osr = osr->osr_link();
3610   }
3611 
3612   assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3613   if (best != nullptr && best->comp_level() >= comp_level) {
3614     return best;
3615   }
3616   return nullptr;
3617 }
3618 
3619 // -----------------------------------------------------------------------------------------------------
3620 // Printing
3621 
3622 #define BULLET  " - "
3623 
3624 static const char* state_names[] = {
3625   "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3626 };
3627 
3628 static void print_vtable(intptr_t* start, int len, outputStream* st) {



3629   for (int i = 0; i < len; i++) {
3630     intptr_t e = start[i];
3631     st->print("%d : " INTPTR_FORMAT, i, e);





3632     if (MetaspaceObj::is_valid((Metadata*)e)) {
3633       st->print(" ");
3634       ((Metadata*)e)->print_value_on(st);






3635     }
3636     st->cr();
3637   }
3638 }
3639 
3640 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3641   return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);





















3642 }
3643 
3644 const char* InstanceKlass::init_state_name() const {
3645   return state_names[init_state()];
3646 }
3647 
3648 void InstanceKlass::print_on(outputStream* st) const {
3649   assert(is_klass(), "must be klass");
3650   Klass::print_on(st);
3651 
3652   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
3653   st->print(BULLET"klass size:        %d", size());                               st->cr();
3654   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
3655   st->print(BULLET"flags:             "); _misc_flags.print_on(st);               st->cr();
3656   st->print(BULLET"state:             "); st->print_cr("%s", init_state_name());
3657   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
3658   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3659   st->print(BULLET"sub:               ");
3660   Klass* sub = subklass();
3661   int n;
3662   for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3663     if (n < MaxSubklassPrintSize) {
3664       sub->print_value_on(st);
3665       st->print("   ");
3666     }
3667   }
3668   if (n >= MaxSubklassPrintSize) st->print("(%zd more klasses...)", n - MaxSubklassPrintSize);
3669   st->cr();
3670 
3671   if (is_interface()) {
3672     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
3673     if (nof_implementors() == 1) {
3674       st->print_cr(BULLET"implementor:    ");
3675       st->print("   ");
3676       implementor()->print_value_on(st);
3677       st->cr();
3678     }
3679   }
3680 
3681   st->print(BULLET"arrays:            "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3682   st->print(BULLET"methods:           "); methods()->print_value_on(st);               st->cr();
3683   if (Verbose || WizardMode) {
3684     Array<Method*>* method_array = methods();
3685     for (int i = 0; i < method_array->length(); i++) {
3686       st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3687     }
3688   }
3689   st->print(BULLET"method ordering:   "); method_ordering()->print_value_on(st);      st->cr();
3690   if (default_methods() != nullptr) {
3691     st->print(BULLET"default_methods:   "); default_methods()->print_value_on(st);    st->cr();
3692     if (Verbose) {
3693       Array<Method*>* method_array = default_methods();
3694       for (int i = 0; i < method_array->length(); i++) {
3695         st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3696       }
3697     }
3698   }
3699   print_on_maybe_null(st, BULLET"default vtable indices:   ", default_vtable_indices());
3700   st->print(BULLET"local interfaces:  "); local_interfaces()->print_value_on(st);      st->cr();
3701   st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3702 
3703   st->print(BULLET"secondary supers: "); secondary_supers()->print_value_on(st); st->cr();
3704 
3705   st->print(BULLET"hash_slot:         %d", hash_slot()); st->cr();
3706   st->print(BULLET"secondary bitmap: " UINTX_FORMAT_X_0, _secondary_supers_bitmap); st->cr();
3707 
3708   if (secondary_supers() != nullptr) {
3709     if (Verbose) {
3710       bool is_hashed = (_secondary_supers_bitmap != SECONDARY_SUPERS_BITMAP_FULL);
3711       st->print_cr(BULLET"---- secondary supers (%d words):", _secondary_supers->length());
3712       for (int i = 0; i < _secondary_supers->length(); i++) {
3713         ResourceMark rm; // for external_name()
3714         Klass* secondary_super = _secondary_supers->at(i);
3715         st->print(BULLET"%2d:", i);
3716         if (is_hashed) {
3717           int home_slot = compute_home_slot(secondary_super, _secondary_supers_bitmap);

3737   print_on_maybe_null(st, BULLET"field type annotations:  ", fields_type_annotations());
3738   {
3739     bool have_pv = false;
3740     // previous versions are linked together through the InstanceKlass
3741     for (InstanceKlass* pv_node = previous_versions();
3742          pv_node != nullptr;
3743          pv_node = pv_node->previous_versions()) {
3744       if (!have_pv)
3745         st->print(BULLET"previous version:  ");
3746       have_pv = true;
3747       pv_node->constants()->print_value_on(st);
3748     }
3749     if (have_pv) st->cr();
3750   }
3751 
3752   print_on_maybe_null(st, BULLET"generic signature: ", generic_signature());
3753   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
3754   st->print(BULLET"nest members:     "); nest_members()->print_value_on(st);     st->cr();
3755   print_on_maybe_null(st, BULLET"record components:     ", record_components());
3756   st->print(BULLET"permitted subclasses:     "); permitted_subclasses()->print_value_on(st);     st->cr();

3757   if (java_mirror() != nullptr) {
3758     st->print(BULLET"java mirror:       ");
3759     java_mirror()->print_value_on(st);
3760     st->cr();
3761   } else {
3762     st->print_cr(BULLET"java mirror:       null");
3763   }
3764   st->print(BULLET"vtable length      %d  (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3765   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
3766   st->print(BULLET"itable length      %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3767   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_itable(), itable_length(), st);
3768   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3769 
3770   FieldPrinter print_static_field(st);
3771   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3772   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3773   FieldPrinter print_nonstatic_field(st);
3774   InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3775   ik->print_nonstatic_fields(&print_nonstatic_field);
3776 
3777   st->print(BULLET"non-static oop maps (%d entries): ", nonstatic_oop_map_count());
3778   OopMapBlock* map     = start_of_nonstatic_oop_maps();
3779   OopMapBlock* end_map = map + nonstatic_oop_map_count();
3780   while (map < end_map) {
3781     st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3782     map++;
3783   }
3784   st->cr();
3785 
3786   if (fieldinfo_search_table() != nullptr) {
3787     st->print_cr(BULLET"---- field info search table:");
3788     FieldInfoStream::print_search_table(st, _constants, _fieldinfo_stream, _fieldinfo_search_table);
3789   }
3790 }
3791 
3792 void InstanceKlass::print_value_on(outputStream* st) const {
3793   assert(is_klass(), "must be klass");
3794   if (Verbose || WizardMode)  access_flags().print_on(st);
3795   name()->print_value_on(st);
3796 }
3797 
3798 void FieldPrinter::do_field(fieldDescriptor* fd) {

3799   _st->print(BULLET);
3800    if (_obj == nullptr) {
3801      fd->print_on(_st);
3802      _st->cr();
3803    } else {
3804      fd->print_on_for(_st, _obj);
3805      _st->cr();
3806    }
3807 }
3808 
3809 
3810 void InstanceKlass::oop_print_on(oop obj, outputStream* st) {
3811   Klass::oop_print_on(obj, st);
3812 
3813   if (this == vmClasses::String_klass()) {
3814     typeArrayOop value  = java_lang_String::value(obj);
3815     juint        length = java_lang_String::length(obj);
3816     if (value != nullptr &&
3817         value->is_typeArray() &&
3818         length <= (juint) value->length()) {
3819       st->print(BULLET"string: ");
3820       java_lang_String::print(obj, st);
3821       st->cr();
3822     }
3823   }
3824 
3825   st->print_cr(BULLET"---- fields (total size %zu words):", oop_size(obj));
3826   FieldPrinter print_field(st, obj);
3827   print_nonstatic_fields(&print_field);
3828 
3829   if (this == vmClasses::Class_klass()) {
3830     st->print(BULLET"signature: ");
3831     java_lang_Class::print_signature(obj, st);
3832     st->cr();
3833     Klass* real_klass = java_lang_Class::as_Klass(obj);
3834     if (real_klass != nullptr && real_klass->is_instance_klass()) {
3835       st->print_cr(BULLET"---- static fields (%d):", java_lang_Class::static_oop_field_count(obj));
3836       InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field);
3837     }
3838   } else if (this == vmClasses::MethodType_klass()) {
3839     st->print(BULLET"signature: ");
3840     java_lang_invoke_MethodType::print_signature(obj, st);
3841     st->cr();
3842   }
3843 }
3844 
3845 #ifndef PRODUCT
3846 

  52 #include "jvmtifiles/jvmti.h"
  53 #include "logging/log.hpp"
  54 #include "klass.inline.hpp"
  55 #include "logging/logMessage.hpp"
  56 #include "logging/logStream.hpp"
  57 #include "memory/allocation.inline.hpp"
  58 #include "memory/iterator.inline.hpp"
  59 #include "memory/metadataFactory.hpp"
  60 #include "memory/metaspaceClosure.hpp"
  61 #include "memory/oopFactory.hpp"
  62 #include "memory/resourceArea.hpp"
  63 #include "memory/universe.hpp"
  64 #include "oops/fieldStreams.inline.hpp"
  65 #include "oops/constantPool.hpp"
  66 #include "oops/instanceClassLoaderKlass.hpp"
  67 #include "oops/instanceKlass.inline.hpp"
  68 #include "oops/instanceMirrorKlass.hpp"
  69 #include "oops/instanceOop.hpp"
  70 #include "oops/instanceStackChunkKlass.hpp"
  71 #include "oops/klass.inline.hpp"
  72 #include "oops/markWord.hpp"
  73 #include "oops/method.hpp"
  74 #include "oops/oop.inline.hpp"
  75 #include "oops/recordComponent.hpp"
  76 #include "oops/symbol.hpp"
  77 #include "oops/inlineKlass.hpp"
  78 #include "oops/refArrayKlass.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/deoptimization.hpp"
  85 #include "runtime/atomic.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"
  98 #include "services/threadService.hpp"

 135 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait)     \
 136   {                                                              \
 137     char* data = nullptr;                                        \
 138     int len = 0;                                                 \
 139     Symbol* clss_name = name();                                  \
 140     if (clss_name != nullptr) {                                  \
 141       data = (char*)clss_name->bytes();                          \
 142       len = clss_name->utf8_length();                            \
 143     }                                                            \
 144     HOTSPOT_CLASS_INITIALIZATION_##type(                         \
 145       data, len, (void*)class_loader(), thread_type, wait);      \
 146   }
 147 
 148 #else //  ndef DTRACE_ENABLED
 149 
 150 #define DTRACE_CLASSINIT_PROBE(type, thread_type)
 151 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait)
 152 
 153 #endif //  ndef DTRACE_ENABLED
 154 
 155 void InlineLayoutInfo::metaspace_pointers_do(MetaspaceClosure* it) {
 156   log_trace(cds)("Iter(InlineFieldInfo): %p", this);
 157   it->push(&_klass);
 158 }
 159 
 160 bool InstanceKlass::_finalization_enabled = true;
 161 
 162 static inline bool is_class_loader(const Symbol* class_name,
 163                                    const ClassFileParser& parser) {
 164   assert(class_name != nullptr, "invariant");
 165 
 166   if (class_name == vmSymbols::java_lang_ClassLoader()) {
 167     return true;
 168   }
 169 
 170   if (vmClasses::ClassLoader_klass_loaded()) {
 171     const Klass* const super_klass = parser.super_klass();
 172     if (super_klass != nullptr) {
 173       if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
 174         return true;
 175       }
 176     }
 177   }
 178   return false;
 179 }
 180 
 181 bool InstanceKlass::field_is_null_free_inline_type(int index) const {
 182   return field(index).field_flags().is_null_free_inline_type();
 183 }
 184 
 185 bool InstanceKlass::is_class_in_loadable_descriptors_attribute(Symbol* name) const {
 186   if (_loadable_descriptors == nullptr) return false;
 187   for (int i = 0; i < _loadable_descriptors->length(); i++) {
 188         Symbol* class_name = _constants->symbol_at(_loadable_descriptors->at(i));
 189         if (class_name == name) return true;
 190   }
 191   return false;
 192 }
 193 
 194 static inline bool is_stack_chunk_class(const Symbol* class_name,
 195                                         const ClassLoaderData* loader_data) {
 196   return (class_name == vmSymbols::jdk_internal_vm_StackChunk() &&
 197           loader_data->is_the_null_class_loader_data());
 198 }
 199 
 200 // private: called to verify that k is a static member of this nest.
 201 // We know that k is an instance class in the same package and hence the
 202 // same classloader.
 203 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
 204   assert(!is_hidden(), "unexpected hidden class");
 205   if (_nest_members == nullptr || _nest_members == Universe::the_empty_short_array()) {
 206     if (log_is_enabled(Trace, class, nestmates)) {
 207       ResourceMark rm(current);
 208       log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
 209                                   k->external_name(), this->external_name());
 210     }
 211     return false;
 212   }
 213 

 468 }
 469 
 470 const char* InstanceKlass::nest_host_error() {
 471   if (_nest_host_index == 0) {
 472     return nullptr;
 473   } else {
 474     constantPoolHandle cph(Thread::current(), constants());
 475     return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
 476   }
 477 }
 478 
 479 void* InstanceKlass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size,
 480                                   bool use_class_space, TRAPS) throw() {
 481   return Metaspace::allocate(loader_data, word_size, ClassType, use_class_space, THREAD);
 482 }
 483 
 484 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
 485   const int size = InstanceKlass::size(parser.vtable_size(),
 486                                        parser.itable_size(),
 487                                        nonstatic_oop_map_size(parser.total_oop_map_count()),
 488                                        parser.is_interface(),
 489                                        parser.is_inline_type());
 490 
 491   const Symbol* const class_name = parser.class_name();
 492   assert(class_name != nullptr, "invariant");
 493   ClassLoaderData* loader_data = parser.loader_data();
 494   assert(loader_data != nullptr, "invariant");
 495 
 496   InstanceKlass* ik;
 497   const bool use_class_space = parser.klass_needs_narrow_id();
 498 
 499   // Allocation
 500   if (parser.is_instance_ref_klass()) {
 501     // java.lang.ref.Reference
 502     ik = new (loader_data, size, use_class_space, THREAD) InstanceRefKlass(parser);
 503   } else if (class_name == vmSymbols::java_lang_Class()) {
 504     // mirror - java.lang.Class
 505     ik = new (loader_data, size, use_class_space, THREAD) InstanceMirrorKlass(parser);
 506   } else if (is_stack_chunk_class(class_name, loader_data)) {
 507     // stack chunk
 508     ik = new (loader_data, size, use_class_space, THREAD) InstanceStackChunkKlass(parser);
 509   } else if (is_class_loader(class_name, parser)) {
 510     // class loader - java.lang.ClassLoader
 511     ik = new (loader_data, size, use_class_space, THREAD) InstanceClassLoaderKlass(parser);
 512   } else if (parser.is_inline_type()) {
 513     // inline type
 514     ik = new (loader_data, size, use_class_space, THREAD) InlineKlass(parser);
 515   } else {
 516     // normal
 517     ik = new (loader_data, size, use_class_space, THREAD) InstanceKlass(parser);
 518   }
 519 
 520   if (ik != nullptr && UseCompressedClassPointers && use_class_space) {
 521     assert(CompressedKlassPointers::is_encodable(ik),
 522            "Klass " PTR_FORMAT "needs a narrow Klass ID, but is not encodable", p2i(ik));
 523   }
 524 
 525   // Check for pending exception before adding to the loader data and incrementing
 526   // class count.  Can get OOM here.
 527   if (HAS_PENDING_EXCEPTION) {
 528     return nullptr;
 529   }
 530 
 531 #ifdef ASSERT
 532   ik->bounds_check((address) ik->start_of_vtable(), false, size);
 533   ik->bounds_check((address) ik->start_of_itable(), false, size);
 534   ik->bounds_check((address) ik->end_of_itable(), true, size);
 535   ik->bounds_check((address) ik->end_of_nonstatic_oop_maps(), true, size);
 536 #endif //ASSERT
 537   return ik;
 538 }
 539 
 540 #ifndef PRODUCT
 541 bool InstanceKlass::bounds_check(address addr, bool edge_ok, intptr_t size_in_bytes) const {
 542   const char* bad = nullptr;
 543   address end = nullptr;
 544   if (addr < (address)this) {
 545     bad = "before";
 546   } else if (addr == (address)this) {
 547     if (edge_ok)  return true;
 548     bad = "just before";
 549   } else if (addr == (end = (address)this + sizeof(intptr_t) * (size_in_bytes < 0 ? size() : size_in_bytes))) {
 550     if (edge_ok)  return true;
 551     bad = "just after";
 552   } else if (addr > end) {
 553     bad = "after";
 554   } else {
 555     return true;
 556   }
 557   tty->print_cr("%s object bounds: " INTPTR_FORMAT " [" INTPTR_FORMAT ".." INTPTR_FORMAT "]",
 558       bad, (intptr_t)addr, (intptr_t)this, (intptr_t)end);
 559   Verbose = WizardMode = true; this->print(); //@@
 560   return false;
 561 }
 562 #endif //PRODUCT
 563 
 564 // copy method ordering from resource area to Metaspace
 565 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
 566   if (m != nullptr) {
 567     // allocate a new array and copy contents (memcpy?)
 568     _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
 569     for (int i = 0; i < m->length(); i++) {
 570       _method_ordering->at_put(i, m->at(i));
 571     }
 572   } else {
 573     _method_ordering = Universe::the_empty_int_array();
 574   }
 575 }
 576 
 577 // create a new array of vtable_indices for default methods
 578 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
 579   Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
 580   assert(default_vtable_indices() == nullptr, "only create once");
 581   set_default_vtable_indices(vtable_indices);
 582   return vtable_indices;
 583 }
 584 
 585 
 586 InstanceKlass::InstanceKlass() {
 587   assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
 588 }
 589 
 590 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, markWord prototype_header, ReferenceType reference_type) :
 591   Klass(kind, prototype_header),
 592   _nest_members(nullptr),
 593   _nest_host(nullptr),
 594   _permitted_subclasses(nullptr),
 595   _record_components(nullptr),
 596   _static_field_size(parser.static_field_size()),
 597   _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
 598   _itable_len(parser.itable_size()),
 599   _nest_host_index(0),
 600   _init_state(allocated),
 601   _reference_type(reference_type),
 602   _init_thread(nullptr),
 603   _inline_layout_info_array(nullptr),
 604   _loadable_descriptors(nullptr),
 605   _adr_inlineklass_fixed_block(nullptr)
 606 {
 607   set_vtable_length(parser.vtable_size());
 608   set_access_flags(parser.access_flags());
 609   if (parser.is_hidden()) set_is_hidden();
 610   set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
 611                                                     false));
 612   if (parser.has_inline_fields()) {
 613     set_has_inline_type_fields();
 614   }
 615 
 616   assert(nullptr == _methods, "underlying memory not zeroed?");
 617   assert(is_instance_klass(), "is layout incorrect?");
 618   assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
 619 }
 620 
 621 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
 622                                        Array<Method*>* methods) {
 623   if (methods != nullptr && methods != Universe::the_empty_method_array() &&
 624       !methods->is_shared()) {
 625     for (int i = 0; i < methods->length(); i++) {
 626       Method* method = methods->at(i);
 627       if (method == nullptr) continue;  // maybe null if error processing
 628       // Only want to delete methods that are not executing for RedefineClasses.
 629       // The previous version will point to them so they're not totally dangling
 630       assert (!method->on_stack(), "shouldn't be called with methods on stack");
 631       MetadataFactory::free_metadata(loader_data, method);
 632     }
 633     MetadataFactory::free_array<Method*>(loader_data, methods);
 634   }

 739 
 740   deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
 741   set_transitive_interfaces(nullptr);
 742   set_local_interfaces(nullptr);
 743 
 744   if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->is_shared()) {
 745     MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
 746   }
 747   set_fieldinfo_stream(nullptr);
 748 
 749   if (fieldinfo_search_table() != nullptr && !fieldinfo_search_table()->is_shared()) {
 750     MetadataFactory::free_array<u1>(loader_data, fieldinfo_search_table());
 751   }
 752   set_fieldinfo_search_table(nullptr);
 753 
 754   if (fields_status() != nullptr && !fields_status()->is_shared()) {
 755     MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
 756   }
 757   set_fields_status(nullptr);
 758 
 759   if (inline_layout_info_array() != nullptr) {
 760     MetadataFactory::free_array<InlineLayoutInfo>(loader_data, inline_layout_info_array());
 761   }
 762   set_inline_layout_info_array(nullptr);
 763 
 764   // If a method from a redefined class is using this constant pool, don't
 765   // delete it, yet.  The new class's previous version will point to this.
 766   if (constants() != nullptr) {
 767     assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
 768     if (!constants()->is_shared()) {
 769       MetadataFactory::free_metadata(loader_data, constants());
 770     }
 771     // Delete any cached resolution errors for the constant pool
 772     SystemDictionary::delete_resolution_error(constants());
 773 
 774     set_constants(nullptr);
 775   }
 776 
 777   if (inner_classes() != nullptr &&
 778       inner_classes() != Universe::the_empty_short_array() &&
 779       !inner_classes()->is_shared()) {
 780     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
 781   }
 782   set_inner_classes(nullptr);
 783 
 784   if (nest_members() != nullptr &&
 785       nest_members() != Universe::the_empty_short_array() &&
 786       !nest_members()->is_shared()) {
 787     MetadataFactory::free_array<jushort>(loader_data, nest_members());
 788   }
 789   set_nest_members(nullptr);
 790 
 791   if (permitted_subclasses() != nullptr &&
 792       permitted_subclasses() != Universe::the_empty_short_array() &&
 793       !permitted_subclasses()->is_shared()) {
 794     MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
 795   }
 796   set_permitted_subclasses(nullptr);
 797 
 798   if (loadable_descriptors() != nullptr &&
 799       loadable_descriptors() != Universe::the_empty_short_array() &&
 800       !loadable_descriptors()->is_shared()) {
 801     MetadataFactory::free_array<jushort>(loader_data, loadable_descriptors());
 802   }
 803   set_loadable_descriptors(nullptr);
 804 
 805   // We should deallocate the Annotations instance if it's not in shared spaces.
 806   if (annotations() != nullptr && !annotations()->is_shared()) {
 807     MetadataFactory::free_metadata(loader_data, annotations());
 808   }
 809   set_annotations(nullptr);
 810 
 811   SystemDictionaryShared::handle_class_unloading(this);
 812 
 813 #if INCLUDE_CDS_JAVA_HEAP
 814   if (CDSConfig::is_dumping_heap()) {
 815     HeapShared::remove_scratch_objects(this);
 816   }
 817 #endif
 818 }
 819 
 820 bool InstanceKlass::is_record() const {
 821   return _record_components != nullptr &&
 822          is_final() &&
 823          java_super() == vmClasses::Record_klass();
 824 }

1024         vmSymbols::java_lang_IncompatibleClassChangeError(),
1025         "class %s has interface %s as super class",
1026         external_name(),
1027         super_klass->external_name()
1028       );
1029       return false;
1030     }
1031 
1032     InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
1033     ik_super->link_class_impl(CHECK_false);
1034   }
1035 
1036   // link all interfaces implemented by this class before linking this class
1037   Array<InstanceKlass*>* interfaces = local_interfaces();
1038   int num_interfaces = interfaces->length();
1039   for (int index = 0; index < num_interfaces; index++) {
1040     InstanceKlass* interk = interfaces->at(index);
1041     interk->link_class_impl(CHECK_false);
1042   }
1043 
1044 
1045   // If a class declares a method that uses an inline class as an argument
1046   // type or return inline type, this inline class must be loaded during the
1047   // linking of this class because size and properties of the inline class
1048   // must be known in order to be able to perform inline type optimizations.
1049   // The implementation below is an approximation of this rule, the code
1050   // iterates over all methods of the current class (including overridden
1051   // methods), not only the methods declared by this class. This
1052   // approximation makes the code simpler, and doesn't change the semantic
1053   // because classes declaring methods overridden by the current class are
1054   // linked (and have performed their own pre-loading) before the linking
1055   // of the current class.
1056 
1057 
1058   // Note:
1059   // Inline class types are loaded during
1060   // the loading phase (see ClassFileParser::post_process_parsed_stream()).
1061   // Inline class types used as element types for array creation
1062   // are not pre-loaded. Their loading is triggered by either anewarray
1063   // or multianewarray bytecodes.
1064 
1065   // Could it be possible to do the following processing only if the
1066   // class uses inline types?
1067   if (EnableValhalla) {
1068     ResourceMark rm(THREAD);
1069     for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1070       if (fs.is_null_free_inline_type() && fs.access_flags().is_static()) {
1071         assert(fs.access_flags().is_strict(), "null-free fields must be strict");
1072         Symbol* sig = fs.signature();
1073         TempNewSymbol s = Signature::strip_envelope(sig);
1074         if (s != name()) {
1075           log_info(class, preload)("Preloading of class %s during linking of class %s. Cause: a null-free static field is declared with this type", s->as_C_string(), name()->as_C_string());
1076           Klass* klass = SystemDictionary::resolve_or_fail(s,
1077                                                           Handle(THREAD, class_loader()), true,
1078                                                           CHECK_false);
1079           if (HAS_PENDING_EXCEPTION) {
1080             log_warning(class, preload)("Preloading of class %s during linking of class %s (cause: null-free static field) failed: %s",
1081                                       s->as_C_string(), name()->as_C_string(), PENDING_EXCEPTION->klass()->name()->as_C_string());
1082             return false; // Exception is still pending
1083           }
1084           log_info(class, preload)("Preloading of class %s during linking of class %s (cause: null-free static field) succeeded",
1085                                    s->as_C_string(), name()->as_C_string());
1086           assert(klass != nullptr, "Sanity check");
1087           if (klass->is_abstract()) {
1088             THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
1089                       err_msg("Class %s expects class %s to be concrete value class, but it is an abstract class",
1090                       name()->as_C_string(),
1091                       InstanceKlass::cast(klass)->external_name()), false);
1092           }
1093           if (!klass->is_inline_klass()) {
1094             THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
1095                        err_msg("class %s expects class %s to be a value class but it is an identity class",
1096                        name()->as_C_string(), klass->external_name()), false);
1097           }
1098           InlineKlass* vk = InlineKlass::cast(klass);
1099           // the inline_type_field_klasses_array might have been loaded with CDS, so update only if not already set and check consistency
1100           InlineLayoutInfo* li = inline_layout_info_adr(fs.index());
1101           if (li->klass() == nullptr) {
1102             li->set_klass(InlineKlass::cast(vk));
1103             li->set_kind(LayoutKind::REFERENCE);
1104           }
1105           assert(get_inline_type_field_klass(fs.index()) == vk, "Must match");
1106         } else {
1107           InlineLayoutInfo* li = inline_layout_info_adr(fs.index());
1108           if (li->klass() == nullptr) {
1109             li->set_klass(InlineKlass::cast(this));
1110             li->set_kind(LayoutKind::REFERENCE);
1111           }
1112           assert(get_inline_type_field_klass(fs.index()) == this, "Must match");
1113         }
1114       }
1115     }
1116 
1117     // Aggressively preloading all classes from the LoadableDescriptors attribute
1118     if (loadable_descriptors() != nullptr && PreloadClasses) {
1119       HandleMark hm(THREAD);
1120       for (int i = 0; i < loadable_descriptors()->length(); i++) {
1121         Symbol* sig = constants()->symbol_at(loadable_descriptors()->at(i));
1122         if (!Signature::has_envelope(sig)) continue;
1123         TempNewSymbol class_name = Signature::strip_envelope(sig);
1124         if (class_name == name()) continue;
1125         log_info(class, preload)("Preloading of class %s during linking of class %s because of the class is listed in the LoadableDescriptors attribute", sig->as_C_string(), name()->as_C_string());
1126         oop loader = class_loader();
1127         Klass* klass = SystemDictionary::resolve_or_null(class_name,
1128                                                          Handle(THREAD, loader), THREAD);
1129         if (HAS_PENDING_EXCEPTION) {
1130           CLEAR_PENDING_EXCEPTION;
1131         }
1132         if (klass != nullptr) {
1133           log_info(class, preload)("Preloading of class %s during linking of class %s (cause: LoadableDescriptors attribute) succeeded", class_name->as_C_string(), name()->as_C_string());
1134           if (!klass->is_inline_klass()) {
1135             // Non value class are allowed by the current spec, but it could be an indication of an issue so let's log a warning
1136             log_warning(class, preload)("Preloading of class %s during linking of class %s (cause: LoadableDescriptors attribute) but loaded class is not a value class", class_name->as_C_string(), name()->as_C_string());
1137           }
1138         } else {
1139           log_warning(class, preload)("Preloading of class %s during linking of class %s (cause: LoadableDescriptors attribute) failed", class_name->as_C_string(), name()->as_C_string());
1140         }
1141       }
1142     }
1143   }
1144 
1145   // in case the class is linked in the process of linking its superclasses
1146   if (is_linked()) {
1147     return true;
1148   }
1149 
1150   // trace only the link time for this klass that includes
1151   // the verification time
1152   PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
1153                              ClassLoader::perf_class_link_selftime(),
1154                              ClassLoader::perf_classes_linked(),
1155                              jt->get_thread_stat()->perf_recursion_counts_addr(),
1156                              jt->get_thread_stat()->perf_timers_addr(),
1157                              PerfClassTraceTime::CLASS_LINK);
1158 
1159   // verification & rewriting
1160   {
1161     HandleMark hm(THREAD);
1162     Handle h_init_lock(THREAD, init_lock());
1163     ObjectLocker ol(h_init_lock, jt);
1164     // rewritten will have been set if loader constraint error found

1429       ss.print("Could not initialize class %s", external_name());
1430       if (cause.is_null()) {
1431         THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1432       } else {
1433         THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1434                         ss.as_string(), cause);
1435       }
1436     } else {
1437 
1438       // Step 6
1439       set_init_state(being_initialized);
1440       set_init_thread(jt);
1441       if (debug_logging_enabled) {
1442         ResourceMark rm(jt);
1443         log_debug(class, init)("Thread \"%s\" is initializing %s",
1444                                jt->name(), external_name());
1445       }
1446     }
1447   }
1448 
1449   // Pre-allocating an all-zero value to be used to reset nullable flat storages
1450   if (is_inline_klass()) {
1451       InlineKlass* vk = InlineKlass::cast(this);
1452       if (vk->has_nullable_atomic_layout()) {
1453         oop val = vk->allocate_instance(THREAD);
1454         if (HAS_PENDING_EXCEPTION) {
1455             Handle e(THREAD, PENDING_EXCEPTION);
1456             CLEAR_PENDING_EXCEPTION;
1457             {
1458                 EXCEPTION_MARK;
1459                 add_initialization_error(THREAD, e);
1460                 // Locks object, set state, and notify all waiting threads
1461                 set_initialization_state_and_notify(initialization_error, THREAD);
1462                 CLEAR_PENDING_EXCEPTION;
1463             }
1464             THROW_OOP(e());
1465         }
1466         vk->set_null_reset_value(val);
1467       }
1468   }
1469 
1470   // Step 7
1471   // Next, if C is a class rather than an interface, initialize it's super class and super
1472   // interfaces.
1473   if (!is_interface()) {
1474     Klass* super_klass = super();
1475     if (super_klass != nullptr && super_klass->should_be_initialized()) {
1476       super_klass->initialize(THREAD);
1477     }
1478     // If C implements any interface that declares a non-static, concrete method,
1479     // the initialization of C triggers initialization of its super interfaces.
1480     // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1481     // having a superinterface that declares, non-static, concrete methods
1482     if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1483       initialize_super_interfaces(THREAD);
1484     }
1485 
1486     // If any exceptions, complete abruptly, throwing the same exception as above.
1487     if (HAS_PENDING_EXCEPTION) {
1488       Handle e(THREAD, PENDING_EXCEPTION);
1489       CLEAR_PENDING_EXCEPTION;
1490       {
1491         EXCEPTION_MARK;
1492         add_initialization_error(THREAD, e);
1493         // Locks object, set state, and notify all waiting threads
1494         set_initialization_state_and_notify(initialization_error, THREAD);
1495         CLEAR_PENDING_EXCEPTION;
1496       }
1497       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1498       THROW_OOP(e());
1499     }
1500   }
1501 

1502   // Step 8
1503   {
1504     DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1505     if (class_initializer() != nullptr) {
1506       // Timer includes any side effects of class initialization (resolution,
1507       // etc), but not recursive entry into call_class_initializer().
1508       PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1509                                ClassLoader::perf_class_init_selftime(),
1510                                ClassLoader::perf_classes_inited(),
1511                                jt->get_thread_stat()->perf_recursion_counts_addr(),
1512                                jt->get_thread_stat()->perf_timers_addr(),
1513                                PerfClassTraceTime::CLASS_CLINIT);
1514       call_class_initializer(THREAD);
1515     } else {
1516       // The elapsed time is so small it's not worth counting.
1517       if (UsePerfData) {
1518         ClassLoader::perf_classes_inited()->inc();
1519       }
1520       call_class_initializer(THREAD);
1521     }
1522 
1523     if (has_strict_static_fields() && !HAS_PENDING_EXCEPTION) {
1524       // Step 9 also verifies that strict static fields have been initialized.
1525       // Status bits were set in ClassFileParser::post_process_parsed_stream.
1526       // After <clinit>, bits must all be clear, or else we must throw an error.
1527       // This is an extremely fast check, so we won't bother with a timer.
1528       assert(fields_status() != nullptr, "");
1529       Symbol* bad_strict_static = nullptr;
1530       for (int index = 0; index < fields_status()->length(); index++) {
1531         // Very fast loop over single byte array looking for a set bit.
1532         if (fields_status()->adr_at(index)->is_strict_static_unset()) {
1533           // This strict static field has not been set by the class initializer.
1534           // Note that in the common no-error case, we read no field metadata.
1535           // We only unpack it when we need to report an error.
1536           FieldInfo fi = field(index);
1537           bad_strict_static = fi.name(constants());
1538           if (debug_logging_enabled) {
1539             ResourceMark rm(jt);
1540             const char* msg = format_strict_static_message(bad_strict_static);
1541             log_debug(class, init)("%s", msg);
1542           } else {
1543             // If we are not logging, do not bother to look for a second offense.
1544             break;
1545           }
1546         }
1547       }
1548       if (bad_strict_static != nullptr) {
1549         throw_strict_static_exception(bad_strict_static, "is unset after initialization of", THREAD);
1550       }
1551     }
1552   }
1553 
1554   // Step 9
1555   if (!HAS_PENDING_EXCEPTION) {
1556     set_initialization_state_and_notify(fully_initialized, CHECK);
1557     DEBUG_ONLY(vtable().verify(tty, true);)
1558     CompilationPolicy::replay_training_at_init(this, THREAD);
1559   }
1560   else {
1561     // Step 10 and 11
1562     Handle e(THREAD, PENDING_EXCEPTION);
1563     CLEAR_PENDING_EXCEPTION;
1564     // JVMTI has already reported the pending exception
1565     // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1566     JvmtiExport::clear_detected_exception(jt);
1567     {
1568       EXCEPTION_MARK;
1569       add_initialization_error(THREAD, e);
1570       set_initialization_state_and_notify(initialization_error, THREAD);
1571       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below

1585   }
1586   DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait);
1587 }
1588 
1589 
1590 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
1591   Handle h_init_lock(THREAD, init_lock());
1592   if (h_init_lock() != nullptr) {
1593     ObjectLocker ol(h_init_lock, THREAD);
1594     set_init_thread(nullptr); // reset _init_thread before changing _init_state
1595     set_init_state(state);
1596     fence_and_clear_init_lock();
1597     ol.notify_all(CHECK);
1598   } else {
1599     assert(h_init_lock() != nullptr, "The initialization state should never be set twice");
1600     set_init_thread(nullptr); // reset _init_thread before changing _init_state
1601     set_init_state(state);
1602   }
1603 }
1604 
1605 void InstanceKlass::notify_strict_static_access(int field_index, bool is_writing, TRAPS) {
1606   guarantee(field_index >= 0 && field_index < fields_status()->length(), "valid field index");
1607   DEBUG_ONLY(FieldInfo debugfi = field(field_index));
1608   assert(debugfi.access_flags().is_strict(), "");
1609   assert(debugfi.access_flags().is_static(), "");
1610   FieldStatus& fs = *fields_status()->adr_at(field_index);
1611   LogTarget(Trace, class, init) lt;
1612   if (lt.is_enabled()) {
1613     ResourceMark rm(THREAD);
1614     LogStream ls(lt);
1615     FieldInfo fi = field(field_index);
1616     ls.print("notify %s %s %s%s ",
1617              external_name(), is_writing? "Write" : "Read",
1618              fs.is_strict_static_unset() ? "Unset" : "(set)",
1619              fs.is_strict_static_unread() ? "+Unread" : "");
1620     fi.print(&ls, constants());
1621   }
1622   if (fs.is_strict_static_unset()) {
1623     assert(fs.is_strict_static_unread(), "ClassFileParser resp.");
1624     // If it is not set, there are only two reasonable things we can do here:
1625     // - mark it set if this is putstatic
1626     // - throw an error (Read-Before-Write) if this is getstatic
1627 
1628     // The unset state is (or should be) transient, and observable only in one
1629     // thread during the execution of <clinit>.  Something is wrong here as this
1630     // should not be possible
1631     guarantee(is_reentrant_initialization(THREAD), "unscoped access to strict static");
1632     if (is_writing) {
1633       // clear the "unset" bit, since the field is actually going to be written
1634       fs.update_strict_static_unset(false);
1635     } else {
1636       // throw an IllegalStateException, since we are reading before writing
1637       // see also InstanceKlass::initialize_impl, Step 8 (at end)
1638       Symbol* bad_strict_static = field(field_index).name(constants());
1639       throw_strict_static_exception(bad_strict_static, "is unset before first read in", CHECK);
1640     }
1641   } else {
1642     // Ensure no write after read for final strict statics
1643     FieldInfo fi = field(field_index);
1644     bool is_final = fi.access_flags().is_final();
1645     if (is_final) {
1646       // no final write after read, so observing a constant freezes it, as if <clinit> ended early
1647       // (maybe we could trust the constant a little earlier, before <clinit> ends)
1648       if (is_writing && !fs.is_strict_static_unread()) {
1649         Symbol* bad_strict_static = fi.name(constants());
1650         throw_strict_static_exception(bad_strict_static, "is set after read (as final) in", CHECK);
1651       } else if (!is_writing && fs.is_strict_static_unread()) {
1652         fs.update_strict_static_unread(false);
1653       }
1654     }
1655   }
1656 }
1657 
1658 void InstanceKlass::throw_strict_static_exception(Symbol* field_name, const char* when, TRAPS) {
1659   ResourceMark rm(THREAD);
1660   const char* msg = format_strict_static_message(field_name, when);
1661   THROW_MSG(vmSymbols::java_lang_IllegalStateException(), msg);
1662 }
1663 
1664 const char* InstanceKlass::format_strict_static_message(Symbol* field_name, const char* when) {
1665   stringStream ss;
1666   ss.print("Strict static \"%s\" %s %s",
1667            field_name->as_C_string(),
1668            when == nullptr ? "is unset in" : when,
1669            external_name());
1670   return ss.as_string();
1671 }
1672 
1673 // Update hierarchy. This is done before the new klass has been added to the SystemDictionary. The Compile_lock
1674 // is grabbed, to ensure that the compiler is not using the class hierarchy.
1675 void InstanceKlass::add_to_hierarchy(JavaThread* current) {
1676   assert(!SafepointSynchronize::is_at_safepoint(), "must NOT be at safepoint");
1677 
1678   DeoptimizationScope deopt_scope;
1679   {
1680     MutexLocker ml(current, Compile_lock);
1681 
1682     set_init_state(InstanceKlass::loaded);
1683     // make sure init_state store is already done.
1684     // The compiler reads the hierarchy outside of the Compile_lock.
1685     // Access ordering is used to add to hierarchy.
1686 
1687     // Link into hierarchy.
1688     append_to_sibling_list();                    // add to superklass/sibling list
1689     process_interfaces();                        // handle all "implements" declarations
1690 
1691     // Now mark all code that depended on old class hierarchy.
1692     // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)

1836   for (int i = 0; i < transitive_interfaces()->length(); i++) {
1837     if (transitive_interfaces()->at(i) == k) {
1838       return true;
1839     }
1840   }
1841   return false;
1842 }
1843 
1844 bool InstanceKlass::is_same_or_direct_interface(Klass *k) const {
1845   // Verify direct super interface
1846   if (this == k) return true;
1847   assert(k->is_interface(), "should be an interface class");
1848   for (int i = 0; i < local_interfaces()->length(); i++) {
1849     if (local_interfaces()->at(i) == k) {
1850       return true;
1851     }
1852   }
1853   return false;
1854 }
1855 
1856 objArrayOop InstanceKlass::allocate_objArray(int length, ArrayKlass::ArrayProperties props, TRAPS) {
1857   ArrayKlass* ak = array_klass(CHECK_NULL);
1858   return ObjArrayKlass::cast(ak)->allocate_instance(length, props, CHECK_NULL);




1859 }
1860 
1861 instanceOop InstanceKlass::register_finalizer(instanceOop i, TRAPS) {
1862   if (TraceFinalizerRegistration) {
1863     tty->print("Registered ");
1864     i->print_value_on(tty);
1865     tty->print_cr(" (" PTR_FORMAT ") as finalizable", p2i(i));
1866   }
1867   instanceHandle h_i(THREAD, i);
1868   // Pass the handle as argument, JavaCalls::call expects oop as jobjects
1869   JavaValue result(T_VOID);
1870   JavaCallArguments args(h_i);
1871   methodHandle mh(THREAD, Universe::finalizer_register_method());
1872   JavaCalls::call(&result, mh, &args, CHECK_NULL);
1873   MANAGEMENT_ONLY(FinalizerService::on_register(h_i(), THREAD);)
1874   return h_i();
1875 }
1876 
1877 instanceOop InstanceKlass::allocate_instance(TRAPS) {
1878   assert(!is_abstract() && !is_interface(), "Should not create this object");

1908               : vmSymbols::java_lang_IllegalAccessException(), external_name());
1909   }
1910 }
1911 
1912 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1913   // Need load-acquire for lock-free read
1914   if (array_klasses_acquire() == nullptr) {
1915 
1916     // Recursively lock array allocation
1917     RecursiveLocker rl(MultiArray_lock, THREAD);
1918 
1919     // Check if another thread created the array klass while we were waiting for the lock.
1920     if (array_klasses() == nullptr) {
1921       ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);
1922       // use 'release' to pair with lock-free load
1923       release_set_array_klasses(k);
1924     }
1925   }
1926 
1927   // array_klasses() will always be set at this point
1928   ArrayKlass* ak = array_klasses();
1929   assert(ak != nullptr, "should be set");
1930   return ak->array_klass(n, THREAD);
1931 }
1932 
1933 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1934   // Need load-acquire for lock-free read
1935   ArrayKlass* ak = array_klasses_acquire();
1936   if (ak == nullptr) {
1937     return nullptr;
1938   } else {
1939     return ak->array_klass_or_null(n);
1940   }
1941 }
1942 
1943 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1944   return array_klass(1, THREAD);
1945 }
1946 
1947 ArrayKlass* InstanceKlass::array_klass_or_null() {
1948   return array_klass_or_null(1);
1949 }
1950 
1951 static int call_class_initializer_counter = 0;   // for debugging
1952 
1953 Method* InstanceKlass::class_initializer() const {
1954   Method* clinit = find_method(
1955       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1956   if (clinit != nullptr && clinit->is_class_initializer()) {
1957     return clinit;
1958   }
1959   return nullptr;
1960 }
1961 
1962 void InstanceKlass::call_class_initializer(TRAPS) {
1963   if (ReplayCompiles &&
1964       (ReplaySuppressInitializers == 1 ||
1965        (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1966     // Hide the existence of the initializer for the purpose of replaying the compile
1967     return;
1968   }
1969 
1970 #if INCLUDE_CDS
1971   // This is needed to ensure the consistency of the archived heap objects.
1972   if (has_aot_initialized_mirror() && CDSConfig::is_loading_heap()) {
1973     AOTClassInitializer::call_runtime_setup(THREAD, this);
1974     return;
1975   } else if (has_archived_enum_objs()) {
1976     assert(is_shared(), "must be");

2045 
2046 void InstanceKlass::mask_for(const methodHandle& method, int bci,
2047   InterpreterOopMap* entry_for) {
2048   // Lazily create the _oop_map_cache at first request.
2049   // Load_acquire is needed to safely get instance published with CAS by another thread.
2050   OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
2051   if (oop_map_cache == nullptr) {
2052     // Try to install new instance atomically.
2053     oop_map_cache = new OopMapCache();
2054     OopMapCache* other = Atomic::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
2055     if (other != nullptr) {
2056       // Someone else managed to install before us, ditch local copy and use the existing one.
2057       delete oop_map_cache;
2058       oop_map_cache = other;
2059     }
2060   }
2061   // _oop_map_cache is constant after init; lookup below does its own locking.
2062   oop_map_cache->lookup(method, bci, entry_for);
2063 }
2064 




2065 
2066 FieldInfo InstanceKlass::field(int index) const {
2067   for (AllFieldStream fs(this); !fs.done(); fs.next()) {
2068     if (fs.index() == index) {
2069       return fs.to_FieldInfo();
2070     }
2071   }
2072   fatal("Field not found");
2073   return FieldInfo();
2074 }
2075 
2076 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
2077   JavaFieldStream fs(this);
2078   if (fs.lookup(name, sig)) {
2079     assert(fs.name() == name, "name must match");
2080     assert(fs.signature() == sig, "signature must match");
2081     fd->reinitialize(const_cast<InstanceKlass*>(this), fs.to_FieldInfo());
2082     return true;
2083   }
2084   return false;

2125 
2126 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
2127   // search order according to newest JVM spec (5.4.3.2, p.167).
2128   // 1) search for field in current klass
2129   if (find_local_field(name, sig, fd)) {
2130     if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
2131   }
2132   // 2) search for field recursively in direct superinterfaces
2133   if (is_static) {
2134     Klass* intf = find_interface_field(name, sig, fd);
2135     if (intf != nullptr) return intf;
2136   }
2137   // 3) apply field lookup recursively if superclass exists
2138   { Klass* supr = super();
2139     if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
2140   }
2141   // 4) otherwise field lookup fails
2142   return nullptr;
2143 }
2144 
2145 bool InstanceKlass::contains_field_offset(int offset) {
2146   if (this->is_inline_klass()) {
2147     InlineKlass* vk = InlineKlass::cast(this);
2148     return offset >= vk->payload_offset() && offset < (vk->payload_offset() + vk->payload_size_in_bytes());
2149   } else {
2150     fieldDescriptor fd;
2151     return find_field_from_offset(offset, false, &fd);
2152   }
2153 }
2154 
2155 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
2156   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
2157     if (fs.offset() == offset) {
2158       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.to_FieldInfo());
2159       if (fd->is_static() == is_static) return true;
2160     }
2161   }
2162   return false;
2163 }
2164 
2165 
2166 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
2167   Klass* klass = const_cast<InstanceKlass*>(this);
2168   while (klass != nullptr) {
2169     if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
2170       return true;
2171     }
2172     klass = klass->super();
2173   }

2517 }
2518 
2519 // uncached_lookup_method searches both the local class methods array and all
2520 // superclasses methods arrays, skipping any overpass methods in superclasses,
2521 // and possibly skipping private methods.
2522 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2523                                               const Symbol* signature,
2524                                               OverpassLookupMode overpass_mode,
2525                                               PrivateLookupMode private_mode) const {
2526   OverpassLookupMode overpass_local_mode = overpass_mode;
2527   const Klass* klass = this;
2528   while (klass != nullptr) {
2529     Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2530                                                                         signature,
2531                                                                         overpass_local_mode,
2532                                                                         StaticLookupMode::find,
2533                                                                         private_mode);
2534     if (method != nullptr) {
2535       return method;
2536     }
2537     if (name == vmSymbols::object_initializer_name()) {
2538       break;  // <init> is never inherited
2539     }
2540     klass = klass->super();
2541     overpass_local_mode = OverpassLookupMode::skip;   // Always ignore overpass methods in superclasses
2542   }
2543   return nullptr;
2544 }
2545 
2546 #ifdef ASSERT
2547 // search through class hierarchy and return true if this class or
2548 // one of the superclasses was redefined
2549 bool InstanceKlass::has_redefined_this_or_super() const {
2550   const Klass* klass = this;
2551   while (klass != nullptr) {
2552     if (InstanceKlass::cast(klass)->has_been_redefined()) {
2553       return true;
2554     }
2555     klass = klass->super();
2556   }
2557   return false;
2558 }
2559 #endif

2932     int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2933 
2934     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2935                          / itableOffsetEntry::size();
2936 
2937     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2938       if (ioe->interface_klass() != nullptr) {
2939         it->push(ioe->interface_klass_addr());
2940         itableMethodEntry* ime = ioe->first_method_entry(this);
2941         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2942         for (int index = 0; index < n; index ++) {
2943           it->push(ime[index].method_addr());
2944         }
2945       }
2946     }
2947   }
2948 
2949   it->push(&_nest_host);
2950   it->push(&_nest_members);
2951   it->push(&_permitted_subclasses);
2952   it->push(&_loadable_descriptors);
2953   it->push(&_record_components);
2954   it->push(&_inline_layout_info_array, MetaspaceClosure::_writable);
2955 }
2956 
2957 #if INCLUDE_CDS
2958 void InstanceKlass::remove_unshareable_info() {
2959 
2960   if (is_linked()) {
2961     assert(can_be_verified_at_dumptime(), "must be");
2962     // Remember this so we can avoid walking the hierarchy at runtime.
2963     set_verified_at_dump_time();
2964   }
2965 
2966   _misc_flags.set_has_init_deps_processed(false);
2967 
2968   Klass::remove_unshareable_info();
2969 
2970   if (SystemDictionaryShared::has_class_failed_verification(this)) {
2971     // Classes are attempted to link during dumping and may fail,
2972     // but these classes are still in the dictionary and class list in CLD.
2973     // If the class has failed verification, there is nothing else to remove.
2974     return;

2982 
2983   { // Otherwise this needs to take out the Compile_lock.
2984     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2985     init_implementor();
2986   }
2987 
2988   // Call remove_unshareable_info() on other objects that belong to this class, except
2989   // for constants()->remove_unshareable_info(), which is called in a separate pass in
2990   // ArchiveBuilder::make_klasses_shareable(),
2991 
2992   for (int i = 0; i < methods()->length(); i++) {
2993     Method* m = methods()->at(i);
2994     m->remove_unshareable_info();
2995   }
2996 
2997   // do array classes also.
2998   if (array_klasses() != nullptr) {
2999     array_klasses()->remove_unshareable_info();
3000   }
3001 
3002   // These are not allocated from metaspace. They are safe to set to nullptr.
3003   _source_debug_extension = nullptr;
3004   _dep_context = nullptr;
3005   _osr_nmethods_head = nullptr;
3006 #if INCLUDE_JVMTI
3007   _breakpoints = nullptr;
3008   _previous_versions = nullptr;
3009   _cached_class_file = nullptr;
3010   _jvmti_cached_class_field_map = nullptr;
3011 #endif
3012 
3013   _init_thread = nullptr;
3014   _methods_jmethod_ids = nullptr;
3015   _jni_ids = nullptr;
3016   _oop_map_cache = nullptr;
3017   if (CDSConfig::is_dumping_method_handles() && HeapShared::is_lambda_proxy_klass(this)) {
3018     // keep _nest_host
3019   } else {
3020     // clear _nest_host to ensure re-load at runtime
3021     _nest_host = nullptr;
3022   }

3073 void InstanceKlass::compute_has_loops_flag_for_methods() {
3074   Array<Method*>* methods = this->methods();
3075   for (int index = 0; index < methods->length(); ++index) {
3076     Method* m = methods->at(index);
3077     if (!m->is_overpass()) { // work around JDK-8305771
3078       m->compute_has_loops_flag();
3079     }
3080   }
3081 }
3082 
3083 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
3084                                              PackageEntry* pkg_entry, TRAPS) {
3085   // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
3086   // before the InstanceKlass is added to the SystemDictionary. Make
3087   // sure the current state is <loaded.
3088   assert(!is_loaded(), "invalid init state");
3089   assert(!shared_loading_failed(), "Must not try to load failed class again");
3090   set_package(loader_data, pkg_entry, CHECK);
3091   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
3092 
3093   if (is_inline_klass()) {
3094     InlineKlass::cast(this)->initialize_calling_convention(CHECK);
3095   }
3096 
3097   Array<Method*>* methods = this->methods();
3098   int num_methods = methods->length();
3099   for (int index = 0; index < num_methods; ++index) {
3100     methods->at(index)->restore_unshareable_info(CHECK);
3101   }
3102 #if INCLUDE_JVMTI
3103   if (JvmtiExport::has_redefined_a_class()) {
3104     // Reinitialize vtable because RedefineClasses may have changed some
3105     // entries in this vtable for super classes so the CDS vtable might
3106     // point to old or obsolete entries.  RedefineClasses doesn't fix up
3107     // vtables in the shared system dictionary, only the main one.
3108     // It also redefines the itable too so fix that too.
3109     // First fix any default methods that point to a super class that may
3110     // have been redefined.
3111     bool trace_name_printed = false;
3112     adjust_default_methods(&trace_name_printed);
3113     if (verified_at_dump_time()) {
3114       // Initialize vtable and itable for classes which can be verified at dump time.
3115       // Unlinked classes such as old classes with major version < 50 cannot be verified
3116       // at dump time.
3117       vtable().initialize_vtable();
3118       itable().initialize_itable();
3119     }
3120   }
3121 #endif // INCLUDE_JVMTI
3122 
3123   // restore constant pool resolved references
3124   constants()->restore_unshareable_info(CHECK);
3125 
3126   if (array_klasses() != nullptr) {
3127     // To get a consistent list of classes we need MultiArray_lock to ensure
3128     // array classes aren't observed while they are being restored.
3129     RecursiveLocker rl(MultiArray_lock, THREAD);
3130     assert(this == ObjArrayKlass::cast(array_klasses())->bottom_klass(), "sanity");
3131     // Array classes have null protection domain.
3132     // --> see ArrayKlass::complete_create_array_klass()
3133     if (class_loader_data() == nullptr) {
3134       ResourceMark rm(THREAD);
3135       log_debug(cds)("  loader_data %s ", loader_data == nullptr ? "nullptr" : "non null");
3136       log_debug(cds)("  this %s array_klasses %s ", this->name()->as_C_string(), array_klasses()->name()->as_C_string());
3137     }
3138     assert(!array_klasses()->is_refined_objArray_klass(), "must be non-refined objarrayklass");
3139     array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
3140   }
3141 
3142   // Initialize @ValueBased class annotation if not already set in the archived klass.
3143   if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
3144     set_is_value_based();
3145   }
3146 
3147   DEBUG_ONLY(FieldInfoStream::validate_search_table(_constants, _fieldinfo_stream, _fieldinfo_search_table));
3148 }
3149 
3150 // Check if a class or any of its supertypes has a version older than 50.
3151 // CDS will not perform verification of old classes during dump time because
3152 // without changing the old verifier, the verification constraint cannot be
3153 // retrieved during dump time.
3154 // Verification of archived old classes will be performed during run time.
3155 bool InstanceKlass::can_be_verified_at_dumptime() const {
3156   if (MetaspaceShared::is_in_shared_metaspace(this)) {
3157     // This is a class that was dumped into the base archive, so we know
3158     // it was verified at dump time.

3272     constants()->release_C_heap_structures();
3273   }
3274 }
3275 
3276 // The constant pool is on stack if any of the methods are executing or
3277 // referenced by handles.
3278 bool InstanceKlass::on_stack() const {
3279   return _constants->on_stack();
3280 }
3281 
3282 Symbol* InstanceKlass::source_file_name() const               { return _constants->source_file_name(); }
3283 u2 InstanceKlass::source_file_name_index() const              { return _constants->source_file_name_index(); }
3284 void InstanceKlass::set_source_file_name_index(u2 sourcefile_index) { _constants->set_source_file_name_index(sourcefile_index); }
3285 
3286 // minor and major version numbers of class file
3287 u2 InstanceKlass::minor_version() const                 { return _constants->minor_version(); }
3288 void InstanceKlass::set_minor_version(u2 minor_version) { _constants->set_minor_version(minor_version); }
3289 u2 InstanceKlass::major_version() const                 { return _constants->major_version(); }
3290 void InstanceKlass::set_major_version(u2 major_version) { _constants->set_major_version(major_version); }
3291 
3292 bool InstanceKlass::supports_inline_types() const {
3293   return major_version() >= Verifier::VALUE_TYPES_MAJOR_VERSION && minor_version() == Verifier::JAVA_PREVIEW_MINOR_VERSION;
3294 }
3295 
3296 const InstanceKlass* InstanceKlass::get_klass_version(int version) const {
3297   for (const InstanceKlass* ik = this; ik != nullptr; ik = ik->previous_versions()) {
3298     if (ik->constants()->version() == version) {
3299       return ik;
3300     }
3301   }
3302   return nullptr;
3303 }
3304 
3305 void InstanceKlass::set_source_debug_extension(const char* array, int length) {
3306   if (array == nullptr) {
3307     _source_debug_extension = nullptr;
3308   } else {
3309     // Adding one to the attribute length in order to store a null terminator
3310     // character could cause an overflow because the attribute length is
3311     // already coded with an u4 in the classfile, but in practice, it's
3312     // unlikely to happen.
3313     assert((length+1) > length, "Overflow checking");
3314     char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
3315     for (int i = 0; i < length; i++) {
3316       sde[i] = array[i];
3317     }
3318     sde[length] = '\0';
3319     _source_debug_extension = sde;
3320   }
3321 }
3322 
3323 Symbol* InstanceKlass::generic_signature() const                   { return _constants->generic_signature(); }
3324 u2 InstanceKlass::generic_signature_index() const                  { return _constants->generic_signature_index(); }
3325 void InstanceKlass::set_generic_signature_index(u2 sig_index)      { _constants->set_generic_signature_index(sig_index); }
3326 
3327 const char* InstanceKlass::signature_name() const {
3328   return signature_name_of_carrier(JVM_SIGNATURE_CLASS);
3329 }
3330 
3331 const char* InstanceKlass::signature_name_of_carrier(char c) const {
3332   // Get the internal name as a c string
3333   const char* src = (const char*) (name()->as_C_string());
3334   const int src_length = (int)strlen(src);
3335 
3336   char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
3337 
3338   // Add L or Q as type indicator
3339   int dest_index = 0;
3340   dest[dest_index++] = c;
3341 
3342   // Add the actual class name
3343   for (int src_index = 0; src_index < src_length; ) {
3344     dest[dest_index++] = src[src_index++];
3345   }
3346 
3347   if (is_hidden()) { // Replace the last '+' with a '.'.
3348     for (int index = (int)src_length; index > 0; index--) {
3349       if (dest[index] == '+') {
3350         dest[index] = JVM_SIGNATURE_DOT;
3351         break;
3352       }
3353     }
3354   }
3355 
3356   // Add the semicolon and the null
3357   dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
3358   dest[dest_index] = '\0';
3359   return dest;
3360 }

3601 bool InstanceKlass::find_inner_classes_attr(int* ooff, int* noff, TRAPS) const {
3602   constantPoolHandle i_cp(THREAD, constants());
3603   for (InnerClassesIterator iter(this); !iter.done(); iter.next()) {
3604     int ioff = iter.inner_class_info_index();
3605     if (ioff != 0) {
3606       // Check to see if the name matches the class we're looking for
3607       // before attempting to find the class.
3608       if (i_cp->klass_name_at_matches(this, ioff)) {
3609         Klass* inner_klass = i_cp->klass_at(ioff, CHECK_false);
3610         if (this == inner_klass) {
3611           *ooff = iter.outer_class_info_index();
3612           *noff = iter.inner_name_index();
3613           return true;
3614         }
3615       }
3616     }
3617   }
3618   return false;
3619 }
3620 
3621 void InstanceKlass::check_can_be_annotated_with_NullRestricted(InstanceKlass* type, Symbol* container_klass_name, TRAPS) {
3622   assert(type->is_instance_klass(), "Sanity check");
3623   if (type->is_identity_class()) {
3624     ResourceMark rm(THREAD);
3625     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
3626               err_msg("Class %s expects class %s to be a value class, but it is an identity class",
3627               container_klass_name->as_C_string(),
3628               type->external_name()));
3629   }
3630 
3631   if (type->is_abstract()) {
3632     ResourceMark rm(THREAD);
3633     THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
3634               err_msg("Class %s expects class %s to be concrete value type, but it is an abstract class",
3635               container_klass_name->as_C_string(),
3636               type->external_name()));
3637   }
3638 }
3639 
3640 InstanceKlass* InstanceKlass::compute_enclosing_class(bool* inner_is_member, TRAPS) const {
3641   InstanceKlass* outer_klass = nullptr;
3642   *inner_is_member = false;
3643   int ooff = 0, noff = 0;
3644   bool has_inner_classes_attr = find_inner_classes_attr(&ooff, &noff, THREAD);
3645   if (has_inner_classes_attr) {
3646     constantPoolHandle i_cp(THREAD, constants());
3647     if (ooff != 0) {
3648       Klass* ok = i_cp->klass_at(ooff, CHECK_NULL);
3649       if (!ok->is_instance_klass()) {
3650         // If the outer class is not an instance klass then it cannot have
3651         // declared any inner classes.
3652         ResourceMark rm(THREAD);
3653         // Names are all known to be < 64k so we know this formatted message is not excessively large.
3654         Exceptions::fthrow(
3655           THREAD_AND_LOCATION,
3656           vmSymbols::java_lang_IncompatibleClassChangeError(),
3657           "%s and %s disagree on InnerClasses attribute",
3658           ok->external_name(),
3659           external_name());

3686 u2 InstanceKlass::compute_modifier_flags() const {
3687   u2 access = access_flags().as_unsigned_short();
3688 
3689   // But check if it happens to be member class.
3690   InnerClassesIterator iter(this);
3691   for (; !iter.done(); iter.next()) {
3692     int ioff = iter.inner_class_info_index();
3693     // Inner class attribute can be zero, skip it.
3694     // Strange but true:  JVM spec. allows null inner class refs.
3695     if (ioff == 0) continue;
3696 
3697     // only look at classes that are already loaded
3698     // since we are looking for the flags for our self.
3699     Symbol* inner_name = constants()->klass_name_at(ioff);
3700     if (name() == inner_name) {
3701       // This is really a member class.
3702       access = iter.inner_access_flags();
3703       break;
3704     }
3705   }
3706   return access;

3707 }
3708 
3709 jint InstanceKlass::jvmti_class_status() const {
3710   jint result = 0;
3711 
3712   if (is_linked()) {
3713     result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3714   }
3715 
3716   if (is_initialized()) {
3717     assert(is_linked(), "Class status is not consistent");
3718     result |= JVMTI_CLASS_STATUS_INITIALIZED;
3719   }
3720   if (is_in_error_state()) {
3721     result |= JVMTI_CLASS_STATUS_ERROR;
3722   }
3723   return result;
3724 }
3725 
3726 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {

3940     }
3941     osr = osr->osr_link();
3942   }
3943 
3944   assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3945   if (best != nullptr && best->comp_level() >= comp_level) {
3946     return best;
3947   }
3948   return nullptr;
3949 }
3950 
3951 // -----------------------------------------------------------------------------------------------------
3952 // Printing
3953 
3954 #define BULLET  " - "
3955 
3956 static const char* state_names[] = {
3957   "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3958 };
3959 
3960 static void print_vtable(address self, intptr_t* start, int len, outputStream* st) {
3961   ResourceMark rm;
3962   int* forward_refs = NEW_RESOURCE_ARRAY(int, len);
3963   for (int i = 0; i < len; i++)  forward_refs[i] = 0;
3964   for (int i = 0; i < len; i++) {
3965     intptr_t e = start[i];
3966     st->print("%d : " INTPTR_FORMAT, i, e);
3967     if (forward_refs[i] != 0) {
3968       int from = forward_refs[i];
3969       int off = (int) start[from];
3970       st->print(" (offset %d <= [%d])", off, from);
3971     }
3972     if (MetaspaceObj::is_valid((Metadata*)e)) {
3973       st->print(" ");
3974       ((Metadata*)e)->print_value_on(st);
3975     } else if (self != nullptr && e > 0 && e < 0x10000) {
3976       address location = self + e;
3977       int index = (int)((intptr_t*)location - start);
3978       st->print(" (offset %d => [%d])", (int)e, index);
3979       if (index >= 0 && index < len)
3980         forward_refs[index] = i;
3981     }
3982     st->cr();
3983   }
3984 }
3985 
3986 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3987   return print_vtable(nullptr, reinterpret_cast<intptr_t*>(start), len, st);
3988 }
3989 
3990 template<typename T>
3991  static void print_array_on(outputStream* st, Array<T>* array) {
3992    if (array == nullptr) { st->print_cr("nullptr"); return; }
3993    array->print_value_on(st); st->cr();
3994    if (Verbose || WizardMode) {
3995      for (int i = 0; i < array->length(); i++) {
3996        st->print("%d : ", i); array->at(i)->print_value_on(st); st->cr();
3997      }
3998    }
3999  }
4000 
4001 static void print_array_on(outputStream* st, Array<int>* array) {
4002   if (array == nullptr) { st->print_cr("nullptr"); return; }
4003   array->print_value_on(st); st->cr();
4004   if (Verbose || WizardMode) {
4005     for (int i = 0; i < array->length(); i++) {
4006       st->print("%d : %d", i, array->at(i)); st->cr();
4007     }
4008   }
4009 }
4010 
4011 const char* InstanceKlass::init_state_name() const {
4012   return state_names[init_state()];
4013 }
4014 
4015 void InstanceKlass::print_on(outputStream* st) const {
4016   assert(is_klass(), "must be klass");
4017   Klass::print_on(st);
4018 
4019   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
4020   st->print(BULLET"klass size:        %d", size());                               st->cr();
4021   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
4022   st->print(BULLET"flags:             "); _misc_flags.print_on(st);               st->cr();
4023   st->print(BULLET"state:             "); st->print_cr("%s", init_state_name());
4024   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
4025   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
4026   st->print(BULLET"sub:               ");
4027   Klass* sub = subklass();
4028   int n;
4029   for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
4030     if (n < MaxSubklassPrintSize) {
4031       sub->print_value_on(st);
4032       st->print("   ");
4033     }
4034   }
4035   if (n >= MaxSubklassPrintSize) st->print("(%zd more klasses...)", n - MaxSubklassPrintSize);
4036   st->cr();
4037 
4038   if (is_interface()) {
4039     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
4040     if (nof_implementors() == 1) {
4041       st->print_cr(BULLET"implementor:    ");
4042       st->print("   ");
4043       implementor()->print_value_on(st);
4044       st->cr();
4045     }
4046   }
4047 
4048   st->print(BULLET"arrays:            "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
4049   st->print(BULLET"methods:           "); print_array_on(st, methods());
4050   st->print(BULLET"method ordering:   "); print_array_on(st, method_ordering());






4051   if (default_methods() != nullptr) {
4052     st->print(BULLET"default_methods:   "); print_array_on(st, default_methods());






4053   }
4054   print_on_maybe_null(st, BULLET"default vtable indices:   ", default_vtable_indices());
4055   st->print(BULLET"local interfaces:  "); local_interfaces()->print_value_on(st);      st->cr();
4056   st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
4057 
4058   st->print(BULLET"secondary supers: "); secondary_supers()->print_value_on(st); st->cr();
4059 
4060   st->print(BULLET"hash_slot:         %d", hash_slot()); st->cr();
4061   st->print(BULLET"secondary bitmap: " UINTX_FORMAT_X_0, _secondary_supers_bitmap); st->cr();
4062 
4063   if (secondary_supers() != nullptr) {
4064     if (Verbose) {
4065       bool is_hashed = (_secondary_supers_bitmap != SECONDARY_SUPERS_BITMAP_FULL);
4066       st->print_cr(BULLET"---- secondary supers (%d words):", _secondary_supers->length());
4067       for (int i = 0; i < _secondary_supers->length(); i++) {
4068         ResourceMark rm; // for external_name()
4069         Klass* secondary_super = _secondary_supers->at(i);
4070         st->print(BULLET"%2d:", i);
4071         if (is_hashed) {
4072           int home_slot = compute_home_slot(secondary_super, _secondary_supers_bitmap);

4092   print_on_maybe_null(st, BULLET"field type annotations:  ", fields_type_annotations());
4093   {
4094     bool have_pv = false;
4095     // previous versions are linked together through the InstanceKlass
4096     for (InstanceKlass* pv_node = previous_versions();
4097          pv_node != nullptr;
4098          pv_node = pv_node->previous_versions()) {
4099       if (!have_pv)
4100         st->print(BULLET"previous version:  ");
4101       have_pv = true;
4102       pv_node->constants()->print_value_on(st);
4103     }
4104     if (have_pv) st->cr();
4105   }
4106 
4107   print_on_maybe_null(st, BULLET"generic signature: ", generic_signature());
4108   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
4109   st->print(BULLET"nest members:     "); nest_members()->print_value_on(st);     st->cr();
4110   print_on_maybe_null(st, BULLET"record components:     ", record_components());
4111   st->print(BULLET"permitted subclasses:     "); permitted_subclasses()->print_value_on(st);     st->cr();
4112   st->print(BULLET"loadable descriptors:     "); loadable_descriptors()->print_value_on(st); st->cr();
4113   if (java_mirror() != nullptr) {
4114     st->print(BULLET"java mirror:       ");
4115     java_mirror()->print_value_on(st);
4116     st->cr();
4117   } else {
4118     st->print_cr(BULLET"java mirror:       null");
4119   }
4120   st->print(BULLET"vtable length      %d  (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
4121   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
4122   st->print(BULLET"itable length      %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
4123   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(nullptr, start_of_itable(), itable_length(), st);
4124   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
4125 
4126   FieldPrinter print_static_field(st);
4127   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
4128   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
4129   FieldPrinter print_nonstatic_field(st);
4130   InstanceKlass* ik = const_cast<InstanceKlass*>(this);
4131   ik->print_nonstatic_fields(&print_nonstatic_field);
4132 
4133   st->print(BULLET"non-static oop maps (%d entries): ", nonstatic_oop_map_count());
4134   OopMapBlock* map     = start_of_nonstatic_oop_maps();
4135   OopMapBlock* end_map = map + nonstatic_oop_map_count();
4136   while (map < end_map) {
4137     st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
4138     map++;
4139   }
4140   st->cr();
4141 
4142   if (fieldinfo_search_table() != nullptr) {
4143     st->print_cr(BULLET"---- field info search table:");
4144     FieldInfoStream::print_search_table(st, _constants, _fieldinfo_stream, _fieldinfo_search_table);
4145   }
4146 }
4147 
4148 void InstanceKlass::print_value_on(outputStream* st) const {
4149   assert(is_klass(), "must be klass");
4150   if (Verbose || WizardMode)  access_flags().print_on(st);
4151   name()->print_value_on(st);
4152 }
4153 
4154 void FieldPrinter::do_field(fieldDescriptor* fd) {
4155   for (int i = 0; i < _indent; i++) _st->print("  ");
4156   _st->print(BULLET);
4157    if (_obj == nullptr) {
4158      fd->print_on(_st, _base_offset);
4159      _st->cr();
4160    } else {
4161      fd->print_on_for(_st, _obj, _indent, _base_offset);
4162      if (!fd->field_flags().is_flat()) _st->cr();
4163    }
4164 }
4165 
4166 
4167 void InstanceKlass::oop_print_on(oop obj, outputStream* st, int indent, int base_offset) {
4168   Klass::oop_print_on(obj, st);
4169 
4170   if (this == vmClasses::String_klass()) {
4171     typeArrayOop value  = java_lang_String::value(obj);
4172     juint        length = java_lang_String::length(obj);
4173     if (value != nullptr &&
4174         value->is_typeArray() &&
4175         length <= (juint) value->length()) {
4176       st->print(BULLET"string: ");
4177       java_lang_String::print(obj, st);
4178       st->cr();
4179     }
4180   }
4181 
4182   st->print_cr(BULLET"---- fields (total size %zu words):", oop_size(obj));
4183   FieldPrinter print_field(st, obj, indent, base_offset);
4184   print_nonstatic_fields(&print_field);
4185 
4186   if (this == vmClasses::Class_klass()) {
4187     st->print(BULLET"signature: ");
4188     java_lang_Class::print_signature(obj, st);
4189     st->cr();
4190     Klass* real_klass = java_lang_Class::as_Klass(obj);
4191     if (real_klass != nullptr && real_klass->is_instance_klass()) {
4192       st->print_cr(BULLET"---- static fields (%d):", java_lang_Class::static_oop_field_count(obj));
4193       InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field);
4194     }
4195   } else if (this == vmClasses::MethodType_klass()) {
4196     st->print(BULLET"signature: ");
4197     java_lang_invoke_MethodType::print_signature(obj, st);
4198     st->cr();
4199   }
4200 }
4201 
4202 #ifndef PRODUCT
4203 
< prev index next >