< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page

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

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

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













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

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

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



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






 477   return ik;
 478 }
 479 























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




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



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

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










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







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

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






































































































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

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



















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

































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

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

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

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









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

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



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

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

2498   it->push(&_record_components);



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

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

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




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

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


2849 

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

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

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



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





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






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





















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

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

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

  55 #include "logging/logStream.hpp"
  56 #include "memory/allocation.inline.hpp"
  57 #include "memory/iterator.inline.hpp"
  58 #include "memory/metadataFactory.hpp"
  59 #include "memory/metaspaceClosure.hpp"
  60 #include "memory/oopFactory.hpp"
  61 #include "memory/resourceArea.hpp"
  62 #include "memory/universe.hpp"
  63 #include "oops/fieldStreams.inline.hpp"
  64 #include "oops/constantPool.hpp"
  65 #include "oops/instanceClassLoaderKlass.hpp"
  66 #include "oops/instanceKlass.inline.hpp"
  67 #include "oops/instanceMirrorKlass.hpp"
  68 #include "oops/instanceOop.hpp"
  69 #include "oops/instanceStackChunkKlass.hpp"
  70 #include "oops/klass.inline.hpp"
  71 #include "oops/method.hpp"
  72 #include "oops/oop.inline.hpp"
  73 #include "oops/recordComponent.hpp"
  74 #include "oops/symbol.hpp"
  75 #include "oops/inlineKlass.hpp"
  76 #include "prims/jvmtiExport.hpp"
  77 #include "prims/jvmtiRedefineClasses.hpp"
  78 #include "prims/jvmtiThreadState.hpp"
  79 #include "prims/methodComparator.hpp"
  80 #include "runtime/arguments.hpp"
  81 #include "runtime/deoptimization.hpp"
  82 #include "runtime/atomic.hpp"
  83 #include "runtime/fieldDescriptor.inline.hpp"
  84 #include "runtime/handles.inline.hpp"
  85 #include "runtime/javaCalls.hpp"
  86 #include "runtime/javaThread.inline.hpp"
  87 #include "runtime/mutexLocker.hpp"
  88 #include "runtime/orderAccess.hpp"
  89 #include "runtime/os.inline.hpp"
  90 #include "runtime/reflection.hpp"
  91 #include "runtime/synchronizer.hpp"
  92 #include "runtime/threads.hpp"
  93 #include "services/classLoadingService.hpp"
  94 #include "services/finalizerService.hpp"
  95 #include "services/threadService.hpp"

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

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

 699       (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
 700       !secondary_supers()->is_shared()) {
 701     MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
 702   }
 703   set_secondary_supers(nullptr);
 704 
 705   deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
 706   set_transitive_interfaces(nullptr);
 707   set_local_interfaces(nullptr);
 708 
 709   if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->is_shared()) {
 710     MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
 711   }
 712   set_fieldinfo_stream(nullptr);
 713 
 714   if (fields_status() != nullptr && !fields_status()->is_shared()) {
 715     MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
 716   }
 717   set_fields_status(nullptr);
 718 
 719   if (inline_type_field_klasses_array() != nullptr) {
 720     MetadataFactory::free_array<InlineKlass*>(loader_data, inline_type_field_klasses_array());
 721     set_inline_type_field_klasses_array(nullptr);
 722   }
 723 
 724   if (null_marker_offsets_array() != nullptr) {
 725     MetadataFactory::free_array<int>(loader_data, null_marker_offsets_array());
 726     set_null_marker_offsets_array(nullptr);
 727   }
 728 
 729   // If a method from a redefined class is using this constant pool, don't
 730   // delete it, yet.  The new class's previous version will point to this.
 731   if (constants() != nullptr) {
 732     assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
 733     if (!constants()->is_shared()) {
 734       MetadataFactory::free_metadata(loader_data, constants());
 735     }
 736     // Delete any cached resolution errors for the constant pool
 737     SystemDictionary::delete_resolution_error(constants());
 738 
 739     set_constants(nullptr);
 740   }
 741 
 742   if (inner_classes() != nullptr &&
 743       inner_classes() != Universe::the_empty_short_array() &&
 744       !inner_classes()->is_shared()) {
 745     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
 746   }
 747   set_inner_classes(nullptr);
 748 
 749   if (nest_members() != nullptr &&
 750       nest_members() != Universe::the_empty_short_array() &&
 751       !nest_members()->is_shared()) {
 752     MetadataFactory::free_array<jushort>(loader_data, nest_members());
 753   }
 754   set_nest_members(nullptr);
 755 
 756   if (permitted_subclasses() != nullptr &&
 757       permitted_subclasses() != Universe::the_empty_short_array() &&
 758       !permitted_subclasses()->is_shared()) {
 759     MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
 760   }
 761   set_permitted_subclasses(nullptr);
 762 
 763   if (loadable_descriptors() != nullptr &&
 764       loadable_descriptors() != Universe::the_empty_short_array() &&
 765       !loadable_descriptors()->is_shared()) {
 766     MetadataFactory::free_array<jushort>(loader_data, loadable_descriptors());
 767   }
 768   set_loadable_descriptors(nullptr);
 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 }

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

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

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

