< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page

  55 #include "logging/logStream.hpp"
  56 #include "memory/allocation.inline.hpp"
  57 #include "memory/iterator.inline.hpp"
  58 #include "memory/metadataFactory.hpp"
  59 #include "memory/metaspaceClosure.hpp"
  60 #include "memory/oopFactory.hpp"
  61 #include "memory/resourceArea.hpp"
  62 #include "memory/universe.hpp"
  63 #include "oops/fieldStreams.inline.hpp"
  64 #include "oops/constantPool.hpp"
  65 #include "oops/instanceClassLoaderKlass.hpp"
  66 #include "oops/instanceKlass.inline.hpp"
  67 #include "oops/instanceMirrorKlass.hpp"
  68 #include "oops/instanceOop.hpp"
  69 #include "oops/instanceStackChunkKlass.hpp"
  70 #include "oops/klass.inline.hpp"
  71 #include "oops/method.hpp"
  72 #include "oops/oop.inline.hpp"
  73 #include "oops/recordComponent.hpp"
  74 #include "oops/symbol.hpp"

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

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





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













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

 429 }
 430 
 431 const char* InstanceKlass::nest_host_error() {
 432   if (_nest_host_index == 0) {
 433     return nullptr;
 434   } else {
 435     constantPoolHandle cph(Thread::current(), constants());
 436     return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
 437   }
 438 }
 439 
 440 void* InstanceKlass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size,
 441                                   bool use_class_space, TRAPS) throw() {
 442   return Metaspace::allocate(loader_data, word_size, ClassType, use_class_space, THREAD);
 443 }
 444 
 445 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
 446   const int size = InstanceKlass::size(parser.vtable_size(),
 447                                        parser.itable_size(),
 448                                        nonstatic_oop_map_size(parser.total_oop_map_count()),
 449                                        parser.is_interface());

 450 
 451   const Symbol* const class_name = parser.class_name();
 452   assert(class_name != nullptr, "invariant");
 453   ClassLoaderData* loader_data = parser.loader_data();
 454   assert(loader_data != nullptr, "invariant");
 455 
 456   InstanceKlass* ik;
 457   const bool use_class_space = !parser.is_interface() && !parser.is_abstract();
 458 
 459   // Allocation
 460   if (parser.is_instance_ref_klass()) {
 461     // java.lang.ref.Reference
 462     ik = new (loader_data, size, use_class_space, THREAD) InstanceRefKlass(parser);
 463   } else if (class_name == vmSymbols::java_lang_Class()) {
 464     // mirror - java.lang.Class
 465     ik = new (loader_data, size, use_class_space, THREAD) InstanceMirrorKlass(parser);
 466   } else if (is_stack_chunk_class(class_name, loader_data)) {
 467     // stack chunk
 468     ik = new (loader_data, size, use_class_space, THREAD) InstanceStackChunkKlass(parser);
 469   } else if (is_class_loader(class_name, parser)) {
 470     // class loader - java.lang.ClassLoader
 471     ik = new (loader_data, size, use_class_space, THREAD) InstanceClassLoaderKlass(parser);



 472   } else {
 473     // normal
 474     ik = new (loader_data, size, use_class_space, THREAD) InstanceKlass(parser);
 475   }
 476 
 477   // Check for pending exception before adding to the loader data and incrementing
 478   // class count.  Can get OOM here.
 479   if (HAS_PENDING_EXCEPTION) {
 480     return nullptr;
 481   }
 482 






 483   return ik;
 484 }
 485 























 486 
 487 // copy method ordering from resource area to Metaspace
 488 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
 489   if (m != nullptr) {
 490     // allocate a new array and copy contents (memcpy?)
 491     _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
 492     for (int i = 0; i < m->length(); i++) {
 493       _method_ordering->at_put(i, m->at(i));
 494     }
 495   } else {
 496     _method_ordering = Universe::the_empty_int_array();
 497   }
 498 }
 499 
 500 // create a new array of vtable_indices for default methods
 501 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
 502   Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
 503   assert(default_vtable_indices() == nullptr, "only create once");
 504   set_default_vtable_indices(vtable_indices);
 505   return vtable_indices;
 506 }
 507 
 508 
 509 InstanceKlass::InstanceKlass() {
 510   assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
 511 }
 512 
 513 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) :
 514   Klass(kind),
 515   _nest_members(nullptr),
 516   _nest_host(nullptr),
 517   _permitted_subclasses(nullptr),
 518   _record_components(nullptr),
 519   _static_field_size(parser.static_field_size()),
 520   _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
 521   _itable_len(parser.itable_size()),
 522   _nest_host_index(0),
 523   _init_state(allocated),
 524   _reference_type(reference_type),
 525   _init_thread(nullptr)



 526 {
 527   set_vtable_length(parser.vtable_size());
 528   set_access_flags(parser.access_flags());
 529   if (parser.is_hidden()) set_is_hidden();
 530   set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
 531                                                     false));



 532 
 533   assert(nullptr == _methods, "underlying memory not zeroed?");
 534   assert(is_instance_klass(), "is layout incorrect?");
 535   assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
 536 }
 537 
 538 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
 539                                        Array<Method*>* methods) {
 540   if (methods != nullptr && methods != Universe::the_empty_method_array() &&
 541       !methods->is_shared()) {
 542     for (int i = 0; i < methods->length(); i++) {
 543       Method* method = methods->at(i);
 544       if (method == nullptr) continue;  // maybe null if error processing
 545       // Only want to delete methods that are not executing for RedefineClasses.
 546       // The previous version will point to them so they're not totally dangling
 547       assert (!method->on_stack(), "shouldn't be called with methods on stack");
 548       MetadataFactory::free_metadata(loader_data, method);
 549     }
 550     MetadataFactory::free_array<Method*>(loader_data, methods);
 551   }

 651       (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
 652       !secondary_supers()->is_shared()) {
 653     MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
 654   }
 655   set_secondary_supers(nullptr);
 656 
 657   deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
 658   set_transitive_interfaces(nullptr);
 659   set_local_interfaces(nullptr);
 660 
 661   if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->is_shared()) {
 662     MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
 663   }
 664   set_fieldinfo_stream(nullptr);
 665 
 666   if (fields_status() != nullptr && !fields_status()->is_shared()) {
 667     MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
 668   }
 669   set_fields_status(nullptr);
 670 





 671   // If a method from a redefined class is using this constant pool, don't
 672   // delete it, yet.  The new class's previous version will point to this.
 673   if (constants() != nullptr) {
 674     assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
 675     if (!constants()->is_shared()) {
 676       MetadataFactory::free_metadata(loader_data, constants());
 677     }
 678     // Delete any cached resolution errors for the constant pool
 679     SystemDictionary::delete_resolution_error(constants());
 680 
 681     set_constants(nullptr);
 682   }
 683 
 684   if (inner_classes() != nullptr &&
 685       inner_classes() != Universe::the_empty_short_array() &&
 686       !inner_classes()->is_shared()) {
 687     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
 688   }
 689   set_inner_classes(nullptr);
 690 
 691   if (nest_members() != nullptr &&
 692       nest_members() != Universe::the_empty_short_array() &&
 693       !nest_members()->is_shared()) {
 694     MetadataFactory::free_array<jushort>(loader_data, nest_members());
 695   }
 696   set_nest_members(nullptr);
 697 
 698   if (permitted_subclasses() != nullptr &&
 699       permitted_subclasses() != Universe::the_empty_short_array() &&
 700       !permitted_subclasses()->is_shared()) {
 701     MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
 702   }
 703   set_permitted_subclasses(nullptr);
 704 







 705   // We should deallocate the Annotations instance if it's not in shared spaces.
 706   if (annotations() != nullptr && !annotations()->is_shared()) {
 707     MetadataFactory::free_metadata(loader_data, annotations());
 708   }
 709   set_annotations(nullptr);
 710 
 711   SystemDictionaryShared::handle_class_unloading(this);
 712 
 713 #if INCLUDE_CDS_JAVA_HEAP
 714   if (CDSConfig::is_dumping_heap()) {
 715     HeapShared::remove_scratch_objects(this);
 716   }
 717 #endif
 718 }
 719 
 720 bool InstanceKlass::is_record() const {
 721   return _record_components != nullptr &&
 722          is_final() &&
 723          java_super() == vmClasses::Record_klass();
 724 }

 843         vmSymbols::java_lang_IncompatibleClassChangeError(),
 844         "class %s has interface %s as super class",
 845         external_name(),
 846         super_klass->external_name()
 847       );
 848       return false;
 849     }
 850 
 851     InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
 852     ik_super->link_class_impl(CHECK_false);
 853   }
 854 
 855   // link all interfaces implemented by this class before linking this class
 856   Array<InstanceKlass*>* interfaces = local_interfaces();
 857   int num_interfaces = interfaces->length();
 858   for (int index = 0; index < num_interfaces; index++) {
 859     InstanceKlass* interk = interfaces->at(index);
 860     interk->link_class_impl(CHECK_false);
 861   }
 862 










































































































 863   // in case the class is linked in the process of linking its superclasses
 864   if (is_linked()) {
 865     return true;
 866   }
 867 
 868   // trace only the link time for this klass that includes
 869   // the verification time
 870   PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
 871                              ClassLoader::perf_class_link_selftime(),
 872                              ClassLoader::perf_classes_linked(),
 873                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 874                              jt->get_thread_stat()->perf_timers_addr(),
 875                              PerfClassTraceTime::CLASS_LINK);
 876 
 877   // verification & rewriting
 878   {
 879     HandleMark hm(THREAD);
 880     Handle h_init_lock(THREAD, init_lock());
 881     ObjectLocker ol(h_init_lock, jt);
 882     // rewritten will have been set if loader constraint error found

1147       ss.print("Could not initialize class %s", external_name());
1148       if (cause.is_null()) {
1149         THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1150       } else {
1151         THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1152                         ss.as_string(), cause);
1153       }
1154     } else {
1155 
1156       // Step 6
1157       set_init_state(being_initialized);
1158       set_init_thread(jt);
1159       if (debug_logging_enabled) {
1160         ResourceMark rm(jt);
1161         log_debug(class, init)("Thread \"%s\" is initializing %s",
1162                                jt->name(), external_name());
1163       }
1164     }
1165   }
1166 



































