< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page

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

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

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













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

 422   log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
 423                               this->external_name(),
 424                               access ? "" : "NOT ",
 425                               k->external_name());
 426   return access;
 427 }
 428 
 429 const char* InstanceKlass::nest_host_error() {
 430   if (_nest_host_index == 0) {
 431     return nullptr;
 432   } else {
 433     constantPoolHandle cph(Thread::current(), constants());
 434     return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
 435   }
 436 }
 437 
 438 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
 439   const int size = InstanceKlass::size(parser.vtable_size(),
 440                                        parser.itable_size(),
 441                                        nonstatic_oop_map_size(parser.total_oop_map_count()),
 442                                        parser.is_interface());

 443 
 444   const Symbol* const class_name = parser.class_name();
 445   assert(class_name != nullptr, "invariant");
 446   ClassLoaderData* loader_data = parser.loader_data();
 447   assert(loader_data != nullptr, "invariant");
 448 
 449   InstanceKlass* ik;
 450 
 451   // Allocation
 452   if (parser.is_instance_ref_klass()) {
 453     // java.lang.ref.Reference
 454     ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
 455   } else if (class_name == vmSymbols::java_lang_Class()) {
 456     // mirror - java.lang.Class
 457     ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
 458   } else if (is_stack_chunk_class(class_name, loader_data)) {
 459     // stack chunk
 460     ik = new (loader_data, size, THREAD) InstanceStackChunkKlass(parser);
 461   } else if (is_class_loader(class_name, parser)) {
 462     // class loader - java.lang.ClassLoader
 463     ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);



 464   } else {
 465     // normal
 466     ik = new (loader_data, size, THREAD) InstanceKlass(parser);
 467   }
 468 
 469   // Check for pending exception before adding to the loader data and incrementing
 470   // class count.  Can get OOM here.
 471   if (HAS_PENDING_EXCEPTION) {
 472     return nullptr;
 473   }
 474 






 475   return ik;
 476 }
 477 























 478 
 479 // copy method ordering from resource area to Metaspace
 480 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
 481   if (m != nullptr) {
 482     // allocate a new array and copy contents (memcpy?)
 483     _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
 484     for (int i = 0; i < m->length(); i++) {
 485       _method_ordering->at_put(i, m->at(i));
 486     }
 487   } else {
 488     _method_ordering = Universe::the_empty_int_array();
 489   }
 490 }
 491 
 492 // create a new array of vtable_indices for default methods
 493 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
 494   Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
 495   assert(default_vtable_indices() == nullptr, "only create once");
 496   set_default_vtable_indices(vtable_indices);
 497   return vtable_indices;

 501   return new Monitor(Mutex::safepoint, name);
 502 }
 503 
 504 InstanceKlass::InstanceKlass() {
 505   assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS");
 506 }
 507 
 508 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) :
 509   Klass(kind),
 510   _nest_members(nullptr),
 511   _nest_host(nullptr),
 512   _permitted_subclasses(nullptr),
 513   _record_components(nullptr),
 514   _static_field_size(parser.static_field_size()),
 515   _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
 516   _itable_len(parser.itable_size()),
 517   _nest_host_index(0),
 518   _init_state(allocated),
 519   _reference_type(reference_type),
 520   _init_monitor(create_init_monitor("InstanceKlassInitMonitor_lock")),
 521   _init_thread(nullptr)




 522 {
 523   set_vtable_length(parser.vtable_size());
 524   set_access_flags(parser.access_flags());
 525   if (parser.is_hidden()) set_is_hidden();
 526   set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
 527                                                     false));



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

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










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







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

 860         vmSymbols::java_lang_IncompatibleClassChangeError(),
 861         "class %s has interface %s as super class",
 862         external_name(),
 863         super_klass->external_name()
 864       );
 865       return false;
 866     }
 867 
 868     InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
 869     ik_super->link_class_impl(CHECK_false);
 870   }
 871 
 872   // link all interfaces implemented by this class before linking this class
 873   Array<InstanceKlass*>* interfaces = local_interfaces();
 874   int num_interfaces = interfaces->length();
 875   for (int index = 0; index < num_interfaces; index++) {
 876     InstanceKlass* interk = interfaces->at(index);
 877     interk->link_class_impl(CHECK_false);
 878   }
 879 





































































































 880   // in case the class is linked in the process of linking its superclasses
 881   if (is_linked()) {
 882     return true;
 883   }
 884 
 885   // trace only the link time for this klass that includes
 886   // the verification time
 887   PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
 888                              ClassLoader::perf_class_link_selftime(),
 889                              ClassLoader::perf_classes_linked(),
 890                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 891                              jt->get_thread_stat()->perf_timers_addr(),
 892                              PerfClassTraceTime::CLASS_LINK);
 893 
 894   // verification & rewriting
 895   {
 896     LockLinkState init_lock(this, jt);
 897 
 898     // rewritten will have been set if loader constraint error found
 899     // on an earlier link attempt

1149       }
1150     }
1151   }
1152 
1153   // Throw error outside lock
1154   if (throw_error) {
1155     DTRACE_CLASSINIT_PROBE_WAIT(erroneous, -1, wait);
1156     ResourceMark rm(THREAD);
1157     Handle cause(THREAD, get_initialization_error(THREAD));
1158 
1159     stringStream ss;
1160     ss.print("Could not initialize class %s", external_name());
1161     if (cause.is_null()) {
1162       THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1163     } else {
1164       THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1165                       ss.as_string(), cause);
1166     }
1167   }
1168 



















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

































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