1731     ResourceMark rm(THREAD);
1732     THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1733               : vmSymbols::java_lang_InstantiationException(), external_name());
1734   }
1735   if (this == vmClasses::Class_klass()) {
1736     ResourceMark rm(THREAD);
1737     THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1738               : vmSymbols::java_lang_IllegalAccessException(), external_name());
1739   }
1740 }
1741 
1742 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1743   // Need load-acquire for lock-free read
1744   if (array_klasses_acquire() == nullptr) {
1745 
1746     // Recursively lock array allocation
1747     RecursiveLocker rl(MultiArray_lock, THREAD);
1748 
1749     // Check if another thread created the array klass while we were waiting for the lock.
1750     if (array_klasses() == nullptr) {
1751       ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, false, CHECK_NULL);
1752       // use 'release' to pair with lock-free load
1753       release_set_array_klasses(k);
1754     }
1755   }
1756 
1757   // array_klasses() will always be set at this point
1758   ArrayKlass* ak = array_klasses();
1759   assert(ak != nullptr, "should be set");
1760   return ak->array_klass(n, THREAD);
1761 }
1762 
1763 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1764   // Need load-acquire for lock-free read
1765   ArrayKlass* ak = array_klasses_acquire();
1766   if (ak == nullptr) {
1767     return nullptr;
1768   } else {
1769     return ak->array_klass_or_null(n);
1770   }
1771 }
1772 
1773 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1774   return array_klass(1, THREAD);
1775 }
1776 
1777 ArrayKlass* InstanceKlass::array_klass_or_null() {
1778   return array_klass_or_null(1);
1779 }
1780 
1781 static int call_class_initializer_counter = 0;   // for debugging
1782 
1783 Method* InstanceKlass::class_initializer() const {
1784   Method* clinit = find_method(
1785       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1786   if (clinit != nullptr && clinit->is_class_initializer()) {
1787     return clinit;
1788   }
1789   return nullptr;
1790 }
1791 
1792 void InstanceKlass::call_class_initializer(TRAPS) {
1793   if (ReplayCompiles &&
1794       (ReplaySuppressInitializers == 1 ||
1795        (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1796     // Hide the existence of the initializer for the purpose of replaying the compile
1797     return;
1798   }
1799 
1800 #if INCLUDE_CDS
1801   // This is needed to ensure the consistency of the archived heap objects.
1802   if (has_archived_enum_objs()) {
1803     assert(is_shared(), "must be");
1804     bool initialized = CDSEnumKlass::initialize_enum_klass(this, CHECK);
1805     if (initialized) {
1806       return;

1830 
1831 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1832   InterpreterOopMap* entry_for) {
1833   // Lazily create the _oop_map_cache at first request.
1834   // Load_acquire is needed to safely get instance published with CAS by another thread.
1835   OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1836   if (oop_map_cache == nullptr) {
1837     // Try to install new instance atomically.
1838     oop_map_cache = new OopMapCache();
1839     OopMapCache* other = Atomic::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
1840     if (other != nullptr) {
1841       // Someone else managed to install before us, ditch local copy and use the existing one.
1842       delete oop_map_cache;
1843       oop_map_cache = other;
1844     }
1845   }
1846   // _oop_map_cache is constant after init; lookup below does its own locking.
1847   oop_map_cache->lookup(method, bci, entry_for);
1848 }
1849 




1850 
1851 FieldInfo InstanceKlass::field(int index) const {
1852   for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1853     if (fs.index() == index) {
1854       return fs.to_FieldInfo();
1855     }
1856   }
1857   fatal("Field not found");
1858   return FieldInfo();
1859 }
1860 
1861 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1862   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1863     Symbol* f_name = fs.name();
1864     Symbol* f_sig  = fs.signature();
1865     if (f_name == name && f_sig == sig) {
1866       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1867       return true;
1868     }
1869   }

1911 
1912 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1913   // search order according to newest JVM spec (5.4.3.2, p.167).
1914   // 1) search for field in current klass
1915   if (find_local_field(name, sig, fd)) {
1916     if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1917   }
1918   // 2) search for field recursively in direct superinterfaces
1919   if (is_static) {
1920     Klass* intf = find_interface_field(name, sig, fd);
1921     if (intf != nullptr) return intf;
1922   }
1923   // 3) apply field lookup recursively if superclass exists
1924   { Klass* supr = super();
1925     if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1926   }
1927   // 4) otherwise field lookup fails
1928   return nullptr;
1929 }
1930 
1931 bool InstanceKlass::contains_field_offset(int offset) {
1932   if (this->is_inline_klass()) {
1933     InlineKlass* vk = InlineKlass::cast(this);
1934     return offset >= vk->first_field_offset() && offset < (vk->first_field_offset() + vk->get_payload_size_in_bytes());
1935   } else {
1936     fieldDescriptor fd;
1937     return find_field_from_offset(offset, false, &fd);
1938   }
1939 }
1940 
1941 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1942   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1943     if (fs.offset() == offset) {
1944       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1945       if (fd->is_static() == is_static) return true;
1946     }
1947   }
1948   return false;
1949 }
1950 
1951 
1952 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1953   Klass* klass = const_cast<InstanceKlass*>(this);
1954   while (klass != nullptr) {
1955     if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1956       return true;
1957     }
1958     klass = klass->super();
1959   }