1167   // Step 7
1168   // Next, if C is a class rather than an interface, initialize it's super class and super
1169   // interfaces.
1170   if (!is_interface()) {
1171     Klass* super_klass = super();
1172     if (super_klass != nullptr && super_klass->should_be_initialized()) {
1173       super_klass->initialize(THREAD);
1174     }
1175     // If C implements any interface that declares a non-static, concrete method,
1176     // the initialization of C triggers initialization of its super interfaces.
1177     // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1178     // having a superinterface that declares, non-static, concrete methods
1179     if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1180       initialize_super_interfaces(THREAD);
1181     }
1182 
1183     // If any exceptions, complete abruptly, throwing the same exception as above.
1184     if (HAS_PENDING_EXCEPTION) {
1185       Handle e(THREAD, PENDING_EXCEPTION);
1186       CLEAR_PENDING_EXCEPTION;
1187       {
1188         EXCEPTION_MARK;
1189         add_initialization_error(THREAD, e);
1190         // Locks object, set state, and notify all waiting threads
1191         set_initialization_state_and_notify(initialization_error, THREAD);
1192         CLEAR_PENDING_EXCEPTION;
1193       }
1194       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1195       THROW_OOP(e());
1196     }
1197   }
1198 
1199 
1200   // Step 8

































1201   {
1202     DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1203     if (class_initializer() != nullptr) {
1204       // Timer includes any side effects of class initialization (resolution,
1205       // etc), but not recursive entry into call_class_initializer().
1206       PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1207                                ClassLoader::perf_class_init_selftime(),
1208                                ClassLoader::perf_classes_inited(),
1209                                jt->get_thread_stat()->perf_recursion_counts_addr(),
1210                                jt->get_thread_stat()->perf_timers_addr(),
1211                                PerfClassTraceTime::CLASS_CLINIT);
1212       call_class_initializer(THREAD);
1213     } else {
1214       // The elapsed time is so small it's not worth counting.
1215       if (UsePerfData) {
1216         ClassLoader::perf_classes_inited()->inc();
1217       }
1218       call_class_initializer(THREAD);
1219     }
1220   }
1221 
1222   // Step 9
1223   if (!HAS_PENDING_EXCEPTION) {
1224     set_initialization_state_and_notify(fully_initialized, CHECK);
1225     debug_only(vtable().verify(tty, true);)
1226   }
1227   else {
1228     // Step 10 and 11
1229     Handle e(THREAD, PENDING_EXCEPTION);
1230     CLEAR_PENDING_EXCEPTION;
1231     // JVMTI has already reported the pending exception
1232     // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1233     JvmtiExport::clear_detected_exception(jt);
1234     {
1235       EXCEPTION_MARK;
1236       add_initialization_error(THREAD, e);
1237       set_initialization_state_and_notify(initialization_error, THREAD);
1238       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below
1239       // JVMTI has already reported the pending exception
1240       // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1241       JvmtiExport::clear_detected_exception(jt);
1242     }
1243     DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1244     if (e->is_a(vmClasses::Error_klass())) {
1245       THROW_OOP(e());
1246     } else {
1247       JavaCallArguments args(e);
1248       THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),

1513     ResourceMark rm(THREAD);
1514     THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1515               : vmSymbols::java_lang_InstantiationException(), external_name());
1516   }
1517   if (this == vmClasses::Class_klass()) {
1518     ResourceMark rm(THREAD);
1519     THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1520               : vmSymbols::java_lang_IllegalAccessException(), external_name());
1521   }
1522 }
1523 
1524 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1525   // Need load-acquire for lock-free read
1526   if (array_klasses_acquire() == nullptr) {
1527 
1528     // Recursively lock array allocation
1529     RecursiveLocker rl(MultiArray_lock, THREAD);
1530 
1531     // Check if another thread created the array klass while we were waiting for the lock.
1532     if (array_klasses() == nullptr) {
1533       ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);
1534       // use 'release' to pair with lock-free load
1535       release_set_array_klasses(k);
1536     }
1537   }
1538 
1539   // array_klasses() will always be set at this point
1540   ObjArrayKlass* ak = array_klasses();
1541   assert(ak != nullptr, "should be set");
1542   return ak->array_klass(n, THREAD);
1543 }
1544 
1545 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1546   // Need load-acquire for lock-free read
1547   ObjArrayKlass* oak = array_klasses_acquire();
1548   if (oak == nullptr) {
1549     return nullptr;
1550   } else {
1551     return oak->array_klass_or_null(n);
1552   }
1553 }
1554 
1555 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1556   return array_klass(1, THREAD);
1557 }
1558 
1559 ArrayKlass* InstanceKlass::array_klass_or_null() {
1560   return array_klass_or_null(1);
1561 }
1562 
1563 static int call_class_initializer_counter = 0;   // for debugging
1564 
1565 Method* InstanceKlass::class_initializer() const {
1566   Method* clinit = find_method(
1567       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1568   if (clinit != nullptr && clinit->has_valid_initializer_flags()) {
1569     return clinit;
1570   }
1571   return nullptr;
1572 }
1573 
1574 void InstanceKlass::call_class_initializer(TRAPS) {
1575   if (ReplayCompiles &&
1576       (ReplaySuppressInitializers == 1 ||
1577        (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1578     // Hide the existence of the initializer for the purpose of replaying the compile
1579     return;
1580   }
1581 
1582 #if INCLUDE_CDS
1583   // This is needed to ensure the consistency of the archived heap objects.
1584   if (has_archived_enum_objs()) {
1585     assert(is_shared(), "must be");
1586     bool initialized = CDSEnumKlass::initialize_enum_klass(this, CHECK);
1587     if (initialized) {
1588       return;

1612 
1613 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1614   InterpreterOopMap* entry_for) {
1615   // Lazily create the _oop_map_cache at first request.
1616   // Load_acquire is needed to safely get instance published with CAS by another thread.
1617   OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1618   if (oop_map_cache == nullptr) {
1619     // Try to install new instance atomically.
1620     oop_map_cache = new OopMapCache();
1621     OopMapCache* other = Atomic::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
1622     if (other != nullptr) {
1623       // Someone else managed to install before us, ditch local copy and use the existing one.
1624       delete oop_map_cache;
1625       oop_map_cache = other;
1626     }
1627   }
1628   // _oop_map_cache is constant after init; lookup below does its own locking.
1629   oop_map_cache->lookup(method, bci, entry_for);
1630 }
1631 
1632 bool InstanceKlass::contains_field_offset(int offset) {
1633   fieldDescriptor fd;
1634   return find_field_from_offset(offset, false, &fd);
1635 }
1636 
1637 FieldInfo InstanceKlass::field(int index) const {
1638   for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1639     if (fs.index() == index) {
1640       return fs.to_FieldInfo();
1641     }
1642   }
1643   fatal("Field not found");
1644   return FieldInfo();
1645 }
1646 
1647 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1648   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1649     Symbol* f_name = fs.name();
1650     Symbol* f_sig  = fs.signature();
1651     if (f_name == name && f_sig == sig) {
1652       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1653       return true;
1654     }
1655   }

1697 
1698 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1699   // search order according to newest JVM spec (5.4.3.2, p.167).
1700   // 1) search for field in current klass
1701   if (find_local_field(name, sig, fd)) {
1702     if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1703   }
1704   // 2) search for field recursively in direct superinterfaces
1705   if (is_static) {
1706     Klass* intf = find_interface_field(name, sig, fd);
1707     if (intf != nullptr) return intf;
1708   }
1709   // 3) apply field lookup recursively if superclass exists
1710   { Klass* supr = super();
1711     if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1712   }
1713   // 4) otherwise field lookup fails
1714   return nullptr;
1715 }
1716 









1717 
1718 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1719   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1720     if (fs.offset() == offset) {
1721       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1722       if (fd->is_static() == is_static) return true;
1723     }
1724   }
1725   return false;
1726 }
1727 
1728 
1729 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1730   Klass* klass = const_cast<InstanceKlass*>(this);
1731   while (klass != nullptr) {
1732     if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1733       return true;
1734     }
1735     klass = klass->super();
1736   }

2088 }
2089 
2090 // uncached_lookup_method searches both the local class methods array and all
2091 // superclasses methods arrays, skipping any overpass methods in superclasses,
2092 // and possibly skipping private methods.
2093 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2094                                               const Symbol* signature,
2095                                               OverpassLookupMode overpass_mode,
2096                                               PrivateLookupMode private_mode) const {
2097   OverpassLookupMode overpass_local_mode = overpass_mode;
2098   const Klass* klass = this;
2099   while (klass != nullptr) {
2100     Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2101                                                                         signature,
2102                                                                         overpass_local_mode,
2103                                                                         StaticLookupMode::find,
2104                                                                         private_mode);
2105     if (method != nullptr) {
2106       return method;
2107     }



2108     klass = klass->super();
2109     overpass_local_mode = OverpassLookupMode::skip;   // Always ignore overpass methods in superclasses
2110   }
2111   return nullptr;
2112 }
2113 
2114 #ifdef ASSERT
2115 // search through class hierarchy and return true if this class or
2116 // one of the superclasses was redefined
2117 bool InstanceKlass::has_redefined_this_or_super() const {
2118   const Klass* klass = this;
2119   while (klass != nullptr) {
2120     if (InstanceKlass::cast(klass)->has_been_redefined()) {
2121       return true;
2122     }
2123     klass = klass->super();
2124   }
2125   return false;
2126 }
2127 #endif

