< 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   }
 724   set_inline_type_field_klasses_array(nullptr);
 725 
 726   if (null_marker_offsets_array() != nullptr) {
 727     MetadataFactory::free_array<int>(loader_data, null_marker_offsets_array());
 728   }
 729 
 730   // If a method from a redefined class is using this constant pool, don't
 731   // delete it, yet.  The new class's previous version will point to this.
 732   if (constants() != nullptr) {
 733     assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
 734     if (!constants()->is_shared()) {
 735       MetadataFactory::free_metadata(loader_data, constants());
 736     }
 737     // Delete any cached resolution errors for the constant pool
 738     SystemDictionary::delete_resolution_error(constants());
 739 
 740     set_constants(nullptr);
 741   }
 742 
 743   if (inner_classes() != nullptr &&
 744       inner_classes() != Universe::the_empty_short_array() &&
 745       !inner_classes()->is_shared()) {
 746     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
 747   }
 748   set_inner_classes(nullptr);
 749 
 750   if (nest_members() != nullptr &&
 751       nest_members() != Universe::the_empty_short_array() &&
 752       !nest_members()->is_shared()) {
 753     MetadataFactory::free_array<jushort>(loader_data, nest_members());
 754   }
 755   set_nest_members(nullptr);
 756 
 757   if (permitted_subclasses() != nullptr &&
 758       permitted_subclasses() != Universe::the_empty_short_array() &&
 759       !permitted_subclasses()->is_shared()) {
 760     MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
 761   }
 762   set_permitted_subclasses(nullptr);
 763 
 764   if (loadable_descriptors() != nullptr &&
 765       loadable_descriptors() != Universe::the_empty_short_array() &&
 766       !loadable_descriptors()->is_shared()) {
 767     MetadataFactory::free_array<jushort>(loader_data, loadable_descriptors());
 768   }
 769 
 770   // We should deallocate the Annotations instance if it's not in shared spaces.
 771   if (annotations() != nullptr && !annotations()->is_shared()) {
 772     MetadataFactory::free_metadata(loader_data, annotations());
 773   }
 774   set_annotations(nullptr);
 775 
 776   SystemDictionaryShared::handle_class_unloading(this);
 777 
 778 #if INCLUDE_CDS_JAVA_HEAP
 779   if (CDSConfig::is_dumping_heap()) {
 780     HeapShared::remove_scratch_objects(this);
 781   }
 782 #endif
 783 }
 784 
 785 bool InstanceKlass::is_record() const {
 786   return _record_components != nullptr &&
 787          is_final() &&
 788          java_super() == vmClasses::Record_klass();
 789 }

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

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

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

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

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




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

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

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

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

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

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

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

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

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

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












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

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