1536               : vmSymbols::java_lang_InstantiationException(), external_name());
1537   }
1538   if (this == vmClasses::Class_klass()) {
1539     ResourceMark rm(THREAD);
1540     THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1541               : vmSymbols::java_lang_IllegalAccessException(), external_name());
1542   }
1543 }
1544 
1545 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1546   // Need load-acquire for lock-free read
1547   if (array_klasses_acquire() == nullptr) {
1548     ResourceMark rm(THREAD);
1549     JavaThread *jt = THREAD;
1550     {
1551       // Atomic creation of array_klasses
1552       MutexLocker ma(THREAD, MultiArray_lock);
1553 
1554       // Check if update has already taken place
1555       if (array_klasses() == nullptr) {
1556         ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);

1557         // use 'release' to pair with lock-free load
1558         release_set_array_klasses(k);
1559       }
1560     }
1561   }
1562   // array_klasses() will always be set at this point
1563   ObjArrayKlass* oak = array_klasses();
1564   return oak->array_klass(n, THREAD);
1565 }
1566 
1567 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1568   // Need load-acquire for lock-free read
1569   ObjArrayKlass* oak = array_klasses_acquire();
1570   if (oak == nullptr) {
1571     return nullptr;
1572   } else {
1573     return oak->array_klass_or_null(n);
1574   }
1575 }
1576 
1577 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1578   return array_klass(1, THREAD);
1579 }
1580 
1581 ArrayKlass* InstanceKlass::array_klass_or_null() {
1582   return array_klass_or_null(1);
1583 }
1584 
1585 static int call_class_initializer_counter = 0;   // for debugging
1586 
1587 Method* InstanceKlass::class_initializer() const {
1588   Method* clinit = find_method(
1589       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1590   if (clinit != nullptr && clinit->has_valid_initializer_flags()) {
1591     return clinit;
1592   }
1593   return nullptr;
1594 }
1595 
1596 void InstanceKlass::call_class_initializer(TRAPS) {
1597   if (ReplayCompiles &&
1598       (ReplaySuppressInitializers == 1 ||
1599        (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1600     // Hide the existence of the initializer for the purpose of replaying the compile
1601     return;
1602   }
1603 
1604 #if INCLUDE_CDS
1605   // This is needed to ensure the consistency of the archived heap objects.
1606   if (has_archived_enum_objs()) {
1607     assert(is_shared(), "must be");
1608     bool initialized = HeapShared::initialize_enum_klass(this, CHECK);
1609     if (initialized) {
1610       return;

1621     ls.print("%d Initializing ", call_class_initializer_counter++);
1622     name()->print_value_on(&ls);
1623     ls.print_cr("%s (" PTR_FORMAT ") by thread \"%s\"",
1624                 h_method() == nullptr ? "(no method)" : "", p2i(this),
1625                 THREAD->name());
1626   }
1627   if (h_method() != nullptr) {
1628     JavaCallArguments args; // No arguments
1629     JavaValue result(T_VOID);
1630     JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1631   }
1632 }
1633 
1634 
1635 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1636   InterpreterOopMap* entry_for) {
1637   // Lazily create the _oop_map_cache at first request
1638   // Lock-free access requires load_acquire.
1639   OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1640   if (oop_map_cache == nullptr) {
1641     MutexLocker x(OopMapCacheAlloc_lock);
1642     // Check if _oop_map_cache was allocated while we were waiting for this lock
1643     if ((oop_map_cache = _oop_map_cache) == nullptr) {
1644       oop_map_cache = new OopMapCache();
1645       // Ensure _oop_map_cache is stable, since it is examined without a lock
1646       Atomic::release_store(&_oop_map_cache, oop_map_cache);
1647     }
1648   }
1649   // _oop_map_cache is constant after init; lookup below does its own locking.
1650   oop_map_cache->lookup(method, bci, entry_for);
1651 }
1652 
1653 bool InstanceKlass::contains_field_offset(int offset) {
1654   fieldDescriptor fd;
1655   return find_field_from_offset(offset, false, &fd);
1656 }
1657 
1658 FieldInfo InstanceKlass::field(int index) const {
1659   for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1660     if (fs.index() == index) {
1661       return fs.to_FieldInfo();
1662     }
1663   }
1664   fatal("Field not found");
1665   return FieldInfo();
1666 }
1667 
1668 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1669   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1670     Symbol* f_name = fs.name();
1671     Symbol* f_sig  = fs.signature();
1672     if (f_name == name && f_sig == sig) {
1673       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1674       return true;
1675     }
1676   }

1718 
1719 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1720   // search order according to newest JVM spec (5.4.3.2, p.167).
1721   // 1) search for field in current klass
1722   if (find_local_field(name, sig, fd)) {
1723     if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1724   }
1725   // 2) search for field recursively in direct superinterfaces
1726   if (is_static) {
1727     Klass* intf = find_interface_field(name, sig, fd);
1728     if (intf != nullptr) return intf;
1729   }
1730   // 3) apply field lookup recursively if superclass exists
1731   { Klass* supr = super();
1732     if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1733   }
1734   // 4) otherwise field lookup fails
1735   return nullptr;
1736 }
1737 









1738 
1739 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1740   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1741     if (fs.offset() == offset) {
1742       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1743       if (fd->is_static() == is_static) return true;
1744     }
1745   }
1746   return false;
1747 }
1748 
1749 
1750 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1751   Klass* klass = const_cast<InstanceKlass*>(this);
1752   while (klass != nullptr) {
1753     if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1754       return true;
1755     }
1756     klass = klass->super();
1757   }

2109 }
2110 
2111 // uncached_lookup_method searches both the local class methods array and all
2112 // superclasses methods arrays, skipping any overpass methods in superclasses,
2113 // and possibly skipping private methods.
2114 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2115                                               const Symbol* signature,
2116                                               OverpassLookupMode overpass_mode,
2117                                               PrivateLookupMode private_mode) const {
2118   OverpassLookupMode overpass_local_mode = overpass_mode;
2119   const Klass* klass = this;
2120   while (klass != nullptr) {
2121     Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2122                                                                         signature,
2123                                                                         overpass_local_mode,
2124                                                                         StaticLookupMode::find,
2125                                                                         private_mode);
2126     if (method != nullptr) {
2127       return method;
2128     }



2129     klass = klass->super();
2130     overpass_local_mode = OverpassLookupMode::skip;   // Always ignore overpass methods in superclasses
2131   }
2132   return nullptr;
2133 }
2134 
2135 #ifdef ASSERT
2136 // search through class hierarchy and return true if this class or
2137 // one of the superclasses was redefined
2138 bool InstanceKlass::has_redefined_this_or_super() const {
2139   const Klass* klass = this;
2140   while (klass != nullptr) {
2141     if (InstanceKlass::cast(klass)->has_been_redefined()) {
2142       return true;
2143     }
2144     klass = klass->super();
2145   }
2146   return false;
2147 }
2148 #endif

2589     int method_table_offset_in_words = ioe->offset()/wordSize;
2590     int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2591 
2592     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2593                          / itableOffsetEntry::size();
2594 
2595     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2596       if (ioe->interface_klass() != nullptr) {
2597         it->push(ioe->interface_klass_addr());
2598         itableMethodEntry* ime = ioe->first_method_entry(this);
2599         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2600         for (int index = 0; index < n; index ++) {
2601           it->push(ime[index].method_addr());
2602         }
2603       }
2604     }
2605   }
2606 
2607   it->push(&_nest_members);
2608   it->push(&_permitted_subclasses);

2609   it->push(&_record_components);