2484     int method_table_offset_in_words = ioe->offset()/wordSize;
2485     int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2486 
2487     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2488                          / itableOffsetEntry::size();
2489 
2490     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2491       if (ioe->interface_klass() != nullptr) {
2492         it->push(ioe->interface_klass_addr());
2493         itableMethodEntry* ime = ioe->first_method_entry(this);
2494         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2495         for (int index = 0; index < n; index ++) {
2496           it->push(ime[index].method_addr());
2497         }
2498       }
2499     }
2500   }
2501 
2502   it->push(&_nest_members);
2503   it->push(&_permitted_subclasses);

2504   it->push(&_record_components);

2505 }
2506 
2507 #if INCLUDE_CDS
2508 void InstanceKlass::remove_unshareable_info() {
2509 
2510   if (is_linked()) {
2511     assert(can_be_verified_at_dumptime(), "must be");
2512     // Remember this so we can avoid walking the hierarchy at runtime.
2513     set_verified_at_dump_time();
2514   }
2515 
2516   Klass::remove_unshareable_info();
2517 
2518   if (SystemDictionaryShared::has_class_failed_verification(this)) {
2519     // Classes are attempted to link during dumping and may fail,
2520     // but these classes are still in the dictionary and class list in CLD.
2521     // If the class has failed verification, there is nothing else to remove.
2522     return;
2523   }
2524 

2530 
2531   { // Otherwise this needs to take out the Compile_lock.
2532     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2533     init_implementor();
2534   }
2535 
2536   // Call remove_unshareable_info() on other objects that belong to this class, except
2537   // for constants()->remove_unshareable_info(), which is called in a separate pass in
2538   // ArchiveBuilder::make_klasses_shareable(),
2539 
2540   for (int i = 0; i < methods()->length(); i++) {
2541     Method* m = methods()->at(i);
2542     m->remove_unshareable_info();
2543   }
2544 
2545   // do array classes also.
2546   if (array_klasses() != nullptr) {
2547     array_klasses()->remove_unshareable_info();
2548   }
2549 
2550   // These are not allocated from metaspace. They are safe to set to null.
2551   _source_debug_extension = nullptr;
2552   _dep_context = nullptr;
2553   _osr_nmethods_head = nullptr;
2554 #if INCLUDE_JVMTI
2555   _breakpoints = nullptr;
2556   _previous_versions = nullptr;
2557   _cached_class_file = nullptr;
2558   _jvmti_cached_class_field_map = nullptr;
2559 #endif
2560 
2561   _init_thread = nullptr;
2562   _methods_jmethod_ids = nullptr;
2563   _jni_ids = nullptr;
2564   _oop_map_cache = nullptr;
2565   // clear _nest_host to ensure re-load at runtime
2566   _nest_host = nullptr;
2567   init_shared_package_entry();
2568   _dep_context_last_cleaned = 0;
2569 
2570   remove_unshareable_flags();

2614 void InstanceKlass::compute_has_loops_flag_for_methods() {
2615   Array<Method*>* methods = this->methods();
2616   for (int index = 0; index < methods->length(); ++index) {
2617     Method* m = methods->at(index);
2618     if (!m->is_overpass()) { // work around JDK-8305771
2619       m->compute_has_loops_flag();
2620     }
2621   }
2622 }
2623 
2624 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2625                                              PackageEntry* pkg_entry, TRAPS) {
2626   // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2627   // before the InstanceKlass is added to the SystemDictionary. Make
2628   // sure the current state is <loaded.
2629   assert(!is_loaded(), "invalid init state");
2630   assert(!shared_loading_failed(), "Must not try to load failed class again");
2631   set_package(loader_data, pkg_entry, CHECK);
2632   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2633 




2634   Array<Method*>* methods = this->methods();
2635   int num_methods = methods->length();
2636   for (int index = 0; index < num_methods; ++index) {
2637     methods->at(index)->restore_unshareable_info(CHECK);
2638   }
2639 #if INCLUDE_JVMTI
2640   if (JvmtiExport::has_redefined_a_class()) {
2641     // Reinitialize vtable because RedefineClasses may have changed some
2642     // entries in this vtable for super classes so the CDS vtable might
2643     // point to old or obsolete entries.  RedefineClasses doesn't fix up
2644     // vtables in the shared system dictionary, only the main one.
2645     // It also redefines the itable too so fix that too.
2646     // First fix any default methods that point to a super class that may
2647     // have been redefined.
2648     bool trace_name_printed = false;
2649     adjust_default_methods(&trace_name_printed);
2650     vtable().initialize_vtable();
2651     itable().initialize_itable();
2652   }
2653 #endif
2654 
2655   // restore constant pool resolved references
2656   constants()->restore_unshareable_info(CHECK);
2657 
2658   if (array_klasses() != nullptr) {
2659     // To get a consistent list of classes we need MultiArray_lock to ensure
2660     // array classes aren't observed while they are being restored.
2661     RecursiveLocker rl(MultiArray_lock, THREAD);
2662     assert(this == array_klasses()->bottom_klass(), "sanity");
2663     // Array classes have null protection domain.
2664     // --> see ArrayKlass::complete_create_array_klass()
2665     array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2666   }
2667 
2668   // Initialize @ValueBased class annotation if not already set in the archived klass.
2669   if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
2670     set_is_value_based();
2671   }
2672 }
2673 
2674 // Check if a class or any of its supertypes has a version older than 50.
2675 // CDS will not perform verification of old classes during dump time because
2676 // without changing the old verifier, the verification constraint cannot be
2677 // retrieved during dump time.
2678 // Verification of archived old classes will be performed during run time.
2679 bool InstanceKlass::can_be_verified_at_dumptime() const {
2680   if (MetaspaceShared::is_in_shared_metaspace(this)) {
2681     // This is a class that was dumped into the base archive, so we know
2682     // it was verified at dump time.

2827   } else {
2828     // Adding one to the attribute length in order to store a null terminator
2829     // character could cause an overflow because the attribute length is
2830     // already coded with an u4 in the classfile, but in practice, it's
2831     // unlikely to happen.
2832     assert((length+1) > length, "Overflow checking");
2833     char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
2834     for (int i = 0; i < length; i++) {
2835       sde[i] = array[i];
2836     }
2837     sde[length] = '\0';
2838     _source_debug_extension = sde;
2839   }
2840 }
2841 
2842 Symbol* InstanceKlass::generic_signature() const                   { return _constants->generic_signature(); }
2843 u2 InstanceKlass::generic_signature_index() const                  { return _constants->generic_signature_index(); }
2844 void InstanceKlass::set_generic_signature_index(u2 sig_index)      { _constants->set_generic_signature_index(sig_index); }
2845 
2846 const char* InstanceKlass::signature_name() const {


2847 

2848   // Get the internal name as a c string
2849   const char* src = (const char*) (name()->as_C_string());
2850   const int src_length = (int)strlen(src);
2851 
2852   char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
2853 
2854   // Add L as type indicator
2855   int dest_index = 0;
2856   dest[dest_index++] = JVM_SIGNATURE_CLASS;
2857 
2858   // Add the actual class name
2859   for (int src_index = 0; src_index < src_length; ) {
2860     dest[dest_index++] = src[src_index++];
2861   }
2862 
2863   if (is_hidden()) { // Replace the last '+' with a '.'.
2864     for (int index = (int)src_length; index > 0; index--) {
2865       if (dest[index] == '+') {
2866         dest[index] = JVM_SIGNATURE_DOT;
2867         break;
2868       }
2869     }
2870   }
2871 
2872   // Add the semicolon and the null
2873   dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
2874   dest[dest_index] = '\0';
2875   return dest;
2876 }

3178 jint InstanceKlass::compute_modifier_flags() const {
3179   jint access = access_flags().as_int();
3180 
3181   // But check if it happens to be member class.
3182   InnerClassesIterator iter(this);
3183   for (; !iter.done(); iter.next()) {
3184     int ioff = iter.inner_class_info_index();
3185     // Inner class attribute can be zero, skip it.
3186     // Strange but true:  JVM spec. allows null inner class refs.
3187     if (ioff == 0) continue;
3188 
3189     // only look at classes that are already loaded
3190     // since we are looking for the flags for our self.
3191     Symbol* inner_name = constants()->klass_name_at(ioff);
3192     if (name() == inner_name) {
3193       // This is really a member class.
3194       access = iter.inner_access_flags();
3195       break;
3196     }
3197   }
3198   // Remember to strip ACC_SUPER bit
3199   return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
3200 }
3201 
3202 jint InstanceKlass::jvmti_class_status() const {
3203   jint result = 0;
3204 
3205   if (is_linked()) {
3206     result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3207   }
3208 
3209   if (is_initialized()) {
3210     assert(is_linked(), "Class status is not consistent");
3211     result |= JVMTI_CLASS_STATUS_INITIALIZED;
3212   }
3213   if (is_in_error_state()) {
3214     result |= JVMTI_CLASS_STATUS_ERROR;
3215   }
3216   return result;
3217 }
3218 
3219 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {

3433     }
3434     osr = osr->osr_link();
3435   }
3436 
3437   assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3438   if (best != nullptr && best->comp_level() >= comp_level) {
3439     return best;
3440   }
3441   return nullptr;
3442 }
3443 
3444 // -----------------------------------------------------------------------------------------------------
3445 // Printing
3446 
3447 #define BULLET  " - "
3448 
3449 static const char* state_names[] = {
3450   "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3451 };
3452 
3453 static void print_vtable(intptr_t* start, int len, outputStream* st) {



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





3457     if (MetaspaceObj::is_valid((Metadata*)e)) {
3458       st->print(" ");
3459       ((Metadata*)e)->print_value_on(st);






3460     }
3461     st->cr();
3462   }
3463 }
3464 
3465 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3466   return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);





