2311 }
2312 
2313 // uncached_lookup_method searches both the local class methods array and all
2314 // superclasses methods arrays, skipping any overpass methods in superclasses,
2315 // and possibly skipping private methods.
2316 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2317                                               const Symbol* signature,
2318                                               OverpassLookupMode overpass_mode,
2319                                               PrivateLookupMode private_mode) const {
2320   OverpassLookupMode overpass_local_mode = overpass_mode;
2321   const Klass* klass = this;
2322   while (klass != nullptr) {
2323     Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2324                                                                         signature,
2325                                                                         overpass_local_mode,
2326                                                                         StaticLookupMode::find,
2327                                                                         private_mode);
2328     if (method != nullptr) {
2329       return method;
2330     }
2331     if (name == vmSymbols::object_initializer_name()) {
2332       break;  // <init> is never inherited
2333     }
2334     klass = klass->super();
2335     overpass_local_mode = OverpassLookupMode::skip;   // Always ignore overpass methods in superclasses
2336   }
2337   return nullptr;
2338 }
2339 
2340 #ifdef ASSERT
2341 // search through class hierarchy and return true if this class or
2342 // one of the superclasses was redefined
2343 bool InstanceKlass::has_redefined_this_or_super() const {
2344   const Klass* klass = this;
2345   while (klass != nullptr) {
2346     if (InstanceKlass::cast(klass)->has_been_redefined()) {
2347       return true;
2348     }
2349     klass = klass->super();
2350   }
2351   return false;
2352 }
2353 #endif