2610 }
2611 
2612 #if INCLUDE_CDS
2613 void InstanceKlass::remove_unshareable_info() {
2614 
2615   if (is_linked()) {
2616     assert(can_be_verified_at_dumptime(), "must be");
2617     // Remember this so we can avoid walking the hierarchy at runtime.
2618     set_verified_at_dump_time();
2619   }
2620 
2621   Klass::remove_unshareable_info();
2622 
2623   if (SystemDictionaryShared::has_class_failed_verification(this)) {
2624     // Classes are attempted to link during dumping and may fail,
2625     // but these classes are still in the dictionary and class list in CLD.
2626     // If the class has failed verification, there is nothing else to remove.
2627     return;
2628   }
2629 

2633   // being added to class hierarchy (see InstanceKlass:::add_to_hierarchy()).
2634   _init_state = allocated;
2635 
2636   { // Otherwise this needs to take out the Compile_lock.
2637     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2638     init_implementor();
2639   }
2640 
2641   constants()->remove_unshareable_info();
2642 
2643   for (int i = 0; i < methods()->length(); i++) {
2644     Method* m = methods()->at(i);
2645     m->remove_unshareable_info();
2646   }
2647 
2648   // do array classes also.
2649   if (array_klasses() != nullptr) {
2650     array_klasses()->remove_unshareable_info();
2651   }
2652 
2653   // These are not allocated from metaspace. They are safe to set to null.
2654   _source_debug_extension = nullptr;
2655   _dep_context = nullptr;
2656   _osr_nmethods_head = nullptr;
2657 #if INCLUDE_JVMTI
2658   _breakpoints = nullptr;
2659   _previous_versions = nullptr;
2660   _cached_class_file = nullptr;
2661   _jvmti_cached_class_field_map = nullptr;
2662 #endif
2663 
2664   _init_thread = nullptr;
2665   _methods_jmethod_ids = nullptr;
2666   _jni_ids = nullptr;
2667   _oop_map_cache = nullptr;
2668   // clear _nest_host to ensure re-load at runtime
2669   _nest_host = nullptr;
2670   init_shared_package_entry();
2671   _dep_context_last_cleaned = 0;
2672   _init_monitor = nullptr;
2673 

2718 void InstanceKlass::compute_has_loops_flag_for_methods() {
2719   Array<Method*>* methods = this->methods();
2720   for (int index = 0; index < methods->length(); ++index) {
2721     Method* m = methods->at(index);
2722     if (!m->is_overpass()) { // work around JDK-8305771
2723       m->compute_has_loops_flag();
2724     }
2725   }
2726 }
2727 
2728 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2729                                              PackageEntry* pkg_entry, TRAPS) {
2730   // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2731   // before the InstanceKlass is added to the SystemDictionary. Make
2732   // sure the current state is <loaded.
2733   assert(!is_loaded(), "invalid init state");
2734   assert(!shared_loading_failed(), "Must not try to load failed class again");
2735   set_package(loader_data, pkg_entry, CHECK);
2736   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2737 




2738   Array<Method*>* methods = this->methods();
2739   int num_methods = methods->length();
2740   for (int index = 0; index < num_methods; ++index) {
2741     methods->at(index)->restore_unshareable_info(CHECK);
2742   }
2743 #if INCLUDE_JVMTI
2744   if (JvmtiExport::has_redefined_a_class()) {
2745     // Reinitialize vtable because RedefineClasses may have changed some
2746     // entries in this vtable for super classes so the CDS vtable might
2747     // point to old or obsolete entries.  RedefineClasses doesn't fix up
2748     // vtables in the shared system dictionary, only the main one.
2749     // It also redefines the itable too so fix that too.
2750     // First fix any default methods that point to a super class that may
2751     // have been redefined.
2752     bool trace_name_printed = false;
2753     adjust_default_methods(&trace_name_printed);
2754     vtable().initialize_vtable();
2755     itable().initialize_itable();
2756   }
2757 #endif
2758 
2759   // restore constant pool resolved references
2760   constants()->restore_unshareable_info(CHECK);
2761 
2762   if (array_klasses() != nullptr) {
2763     // To get a consistent list of classes we need MultiArray_lock to ensure
2764     // array classes aren't observed while they are being restored.
2765     MutexLocker ml(MultiArray_lock);
2766     assert(this == array_klasses()->bottom_klass(), "sanity");
2767     // Array classes have null protection domain.
2768     // --> see ArrayKlass::complete_create_array_klass()
2769     array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2770   }
2771 
2772   // Initialize @ValueBased class annotation
2773   if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation()) {
2774     set_is_value_based();
2775   }
2776 
2777   // restore the monitor
2778   _init_monitor = create_init_monitor("InstanceKlassInitMonitorRestored_lock");
2779 }
2780 
2781 // Check if a class or any of its supertypes has a version older than 50.
2782 // CDS will not perform verification of old classes during dump time because
2783 // without changing the old verifier, the verification constraint cannot be
2784 // retrieved during dump time.
2785 // Verification of archived old classes will be performed during run time.
2786 bool InstanceKlass::can_be_verified_at_dumptime() const {

2945   } else {
2946     // Adding one to the attribute length in order to store a null terminator
2947     // character could cause an overflow because the attribute length is
2948     // already coded with an u4 in the classfile, but in practice, it's
2949     // unlikely to happen.
2950     assert((length+1) > length, "Overflow checking");
2951     char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
2952     for (int i = 0; i < length; i++) {
2953       sde[i] = array[i];
2954     }
2955     sde[length] = '\0';
2956     _source_debug_extension = sde;
2957   }
2958 }
2959 
2960 Symbol* InstanceKlass::generic_signature() const                   { return _constants->generic_signature(); }
2961 u2 InstanceKlass::generic_signature_index() const                  { return _constants->generic_signature_index(); }
2962 void InstanceKlass::set_generic_signature_index(u2 sig_index)      { _constants->set_generic_signature_index(sig_index); }
2963 
2964 const char* InstanceKlass::signature_name() const {


2965 

2966   // Get the internal name as a c string
2967   const char* src = (const char*) (name()->as_C_string());
2968   const int src_length = (int)strlen(src);
2969 
2970   char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
2971 
2972   // Add L as type indicator
2973   int dest_index = 0;
2974   dest[dest_index++] = JVM_SIGNATURE_CLASS;
2975 
2976   // Add the actual class name
2977   for (int src_index = 0; src_index < src_length; ) {
2978     dest[dest_index++] = src[src_index++];
2979   }
2980 
2981   if (is_hidden()) { // Replace the last '+' with a '.'.
2982     for (int index = (int)src_length; index > 0; index--) {
2983       if (dest[index] == '+') {
2984         dest[index] = JVM_SIGNATURE_DOT;
2985         break;
2986       }
2987     }
2988   }
2989 
2990   // Add the semicolon and the null
2991   dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
2992   dest[dest_index] = '\0';
2993   return dest;
2994 }