3467 }
3468 
3469 const char* InstanceKlass::init_state_name() const {
3470   return state_names[init_state()];
3471 }
3472 
3473 void InstanceKlass::print_on(outputStream* st) const {
3474   assert(is_klass(), "must be klass");
3475   Klass::print_on(st);
3476 
3477   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
3478   st->print(BULLET"klass size:        %d", size());                               st->cr();
3479   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
3480   st->print(BULLET"flags:             "); _misc_flags.print_on(st);               st->cr();
3481   st->print(BULLET"state:             "); st->print_cr("%s", init_state_name());
3482   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
3483   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3484   st->print(BULLET"sub:               ");
3485   Klass* sub = subklass();
3486   int n;
3487   for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3488     if (n < MaxSubklassPrintSize) {
3489       sub->print_value_on(st);
3490       st->print("   ");
3491     }
3492   }
3493   if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3494   st->cr();
3495 
3496   if (is_interface()) {
3497     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
3498     if (nof_implementors() == 1) {
3499       st->print_cr(BULLET"implementor:    ");
3500       st->print("   ");
3501       implementor()->print_value_on(st);
3502       st->cr();
3503     }
3504   }
3505 
3506   st->print(BULLET"arrays:            "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3507   st->print(BULLET"methods:           "); methods()->print_value_on(st);               st->cr();
3508   if (Verbose || WizardMode) {
3509     Array<Method*>* method_array = methods();
3510     for (int i = 0; i < method_array->length(); i++) {
3511       st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3512     }
3513   }
3514   st->print(BULLET"method ordering:   "); method_ordering()->print_value_on(st);      st->cr();
3515   if (default_methods() != nullptr) {
3516     st->print(BULLET"default_methods:   "); default_methods()->print_value_on(st);    st->cr();
3517     if (Verbose) {
3518       Array<Method*>* method_array = default_methods();
3519       for (int i = 0; i < method_array->length(); i++) {
3520         st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3521       }
3522     }
3523   }
3524   print_on_maybe_null(st, BULLET"default vtable indices:   ", default_vtable_indices());
3525   st->print(BULLET"local interfaces:  "); local_interfaces()->print_value_on(st);      st->cr();
3526   st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3527 
3528   st->print(BULLET"secondary supers: "); secondary_supers()->print_value_on(st); st->cr();
3529   if (UseSecondarySupersTable) {
3530     st->print(BULLET"hash_slot:         %d", hash_slot()); st->cr();
3531     st->print(BULLET"bitmap:            " UINTX_FORMAT_X_0, _bitmap); st->cr();
3532   }
3533   if (secondary_supers() != nullptr) {
3534     if (Verbose) {
3535       bool is_hashed = UseSecondarySupersTable && (_bitmap != SECONDARY_SUPERS_BITMAP_FULL);
3536       st->print_cr(BULLET"---- secondary supers (%d words):", _secondary_supers->length());
3537       for (int i = 0; i < _secondary_supers->length(); i++) {
3538         ResourceMark rm; // for external_name()
3539         Klass* secondary_super = _secondary_supers->at(i);
3540         st->print(BULLET"%2d:", i);
3541         if (is_hashed) {
3542           int home_slot = compute_home_slot(secondary_super, _bitmap);

3562   print_on_maybe_null(st, BULLET"field type annotations:  ", fields_type_annotations());
3563   {
3564     bool have_pv = false;
3565     // previous versions are linked together through the InstanceKlass
3566     for (InstanceKlass* pv_node = previous_versions();
3567          pv_node != nullptr;
3568          pv_node = pv_node->previous_versions()) {
3569       if (!have_pv)
3570         st->print(BULLET"previous version:  ");
3571       have_pv = true;
3572       pv_node->constants()->print_value_on(st);
3573     }
3574     if (have_pv) st->cr();
3575   }
3576 
3577   print_on_maybe_null(st, BULLET"generic signature: ", generic_signature());
3578   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
3579   st->print(BULLET"nest members:     "); nest_members()->print_value_on(st);     st->cr();
3580   print_on_maybe_null(st, BULLET"record components:     ", record_components());
3581   st->print(BULLET"permitted subclasses:     "); permitted_subclasses()->print_value_on(st);     st->cr();

3582   if (java_mirror() != nullptr) {
3583     st->print(BULLET"java mirror:       ");
3584     java_mirror()->print_value_on(st);
3585     st->cr();
3586   } else {
3587     st->print_cr(BULLET"java mirror:       null");
3588   }
3589   st->print(BULLET"vtable length      %d  (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3590   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
3591   st->print(BULLET"itable length      %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3592   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_itable(), itable_length(), st);
3593   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3594 
3595   FieldPrinter print_static_field(st);
3596   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3597   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3598   FieldPrinter print_nonstatic_field(st);
3599   InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3600   ik->print_nonstatic_fields(&print_nonstatic_field);
3601 
3602   st->print(BULLET"non-static oop maps: ");
3603   OopMapBlock* map     = start_of_nonstatic_oop_maps();
3604   OopMapBlock* end_map = map + nonstatic_oop_map_count();
3605   while (map < end_map) {
3606     st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3607     map++;
3608   }
3609   st->cr();
3610 }
3611 
3612 void InstanceKlass::print_value_on(outputStream* st) const {

  55 #include "logging/logStream.hpp"
  56 #include "memory/allocation.inline.hpp"
  57 #include "memory/iterator.inline.hpp"
  58 #include "memory/metadataFactory.hpp"
  59 #include "memory/metaspaceClosure.hpp"
  60 #include "memory/oopFactory.hpp"
  61 #include "memory/resourceArea.hpp"
  62 #include "memory/universe.hpp"
  63 #include "oops/fieldStreams.inline.hpp"
  64 #include "oops/constantPool.hpp"
  65 #include "oops/instanceClassLoaderKlass.hpp"
  66 #include "oops/instanceKlass.inline.hpp"
  67 #include "oops/instanceMirrorKlass.hpp"
  68 #include "oops/instanceOop.hpp"
  69 #include "oops/instanceStackChunkKlass.hpp"
  70 #include "oops/klass.inline.hpp"
  71 #include "oops/method.hpp"
  72 #include "oops/oop.inline.hpp"
  73 #include "oops/recordComponent.hpp"
  74 #include "oops/symbol.hpp"
  75 #include "oops/inlineKlass.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 void InlineLayoutInfo::metaspace_pointers_do(MetaspaceClosure* it) {
 153   log_trace(cds)("Iter(InlineFieldInfo): %p", this);
 154   it->push(&_klass);
 155 }
 156 
 157 bool InstanceKlass::_finalization_enabled = true;
 158 
 159 static inline bool is_class_loader(const Symbol* class_name,
 160                                    const ClassFileParser& parser) {
 161   assert(class_name != nullptr, "invariant");
 162 
 163   if (class_name == vmSymbols::java_lang_ClassLoader()) {
 164     return true;
 165   }
 166 
 167   if (vmClasses::ClassLoader_klass_loaded()) {
 168     const Klass* const super_klass = parser.super_klass();
 169     if (super_klass != nullptr) {
 170       if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
 171         return true;
 172       }
 173     }
 174   }
 175   return false;
 176 }
 177 
 178 bool InstanceKlass::field_is_null_free_inline_type(int index) const {
 179   return field(index).field_flags().is_null_free_inline_type();
 180 }
 181 
 182 bool InstanceKlass::is_class_in_loadable_descriptors_attribute(Symbol* name) const {
 183   if (_loadable_descriptors == nullptr) return false;
 184   for (int i = 0; i < _loadable_descriptors->length(); i++) {
 185         Symbol* class_name = _constants->symbol_at(_loadable_descriptors->at(i));
 186         if (class_name == name) return true;
 187   }
 188   return false;
 189 }
 190 
 191 static inline bool is_stack_chunk_class(const Symbol* class_name,
 192                                         const ClassLoaderData* loader_data) {
 193   return (class_name == vmSymbols::jdk_internal_vm_StackChunk() &&
 194           loader_data->is_the_null_class_loader_data());
 195 }
 196 
 197 // private: called to verify that k is a static member of this nest.
 198 // We know that k is an instance class in the same package and hence the
 199 // same classloader.
 200 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
 201   assert(!is_hidden(), "unexpected hidden class");
 202   if (_nest_members == nullptr || _nest_members == Universe::the_empty_short_array()) {
 203     if (log_is_enabled(Trace, class, nestmates)) {
 204       ResourceMark rm(current);
 205       log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
 206                                   k->external_name(), this->external_name());
 207     }
 208     return false;
 209   }
 210 

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

 709       (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
 710       !secondary_supers()->is_shared()) {
 711     MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
 712   }
 713   set_secondary_supers(nullptr);
 714 
 715   deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
 716   set_transitive_interfaces(nullptr);
 717   set_local_interfaces(nullptr);
 718 
 719   if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->is_shared()) {
 720     MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
 721   }
 722   set_fieldinfo_stream(nullptr);
 723 
 724   if (fields_status() != nullptr && !fields_status()->is_shared()) {
 725     MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
 726   }
 727   set_fields_status(nullptr);
 728 
 729   if (inline_layout_info_array() != nullptr) {
 730     MetadataFactory::free_array<InlineLayoutInfo>(loader_data, inline_layout_info_array());
 731   }
 732   set_inline_layout_info_array(nullptr);
 733 
 734   // If a method from a redefined class is using this constant pool, don't
 735   // delete it, yet.  The new class's previous version will point to this.
 736   if (constants() != nullptr) {
 737     assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
 738     if (!constants()->is_shared()) {
 739       MetadataFactory::free_metadata(loader_data, constants());
 740     }
 741     // Delete any cached resolution errors for the constant pool
 742     SystemDictionary::delete_resolution_error(constants());
 743 
 744     set_constants(nullptr);
 745   }
 746 
 747   if (inner_classes() != nullptr &&
 748       inner_classes() != Universe::the_empty_short_array() &&
 749       !inner_classes()->is_shared()) {
 750     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
 751   }
 752   set_inner_classes(nullptr);
 753 
 754   if (nest_members() != nullptr &&
 755       nest_members() != Universe::the_empty_short_array() &&
 756       !nest_members()->is_shared()) {
 757     MetadataFactory::free_array<jushort>(loader_data, nest_members());
 758   }
 759   set_nest_members(nullptr);
 760 
 761   if (permitted_subclasses() != nullptr &&
 762       permitted_subclasses() != Universe::the_empty_short_array() &&
 763       !permitted_subclasses()->is_shared()) {
 764     MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
 765   }
 766   set_permitted_subclasses(nullptr);
 767 
 768   if (loadable_descriptors() != nullptr &&
 769       loadable_descriptors() != Universe::the_empty_short_array() &&
 770       !loadable_descriptors()->is_shared()) {
 771     MetadataFactory::free_array<jushort>(loader_data, loadable_descriptors());
 772   }
 773   set_loadable_descriptors(nullptr);
 774 
 775   // We should deallocate the Annotations instance if it's not in shared spaces.
 776   if (annotations() != nullptr && !annotations()->is_shared()) {
 777     MetadataFactory::free_metadata(loader_data, annotations());
 778   }
 779   set_annotations(nullptr);
 780 
 781   SystemDictionaryShared::handle_class_unloading(this);
 782 
 783 #if INCLUDE_CDS_JAVA_HEAP
 784   if (CDSConfig::is_dumping_heap()) {
 785     HeapShared::remove_scratch_objects(this);
 786   }
 787 #endif
 788 }
 789 
 790 bool InstanceKlass::is_record() const {
 791   return _record_components != nullptr &&
 792          is_final() &&
 793          java_super() == vmClasses::Record_klass();
 794 }

 913         vmSymbols::java_lang_IncompatibleClassChangeError(),
 914         "class %s has interface %s as super class",
 915         external_name(),
 916         super_klass->external_name()
 917       );
 918       return false;
 919     }
 920 
 921     InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
 922     ik_super->link_class_impl(CHECK_false);
 923   }
 924 
 925   // link all interfaces implemented by this class before linking this class
 926   Array<InstanceKlass*>* interfaces = local_interfaces();
 927   int num_interfaces = interfaces->length();
 928   for (int index = 0; index < num_interfaces; index++) {
 929     InstanceKlass* interk = interfaces->at(index);
 930     interk->link_class_impl(CHECK_false);
 931   }
 932 
 933 
 934   // If a class declares a method that uses an inline class as an argument
 935   // type or return inline type, this inline class must be loaded during the
 936   // linking of this class because size and properties of the inline class
 937   // must be known in order to be able to perform inline type optimizations.
 938   // The implementation below is an approximation of this rule, the code
 939   // iterates over all methods of the current class (including overridden
 940   // methods), not only the methods declared by this class. This
 941   // approximation makes the code simpler, and doesn't change the semantic
 942   // because classes declaring methods overridden by the current class are
 943   // linked (and have performed their own pre-loading) before the linking
 944   // of the current class.
 945 
 946 
 947   // Note:
 948   // Inline class types are loaded during
 949   // the loading phase (see ClassFileParser::post_process_parsed_stream()).
 950   // Inline class types used as element types for array creation
 951   // are not pre-loaded. Their loading is triggered by either anewarray
 952   // or multianewarray bytecodes.
 953 
 954   // Could it be possible to do the following processing only if the
 955   // class uses inline types?
 956   if (EnableValhalla) {
 957     ResourceMark rm(THREAD);
 958     for (AllFieldStream fs(this); !fs.done(); fs.next()) {
 959       if (fs.is_null_free_inline_type() && fs.access_flags().is_static()) {
 960         Symbol* sig = fs.signature();
 961         TempNewSymbol s = Signature::strip_envelope(sig);
 962         if (s != name()) {
 963           log_info(class, preload)("Preloading class %s during linking of class %s. Cause: a null-free static field is declared with this type", s->as_C_string(), name()->as_C_string());
 964           Klass* klass = SystemDictionary::resolve_or_fail(s,
 965                                                           Handle(THREAD, class_loader()), Handle(THREAD, protection_domain()), true,
 966                                                           CHECK_false);
 967           if (HAS_PENDING_EXCEPTION) {
 968             log_warning(class, preload)("Preloading of class %s during linking of class %s (cause: null-free static field) failed: %s",
 969                                       s->as_C_string(), name()->as_C_string(), PENDING_EXCEPTION->klass()->name()->as_C_string());
 970             return false; // Exception is still pending
 971           }
 972           log_info(class, preload)("Preloading of class %s during linking of class %s (cause: null-free static field) succeeded",
 973                                    s->as_C_string(), name()->as_C_string());
 974           assert(klass != nullptr, "Sanity check");
 975           if (klass->is_abstract()) {
 976             THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
 977                       err_msg("Class %s expects class %s to be concrete value class, but it is an abstract class",
 978                       name()->as_C_string(),
 979                       InstanceKlass::cast(klass)->external_name()), false);
 980           }
 981           if (!klass->is_inline_klass()) {
 982             THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
 983                        err_msg("class %s expects class %s to be a value class but it is an identity class",
 984                        name()->as_C_string(), klass->external_name()), false);
 985           }
 986           InlineKlass* vk = InlineKlass::cast(klass);
 987           if (!vk->is_implicitly_constructible()) {
 988              THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
 989                         err_msg("class %s is not implicitly constructible and it is used in a null restricted static field (not supported)",
 990                         klass->external_name()), false);
 991           }
 992           // the inline_type_field_klasses_array might have been loaded with CDS, so update only if not already set and check consistency
 993           InlineLayoutInfo* li = inline_layout_info_adr(fs.index());
 994           if (li->klass() == nullptr) {
 995             li->set_klass(InlineKlass::cast(vk));
 996             li->set_kind(LayoutKind::REFERENCE);
 997           }
 998           assert(get_inline_type_field_klass(fs.index()) == vk, "Must match");
 999         } else {
1000           InlineLayoutInfo* li = inline_layout_info_adr(fs.index());
1001           if (li->klass() == nullptr) {
1002             li->set_klass(InlineKlass::cast(this));
1003             li->set_kind(LayoutKind::REFERENCE);
1004           }
1005           assert(get_inline_type_field_klass(fs.index()) == this, "Must match");
1006         }
1007       }
1008     }
1009 
1010     // Aggressively preloading all classes from the LoadableDescriptors attribute
1011     if (loadable_descriptors() != nullptr) {
1012       HandleMark hm(THREAD);
1013       for (int i = 0; i < loadable_descriptors()->length(); i++) {
1014         Symbol* sig = constants()->symbol_at(loadable_descriptors()->at(i));
1015         if (!Signature::has_envelope(sig)) continue;
1016         TempNewSymbol class_name = Signature::strip_envelope(sig);
1017         if (class_name == name()) continue;
1018         log_info(class, preload)("Preloading class %s during linking of class %s because of the class is listed in the LoadableDescriptors attribute", sig->as_C_string(), name()->as_C_string());
1019         oop loader = class_loader();
1020         oop protection_domain = this->protection_domain();
1021         Klass* klass = SystemDictionary::resolve_or_null(class_name,
1022                                                          Handle(THREAD, loader), Handle(THREAD, protection_domain), THREAD);
1023         if (HAS_PENDING_EXCEPTION) {
1024           CLEAR_PENDING_EXCEPTION;
1025         }
1026         if (klass != nullptr) {
1027           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());
1028           if (!klass->is_inline_klass()) {
1029             // Non value class are allowed by the current spec, but it could be an indication of an issue so let's log a warning
1030               log_warning(class, preload)("Preloading class %s during linking of class %s (cause: LoadableDescriptors attribute) but loaded class is not a value class", class_name->as_C_string(), name()->as_C_string());
1031           }
1032         } else {
1033           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());
1034         }
1035       }
1036     }
1037   }
1038 
1039   // in case the class is linked in the process of linking its superclasses
1040   if (is_linked()) {
1041     return true;
1042   }
1043 
1044   // trace only the link time for this klass that includes
1045   // the verification time
1046   PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
1047                              ClassLoader::perf_class_link_selftime(),
1048                              ClassLoader::perf_classes_linked(),
1049                              jt->get_thread_stat()->perf_recursion_counts_addr(),
1050                              jt->get_thread_stat()->perf_timers_addr(),
1051                              PerfClassTraceTime::CLASS_LINK);
1052 
1053   // verification & rewriting
1054   {
1055     HandleMark hm(THREAD);
1056     Handle h_init_lock(THREAD, init_lock());
1057     ObjectLocker ol(h_init_lock, jt);
1058     // rewritten will have been set if loader constraint error found

1323       ss.print("Could not initialize class %s", external_name());
1324       if (cause.is_null()) {
1325         THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1326       } else {
1327         THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1328                         ss.as_string(), cause);
1329       }
1330     } else {
1331 
1332       // Step 6
1333       set_init_state(being_initialized);
1334       set_init_thread(jt);
1335       if (debug_logging_enabled) {
1336         ResourceMark rm(jt);
1337         log_debug(class, init)("Thread \"%s\" is initializing %s",
1338                                jt->name(), external_name());
1339       }
1340     }
1341   }
1342 
1343   // Pre-allocating an instance of the default value
1344   if (is_inline_klass()) {
1345       InlineKlass* vk = InlineKlass::cast(this);
1346       oop val = vk->allocate_instance(THREAD);
1347       if (HAS_PENDING_EXCEPTION) {
1348           Handle e(THREAD, PENDING_EXCEPTION);
1349           CLEAR_PENDING_EXCEPTION;
1350           {
1351               EXCEPTION_MARK;
1352               add_initialization_error(THREAD, e);
1353               // Locks object, set state, and notify all waiting threads
1354               set_initialization_state_and_notify(initialization_error, THREAD);
1355               CLEAR_PENDING_EXCEPTION;
1356           }
1357           THROW_OOP(e());
1358       }
1359       vk->set_default_value(val);
1360       if (vk->has_nullable_layout()) {
1361         val = vk->allocate_instance(THREAD);
1362         if (HAS_PENDING_EXCEPTION) {
1363             Handle e(THREAD, PENDING_EXCEPTION);
1364             CLEAR_PENDING_EXCEPTION;
1365             {
1366                 EXCEPTION_MARK;
1367                 add_initialization_error(THREAD, e);
1368                 // Locks object, set state, and notify all waiting threads
1369                 set_initialization_state_and_notify(initialization_error, THREAD);
1370                 CLEAR_PENDING_EXCEPTION;
1371             }
1372             THROW_OOP(e());
1373         }
1374         vk->set_null_reset_value(val);
1375       }
1376   }
1377 
1378   // Step 7
1379   // Next, if C is a class rather than an interface, initialize it's super class and super
1380   // interfaces.
1381   if (!is_interface()) {
1382     Klass* super_klass = super();
1383     if (super_klass != nullptr && super_klass->should_be_initialized()) {
1384       super_klass->initialize(THREAD);
1385     }
1386     // If C implements any interface that declares a non-static, concrete method,
1387     // the initialization of C triggers initialization of its super interfaces.
1388     // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1389     // having a superinterface that declares, non-static, concrete methods
1390     if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1391       initialize_super_interfaces(THREAD);
1392     }
1393 
1394     // If any exceptions, complete abruptly, throwing the same exception as above.
1395     if (HAS_PENDING_EXCEPTION) {
1396       Handle e(THREAD, PENDING_EXCEPTION);
1397       CLEAR_PENDING_EXCEPTION;
1398       {
1399         EXCEPTION_MARK;
1400         add_initialization_error(THREAD, e);
1401         // Locks object, set state, and notify all waiting threads
1402         set_initialization_state_and_notify(initialization_error, THREAD);
1403         CLEAR_PENDING_EXCEPTION;
1404       }
1405       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1406       THROW_OOP(e());
1407     }
1408   }
1409 