2710     int method_table_offset_in_words = ioe->offset()/wordSize;
2711     int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2712 
2713     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2714                          / itableOffsetEntry::size();
2715 
2716     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2717       if (ioe->interface_klass() != nullptr) {
2718         it->push(ioe->interface_klass_addr());
2719         itableMethodEntry* ime = ioe->first_method_entry(this);
2720         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2721         for (int index = 0; index < n; index ++) {
2722           it->push(ime[index].method_addr());
2723         }
2724       }
2725     }
2726   }
2727 
2728   it->push(&_nest_members);
2729   it->push(&_permitted_subclasses);
2730   it->push(&_loadable_descriptors);
2731   it->push(&_record_components);
2732 
2733   it->push(&_inline_type_field_klasses, MetaspaceClosure::_writable);
2734   it->push(&_null_marker_offsets);
2735 }
2736 
2737 #if INCLUDE_CDS
2738 void InstanceKlass::remove_unshareable_info() {
2739 
2740   if (is_linked()) {
2741     assert(can_be_verified_at_dumptime(), "must be");
2742     // Remember this so we can avoid walking the hierarchy at runtime.
2743     set_verified_at_dump_time();
2744   }
2745 
2746   Klass::remove_unshareable_info();
2747 
2748   if (SystemDictionaryShared::has_class_failed_verification(this)) {
2749     // Classes are attempted to link during dumping and may fail,
2750     // but these classes are still in the dictionary and class list in CLD.
2751     // If the class has failed verification, there is nothing else to remove.
2752     return;
2753   }
2754 

2760 
2761   { // Otherwise this needs to take out the Compile_lock.
2762     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2763     init_implementor();
2764   }
2765 
2766   // Call remove_unshareable_info() on other objects that belong to this class, except
2767   // for constants()->remove_unshareable_info(), which is called in a separate pass in
2768   // ArchiveBuilder::make_klasses_shareable(),
2769 
2770   for (int i = 0; i < methods()->length(); i++) {
2771     Method* m = methods()->at(i);
2772     m->remove_unshareable_info();
2773   }
2774 
2775   // do array classes also.
2776   if (array_klasses() != nullptr) {
2777     array_klasses()->remove_unshareable_info();
2778   }
2779 
2780   // These are not allocated from metaspace. They are safe to set to nullptr.
2781   _source_debug_extension = nullptr;
2782   _dep_context = nullptr;
2783   _osr_nmethods_head = nullptr;
2784 #if INCLUDE_JVMTI
2785   _breakpoints = nullptr;
2786   _previous_versions = nullptr;
2787   _cached_class_file = nullptr;
2788   _jvmti_cached_class_field_map = nullptr;
2789 #endif
2790 
2791   _init_thread = nullptr;
2792   _methods_jmethod_ids = nullptr;
2793   _jni_ids = nullptr;
2794   _oop_map_cache = nullptr;
2795   // clear _nest_host to ensure re-load at runtime
2796   _nest_host = nullptr;
2797   init_shared_package_entry();
2798   _dep_context_last_cleaned = 0;
2799 
2800   remove_unshareable_flags();

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

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

3423 jint InstanceKlass::compute_modifier_flags() const {
3424   jint access = access_flags().as_int();
3425 
3426   // But check if it happens to be member class.
3427   InnerClassesIterator iter(this);
3428   for (; !iter.done(); iter.next()) {
3429     int ioff = iter.inner_class_info_index();
3430     // Inner class attribute can be zero, skip it.
3431     // Strange but true:  JVM spec. allows null inner class refs.
3432     if (ioff == 0) continue;
3433 
3434     // only look at classes that are already loaded
3435     // since we are looking for the flags for our self.
3436     Symbol* inner_name = constants()->klass_name_at(ioff);
3437     if (name() == inner_name) {
3438       // This is really a member class.
3439       access = iter.inner_access_flags();
3440       break;
3441     }
3442   }
3443   return (access & JVM_ACC_WRITTEN_FLAGS);

3444 }
3445 
3446 jint InstanceKlass::jvmti_class_status() const {
3447   jint result = 0;
3448 
3449   if (is_linked()) {
3450     result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3451   }
3452 
3453   if (is_initialized()) {
3454     assert(is_linked(), "Class status is not consistent");
3455     result |= JVMTI_CLASS_STATUS_INITIALIZED;
3456   }
3457   if (is_in_error_state()) {
3458     result |= JVMTI_CLASS_STATUS_ERROR;
3459   }
3460   return result;
3461 }
3462 
3463 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {

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






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






3790   }
3791   print_on_maybe_null(st, BULLET"default vtable indices:   ", default_vtable_indices());
3792   st->print(BULLET"local interfaces:  "); local_interfaces()->print_value_on(st);      st->cr();
3793   st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3794 
3795   st->print(BULLET"secondary supers: "); secondary_supers()->print_value_on(st); st->cr();
3796   if (UseSecondarySupersTable) {
3797     st->print(BULLET"hash_slot:         %d", hash_slot()); st->cr();
3798     st->print(BULLET"bitmap:            " UINTX_FORMAT_X_0, _bitmap); st->cr();
3799   }
3800   if (secondary_supers() != nullptr) {
3801     if (Verbose) {
3802       bool is_hashed = UseSecondarySupersTable && (_bitmap != SECONDARY_SUPERS_BITMAP_FULL);
3803       st->print_cr(BULLET"---- secondary supers (%d words):", _secondary_supers->length());
3804       for (int i = 0; i < _secondary_supers->length(); i++) {
3805         ResourceMark rm; // for external_name()
3806         Klass* secondary_super = _secondary_supers->at(i);
3807         st->print(BULLET"%2d:", i);
3808         if (is_hashed) {
3809           int home_slot = compute_home_slot(secondary_super, _bitmap);

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