3296 jint InstanceKlass::compute_modifier_flags() const {
3297   jint access = access_flags().as_int();
3298 
3299   // But check if it happens to be member class.
3300   InnerClassesIterator iter(this);
3301   for (; !iter.done(); iter.next()) {
3302     int ioff = iter.inner_class_info_index();
3303     // Inner class attribute can be zero, skip it.
3304     // Strange but true:  JVM spec. allows null inner class refs.
3305     if (ioff == 0) continue;
3306 
3307     // only look at classes that are already loaded
3308     // since we are looking for the flags for our self.
3309     Symbol* inner_name = constants()->klass_name_at(ioff);
3310     if (name() == inner_name) {
3311       // This is really a member class.
3312       access = iter.inner_access_flags();
3313       break;
3314     }
3315   }
3316   // Remember to strip ACC_SUPER bit
3317   return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
3318 }
3319 
3320 jint InstanceKlass::jvmti_class_status() const {
3321   jint result = 0;
3322 
3323   if (is_linked()) {
3324     result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3325   }
3326 
3327   if (is_initialized()) {
3328     assert(is_linked(), "Class status is not consistent");
3329     result |= JVMTI_CLASS_STATUS_INITIALIZED;
3330   }
3331   if (is_in_error_state()) {
3332     result |= JVMTI_CLASS_STATUS_ERROR;
3333   }
3334   return result;
3335 }
3336 
3337 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {

3551     }
3552     osr = osr->osr_link();
3553   }
3554 
3555   assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3556   if (best != nullptr && best->comp_level() >= comp_level) {
3557     return best;
3558   }
3559   return nullptr;
3560 }
3561 
3562 // -----------------------------------------------------------------------------------------------------
3563 // Printing
3564 
3565 #define BULLET  " - "
3566 
3567 static const char* state_names[] = {
3568   "allocated", "loaded", "being_linked", "linked", "being_initialized", "fully_initialized", "initialization_error"
3569 };
3570 
3571 static void print_vtable(intptr_t* start, int len, outputStream* st) {



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





3575     if (MetaspaceObj::is_valid((Metadata*)e)) {
3576       st->print(" ");
3577       ((Metadata*)e)->print_value_on(st);






3578     }
3579     st->cr();
3580   }
3581 }
3582 
3583 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3584   return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);





















3585 }
3586 
3587 const char* InstanceKlass::init_state_name() const {
3588   return state_names[init_state()];
3589 }
3590 
3591 void InstanceKlass::print_on(outputStream* st) const {
3592   assert(is_klass(), "must be klass");
3593   Klass::print_on(st);
3594 
3595   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
3596   st->print(BULLET"klass size:        %d", size());                               st->cr();
3597   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
3598   st->print(BULLET"flags:             "); _misc_flags.print_on(st);               st->cr();
3599   st->print(BULLET"state:             "); st->print_cr("%s", init_state_name());
3600   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
3601   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3602   st->print(BULLET"sub:               ");
3603   Klass* sub = subklass();
3604   int n;
3605   for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3606     if (n < MaxSubklassPrintSize) {
3607       sub->print_value_on(st);
3608       st->print("   ");
3609     }
3610   }
3611   if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3612   st->cr();
3613 
3614   if (is_interface()) {
3615     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
3616     if (nof_implementors() == 1) {
3617       st->print_cr(BULLET"implementor:    ");
3618       st->print("   ");
3619       implementor()->print_value_on(st);
3620       st->cr();
3621     }
3622   }
3623 
3624   st->print(BULLET"arrays:            "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3625   st->print(BULLET"methods:           "); methods()->print_value_on(st);                  st->cr();
3626   if (Verbose || WizardMode) {
3627     Array<Method*>* method_array = methods();
3628     for (int i = 0; i < method_array->length(); i++) {
3629       st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3630     }
3631   }
3632   st->print(BULLET"method ordering:   "); method_ordering()->print_value_on(st);      st->cr();
3633   st->print(BULLET"default_methods:   "); default_methods()->print_value_on(st);      st->cr();
3634   if (Verbose && default_methods() != nullptr) {
3635     Array<Method*>* method_array = default_methods();
3636     for (int i = 0; i < method_array->length(); i++) {
3637       st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3638     }
3639   }
3640   if (default_vtable_indices() != nullptr) {
3641     st->print(BULLET"default vtable indices:   "); default_vtable_indices()->print_value_on(st);       st->cr();
3642   }
3643   st->print(BULLET"local interfaces:  "); local_interfaces()->print_value_on(st);      st->cr();
3644   st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3645   st->print(BULLET"constants:         "); constants()->print_value_on(st);         st->cr();
3646   if (class_loader_data() != nullptr) {
3647     st->print(BULLET"class loader data:  ");
3648     class_loader_data()->print_value_on(st);
3649     st->cr();
3650   }
3651   if (source_file_name() != nullptr) {
3652     st->print(BULLET"source file:       ");
3653     source_file_name()->print_value_on(st);
3654     st->cr();
3655   }
3656   if (source_debug_extension() != nullptr) {
3657     st->print(BULLET"source debug extension:       ");
3658     st->print("%s", source_debug_extension());
3659     st->cr();
3660   }
3661   st->print(BULLET"class annotations:       "); class_annotations()->print_value_on(st); st->cr();
3662   st->print(BULLET"class type annotations:  "); class_type_annotations()->print_value_on(st); st->cr();
3663   st->print(BULLET"field annotations:       "); fields_annotations()->print_value_on(st); st->cr();
3664   st->print(BULLET"field type annotations:  "); fields_type_annotations()->print_value_on(st); st->cr();

3670          pv_node = pv_node->previous_versions()) {
3671       if (!have_pv)
3672         st->print(BULLET"previous version:  ");
3673       have_pv = true;
3674       pv_node->constants()->print_value_on(st);
3675     }
3676     if (have_pv) st->cr();
3677   }
3678 
3679   if (generic_signature() != nullptr) {
3680     st->print(BULLET"generic signature: ");
3681     generic_signature()->print_value_on(st);
3682     st->cr();
3683   }
3684   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
3685   st->print(BULLET"nest members:     "); nest_members()->print_value_on(st);     st->cr();
3686   if (record_components() != nullptr) {
3687     st->print(BULLET"record components:     "); record_components()->print_value_on(st);     st->cr();
3688   }
3689   st->print(BULLET"permitted subclasses:     "); permitted_subclasses()->print_value_on(st);     st->cr();