1410   // Step 8
1411   // Initialize classes of inline fields
1412   if (EnableValhalla) {
1413     for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1414       if (fs.is_null_free_inline_type()) {
1415 
1416         // inline type field klass array entries must have alreadyt been filed at load time or link time
1417         Klass* klass = get_inline_type_field_klass(fs.index());
1418 
1419         InstanceKlass::cast(klass)->initialize(THREAD);
1420         if (fs.access_flags().is_static()) {
1421           if (java_mirror()->obj_field(fs.offset()) == nullptr) {
1422             java_mirror()->obj_field_put(fs.offset(), InlineKlass::cast(klass)->default_value());
1423           }
1424         }
1425 
1426         if (HAS_PENDING_EXCEPTION) {
1427           Handle e(THREAD, PENDING_EXCEPTION);
1428           CLEAR_PENDING_EXCEPTION;
1429           {
1430             EXCEPTION_MARK;
1431             add_initialization_error(THREAD, e);
1432             // Locks object, set state, and notify all waiting threads
1433             set_initialization_state_and_notify(initialization_error, THREAD);
1434             CLEAR_PENDING_EXCEPTION;
1435           }
1436           THROW_OOP(e());
1437         }
1438       }
1439     }
1440   }
1441 
1442 
1443   // Step 9
1444   {
1445     DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1446     if (class_initializer() != nullptr) {
1447       // Timer includes any side effects of class initialization (resolution,
1448       // etc), but not recursive entry into call_class_initializer().
1449       PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1450                                ClassLoader::perf_class_init_selftime(),
1451                                ClassLoader::perf_classes_inited(),
1452                                jt->get_thread_stat()->perf_recursion_counts_addr(),
1453                                jt->get_thread_stat()->perf_timers_addr(),
1454                                PerfClassTraceTime::CLASS_CLINIT);
1455       call_class_initializer(THREAD);
1456     } else {
1457       // The elapsed time is so small it's not worth counting.
1458       if (UsePerfData) {
1459         ClassLoader::perf_classes_inited()->inc();
1460       }
1461       call_class_initializer(THREAD);
1462     }
1463   }
1464 
1465   // Step 10
1466   if (!HAS_PENDING_EXCEPTION) {
1467     set_initialization_state_and_notify(fully_initialized, CHECK);
1468     debug_only(vtable().verify(tty, true);)
1469   }
1470   else {
1471     // Step 11 and 12
1472     Handle e(THREAD, PENDING_EXCEPTION);
1473     CLEAR_PENDING_EXCEPTION;
1474     // JVMTI has already reported the pending exception
1475     // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1476     JvmtiExport::clear_detected_exception(jt);
1477     {
1478       EXCEPTION_MARK;
1479       add_initialization_error(THREAD, e);
1480       set_initialization_state_and_notify(initialization_error, THREAD);
1481       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below
1482       // JVMTI has already reported the pending exception
1483       // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1484       JvmtiExport::clear_detected_exception(jt);
1485     }
1486     DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1487     if (e->is_a(vmClasses::Error_klass())) {
1488       THROW_OOP(e());
1489     } else {
1490       JavaCallArguments args(e);
1491       THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),

1756     ResourceMark rm(THREAD);
1757     THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1758               : vmSymbols::java_lang_InstantiationException(), external_name());
1759   }
1760   if (this == vmClasses::Class_klass()) {
1761     ResourceMark rm(THREAD);
1762     THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1763               : vmSymbols::java_lang_IllegalAccessException(), external_name());
1764   }
1765 }
1766 
1767 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1768   // Need load-acquire for lock-free read
1769   if (array_klasses_acquire() == nullptr) {
1770 
1771     // Recursively lock array allocation
1772     RecursiveLocker rl(MultiArray_lock, THREAD);
1773 
1774     // Check if another thread created the array klass while we were waiting for the lock.
1775     if (array_klasses() == nullptr) {
1776       ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, false, CHECK_NULL);
1777       // use 'release' to pair with lock-free load
1778       release_set_array_klasses(k);
1779     }
1780   }
1781 
1782   // array_klasses() will always be set at this point
1783   ArrayKlass* ak = array_klasses();
1784   assert(ak != nullptr, "should be set");
1785   return ak->array_klass(n, THREAD);
1786 }
1787 
1788 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1789   // Need load-acquire for lock-free read
1790   ArrayKlass* ak = array_klasses_acquire();
1791   if (ak == nullptr) {
1792     return nullptr;
1793   } else {
1794     return ak->array_klass_or_null(n);
1795   }
1796 }
1797 
1798 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1799   return array_klass(1, THREAD);
1800 }
1801 
1802 ArrayKlass* InstanceKlass::array_klass_or_null() {
1803   return array_klass_or_null(1);
1804 }
1805 
1806 static int call_class_initializer_counter = 0;   // for debugging
1807 
1808 Method* InstanceKlass::class_initializer() const {
1809   Method* clinit = find_method(
1810       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1811   if (clinit != nullptr && clinit->is_class_initializer()) {
1812     return clinit;
1813   }
1814   return nullptr;
1815 }
1816 
1817 void InstanceKlass::call_class_initializer(TRAPS) {
1818   if (ReplayCompiles &&
1819       (ReplaySuppressInitializers == 1 ||
1820        (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1821     // Hide the existence of the initializer for the purpose of replaying the compile
1822     return;
1823   }
1824 
1825 #if INCLUDE_CDS
1826   // This is needed to ensure the consistency of the archived heap objects.
1827   if (has_archived_enum_objs()) {
1828     assert(is_shared(), "must be");
1829     bool initialized = CDSEnumKlass::initialize_enum_klass(this, CHECK);
1830     if (initialized) {
1831       return;

1855 
1856 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1857   InterpreterOopMap* entry_for) {
1858   // Lazily create the _oop_map_cache at first request.
1859   // Load_acquire is needed to safely get instance published with CAS by another thread.
1860   OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1861   if (oop_map_cache == nullptr) {
1862     // Try to install new instance atomically.
1863     oop_map_cache = new OopMapCache();
1864     OopMapCache* other = Atomic::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
1865     if (other != nullptr) {
1866       // Someone else managed to install before us, ditch local copy and use the existing one.
1867       delete oop_map_cache;
1868       oop_map_cache = other;
1869     }
1870   }
1871   // _oop_map_cache is constant after init; lookup below does its own locking.
1872   oop_map_cache->lookup(method, bci, entry_for);
1873 }
1874 




1875 
1876 FieldInfo InstanceKlass::field(int index) const {
1877   for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1878     if (fs.index() == index) {
1879       return fs.to_FieldInfo();
1880     }
1881   }
1882   fatal("Field not found");
1883   return FieldInfo();
1884 }
1885 
1886 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1887   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1888     Symbol* f_name = fs.name();
1889     Symbol* f_sig  = fs.signature();
1890     if (f_name == name && f_sig == sig) {
1891       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1892       return true;
1893     }
1894   }

1936 
1937 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1938   // search order according to newest JVM spec (5.4.3.2, p.167).
1939   // 1) search for field in current klass
1940   if (find_local_field(name, sig, fd)) {
1941     if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1942   }
1943   // 2) search for field recursively in direct superinterfaces
1944   if (is_static) {
1945     Klass* intf = find_interface_field(name, sig, fd);
1946     if (intf != nullptr) return intf;
1947   }
1948   // 3) apply field lookup recursively if superclass exists
1949   { Klass* supr = super();
1950     if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1951   }
1952   // 4) otherwise field lookup fails
1953   return nullptr;
1954 }
1955 
1956 bool InstanceKlass::contains_field_offset(int offset) {
1957   if (this->is_inline_klass()) {
1958     InlineKlass* vk = InlineKlass::cast(this);
1959     return offset >= vk->first_field_offset() && offset < (vk->first_field_offset() + vk->payload_size_in_bytes());
1960   } else {
1961     fieldDescriptor fd;
1962     return find_field_from_offset(offset, false, &fd);
1963   }
1964 }
1965 
1966 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1967   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1968     if (fs.offset() == offset) {
1969       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1970       if (fd->is_static() == is_static) return true;
1971     }
1972   }
1973   return false;
1974 }
1975 
1976 
1977 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1978   Klass* klass = const_cast<InstanceKlass*>(this);
1979   while (klass != nullptr) {
1980     if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1981       return true;
1982     }
1983     klass = klass->super();
1984   }