3690   if (java_mirror() != nullptr) {
3691     st->print(BULLET"java mirror:       ");
3692     java_mirror()->print_value_on(st);
3693     st->cr();
3694   } else {
3695     st->print_cr(BULLET"java mirror:       null");
3696   }
3697   st->print(BULLET"vtable length      %d  (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3698   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
3699   st->print(BULLET"itable length      %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3700   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_itable(), itable_length(), st);
3701   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3702   FieldPrinter print_static_field(st);
3703   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3704   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3705   FieldPrinter print_nonstatic_field(st);
3706   InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3707   ik->print_nonstatic_fields(&print_nonstatic_field);
3708 
3709   st->print(BULLET"non-static oop maps: ");
3710   OopMapBlock* map     = start_of_nonstatic_oop_maps();
3711   OopMapBlock* end_map = map + nonstatic_oop_map_count();
3712   while (map < end_map) {
3713     st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3714     map++;
3715   }
3716   st->cr();
3717 }
3718 
3719 void InstanceKlass::print_value_on(outputStream* st) const {
3720   assert(is_klass(), "must be klass");

  54 #include "logging/logStream.hpp"
  55 #include "memory/allocation.inline.hpp"
  56 #include "memory/iterator.inline.hpp"
  57 #include "memory/metadataFactory.hpp"
  58 #include "memory/metaspaceClosure.hpp"
  59 #include "memory/oopFactory.hpp"
  60 #include "memory/resourceArea.hpp"
  61 #include "memory/universe.hpp"
  62 #include "oops/fieldStreams.inline.hpp"
  63 #include "oops/constantPool.hpp"
  64 #include "oops/instanceClassLoaderKlass.hpp"
  65 #include "oops/instanceKlass.inline.hpp"
  66 #include "oops/instanceMirrorKlass.hpp"
  67 #include "oops/instanceOop.hpp"
  68 #include "oops/instanceStackChunkKlass.hpp"
  69 #include "oops/klass.inline.hpp"
  70 #include "oops/method.hpp"
  71 #include "oops/oop.inline.hpp"
  72 #include "oops/recordComponent.hpp"
  73 #include "oops/symbol.hpp"
  74 #include "oops/inlineKlass.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/threads.hpp"
  91 #include "services/classLoadingService.hpp"
  92 #include "services/finalizerService.hpp"
  93 #include "services/threadService.hpp"
  94 #include "utilities/dtrace.hpp"

 151 
 152 static inline bool is_class_loader(const Symbol* class_name,
 153                                    const ClassFileParser& parser) {
 154   assert(class_name != nullptr, "invariant");
 155 
 156   if (class_name == vmSymbols::java_lang_ClassLoader()) {
 157     return true;
 158   }
 159 
 160   if (vmClasses::ClassLoader_klass_loaded()) {
 161     const Klass* const super_klass = parser.super_klass();
 162     if (super_klass != nullptr) {
 163       if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
 164         return true;
 165       }
 166     }
 167   }
 168   return false;
 169 }
 170 
 171 bool InstanceKlass::field_is_null_free_inline_type(int index) const {
 172   return field(index).field_flags().is_null_free_inline_type();
 173 }
 174 
 175 bool InstanceKlass::is_class_in_loadable_descriptors_attribute(Symbol* name) const {
 176   if (_loadable_descriptors == nullptr) return false;
 177   for (int i = 0; i < _loadable_descriptors->length(); i++) {
 178         Symbol* class_name = _constants->klass_at_noresolve(_loadable_descriptors->at(i));
 179         if (class_name == name) return true;
 180   }
 181   return false;
 182 }
 183 
 184 static inline bool is_stack_chunk_class(const Symbol* class_name,
 185                                         const ClassLoaderData* loader_data) {
 186   return (class_name == vmSymbols::jdk_internal_vm_StackChunk() &&
 187           loader_data->is_the_null_class_loader_data());
 188 }
 189 
 190 // private: called to verify that k is a static member of this nest.
 191 // We know that k is an instance class in the same package and hence the
 192 // same classloader.
 193 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
 194   assert(!is_hidden(), "unexpected hidden class");
 195   if (_nest_members == nullptr || _nest_members == Universe::the_empty_short_array()) {
 196     if (log_is_enabled(Trace, class, nestmates)) {
 197       ResourceMark rm(current);
 198       log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
 199                                   k->external_name(), this->external_name());
 200     }
 201     return false;
 202   }
 203 

 436   log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
 437                               this->external_name(),
 438                               access ? "" : "NOT ",
 439                               k->external_name());
 440   return access;
 441 }
 442 
 443 const char* InstanceKlass::nest_host_error() {
 444   if (_nest_host_index == 0) {
 445     return nullptr;
 446   } else {
 447     constantPoolHandle cph(Thread::current(), constants());
 448     return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
 449   }
 450 }
 451 
 452 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
 453   const int size = InstanceKlass::size(parser.vtable_size(),
 454                                        parser.itable_size(),
 455                                        nonstatic_oop_map_size(parser.total_oop_map_count()),
 456                                        parser.is_interface(),
 457                                        parser.is_inline_type());
 458 
 459   const Symbol* const class_name = parser.class_name();
 460   assert(class_name != nullptr, "invariant");
 461   ClassLoaderData* loader_data = parser.loader_data();
 462   assert(loader_data != nullptr, "invariant");
 463 
 464   InstanceKlass* ik;
 465 
 466   // Allocation
 467   if (parser.is_instance_ref_klass()) {
 468     // java.lang.ref.Reference
 469     ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
 470   } else if (class_name == vmSymbols::java_lang_Class()) {
 471     // mirror - java.lang.Class
 472     ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
 473   } else if (is_stack_chunk_class(class_name, loader_data)) {
 474     // stack chunk
 475     ik = new (loader_data, size, THREAD) InstanceStackChunkKlass(parser);
 476   } else if (is_class_loader(class_name, parser)) {
 477     // class loader - java.lang.ClassLoader
 478     ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
 479   } else if (parser.is_inline_type()) {
 480     // inline type
 481     ik = new (loader_data, size, THREAD) InlineKlass(parser);
 482   } else {
 483     // normal
 484     ik = new (loader_data, size, THREAD) InstanceKlass(parser);
 485   }
 486 
 487   // Check for pending exception before adding to the loader data and incrementing
 488   // class count.  Can get OOM here.
 489   if (HAS_PENDING_EXCEPTION) {
 490     return nullptr;
 491   }
 492 
 493 #ifdef ASSERT
 494   ik->bounds_check((address) ik->start_of_vtable(), false, size);
 495   ik->bounds_check((address) ik->start_of_itable(), false, size);
 496   ik->bounds_check((address) ik->end_of_itable(), true, size);
 497   ik->bounds_check((address) ik->end_of_nonstatic_oop_maps(), true, size);
 498 #endif //ASSERT
 499   return ik;
 500 }
 501 
 502 #ifndef PRODUCT
 503 bool InstanceKlass::bounds_check(address addr, bool edge_ok, intptr_t size_in_bytes) const {
 504   const char* bad = nullptr;
 505   address end = nullptr;
 506   if (addr < (address)this) {
 507     bad = "before";
 508   } else if (addr == (address)this) {
 509     if (edge_ok)  return true;
 510     bad = "just before";
 511   } else if (addr == (end = (address)this + sizeof(intptr_t) * (size_in_bytes < 0 ? size() : size_in_bytes))) {
 512     if (edge_ok)  return true;
 513     bad = "just after";
 514   } else if (addr > end) {
 515     bad = "after";
 516   } else {
 517     return true;
 518   }
 519   tty->print_cr("%s object bounds: " INTPTR_FORMAT " [" INTPTR_FORMAT ".." INTPTR_FORMAT "]",
 520       bad, (intptr_t)addr, (intptr_t)this, (intptr_t)end);
 521   Verbose = WizardMode = true; this->print(); //@@
 522   return false;
 523 }
 524 #endif //PRODUCT
 525 
 526 // copy method ordering from resource area to Metaspace
 527 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
 528   if (m != nullptr) {
 529     // allocate a new array and copy contents (memcpy?)
 530     _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
 531     for (int i = 0; i < m->length(); i++) {
 532       _method_ordering->at_put(i, m->at(i));
 533     }
 534   } else {
 535     _method_ordering = Universe::the_empty_int_array();
 536   }
 537 }
 538 
 539 // create a new array of vtable_indices for default methods
 540 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
 541   Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
 542   assert(default_vtable_indices() == nullptr, "only create once");
 543   set_default_vtable_indices(vtable_indices);
 544   return vtable_indices;

 548   return new Monitor(Mutex::safepoint, name);
 549 }
 550 
 551 InstanceKlass::InstanceKlass() {
 552   assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS");
 553 }
 554 
 555 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) :
 556   Klass(kind),
 557   _nest_members(nullptr),
 558   _nest_host(nullptr),
 559   _permitted_subclasses(nullptr),
 560   _record_components(nullptr),
 561   _static_field_size(parser.static_field_size()),
 562   _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
 563   _itable_len(parser.itable_size()),
 564   _nest_host_index(0),
 565   _init_state(allocated),
 566   _reference_type(reference_type),
 567   _init_monitor(create_init_monitor("InstanceKlassInitMonitor_lock")),
 568   _init_thread(nullptr),
 569   _inline_type_field_klasses(nullptr),
 570   _null_marker_offsets(nullptr),
 571   _loadable_descriptors(nullptr),
 572   _adr_inlineklass_fixed_block(nullptr)
 573 {
 574   set_vtable_length(parser.vtable_size());
 575   set_access_flags(parser.access_flags());
 576   if (parser.is_hidden()) set_is_hidden();
 577   set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
 578                                                     false));
 579   if (parser.has_inline_fields()) {
 580     set_has_inline_type_fields();
 581   }
 582 
 583   assert(nullptr == _methods, "underlying memory not zeroed?");
 584   assert(is_instance_klass(), "is layout incorrect?");
 585   assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
 586 }
 587 
 588 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
 589                                        Array<Method*>* methods) {
 590   if (methods != nullptr && methods != Universe::the_empty_method_array() &&
 591       !methods->is_shared()) {
 592     for (int i = 0; i < methods->length(); i++) {
 593       Method* method = methods->at(i);
 594       if (method == nullptr) continue;  // maybe null if error processing
 595       // Only want to delete methods that are not executing for RedefineClasses.
 596       // The previous version will point to them so they're not totally dangling
 597       assert (!method->on_stack(), "shouldn't be called with methods on stack");
 598       MetadataFactory::free_metadata(loader_data, method);
 599     }
 600     MetadataFactory::free_array<Method*>(loader_data, methods);
 601   }

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

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

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

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

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

1845     ls.print("%d Initializing ", call_class_initializer_counter++);
1846     name()->print_value_on(&ls);
1847     ls.print_cr("%s (" PTR_FORMAT ") by thread \"%s\"",
1848                 h_method() == nullptr ? "(no method)" : "", p2i(this),
1849                 THREAD->name());
1850   }
1851   if (h_method() != nullptr) {
1852     JavaCallArguments args; // No arguments
1853     JavaValue result(T_VOID);
1854     JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1855   }
1856 }
1857 
1858 
1859 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1860   InterpreterOopMap* entry_for) {
1861   // Lazily create the _oop_map_cache at first request
1862   // Lock-free access requires load_acquire.
1863   OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1864   if (oop_map_cache == nullptr) {
1865     MutexLocker x(OopMapCacheAlloc_lock,  Mutex::_no_safepoint_check_flag);
1866     // Check if _oop_map_cache was allocated while we were waiting for this lock
1867     if ((oop_map_cache = _oop_map_cache) == nullptr) {
1868       oop_map_cache = new OopMapCache();
1869       // Ensure _oop_map_cache is stable, since it is examined without a lock
1870       Atomic::release_store(&_oop_map_cache, oop_map_cache);
1871     }
1872   }
1873   // _oop_map_cache is constant after init; lookup below does its own locking.
1874   oop_map_cache->lookup(method, bci, entry_for);
1875 }
1876 




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

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

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