2336 }
2337 
2338 // uncached_lookup_method searches both the local class methods array and all
2339 // superclasses methods arrays, skipping any overpass methods in superclasses,
2340 // and possibly skipping private methods.
2341 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2342                                               const Symbol* signature,
2343                                               OverpassLookupMode overpass_mode,
2344                                               PrivateLookupMode private_mode) const {
2345   OverpassLookupMode overpass_local_mode = overpass_mode;
2346   const Klass* klass = this;
2347   while (klass != nullptr) {
2348     Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2349                                                                         signature,
2350                                                                         overpass_local_mode,
2351                                                                         StaticLookupMode::find,
2352                                                                         private_mode);
2353     if (method != nullptr) {
2354       return method;
2355     }
2356     if (name == vmSymbols::object_initializer_name()) {
2357       break;  // <init> is never inherited
2358     }
2359     klass = klass->super();
2360     overpass_local_mode = OverpassLookupMode::skip;   // Always ignore overpass methods in superclasses
2361   }
2362   return nullptr;
2363 }
2364 
2365 #ifdef ASSERT
2366 // search through class hierarchy and return true if this class or
2367 // one of the superclasses was redefined
2368 bool InstanceKlass::has_redefined_this_or_super() const {
2369   const Klass* klass = this;
2370   while (klass != nullptr) {
2371     if (InstanceKlass::cast(klass)->has_been_redefined()) {
2372       return true;
2373     }
2374     klass = klass->super();
2375   }
2376   return false;
2377 }
2378 #endif