2821     int method_table_offset_in_words = ioe->offset()/wordSize;
2822     int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2823 
2824     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2825                          / itableOffsetEntry::size();
2826 
2827     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2828       if (ioe->interface_klass() != nullptr) {
2829         it->push(ioe->interface_klass_addr());
2830         itableMethodEntry* ime = ioe->first_method_entry(this);
2831         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2832         for (int index = 0; index < n; index ++) {
2833           it->push(ime[index].method_addr());
2834         }
2835       }
2836     }
2837   }
2838 
2839   it->push(&_nest_members);
2840   it->push(&_permitted_subclasses);
2841   it->push(&_loadable_descriptors);
2842   it->push(&_record_components);
2843 
2844   it->push(&_inline_type_field_klasses, MetaspaceClosure::_writable);
2845   it->push(&_null_marker_offsets);
2846 }
2847 
2848 #if INCLUDE_CDS
2849 void InstanceKlass::remove_unshareable_info() {
2850 
2851   if (is_linked()) {
2852     assert(can_be_verified_at_dumptime(), "must be");
2853     // Remember this so we can avoid walking the hierarchy at runtime.
2854     set_verified_at_dump_time();
2855   }
2856 
2857   Klass::remove_unshareable_info();
2858 
2859   if (SystemDictionaryShared::has_class_failed_verification(this)) {
2860     // Classes are attempted to link during dumping and may fail,
2861     // but these classes are still in the dictionary and class list in CLD.
2862     // If the class has failed verification, there is nothing else to remove.
2863     return;
2864   }
2865 

2869   // being added to class hierarchy (see InstanceKlass:::add_to_hierarchy()).
2870   _init_state = allocated;
2871 
2872   { // Otherwise this needs to take out the Compile_lock.
2873     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2874     init_implementor();
2875   }
2876 
2877   constants()->remove_unshareable_info();
2878 
2879   for (int i = 0; i < methods()->length(); i++) {
2880     Method* m = methods()->at(i);
2881     m->remove_unshareable_info();
2882   }
2883 
2884   // do array classes also.
2885   if (array_klasses() != nullptr) {
2886     array_klasses()->remove_unshareable_info();
2887   }
2888 
2889   // These are not allocated from metaspace. They are safe to set to nullptr.
2890   _source_debug_extension = nullptr;
2891   _dep_context = nullptr;
2892   _osr_nmethods_head = nullptr;
2893 #if INCLUDE_JVMTI
2894   _breakpoints = nullptr;
2895   _previous_versions = nullptr;
2896   _cached_class_file = nullptr;
2897   _jvmti_cached_class_field_map = nullptr;
2898 #endif
2899 
2900   _init_thread = nullptr;
2901   _methods_jmethod_ids = nullptr;
2902   _jni_ids = nullptr;
2903   _oop_map_cache = nullptr;
2904   // clear _nest_host to ensure re-load at runtime
2905   _nest_host = nullptr;
2906   init_shared_package_entry();
2907   _dep_context_last_cleaned = 0;
2908   _init_monitor = nullptr;
2909 

2954 void InstanceKlass::compute_has_loops_flag_for_methods() {
2955   Array<Method*>* methods = this->methods();
2956   for (int index = 0; index < methods->length(); ++index) {
2957     Method* m = methods->at(index);
2958     if (!m->is_overpass()) { // work around JDK-8305771
2959       m->compute_has_loops_flag();
2960     }
2961   }
2962 }
2963 
2964 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2965                                              PackageEntry* pkg_entry, TRAPS) {
2966   // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2967   // before the InstanceKlass is added to the SystemDictionary. Make
2968   // sure the current state is <loaded.
2969   assert(!is_loaded(), "invalid init state");
2970   assert(!shared_loading_failed(), "Must not try to load failed class again");
2971   set_package(loader_data, pkg_entry, CHECK);
2972   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2973 
2974   if (is_inline_klass()) {
2975     InlineKlass::cast(this)->initialize_calling_convention(CHECK);
2976   }
2977 
2978   Array<Method*>* methods = this->methods();
2979   int num_methods = methods->length();
2980   for (int index = 0; index < num_methods; ++index) {
2981     methods->at(index)->restore_unshareable_info(CHECK);
2982   }
2983 #if INCLUDE_JVMTI
2984   if (JvmtiExport::has_redefined_a_class()) {
2985     // Reinitialize vtable because RedefineClasses may have changed some
2986     // entries in this vtable for super classes so the CDS vtable might
2987     // point to old or obsolete entries.  RedefineClasses doesn't fix up
2988     // vtables in the shared system dictionary, only the main one.
2989     // It also redefines the itable too so fix that too.
2990     // First fix any default methods that point to a super class that may
2991     // have been redefined.
2992     bool trace_name_printed = false;
2993     adjust_default_methods(&trace_name_printed);
2994     vtable().initialize_vtable();
2995     itable().initialize_itable();
2996   }
2997 #endif
2998 
2999   // restore constant pool resolved references
3000   constants()->restore_unshareable_info(CHECK);
3001 
3002   if (array_klasses() != nullptr) {
3003     // To get a consistent list of classes we need MultiArray_lock to ensure
3004     // array classes aren't observed while they are being restored.
3005     MutexLocker ml(MultiArray_lock);
3006     assert(this == ObjArrayKlass::cast(array_klasses())->bottom_klass(), "sanity");
3007     // Array classes have null protection domain.
3008     // --> see ArrayKlass::complete_create_array_klass()
3009     array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
3010   }
3011 
3012   // Initialize @ValueBased class annotation
3013   if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation()) {
3014     set_is_value_based();
3015   }
3016 
3017   // restore the monitor
3018   _init_monitor = create_init_monitor("InstanceKlassInitMonitorRestored_lock");
3019 }
3020 
3021 // Check if a class or any of its supertypes has a version older than 50.
3022 // CDS will not perform verification of old classes during dump time because
3023 // without changing the old verifier, the verification constraint cannot be
3024 // retrieved during dump time.
3025 // Verification of archived old classes will be performed during run time.
3026 bool InstanceKlass::can_be_verified_at_dumptime() const {

3185   } else {
3186     // Adding one to the attribute length in order to store a null terminator
3187     // character could cause an overflow because the attribute length is
3188     // already coded with an u4 in the classfile, but in practice, it's
3189     // unlikely to happen.
3190     assert((length+1) > length, "Overflow checking");
3191     char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
3192     for (int i = 0; i < length; i++) {
3193       sde[i] = array[i];
3194     }
3195     sde[length] = '\0';
3196     _source_debug_extension = sde;
3197   }
3198 }
3199 
3200 Symbol* InstanceKlass::generic_signature() const                   { return _constants->generic_signature(); }
3201 u2 InstanceKlass::generic_signature_index() const                  { return _constants->generic_signature_index(); }
3202 void InstanceKlass::set_generic_signature_index(u2 sig_index)      { _constants->set_generic_signature_index(sig_index); }
3203 
3204 const char* InstanceKlass::signature_name() const {
3205   return signature_name_of_carrier(JVM_SIGNATURE_CLASS);
3206 }
3207 
3208 const char* InstanceKlass::signature_name_of_carrier(char c) const {
3209   // Get the internal name as a c string
3210   const char* src = (const char*) (name()->as_C_string());
3211   const int src_length = (int)strlen(src);
3212 
3213   char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
3214 
3215   // Add L or Q as type indicator
3216   int dest_index = 0;
3217   dest[dest_index++] = c;
3218 
3219   // Add the actual class name
3220   for (int src_index = 0; src_index < src_length; ) {
3221     dest[dest_index++] = src[src_index++];
3222   }
3223 
3224   if (is_hidden()) { // Replace the last '+' with a '.'.
3225     for (int index = (int)src_length; index > 0; index--) {
3226       if (dest[index] == '+') {
3227         dest[index] = JVM_SIGNATURE_DOT;
3228         break;
3229       }
3230     }
3231   }
3232 
3233   // Add the semicolon and the null
3234   dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
3235   dest[dest_index] = '\0';
3236   return dest;
3237 }