2735     int method_table_offset_in_words = ioe->offset()/wordSize;
2736     int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2737 
2738     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2739                          / itableOffsetEntry::size();
2740 
2741     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2742       if (ioe->interface_klass() != nullptr) {
2743         it->push(ioe->interface_klass_addr());
2744         itableMethodEntry* ime = ioe->first_method_entry(this);
2745         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2746         for (int index = 0; index < n; index ++) {
2747           it->push(ime[index].method_addr());
2748         }
2749       }
2750     }
2751   }
2752 
2753   it->push(&_nest_members);
2754   it->push(&_permitted_subclasses);
2755   it->push(&_loadable_descriptors);
2756   it->push(&_record_components);
2757   it->push(&_inline_layout_info_array, MetaspaceClosure::_writable);
2758 }
2759 
2760 #if INCLUDE_CDS
2761 void InstanceKlass::remove_unshareable_info() {
2762 
2763   if (is_linked()) {
2764     assert(can_be_verified_at_dumptime(), "must be");
2765     // Remember this so we can avoid walking the hierarchy at runtime.
2766     set_verified_at_dump_time();
2767   }
2768 
2769   Klass::remove_unshareable_info();
2770 
2771   if (SystemDictionaryShared::has_class_failed_verification(this)) {
2772     // Classes are attempted to link during dumping and may fail,
2773     // but these classes are still in the dictionary and class list in CLD.
2774     // If the class has failed verification, there is nothing else to remove.
2775     return;
2776   }
2777 

2783 
2784   { // Otherwise this needs to take out the Compile_lock.
2785     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2786     init_implementor();
2787   }
2788 
2789   // Call remove_unshareable_info() on other objects that belong to this class, except
2790   // for constants()->remove_unshareable_info(), which is called in a separate pass in
2791   // ArchiveBuilder::make_klasses_shareable(),
2792 
2793   for (int i = 0; i < methods()->length(); i++) {
2794     Method* m = methods()->at(i);
2795     m->remove_unshareable_info();
2796   }
2797 
2798   // do array classes also.
2799   if (array_klasses() != nullptr) {
2800     array_klasses()->remove_unshareable_info();
2801   }
2802 
2803   // These are not allocated from metaspace. They are safe to set to nullptr.
2804   _source_debug_extension = nullptr;
2805   _dep_context = nullptr;
2806   _osr_nmethods_head = nullptr;
2807 #if INCLUDE_JVMTI
2808   _breakpoints = nullptr;
2809   _previous_versions = nullptr;
2810   _cached_class_file = nullptr;
2811   _jvmti_cached_class_field_map = nullptr;
2812 #endif
2813 
2814   _init_thread = nullptr;
2815   _methods_jmethod_ids = nullptr;
2816   _jni_ids = nullptr;
2817   _oop_map_cache = nullptr;
2818   // clear _nest_host to ensure re-load at runtime
2819   _nest_host = nullptr;
2820   init_shared_package_entry();
2821   _dep_context_last_cleaned = 0;
2822 
2823   remove_unshareable_flags();

2867 void InstanceKlass::compute_has_loops_flag_for_methods() {
2868   Array<Method*>* methods = this->methods();
2869   for (int index = 0; index < methods->length(); ++index) {
2870     Method* m = methods->at(index);
2871     if (!m->is_overpass()) { // work around JDK-8305771
2872       m->compute_has_loops_flag();
2873     }
2874   }
2875 }
2876 
2877 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2878                                              PackageEntry* pkg_entry, TRAPS) {
2879   // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2880   // before the InstanceKlass is added to the SystemDictionary. Make
2881   // sure the current state is <loaded.
2882   assert(!is_loaded(), "invalid init state");
2883   assert(!shared_loading_failed(), "Must not try to load failed class again");
2884   set_package(loader_data, pkg_entry, CHECK);
2885   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2886 
2887   if (is_inline_klass()) {
2888     InlineKlass::cast(this)->initialize_calling_convention(CHECK);
2889   }
2890 
2891   Array<Method*>* methods = this->methods();
2892   int num_methods = methods->length();
2893   for (int index = 0; index < num_methods; ++index) {
2894     methods->at(index)->restore_unshareable_info(CHECK);
2895   }
2896 #if INCLUDE_JVMTI
2897   if (JvmtiExport::has_redefined_a_class()) {
2898     // Reinitialize vtable because RedefineClasses may have changed some
2899     // entries in this vtable for super classes so the CDS vtable might
2900     // point to old or obsolete entries.  RedefineClasses doesn't fix up
2901     // vtables in the shared system dictionary, only the main one.
2902     // It also redefines the itable too so fix that too.
2903     // First fix any default methods that point to a super class that may
2904     // have been redefined.
2905     bool trace_name_printed = false;
2906     adjust_default_methods(&trace_name_printed);
2907     vtable().initialize_vtable();
2908     itable().initialize_itable();
2909   }
2910 #endif
2911 
2912   // restore constant pool resolved references
2913   constants()->restore_unshareable_info(CHECK);
2914 
2915   if (array_klasses() != nullptr) {
2916     // To get a consistent list of classes we need MultiArray_lock to ensure
2917     // array classes aren't observed while they are being restored.
2918     RecursiveLocker rl(MultiArray_lock, THREAD);
2919     assert(this == ObjArrayKlass::cast(array_klasses())->bottom_klass(), "sanity");
2920     // Array classes have null protection domain.
2921     // --> see ArrayKlass::complete_create_array_klass()
2922     array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2923   }
2924 
2925   // Initialize @ValueBased class annotation if not already set in the archived klass.
2926   if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
2927     set_is_value_based();
2928   }
2929 }
2930 
2931 // Check if a class or any of its supertypes has a version older than 50.
2932 // CDS will not perform verification of old classes during dump time because
2933 // without changing the old verifier, the verification constraint cannot be
2934 // retrieved during dump time.
2935 // Verification of archived old classes will be performed during run time.
2936 bool InstanceKlass::can_be_verified_at_dumptime() const {
2937   if (MetaspaceShared::is_in_shared_metaspace(this)) {
2938     // This is a class that was dumped into the base archive, so we know
2939     // it was verified at dump time.

3084   } else {
3085     // Adding one to the attribute length in order to store a null terminator
3086     // character could cause an overflow because the attribute length is
3087     // already coded with an u4 in the classfile, but in practice, it's
3088     // unlikely to happen.
3089     assert((length+1) > length, "Overflow checking");
3090     char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
3091     for (int i = 0; i < length; i++) {
3092       sde[i] = array[i];
3093     }
3094     sde[length] = '\0';
3095     _source_debug_extension = sde;
3096   }
3097 }
3098 
3099 Symbol* InstanceKlass::generic_signature() const                   { return _constants->generic_signature(); }
3100 u2 InstanceKlass::generic_signature_index() const                  { return _constants->generic_signature_index(); }
3101 void InstanceKlass::set_generic_signature_index(u2 sig_index)      { _constants->set_generic_signature_index(sig_index); }
3102 
3103 const char* InstanceKlass::signature_name() const {
3104   return signature_name_of_carrier(JVM_SIGNATURE_CLASS);
3105 }
3106 
3107 const char* InstanceKlass::signature_name_of_carrier(char c) const {
3108   // Get the internal name as a c string
3109   const char* src = (const char*) (name()->as_C_string());
3110   const int src_length = (int)strlen(src);
3111 
3112   char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
3113 
3114   // Add L or Q as type indicator
3115   int dest_index = 0;
3116   dest[dest_index++] = c;
3117 
3118   // Add the actual class name
3119   for (int src_index = 0; src_index < src_length; ) {
3120     dest[dest_index++] = src[src_index++];
3121   }
3122 
3123   if (is_hidden()) { // Replace the last '+' with a '.'.
3124     for (int index = (int)src_length; index > 0; index--) {
3125       if (dest[index] == '+') {
3126         dest[index] = JVM_SIGNATURE_DOT;
3127         break;
3128       }
3129     }
3130   }
3131 
3132   // Add the semicolon and the null
3133   dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
3134   dest[dest_index] = '\0';
3135   return dest;
3136 }