3539 jint InstanceKlass::compute_modifier_flags() const {
3540   jint access = access_flags().as_int();
3541 
3542   // But check if it happens to be member class.
3543   InnerClassesIterator iter(this);
3544   for (; !iter.done(); iter.next()) {
3545     int ioff = iter.inner_class_info_index();
3546     // Inner class attribute can be zero, skip it.
3547     // Strange but true:  JVM spec. allows null inner class refs.
3548     if (ioff == 0) continue;
3549 
3550     // only look at classes that are already loaded
3551     // since we are looking for the flags for our self.
3552     Symbol* inner_name = constants()->klass_name_at(ioff);
3553     if (name() == inner_name) {
3554       // This is really a member class.
3555       access = iter.inner_access_flags();
3556       break;
3557     }
3558   }
3559   return (access & JVM_ACC_WRITTEN_FLAGS);

3560 }
3561 
3562 jint InstanceKlass::jvmti_class_status() const {
3563   jint result = 0;
3564 
3565   if (is_linked()) {
3566     result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3567   }
3568 
3569   if (is_initialized()) {
3570     assert(is_linked(), "Class status is not consistent");
3571     result |= JVMTI_CLASS_STATUS_INITIALIZED;
3572   }
3573   if (is_in_error_state()) {
3574     result |= JVMTI_CLASS_STATUS_ERROR;
3575   }
3576   return result;
3577 }
3578 
3579 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {

3793     }
3794     osr = osr->osr_link();
3795   }
3796 
3797   assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3798   if (best != nullptr && best->comp_level() >= comp_level) {
3799     return best;
3800   }
3801   return nullptr;
3802 }
3803 
3804 // -----------------------------------------------------------------------------------------------------
3805 // Printing
3806 
3807 #define BULLET  " - "
3808 
3809 static const char* state_names[] = {
3810   "allocated", "loaded", "being_linked", "linked", "being_initialized", "fully_initialized", "initialization_error"
3811 };
3812 
3813 static void print_vtable(address self, intptr_t* start, int len, outputStream* st) {
3814   ResourceMark rm;
3815   int* forward_refs = NEW_RESOURCE_ARRAY(int, len);
3816   for (int i = 0; i < len; i++)  forward_refs[i] = 0;
3817   for (int i = 0; i < len; i++) {
3818     intptr_t e = start[i];
3819     st->print("%d : " INTPTR_FORMAT, i, e);
3820     if (forward_refs[i] != 0) {
3821       int from = forward_refs[i];
3822       int off = (int) start[from];
3823       st->print(" (offset %d <= [%d])", off, from);
3824     }
3825     if (MetaspaceObj::is_valid((Metadata*)e)) {
3826       st->print(" ");
3827       ((Metadata*)e)->print_value_on(st);
3828     } else if (self != nullptr && e > 0 && e < 0x10000) {
3829       address location = self + e;
3830       int index = (int)((intptr_t*)location - start);
3831       st->print(" (offset %d => [%d])", (int)e, index);
3832       if (index >= 0 && index < len)
3833         forward_refs[index] = i;
3834     }
3835     st->cr();
3836   }
3837 }
3838 
3839 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3840   return print_vtable(nullptr, reinterpret_cast<intptr_t*>(start), len, st);
3841 }
3842 
3843 template<typename T>
3844  static void print_array_on(outputStream* st, Array<T>* array) {
3845    if (array == nullptr) { st->print_cr("nullptr"); return; }
3846    array->print_value_on(st); st->cr();
3847    if (Verbose || WizardMode) {
3848      for (int i = 0; i < array->length(); i++) {
3849        st->print("%d : ", i); array->at(i)->print_value_on(st); st->cr();
3850      }
3851    }
3852  }
3853 
3854 static void print_array_on(outputStream* st, Array<int>* array) {
3855   if (array == nullptr) { st->print_cr("nullptr"); return; }
3856   array->print_value_on(st); st->cr();
3857   if (Verbose || WizardMode) {
3858     for (int i = 0; i < array->length(); i++) {
3859       st->print("%d : %d", i, array->at(i)); st->cr();
3860     }
3861   }
3862 }
3863 
3864 const char* InstanceKlass::init_state_name() const {
3865   return state_names[init_state()];
3866 }
3867 
3868 void InstanceKlass::print_on(outputStream* st) const {
3869   assert(is_klass(), "must be klass");
3870   Klass::print_on(st);
3871 
3872   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
3873   st->print(BULLET"klass size:        %d", size());                               st->cr();
3874   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
3875   st->print(BULLET"flags:             "); _misc_flags.print_on(st);               st->cr();
3876   st->print(BULLET"state:             "); st->print_cr("%s", init_state_name());
3877   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
3878   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3879   st->print(BULLET"sub:               ");
3880   Klass* sub = subklass();
3881   int n;
3882   for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3883     if (n < MaxSubklassPrintSize) {
3884       sub->print_value_on(st);
3885       st->print("   ");
3886     }
3887   }
3888   if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3889   st->cr();
3890 
3891   if (is_interface()) {
3892     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
3893     if (nof_implementors() == 1) {
3894       st->print_cr(BULLET"implementor:    ");
3895       st->print("   ");
3896       implementor()->print_value_on(st);
3897       st->cr();
3898     }
3899   }
3900 
3901   st->print(BULLET"arrays:            "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3902   st->print(BULLET"methods:           "); print_array_on(st, methods());
3903   st->print(BULLET"method ordering:   "); print_array_on(st, method_ordering());
3904   st->print(BULLET"default_methods:   "); print_array_on(st, default_methods());












3905   if (default_vtable_indices() != nullptr) {
3906     st->print(BULLET"default vtable indices:   "); print_array_on(st, default_vtable_indices());
3907   }
3908   st->print(BULLET"local interfaces:  "); print_array_on(st, local_interfaces());
3909   st->print(BULLET"trans. interfaces: "); print_array_on(st, transitive_interfaces());
3910   st->print(BULLET"constants:         "); constants()->print_value_on(st);         st->cr();
3911   if (class_loader_data() != nullptr) {
3912     st->print(BULLET"class loader data:  ");
3913     class_loader_data()->print_value_on(st);
3914     st->cr();
3915   }
3916   if (source_file_name() != nullptr) {
3917     st->print(BULLET"source file:       ");
3918     source_file_name()->print_value_on(st);
3919     st->cr();
3920   }
3921   if (source_debug_extension() != nullptr) {
3922     st->print(BULLET"source debug extension:       ");
3923     st->print("%s", source_debug_extension());
3924     st->cr();
3925   }
3926   st->print(BULLET"class annotations:       "); class_annotations()->print_value_on(st); st->cr();
3927   st->print(BULLET"class type annotations:  "); class_type_annotations()->print_value_on(st); st->cr();
3928   st->print(BULLET"field annotations:       "); fields_annotations()->print_value_on(st); st->cr();
3929   st->print(BULLET"field type annotations:  "); fields_type_annotations()->print_value_on(st); st->cr();

3935          pv_node = pv_node->previous_versions()) {
3936       if (!have_pv)
3937         st->print(BULLET"previous version:  ");
3938       have_pv = true;
3939       pv_node->constants()->print_value_on(st);
3940     }
3941     if (have_pv) st->cr();
3942   }
3943 
3944   if (generic_signature() != nullptr) {
3945     st->print(BULLET"generic signature: ");
3946     generic_signature()->print_value_on(st);
3947     st->cr();
3948   }
3949   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
3950   st->print(BULLET"nest members:     "); nest_members()->print_value_on(st);     st->cr();
3951   if (record_components() != nullptr) {
3952     st->print(BULLET"record components:     "); record_components()->print_value_on(st);     st->cr();
3953   }
3954   st->print(BULLET"permitted subclasses:     "); permitted_subclasses()->print_value_on(st);     st->cr();
3955   st->print(BULLET"loadable descriptors:     "); loadable_descriptors()->print_value_on(st); st->cr();
3956   if (java_mirror() != nullptr) {
3957     st->print(BULLET"java mirror:       ");
3958     java_mirror()->print_value_on(st);
3959     st->cr();
3960   } else {
3961     st->print_cr(BULLET"java mirror:       null");
3962   }
3963   st->print(BULLET"vtable length      %d  (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3964   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
3965   st->print(BULLET"itable length      %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3966   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(nullptr, start_of_itable(), itable_length(), st);
3967   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3968   FieldPrinter print_static_field(st);
3969   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3970   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3971   FieldPrinter print_nonstatic_field(st);
3972   InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3973   ik->print_nonstatic_fields(&print_nonstatic_field);
3974 
3975   st->print(BULLET"non-static oop maps: ");
3976   OopMapBlock* map     = start_of_nonstatic_oop_maps();
3977   OopMapBlock* end_map = map + nonstatic_oop_map_count();
3978   while (map < end_map) {
3979     st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3980     map++;
3981   }
3982   st->cr();
3983 }
3984 
3985 void InstanceKlass::print_value_on(outputStream* st) const {
3986   assert(is_klass(), "must be klass");
< prev index next >