3438 jint InstanceKlass::compute_modifier_flags() const {
3439   jint access = access_flags().as_int();
3440 
3441   // But check if it happens to be member class.
3442   InnerClassesIterator iter(this);
3443   for (; !iter.done(); iter.next()) {
3444     int ioff = iter.inner_class_info_index();
3445     // Inner class attribute can be zero, skip it.
3446     // Strange but true:  JVM spec. allows null inner class refs.
3447     if (ioff == 0) continue;
3448 
3449     // only look at classes that are already loaded
3450     // since we are looking for the flags for our self.
3451     Symbol* inner_name = constants()->klass_name_at(ioff);
3452     if (name() == inner_name) {
3453       // This is really a member class.
3454       access = iter.inner_access_flags();
3455       break;
3456     }
3457   }
3458   return (access & JVM_ACC_WRITTEN_FLAGS);

3459 }
3460 
3461 jint InstanceKlass::jvmti_class_status() const {
3462   jint result = 0;
3463 
3464   if (is_linked()) {
3465     result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3466   }
3467 
3468   if (is_initialized()) {
3469     assert(is_linked(), "Class status is not consistent");
3470     result |= JVMTI_CLASS_STATUS_INITIALIZED;
3471   }
3472   if (is_in_error_state()) {
3473     result |= JVMTI_CLASS_STATUS_ERROR;
3474   }
3475   return result;
3476 }
3477 
3478 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {

3692     }
3693     osr = osr->osr_link();
3694   }
3695 
3696   assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3697   if (best != nullptr && best->comp_level() >= comp_level) {
3698     return best;
3699   }
3700   return nullptr;
3701 }
3702 
3703 // -----------------------------------------------------------------------------------------------------
3704 // Printing
3705 
3706 #define BULLET  " - "
3707 
3708 static const char* state_names[] = {
3709   "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3710 };
3711 
3712 static void print_vtable(address self, intptr_t* start, int len, outputStream* st) {
3713   ResourceMark rm;
3714   int* forward_refs = NEW_RESOURCE_ARRAY(int, len);
3715   for (int i = 0; i < len; i++)  forward_refs[i] = 0;
3716   for (int i = 0; i < len; i++) {
3717     intptr_t e = start[i];
3718     st->print("%d : " INTPTR_FORMAT, i, e);
3719     if (forward_refs[i] != 0) {
3720       int from = forward_refs[i];
3721       int off = (int) start[from];
3722       st->print(" (offset %d <= [%d])", off, from);
3723     }
3724     if (MetaspaceObj::is_valid((Metadata*)e)) {
3725       st->print(" ");
3726       ((Metadata*)e)->print_value_on(st);
3727     } else if (self != nullptr && e > 0 && e < 0x10000) {
3728       address location = self + e;
3729       int index = (int)((intptr_t*)location - start);
3730       st->print(" (offset %d => [%d])", (int)e, index);
3731       if (index >= 0 && index < len)
3732         forward_refs[index] = i;
3733     }
3734     st->cr();
3735   }
3736 }
3737 
3738 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3739   return print_vtable(nullptr, reinterpret_cast<intptr_t*>(start), len, st);
3740 }
3741 
3742 template<typename T>
3743  static void print_array_on(outputStream* st, Array<T>* array) {
3744    if (array == nullptr) { st->print_cr("nullptr"); return; }
3745    array->print_value_on(st); st->cr();
3746    if (Verbose || WizardMode) {
3747      for (int i = 0; i < array->length(); i++) {
3748        st->print("%d : ", i); array->at(i)->print_value_on(st); st->cr();
3749      }
3750    }
3751  }
3752 
3753 static void print_array_on(outputStream* st, Array<int>* array) {
3754   if (array == nullptr) { st->print_cr("nullptr"); return; }
3755   array->print_value_on(st); st->cr();
3756   if (Verbose || WizardMode) {
3757     for (int i = 0; i < array->length(); i++) {
3758       st->print("%d : %d", i, array->at(i)); st->cr();
3759     }
3760   }
3761 }
3762 
3763 const char* InstanceKlass::init_state_name() const {
3764   return state_names[init_state()];
3765 }
3766 
3767 void InstanceKlass::print_on(outputStream* st) const {
3768   assert(is_klass(), "must be klass");
3769   Klass::print_on(st);
3770 
3771   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
3772   st->print(BULLET"klass size:        %d", size());                               st->cr();
3773   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
3774   st->print(BULLET"flags:             "); _misc_flags.print_on(st);               st->cr();
3775   st->print(BULLET"state:             "); st->print_cr("%s", init_state_name());
3776   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
3777   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3778   st->print(BULLET"sub:               ");
3779   Klass* sub = subklass();
3780   int n;
3781   for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3782     if (n < MaxSubklassPrintSize) {
3783       sub->print_value_on(st);
3784       st->print("   ");
3785     }
3786   }
3787   if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3788   st->cr();
3789 
3790   if (is_interface()) {
3791     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
3792     if (nof_implementors() == 1) {
3793       st->print_cr(BULLET"implementor:    ");
3794       st->print("   ");
3795       implementor()->print_value_on(st);
3796       st->cr();
3797     }
3798   }
3799 
3800   st->print(BULLET"arrays:            "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3801   st->print(BULLET"methods:           "); print_array_on(st, methods());
3802   st->print(BULLET"method ordering:   "); print_array_on(st, method_ordering());






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






3805   }
3806   print_on_maybe_null(st, BULLET"default vtable indices:   ", default_vtable_indices());
3807   st->print(BULLET"local interfaces:  "); local_interfaces()->print_value_on(st);      st->cr();
3808   st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3809 
3810   st->print(BULLET"secondary supers: "); secondary_supers()->print_value_on(st); st->cr();
3811   if (UseSecondarySupersTable) {
3812     st->print(BULLET"hash_slot:         %d", hash_slot()); st->cr();
3813     st->print(BULLET"bitmap:            " UINTX_FORMAT_X_0, _bitmap); st->cr();
3814   }
3815   if (secondary_supers() != nullptr) {
3816     if (Verbose) {
3817       bool is_hashed = UseSecondarySupersTable && (_bitmap != SECONDARY_SUPERS_BITMAP_FULL);
3818       st->print_cr(BULLET"---- secondary supers (%d words):", _secondary_supers->length());
3819       for (int i = 0; i < _secondary_supers->length(); i++) {
3820         ResourceMark rm; // for external_name()
3821         Klass* secondary_super = _secondary_supers->at(i);
3822         st->print(BULLET"%2d:", i);
3823         if (is_hashed) {
3824           int home_slot = compute_home_slot(secondary_super, _bitmap);

3844   print_on_maybe_null(st, BULLET"field type annotations:  ", fields_type_annotations());
3845   {
3846     bool have_pv = false;
3847     // previous versions are linked together through the InstanceKlass
3848     for (InstanceKlass* pv_node = previous_versions();
3849          pv_node != nullptr;
3850          pv_node = pv_node->previous_versions()) {
3851       if (!have_pv)
3852         st->print(BULLET"previous version:  ");
3853       have_pv = true;
3854       pv_node->constants()->print_value_on(st);
3855     }
3856     if (have_pv) st->cr();
3857   }
3858 
3859   print_on_maybe_null(st, BULLET"generic signature: ", generic_signature());
3860   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
3861   st->print(BULLET"nest members:     "); nest_members()->print_value_on(st);     st->cr();
3862   print_on_maybe_null(st, BULLET"record components:     ", record_components());
3863   st->print(BULLET"permitted subclasses:     "); permitted_subclasses()->print_value_on(st);     st->cr();
3864   st->print(BULLET"loadable descriptors:     "); loadable_descriptors()->print_value_on(st); st->cr();
3865   if (java_mirror() != nullptr) {
3866     st->print(BULLET"java mirror:       ");
3867     java_mirror()->print_value_on(st);
3868     st->cr();
3869   } else {
3870     st->print_cr(BULLET"java mirror:       null");
3871   }
3872   st->print(BULLET"vtable length      %d  (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3873   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
3874   st->print(BULLET"itable length      %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3875   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(nullptr, start_of_itable(), itable_length(), st);
3876   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3877 
3878   FieldPrinter print_static_field(st);
3879   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3880   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3881   FieldPrinter print_nonstatic_field(st);
3882   InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3883   ik->print_nonstatic_fields(&print_nonstatic_field);
3884 
3885   st->print(BULLET"non-static oop maps: ");
3886   OopMapBlock* map     = start_of_nonstatic_oop_maps();
3887   OopMapBlock* end_map = map + nonstatic_oop_map_count();
3888   while (map < end_map) {
3889     st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3890     map++;
3891   }
3892   st->cr();
3893 }
3894 
3895 void InstanceKlass::print_value_on(outputStream* st) const {
< prev index next >