< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page

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

  72 #include "prims/jvmtiExport.hpp"
  73 #include "prims/jvmtiRedefineClasses.hpp"
  74 #include "prims/jvmtiThreadState.hpp"
  75 #include "prims/methodComparator.hpp"
  76 #include "runtime/arguments.hpp"
  77 #include "runtime/atomic.hpp"
  78 #include "runtime/fieldDescriptor.inline.hpp"
  79 #include "runtime/handles.inline.hpp"
  80 #include "runtime/javaCalls.hpp"
  81 #include "runtime/mutexLocker.hpp"
  82 #include "runtime/orderAccess.hpp"
  83 #include "runtime/reflectionUtils.hpp"
  84 #include "runtime/thread.inline.hpp"
  85 #include "services/classLoadingService.hpp"
  86 #include "services/threadService.hpp"
  87 #include "utilities/dtrace.hpp"
  88 #include "utilities/events.hpp"
  89 #include "utilities/macros.hpp"
  90 #include "utilities/stringUtils.hpp"
  91 #include "utilities/pair.hpp"

 144 
 145 static inline bool is_class_loader(const Symbol* class_name,
 146                                    const ClassFileParser& parser) {
 147   assert(class_name != NULL, "invariant");
 148 
 149   if (class_name == vmSymbols::java_lang_ClassLoader()) {
 150     return true;
 151   }
 152 
 153   if (vmClasses::ClassLoader_klass_loaded()) {
 154     const Klass* const super_klass = parser.super_klass();
 155     if (super_klass != NULL) {
 156       if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
 157         return true;
 158       }
 159     }
 160   }
 161   return false;
 162 }
 163 


 164 // private: called to verify that k is a static member of this nest.
 165 // We know that k is an instance class in the same package and hence the
 166 // same classloader.
 167 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
 168   assert(!is_hidden(), "unexpected hidden class");
 169   if (_nest_members == NULL || _nest_members == Universe::the_empty_short_array()) {
 170     if (log_is_enabled(Trace, class, nestmates)) {
 171       ResourceMark rm(current);
 172       log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
 173                                   k->external_name(), this->external_name());
 174     }
 175     return false;
 176   }
 177 
 178   if (log_is_enabled(Trace, class, nestmates)) {
 179     ResourceMark rm(current);
 180     log_trace(class, nestmates)("Checking nest membership of %s in %s",
 181                                 k->external_name(), this->external_name());
 182   }
 183 

 409   log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
 410                               this->external_name(),
 411                               access ? "" : "NOT ",
 412                               k->external_name());
 413   return access;
 414 }
 415 
 416 const char* InstanceKlass::nest_host_error() {
 417   if (_nest_host_index == 0) {
 418     return NULL;
 419   } else {
 420     constantPoolHandle cph(Thread::current(), constants());
 421     return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
 422   }
 423 }
 424 
 425 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
 426   const int size = InstanceKlass::size(parser.vtable_size(),
 427                                        parser.itable_size(),
 428                                        nonstatic_oop_map_size(parser.total_oop_map_count()),
 429                                        parser.is_interface());


 430 
 431   const Symbol* const class_name = parser.class_name();
 432   assert(class_name != NULL, "invariant");
 433   ClassLoaderData* loader_data = parser.loader_data();
 434   assert(loader_data != NULL, "invariant");
 435 
 436   InstanceKlass* ik;
 437 
 438   // Allocation
 439   if (REF_NONE == parser.reference_type()) {
 440     if (class_name == vmSymbols::java_lang_Class()) {
 441       // mirror
 442       ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
 443     }
 444     else if (is_class_loader(class_name, parser)) {
 445       // class loader
 446       ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);



 447     } else {
 448       // normal
 449       ik = new (loader_data, size, THREAD) InstanceKlass(parser, InstanceKlass::_kind_other);
 450     }
 451   } else {
 452     // reference
 453     ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
 454   }
 455 
 456   // Check for pending exception before adding to the loader data and incrementing
 457   // class count.  Can get OOM here.
 458   if (HAS_PENDING_EXCEPTION) {
 459     return NULL;
 460   }
 461 







 462   return ik;
 463 }
 464 























 465 
 466 // copy method ordering from resource area to Metaspace
 467 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
 468   if (m != NULL) {
 469     // allocate a new array and copy contents (memcpy?)
 470     _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
 471     for (int i = 0; i < m->length(); i++) {
 472       _method_ordering->at_put(i, m->at(i));
 473     }
 474   } else {
 475     _method_ordering = Universe::the_empty_int_array();
 476   }
 477 }
 478 
 479 // create a new array of vtable_indices for default methods
 480 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
 481   Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
 482   assert(default_vtable_indices() == NULL, "only create once");
 483   set_default_vtable_indices(vtable_indices);
 484   return vtable_indices;
 485 }
 486 
 487 InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) :
 488   Klass(id),
 489   _nest_members(NULL),
 490   _nest_host(NULL),
 491   _permitted_subclasses(NULL),
 492   _record_components(NULL),
 493   _static_field_size(parser.static_field_size()),
 494   _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
 495   _itable_len(parser.itable_size()),
 496   _nest_host_index(0),
 497   _init_state(allocated),
 498   _reference_type(parser.reference_type()),
 499   _init_thread(NULL)


 500 {
 501   set_vtable_length(parser.vtable_size());
 502   set_kind(kind);
 503   set_access_flags(parser.access_flags());
 504   if (parser.is_hidden()) set_is_hidden();
 505   set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
 506                                                     false));




 507 
 508   assert(NULL == _methods, "underlying memory not zeroed?");
 509   assert(is_instance_klass(), "is layout incorrect?");
 510   assert(size_helper() == parser.layout_size(), "incorrect size_helper?");




 511 }
 512 
 513 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
 514                                        Array<Method*>* methods) {
 515   if (methods != NULL && methods != Universe::the_empty_method_array() &&
 516       !methods->is_shared()) {
 517     for (int i = 0; i < methods->length(); i++) {
 518       Method* method = methods->at(i);
 519       if (method == NULL) continue;  // maybe null if error processing
 520       // Only want to delete methods that are not executing for RedefineClasses.
 521       // The previous version will point to them so they're not totally dangling
 522       assert (!method->on_stack(), "shouldn't be called with methods on stack");
 523       MetadataFactory::free_metadata(loader_data, method);
 524     }
 525     MetadataFactory::free_array<Method*>(loader_data, methods);
 526   }
 527 }
 528 
 529 void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data,
 530                                           const Klass* super_klass,
 531                                           Array<InstanceKlass*>* local_interfaces,
 532                                           Array<InstanceKlass*>* transitive_interfaces) {
 533   // Only deallocate transitive interfaces if not empty, same as super class
 534   // or same as local interfaces.  See code in parseClassFile.
 535   Array<InstanceKlass*>* ti = transitive_interfaces;
 536   if (ti != Universe::the_empty_instance_klass_array() && ti != local_interfaces) {
 537     // check that the interfaces don't come from super class
 538     Array<InstanceKlass*>* sti = (super_klass == NULL) ? NULL :
 539                     InstanceKlass::cast(super_klass)->transitive_interfaces();
 540     if (ti != sti && ti != NULL && !ti->is_shared()) {


 541       MetadataFactory::free_array<InstanceKlass*>(loader_data, ti);
 542     }
 543   }
 544 
 545   // local interfaces can be empty
 546   if (local_interfaces != Universe::the_empty_instance_klass_array() &&
 547       local_interfaces != NULL && !local_interfaces->is_shared()) {


 548     MetadataFactory::free_array<InstanceKlass*>(loader_data, local_interfaces);
 549   }
 550 }
 551 
 552 void InstanceKlass::deallocate_record_components(ClassLoaderData* loader_data,
 553                                                  Array<RecordComponent*>* record_components) {
 554   if (record_components != NULL && !record_components->is_shared()) {
 555     for (int i = 0; i < record_components->length(); i++) {
 556       RecordComponent* record_component = record_components->at(i);
 557       MetadataFactory::free_metadata(loader_data, record_component);
 558     }
 559     MetadataFactory::free_array<RecordComponent*>(loader_data, record_components);
 560   }
 561 }
 562 
 563 // This function deallocates the metadata and C heap pointers that the
 564 // InstanceKlass points to.
 565 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
 566 
 567   // Orphan the mirror first, CMS thinks it's still live.

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
























































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

1141     if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1142       initialize_super_interfaces(THREAD);
1143     }
1144 
1145     // If any exceptions, complete abruptly, throwing the same exception as above.
1146     if (HAS_PENDING_EXCEPTION) {
1147       Handle e(THREAD, PENDING_EXCEPTION);
1148       CLEAR_PENDING_EXCEPTION;
1149       {
1150         EXCEPTION_MARK;
1151         add_initialization_error(THREAD, e);
1152         // Locks object, set state, and notify all waiting threads
1153         set_initialization_state_and_notify(initialization_error, THREAD);
1154         CLEAR_PENDING_EXCEPTION;
1155       }
1156       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1157       THROW_OOP(e());
1158     }
1159   }
1160 
1161 
1162   // Step 8









































1163   {
1164     DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1165     if (class_initializer() != NULL) {
1166       // Timer includes any side effects of class initialization (resolution,
1167       // etc), but not recursive entry into call_class_initializer().
1168       PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1169                                ClassLoader::perf_class_init_selftime(),
1170                                ClassLoader::perf_classes_inited(),
1171                                jt->get_thread_stat()->perf_recursion_counts_addr(),
1172                                jt->get_thread_stat()->perf_timers_addr(),
1173                                PerfClassTraceTime::CLASS_CLINIT);
1174       call_class_initializer(THREAD);
1175     } else {
1176       // The elapsed time is so small it's not worth counting.
1177       if (UsePerfData) {
1178         ClassLoader::perf_classes_inited()->inc();
1179       }
1180       call_class_initializer(THREAD);
1181     }
1182   }
1183 
1184   // Step 9
1185   if (!HAS_PENDING_EXCEPTION) {
1186     set_initialization_state_and_notify(fully_initialized, CHECK);
1187     debug_only(vtable().verify(tty, true);)
1188   }
1189   else {
1190     // Step 10 and 11
1191     Handle e(THREAD, PENDING_EXCEPTION);
1192     CLEAR_PENDING_EXCEPTION;
1193     // JVMTI has already reported the pending exception
1194     // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1195     JvmtiExport::clear_detected_exception(jt);
1196     {
1197       EXCEPTION_MARK;
1198       add_initialization_error(THREAD, e);
1199       set_initialization_state_and_notify(initialization_error, THREAD);
1200       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below
1201       // JVMTI has already reported the pending exception
1202       // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1203       JvmtiExport::clear_detected_exception(jt);
1204     }
1205     DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1206     if (e->is_a(vmClasses::Error_klass())) {
1207       THROW_OOP(e());
1208     } else {
1209       JavaCallArguments args(e);
1210       THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),

1434               : vmSymbols::java_lang_InstantiationException(), external_name());
1435   }
1436   if (this == vmClasses::Class_klass()) {
1437     ResourceMark rm(THREAD);
1438     THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1439               : vmSymbols::java_lang_IllegalAccessException(), external_name());
1440   }
1441 }
1442 
1443 Klass* InstanceKlass::array_klass(int n, TRAPS) {
1444   // Need load-acquire for lock-free read
1445   if (array_klasses_acquire() == NULL) {
1446     ResourceMark rm(THREAD);
1447     JavaThread *jt = THREAD;
1448     {
1449       // Atomic creation of array_klasses
1450       MutexLocker ma(THREAD, MultiArray_lock);
1451 
1452       // Check if update has already taken place
1453       if (array_klasses() == NULL) {
1454         ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);

1455         // use 'release' to pair with lock-free load
1456         release_set_array_klasses(k);
1457       }
1458     }
1459   }
1460   // array_klasses() will always be set at this point
1461   ObjArrayKlass* oak = array_klasses();
1462   return oak->array_klass(n, THREAD);
1463 }
1464 
1465 Klass* InstanceKlass::array_klass_or_null(int n) {
1466   // Need load-acquire for lock-free read
1467   ObjArrayKlass* oak = array_klasses_acquire();
1468   if (oak == NULL) {
1469     return NULL;
1470   } else {
1471     return oak->array_klass_or_null(n);
1472   }
1473 }
1474 
1475 Klass* InstanceKlass::array_klass(TRAPS) {
1476   return array_klass(1, THREAD);
1477 }
1478 
1479 Klass* InstanceKlass::array_klass_or_null() {
1480   return array_klass_or_null(1);
1481 }
1482 
1483 static int call_class_initializer_counter = 0;   // for debugging
1484 
1485 Method* InstanceKlass::class_initializer() const {
1486   Method* clinit = find_method(
1487       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1488   if (clinit != NULL && clinit->has_valid_initializer_flags()) {
1489     return clinit;
1490   }
1491   return NULL;
1492 }
1493 
1494 void InstanceKlass::call_class_initializer(TRAPS) {
1495   if (ReplayCompiles &&
1496       (ReplaySuppressInitializers == 1 ||
1497        (ReplaySuppressInitializers >= 2 && class_loader() != NULL))) {
1498     // Hide the existence of the initializer for the purpose of replaying the compile
1499     return;
1500   }
1501 
1502   methodHandle h_method(THREAD, class_initializer());
1503   assert(!is_initialized(), "we cannot initialize twice");
1504   LogTarget(Info, class, init) lt;
1505   if (lt.is_enabled()) {
1506     ResourceMark rm(THREAD);
1507     LogStream ls(lt);
1508     ls.print("%d Initializing ", call_class_initializer_counter++);
1509     name()->print_value_on(&ls);
1510     ls.print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", p2i(this));
1511   }
1512   if (h_method() != NULL) {
1513     JavaCallArguments args; // No arguments
1514     JavaValue result(T_VOID);
1515     JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1516   }
1517 }
1518 
1519 
1520 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1521   InterpreterOopMap* entry_for) {
1522   // Lazily create the _oop_map_cache at first request
1523   // Lock-free access requires load_acquire.
1524   OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1525   if (oop_map_cache == NULL) {
1526     MutexLocker x(OopMapCacheAlloc_lock);
1527     // Check if _oop_map_cache was allocated while we were waiting for this lock
1528     if ((oop_map_cache = _oop_map_cache) == NULL) {
1529       oop_map_cache = new OopMapCache();
1530       // Ensure _oop_map_cache is stable, since it is examined without a lock
1531       Atomic::release_store(&_oop_map_cache, oop_map_cache);
1532     }
1533   }
1534   // _oop_map_cache is constant after init; lookup below does its own locking.
1535   oop_map_cache->lookup(method, bci, entry_for);
1536 }
1537 
1538 bool InstanceKlass::contains_field_offset(int offset) {
1539   fieldDescriptor fd;
1540   return find_field_from_offset(offset, false, &fd);
1541 }
1542 
1543 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1544   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1545     Symbol* f_name = fs.name();
1546     Symbol* f_sig  = fs.signature();
1547     if (f_name == name && f_sig == sig) {
1548       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1549       return true;
1550     }
1551   }
1552   return false;
1553 }
1554 
1555 
1556 Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1557   const int n = local_interfaces()->length();
1558   for (int i = 0; i < n; i++) {
1559     Klass* intf1 = local_interfaces()->at(i);
1560     assert(intf1->is_interface(), "just checking type");
1561     // search for field in current interface
1562     if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) {

1593 
1594 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1595   // search order according to newest JVM spec (5.4.3.2, p.167).
1596   // 1) search for field in current klass
1597   if (find_local_field(name, sig, fd)) {
1598     if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1599   }
1600   // 2) search for field recursively in direct superinterfaces
1601   if (is_static) {
1602     Klass* intf = find_interface_field(name, sig, fd);
1603     if (intf != NULL) return intf;
1604   }
1605   // 3) apply field lookup recursively if superclass exists
1606   { Klass* supr = super();
1607     if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1608   }
1609   // 4) otherwise field lookup fails
1610   return NULL;
1611 }
1612 









1613 
1614 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1615   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1616     if (fs.offset() == offset) {
1617       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1618       if (fd->is_static() == is_static) return true;
1619     }
1620   }
1621   return false;
1622 }
1623 
1624 
1625 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1626   Klass* klass = const_cast<InstanceKlass*>(this);
1627   while (klass != NULL) {
1628     if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1629       return true;
1630     }
1631     klass = klass->super();
1632   }

1994 }
1995 
1996 // uncached_lookup_method searches both the local class methods array and all
1997 // superclasses methods arrays, skipping any overpass methods in superclasses,
1998 // and possibly skipping private methods.
1999 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2000                                               const Symbol* signature,
2001                                               OverpassLookupMode overpass_mode,
2002                                               PrivateLookupMode private_mode) const {
2003   OverpassLookupMode overpass_local_mode = overpass_mode;
2004   const Klass* klass = this;
2005   while (klass != NULL) {
2006     Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2007                                                                         signature,
2008                                                                         overpass_local_mode,
2009                                                                         StaticLookupMode::find,
2010                                                                         private_mode);
2011     if (method != NULL) {
2012       return method;
2013     }



2014     klass = klass->super();
2015     overpass_local_mode = OverpassLookupMode::skip;   // Always ignore overpass methods in superclasses
2016   }
2017   return NULL;
2018 }
2019 
2020 #ifdef ASSERT
2021 // search through class hierarchy and return true if this class or
2022 // one of the superclasses was redefined
2023 bool InstanceKlass::has_redefined_this_or_super() const {
2024   const Klass* klass = this;
2025   while (klass != NULL) {
2026     if (InstanceKlass::cast(klass)->has_been_redefined()) {
2027       return true;
2028     }
2029     klass = klass->super();
2030   }
2031   return false;
2032 }
2033 #endif

2439     itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable();
2440     int method_table_offset_in_words = ioe->offset()/wordSize;
2441     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words())
2442                          / itableOffsetEntry::size();
2443 
2444     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2445       if (ioe->interface_klass() != NULL) {
2446         it->push(ioe->interface_klass_addr());
2447         itableMethodEntry* ime = ioe->first_method_entry(this);
2448         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2449         for (int index = 0; index < n; index ++) {
2450           it->push(ime[index].method_addr());
2451         }
2452       }
2453     }
2454   }
2455 
2456   it->push(&_nest_members);
2457   it->push(&_permitted_subclasses);
2458   it->push(&_record_components);






2459 }
2460 
2461 void InstanceKlass::remove_unshareable_info() {
2462 
2463   if (is_linked()) {
2464     assert(can_be_verified_at_dumptime(), "must be");
2465     // Remember this so we can avoid walking the hierarchy at runtime.
2466     set_verified_at_dump_time();
2467   }
2468 
2469   Klass::remove_unshareable_info();
2470 
2471   if (SystemDictionaryShared::has_class_failed_verification(this)) {
2472     // Classes are attempted to link during dumping and may fail,
2473     // but these classes are still in the dictionary and class list in CLD.
2474     // If the class has failed verification, there is nothing else to remove.
2475     return;
2476   }
2477 
2478   // Reset to the 'allocated' state to prevent any premature accessing to

2481   // being added to class hierarchy (see SystemDictionary:::add_to_hierarchy()).
2482   _init_state = allocated;
2483 
2484   { // Otherwise this needs to take out the Compile_lock.
2485     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2486     init_implementor();
2487   }
2488 
2489   constants()->remove_unshareable_info();
2490 
2491   for (int i = 0; i < methods()->length(); i++) {
2492     Method* m = methods()->at(i);
2493     m->remove_unshareable_info();
2494   }
2495 
2496   // do array classes also.
2497   if (array_klasses() != NULL) {
2498     array_klasses()->remove_unshareable_info();
2499   }
2500 








2501   // These are not allocated from metaspace. They are safe to set to NULL.
2502   _source_debug_extension = NULL;
2503   _dep_context = NULL;
2504   _osr_nmethods_head = NULL;
2505 #if INCLUDE_JVMTI
2506   _breakpoints = NULL;
2507   _previous_versions = NULL;
2508   _cached_class_file = NULL;
2509   _jvmti_cached_class_field_map = NULL;
2510 #endif
2511 
2512   _init_thread = NULL;
2513   _methods_jmethod_ids = NULL;
2514   _jni_ids = NULL;
2515   _oop_map_cache = NULL;
2516   // clear _nest_host to ensure re-load at runtime
2517   _nest_host = NULL;
2518   init_shared_package_entry();
2519   _dep_context_last_cleaned = 0;
2520 }

2542     if (is_shared_unregistered_class()) {
2543       _package_entry = NULL;
2544     } else {
2545       _package_entry = PackageEntry::get_archived_entry(_package_entry);
2546     }
2547   }
2548   ArchivePtrMarker::mark_pointer((address**)&_package_entry);
2549 #endif
2550 }
2551 
2552 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2553                                              PackageEntry* pkg_entry, TRAPS) {
2554   // SystemDictionary::add_to_hierarchy() sets the init_state to loaded
2555   // before the InstanceKlass is added to the SystemDictionary. Make
2556   // sure the current state is <loaded.
2557   assert(!is_loaded(), "invalid init state");
2558   assert(!shared_loading_failed(), "Must not try to load failed class again");
2559   set_package(loader_data, pkg_entry, CHECK);
2560   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2561 




2562   Array<Method*>* methods = this->methods();
2563   int num_methods = methods->length();
2564   for (int index = 0; index < num_methods; ++index) {
2565     methods->at(index)->restore_unshareable_info(CHECK);
2566   }
2567 #if INCLUDE_JVMTI
2568   if (JvmtiExport::has_redefined_a_class()) {
2569     // Reinitialize vtable because RedefineClasses may have changed some
2570     // entries in this vtable for super classes so the CDS vtable might
2571     // point to old or obsolete entries.  RedefineClasses doesn't fix up
2572     // vtables in the shared system dictionary, only the main one.
2573     // It also redefines the itable too so fix that too.
2574     // First fix any default methods that point to a super class that may
2575     // have been redefined.
2576     bool trace_name_printed = false;
2577     adjust_default_methods(&trace_name_printed);
2578     vtable().initialize_vtable();
2579     itable().initialize_itable();
2580   }
2581 #endif

2742 
2743 void InstanceKlass::set_source_debug_extension(const char* array, int length) {
2744   if (array == NULL) {
2745     _source_debug_extension = NULL;
2746   } else {
2747     // Adding one to the attribute length in order to store a null terminator
2748     // character could cause an overflow because the attribute length is
2749     // already coded with an u4 in the classfile, but in practice, it's
2750     // unlikely to happen.
2751     assert((length+1) > length, "Overflow checking");
2752     char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
2753     for (int i = 0; i < length; i++) {
2754       sde[i] = array[i];
2755     }
2756     sde[length] = '\0';
2757     _source_debug_extension = sde;
2758   }
2759 }
2760 
2761 const char* InstanceKlass::signature_name() const {




2762   int hash_len = 0;
2763   char hash_buf[40];
2764 
2765   // Get the internal name as a c string
2766   const char* src = (const char*) (name()->as_C_string());
2767   const int src_length = (int)strlen(src);
2768 
2769   char* dest = NEW_RESOURCE_ARRAY(char, src_length + hash_len + 3);
2770 
2771   // Add L as type indicator
2772   int dest_index = 0;
2773   dest[dest_index++] = JVM_SIGNATURE_CLASS;
2774 
2775   // Add the actual class name
2776   for (int src_index = 0; src_index < src_length; ) {
2777     dest[dest_index++] = src[src_index++];
2778   }
2779 
2780   if (is_hidden()) { // Replace the last '+' with a '.'.
2781     for (int index = (int)src_length; index > 0; index--) {
2782       if (dest[index] == '+') {
2783         dest[index] = JVM_SIGNATURE_DOT;
2784         break;
2785       }
2786     }
2787   }
2788 
2789   // If we have a hash, append it
2790   for (int hash_index = 0; hash_index < hash_len; ) {
2791     dest[dest_index++] = hash_buf[hash_index++];
2792   }
2793 

3347     }
3348     osr = osr->osr_link();
3349   }
3350 
3351   assert(match_level == false || best == NULL, "shouldn't pick up anything if match_level is set");
3352   if (best != NULL && best->comp_level() >= comp_level) {
3353     return best;
3354   }
3355   return NULL;
3356 }
3357 
3358 // -----------------------------------------------------------------------------------------------------
3359 // Printing
3360 
3361 #define BULLET  " - "
3362 
3363 static const char* state_names[] = {
3364   "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3365 };
3366 
3367 static void print_vtable(intptr_t* start, int len, outputStream* st) {



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





3371     if (MetaspaceObj::is_valid((Metadata*)e)) {
3372       st->print(" ");
3373       ((Metadata*)e)->print_value_on(st);






3374     }
3375     st->cr();
3376   }
3377 }
3378 
3379 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3380   return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);





















3381 }
3382 
3383 void InstanceKlass::print_on(outputStream* st) const {
3384   assert(is_klass(), "must be klass");
3385   Klass::print_on(st);
3386 
3387   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
3388   st->print(BULLET"klass size:        %d", size());                               st->cr();
3389   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();

3390   st->print(BULLET"state:             "); st->print_cr("%s", state_names[_init_state]);
3391   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
3392   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3393   st->print(BULLET"sub:               ");
3394   Klass* sub = subklass();
3395   int n;
3396   for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) {
3397     if (n < MaxSubklassPrintSize) {
3398       sub->print_value_on(st);
3399       st->print("   ");
3400     }
3401   }
3402   if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3403   st->cr();
3404 
3405   if (is_interface()) {
3406     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
3407     if (nof_implementors() == 1) {
3408       st->print_cr(BULLET"implementor:    ");
3409       st->print("   ");
3410       implementor()->print_value_on(st);
3411       st->cr();
3412     }
3413   }
3414 
3415   st->print(BULLET"arrays:            "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3416   st->print(BULLET"methods:           "); methods()->print_value_on(st);                  st->cr();
3417   if (Verbose || WizardMode) {
3418     Array<Method*>* method_array = methods();
3419     for (int i = 0; i < method_array->length(); i++) {
3420       st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3421     }
3422   }
3423   st->print(BULLET"method ordering:   "); method_ordering()->print_value_on(st);      st->cr();
3424   st->print(BULLET"default_methods:   "); default_methods()->print_value_on(st);      st->cr();
3425   if (Verbose && default_methods() != NULL) {
3426     Array<Method*>* method_array = default_methods();
3427     for (int i = 0; i < method_array->length(); i++) {
3428       st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3429     }
3430   }
3431   if (default_vtable_indices() != NULL) {
3432     st->print(BULLET"default vtable indices:   "); default_vtable_indices()->print_value_on(st);       st->cr();
3433   }
3434   st->print(BULLET"local interfaces:  "); local_interfaces()->print_value_on(st);      st->cr();
3435   st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3436   st->print(BULLET"constants:         "); constants()->print_value_on(st);         st->cr();
3437   if (class_loader_data() != NULL) {
3438     st->print(BULLET"class loader data:  ");
3439     class_loader_data()->print_value_on(st);
3440     st->cr();
3441   }
3442   if (source_file_name() != NULL) {
3443     st->print(BULLET"source file:       ");
3444     source_file_name()->print_value_on(st);
3445     st->cr();
3446   }
3447   if (source_debug_extension() != NULL) {
3448     st->print(BULLET"source debug extension:       ");
3449     st->print("%s", source_debug_extension());
3450     st->cr();
3451   }
3452   st->print(BULLET"class annotations:       "); class_annotations()->print_value_on(st); st->cr();
3453   st->print(BULLET"class type annotations:  "); class_type_annotations()->print_value_on(st); st->cr();
3454   st->print(BULLET"field annotations:       "); fields_annotations()->print_value_on(st); st->cr();
3455   st->print(BULLET"field type annotations:  "); fields_type_annotations()->print_value_on(st); st->cr();

3471     st->print(BULLET"generic signature: ");
3472     generic_signature()->print_value_on(st);
3473     st->cr();
3474   }
3475   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
3476   st->print(BULLET"nest members:     "); nest_members()->print_value_on(st);     st->cr();
3477   if (record_components() != NULL) {
3478     st->print(BULLET"record components:     "); record_components()->print_value_on(st);     st->cr();
3479   }
3480   st->print(BULLET"permitted subclasses:     "); permitted_subclasses()->print_value_on(st);     st->cr();
3481   if (java_mirror() != NULL) {
3482     st->print(BULLET"java mirror:       ");
3483     java_mirror()->print_value_on(st);
3484     st->cr();
3485   } else {
3486     st->print_cr(BULLET"java mirror:       NULL");
3487   }
3488   st->print(BULLET"vtable length      %d  (start addr: " INTPTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3489   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
3490   st->print(BULLET"itable length      %d (start addr: " INTPTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3491   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_itable(), itable_length(), st);
3492   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3493   FieldPrinter print_static_field(st);
3494   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3495   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3496   FieldPrinter print_nonstatic_field(st);
3497   InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3498   ik->print_nonstatic_fields(&print_nonstatic_field);
3499 
3500   st->print(BULLET"non-static oop maps: ");
3501   OopMapBlock* map     = start_of_nonstatic_oop_maps();
3502   OopMapBlock* end_map = map + nonstatic_oop_map_count();
3503   while (map < end_map) {
3504     st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3505     map++;
3506   }
3507   st->cr();
3508 }
3509 
3510 void InstanceKlass::print_value_on(outputStream* st) const {
3511   assert(is_klass(), "must be klass");

  52 #include "logging/logMessage.hpp"
  53 #include "logging/logStream.hpp"
  54 #include "memory/allocation.inline.hpp"
  55 #include "memory/iterator.inline.hpp"
  56 #include "memory/metadataFactory.hpp"
  57 #include "memory/metaspaceClosure.hpp"
  58 #include "memory/oopFactory.hpp"
  59 #include "memory/resourceArea.hpp"
  60 #include "memory/universe.hpp"
  61 #include "oops/fieldStreams.inline.hpp"
  62 #include "oops/constantPool.hpp"
  63 #include "oops/instanceClassLoaderKlass.hpp"
  64 #include "oops/instanceKlass.inline.hpp"
  65 #include "oops/instanceMirrorKlass.hpp"
  66 #include "oops/instanceOop.hpp"
  67 #include "oops/klass.inline.hpp"
  68 #include "oops/method.hpp"
  69 #include "oops/oop.inline.hpp"
  70 #include "oops/recordComponent.hpp"
  71 #include "oops/symbol.hpp"
  72 #include "oops/inlineKlass.hpp"
  73 #include "prims/jvmtiExport.hpp"
  74 #include "prims/jvmtiRedefineClasses.hpp"
  75 #include "prims/jvmtiThreadState.hpp"
  76 #include "prims/methodComparator.hpp"
  77 #include "runtime/arguments.hpp"
  78 #include "runtime/atomic.hpp"
  79 #include "runtime/fieldDescriptor.inline.hpp"
  80 #include "runtime/handles.inline.hpp"
  81 #include "runtime/javaCalls.hpp"
  82 #include "runtime/mutexLocker.hpp"
  83 #include "runtime/orderAccess.hpp"
  84 #include "runtime/reflectionUtils.hpp"
  85 #include "runtime/thread.inline.hpp"
  86 #include "services/classLoadingService.hpp"
  87 #include "services/threadService.hpp"
  88 #include "utilities/dtrace.hpp"
  89 #include "utilities/events.hpp"
  90 #include "utilities/macros.hpp"
  91 #include "utilities/stringUtils.hpp"
  92 #include "utilities/pair.hpp"

 145 
 146 static inline bool is_class_loader(const Symbol* class_name,
 147                                    const ClassFileParser& parser) {
 148   assert(class_name != NULL, "invariant");
 149 
 150   if (class_name == vmSymbols::java_lang_ClassLoader()) {
 151     return true;
 152   }
 153 
 154   if (vmClasses::ClassLoader_klass_loaded()) {
 155     const Klass* const super_klass = parser.super_klass();
 156     if (super_klass != NULL) {
 157       if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
 158         return true;
 159       }
 160     }
 161   }
 162   return false;
 163 }
 164 
 165 bool InstanceKlass::field_is_null_free_inline_type(int index) const { return Signature::basic_type(field(index)->signature(constants())) == T_INLINE_TYPE; }
 166 
 167 // private: called to verify that k is a static member of this nest.
 168 // We know that k is an instance class in the same package and hence the
 169 // same classloader.
 170 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
 171   assert(!is_hidden(), "unexpected hidden class");
 172   if (_nest_members == NULL || _nest_members == Universe::the_empty_short_array()) {
 173     if (log_is_enabled(Trace, class, nestmates)) {
 174       ResourceMark rm(current);
 175       log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
 176                                   k->external_name(), this->external_name());
 177     }
 178     return false;
 179   }
 180 
 181   if (log_is_enabled(Trace, class, nestmates)) {
 182     ResourceMark rm(current);
 183     log_trace(class, nestmates)("Checking nest membership of %s in %s",
 184                                 k->external_name(), this->external_name());
 185   }
 186 

 412   log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
 413                               this->external_name(),
 414                               access ? "" : "NOT ",
 415                               k->external_name());
 416   return access;
 417 }
 418 
 419 const char* InstanceKlass::nest_host_error() {
 420   if (_nest_host_index == 0) {
 421     return NULL;
 422   } else {
 423     constantPoolHandle cph(Thread::current(), constants());
 424     return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
 425   }
 426 }
 427 
 428 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
 429   const int size = InstanceKlass::size(parser.vtable_size(),
 430                                        parser.itable_size(),
 431                                        nonstatic_oop_map_size(parser.total_oop_map_count()),
 432                                        parser.is_interface(),
 433                                        parser.has_inline_fields() ? parser.java_fields_count() : 0,
 434                                        parser.is_inline_type());
 435 
 436   const Symbol* const class_name = parser.class_name();
 437   assert(class_name != NULL, "invariant");
 438   ClassLoaderData* loader_data = parser.loader_data();
 439   assert(loader_data != NULL, "invariant");
 440 
 441   InstanceKlass* ik;
 442 
 443   // Allocation
 444   if (REF_NONE == parser.reference_type()) {
 445     if (class_name == vmSymbols::java_lang_Class()) {
 446       // mirror
 447       ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
 448     } else if (is_class_loader(class_name, parser)) {

 449       // class loader
 450       ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
 451     } else if (parser.is_inline_type()) {
 452       // inline type
 453       ik = new (loader_data, size, THREAD) InlineKlass(parser);
 454     } else {
 455       // normal
 456       ik = new (loader_data, size, THREAD) InstanceKlass(parser, InstanceKlass::_kind_other);
 457     }
 458   } else {
 459     // reference
 460     ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
 461   }
 462 
 463   // Check for pending exception before adding to the loader data and incrementing
 464   // class count.  Can get OOM here.
 465   if (HAS_PENDING_EXCEPTION) {
 466     return NULL;
 467   }
 468 
 469 #ifdef ASSERT
 470   assert(ik->size() == size, "");
 471   ik->bounds_check((address) ik->start_of_vtable(), false, size);
 472   ik->bounds_check((address) ik->start_of_itable(), false, size);
 473   ik->bounds_check((address) ik->end_of_itable(), true, size);
 474   ik->bounds_check((address) ik->end_of_nonstatic_oop_maps(), true, size);
 475 #endif //ASSERT
 476   return ik;
 477 }
 478 
 479 #ifndef PRODUCT
 480 bool InstanceKlass::bounds_check(address addr, bool edge_ok, intptr_t size_in_bytes) const {
 481   const char* bad = NULL;
 482   address end = NULL;
 483   if (addr < (address)this) {
 484     bad = "before";
 485   } else if (addr == (address)this) {
 486     if (edge_ok)  return true;
 487     bad = "just before";
 488   } else if (addr == (end = (address)this + sizeof(intptr_t) * (size_in_bytes < 0 ? size() : size_in_bytes))) {
 489     if (edge_ok)  return true;
 490     bad = "just after";
 491   } else if (addr > end) {
 492     bad = "after";
 493   } else {
 494     return true;
 495   }
 496   tty->print_cr("%s object bounds: " INTPTR_FORMAT " [" INTPTR_FORMAT ".." INTPTR_FORMAT "]",
 497       bad, (intptr_t)addr, (intptr_t)this, (intptr_t)end);
 498   Verbose = WizardMode = true; this->print(); //@@
 499   return false;
 500 }
 501 #endif //PRODUCT
 502 
 503 // copy method ordering from resource area to Metaspace
 504 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
 505   if (m != NULL) {
 506     // allocate a new array and copy contents (memcpy?)
 507     _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
 508     for (int i = 0; i < m->length(); i++) {
 509       _method_ordering->at_put(i, m->at(i));
 510     }
 511   } else {
 512     _method_ordering = Universe::the_empty_int_array();
 513   }
 514 }
 515 
 516 // create a new array of vtable_indices for default methods
 517 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
 518   Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
 519   assert(default_vtable_indices() == NULL, "only create once");
 520   set_default_vtable_indices(vtable_indices);
 521   return vtable_indices;
 522 }
 523 
 524 InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) :
 525   Klass(id),
 526   _nest_members(NULL),
 527   _nest_host(NULL),
 528   _permitted_subclasses(NULL),
 529   _record_components(NULL),
 530   _static_field_size(parser.static_field_size()),
 531   _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
 532   _itable_len(parser.itable_size()),
 533   _nest_host_index(0),
 534   _init_state(allocated),
 535   _reference_type(parser.reference_type()),
 536   _init_thread(NULL),
 537   _inline_type_field_klasses(NULL),
 538   _adr_inlineklass_fixed_block(NULL)
 539 {
 540   set_vtable_length(parser.vtable_size());
 541   set_kind(kind);
 542   set_access_flags(parser.access_flags());
 543   if (parser.is_hidden()) set_is_hidden();
 544   set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
 545                                                     false));
 546     if (parser.has_inline_fields()) {
 547       set_has_inline_type_fields();
 548     }
 549     _java_fields_count = parser.java_fields_count();
 550 
 551   assert(NULL == _methods, "underlying memory not zeroed?");
 552   assert(is_instance_klass(), "is layout incorrect?");
 553   assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
 554 
 555   if (has_inline_type_fields()) {
 556     _inline_type_field_klasses = (const Klass**) adr_inline_type_field_klasses();
 557   }
 558 }
 559 
 560 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
 561                                        Array<Method*>* methods) {
 562   if (methods != NULL && methods != Universe::the_empty_method_array() &&
 563       !methods->is_shared()) {
 564     for (int i = 0; i < methods->length(); i++) {
 565       Method* method = methods->at(i);
 566       if (method == NULL) continue;  // maybe null if error processing
 567       // Only want to delete methods that are not executing for RedefineClasses.
 568       // The previous version will point to them so they're not totally dangling
 569       assert (!method->on_stack(), "shouldn't be called with methods on stack");
 570       MetadataFactory::free_metadata(loader_data, method);
 571     }
 572     MetadataFactory::free_array<Method*>(loader_data, methods);
 573   }
 574 }
 575 
 576 void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data,
 577                                           const Klass* super_klass,
 578                                           Array<InstanceKlass*>* local_interfaces,
 579                                           Array<InstanceKlass*>* transitive_interfaces) {
 580   // Only deallocate transitive interfaces if not empty, same as super class
 581   // or same as local interfaces.  See code in parseClassFile.
 582   Array<InstanceKlass*>* ti = transitive_interfaces;
 583   if (ti != Universe::the_empty_instance_klass_array() && ti != local_interfaces) {
 584     // check that the interfaces don't come from super class
 585     Array<InstanceKlass*>* sti = (super_klass == NULL) ? NULL :
 586                     InstanceKlass::cast(super_klass)->transitive_interfaces();
 587     if (ti != sti && ti != NULL && !ti->is_shared() &&
 588         ti != Universe::the_single_IdentityObject_klass_array() &&
 589         ti != Universe::the_single_PrimitiveObject_klass_array()) {
 590       MetadataFactory::free_array<InstanceKlass*>(loader_data, ti);
 591     }
 592   }
 593 
 594   // local interfaces can be empty
 595   if (local_interfaces != Universe::the_empty_instance_klass_array() &&
 596       local_interfaces != NULL && !local_interfaces->is_shared() &&
 597       local_interfaces != Universe::the_single_IdentityObject_klass_array() &&
 598       local_interfaces != Universe::the_single_PrimitiveObject_klass_array()) {
 599     MetadataFactory::free_array<InstanceKlass*>(loader_data, local_interfaces);
 600   }
 601 }
 602 
 603 void InstanceKlass::deallocate_record_components(ClassLoaderData* loader_data,
 604                                                  Array<RecordComponent*>* record_components) {
 605   if (record_components != NULL && !record_components->is_shared()) {
 606     for (int i = 0; i < record_components->length(); i++) {
 607       RecordComponent* record_component = record_components->at(i);
 608       MetadataFactory::free_metadata(loader_data, record_component);
 609     }
 610     MetadataFactory::free_array<RecordComponent*>(loader_data, record_components);
 611   }
 612 }
 613 
 614 // This function deallocates the metadata and C heap pointers that the
 615 // InstanceKlass points to.
 616 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
 617 
 618   // Orphan the mirror first, CMS thinks it's still live.

 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 (int i = 0; i < methods()->length(); i++) {
 954       Method* m = methods()->at(i);
 955       for (SignatureStream ss(m->signature()); !ss.is_done(); ss.next()) {
 956         if (ss.is_reference()) {
 957           if (ss.is_array()) {
 958             continue;
 959           }
 960           if (ss.type() == T_INLINE_TYPE) {
 961             Symbol* symb = ss.as_symbol();
 962 
 963             oop loader = class_loader();
 964             oop protection_domain = this->protection_domain();
 965             Klass* klass = SystemDictionary::resolve_or_fail(symb,
 966                                                              Handle(THREAD, loader), Handle(THREAD, protection_domain), true,
 967                                                              CHECK_false);
 968             if (klass == NULL) {
 969               THROW_(vmSymbols::java_lang_LinkageError(), false);
 970             }
 971             if (!klass->is_inline_klass()) {
 972               Exceptions::fthrow(
 973                 THREAD_AND_LOCATION,
 974                 vmSymbols::java_lang_IncompatibleClassChangeError(),
 975                 "class %s is not an inline type",
 976                 klass->external_name());
 977             }
 978           }
 979         }
 980       }
 981     }
 982   }
 983 
 984   // in case the class is linked in the process of linking its superclasses
 985   if (is_linked()) {
 986     return true;
 987   }
 988 
 989   // trace only the link time for this klass that includes
 990   // the verification time
 991   PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
 992                              ClassLoader::perf_class_link_selftime(),
 993                              ClassLoader::perf_classes_linked(),
 994                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 995                              jt->get_thread_stat()->perf_timers_addr(),
 996                              PerfClassTraceTime::CLASS_LINK);
 997 
 998   // verification & rewriting
 999   {
1000     HandleMark hm(THREAD);
1001     Handle h_init_lock(THREAD, init_lock());
1002     ObjectLocker ol(h_init_lock, jt);
1003     // rewritten will have been set if loader constraint error found

1248     if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1249       initialize_super_interfaces(THREAD);
1250     }
1251 
1252     // If any exceptions, complete abruptly, throwing the same exception as above.
1253     if (HAS_PENDING_EXCEPTION) {
1254       Handle e(THREAD, PENDING_EXCEPTION);
1255       CLEAR_PENDING_EXCEPTION;
1256       {
1257         EXCEPTION_MARK;
1258         add_initialization_error(THREAD, e);
1259         // Locks object, set state, and notify all waiting threads
1260         set_initialization_state_and_notify(initialization_error, THREAD);
1261         CLEAR_PENDING_EXCEPTION;
1262       }
1263       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1264       THROW_OOP(e());
1265     }
1266   }
1267 

1268   // Step 8
1269   // Initialize classes of inline fields
1270   if (EnableValhalla) {
1271     for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1272       if (Signature::basic_type(fs.signature()) == T_INLINE_TYPE) {
1273         Klass* klass = get_inline_type_field_klass_or_null(fs.index());
1274         if (fs.access_flags().is_static() && klass == NULL) {
1275           klass = SystemDictionary::resolve_or_fail(field_signature(fs.index())->fundamental_name(THREAD),
1276               Handle(THREAD, class_loader()),
1277               Handle(THREAD, protection_domain()),
1278               true, THREAD);
1279           set_inline_type_field_klass(fs.index(), klass);
1280         }
1281 
1282         if (!HAS_PENDING_EXCEPTION) {
1283           assert(klass != NULL, "Must  be");
1284           InstanceKlass::cast(klass)->initialize(THREAD);
1285           if (fs.access_flags().is_static()) {
1286             if (java_mirror()->obj_field(fs.offset()) == NULL) {
1287               java_mirror()->obj_field_put(fs.offset(), InlineKlass::cast(klass)->default_value());
1288             }
1289           }
1290         }
1291 
1292         if (HAS_PENDING_EXCEPTION) {
1293           Handle e(THREAD, PENDING_EXCEPTION);
1294           CLEAR_PENDING_EXCEPTION;
1295           {
1296             EXCEPTION_MARK;
1297             add_initialization_error(THREAD, e);
1298             // Locks object, set state, and notify all waiting threads
1299             set_initialization_state_and_notify(initialization_error, THREAD);
1300             CLEAR_PENDING_EXCEPTION;
1301           }
1302           THROW_OOP(e());
1303         }
1304       }
1305     }
1306   }
1307 
1308 
1309   // Step 9
1310   {
1311     DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1312     if (class_initializer() != NULL) {
1313       // Timer includes any side effects of class initialization (resolution,
1314       // etc), but not recursive entry into call_class_initializer().
1315       PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1316                                ClassLoader::perf_class_init_selftime(),
1317                                ClassLoader::perf_classes_inited(),
1318                                jt->get_thread_stat()->perf_recursion_counts_addr(),
1319                                jt->get_thread_stat()->perf_timers_addr(),
1320                                PerfClassTraceTime::CLASS_CLINIT);
1321       call_class_initializer(THREAD);
1322     } else {
1323       // The elapsed time is so small it's not worth counting.
1324       if (UsePerfData) {
1325         ClassLoader::perf_classes_inited()->inc();
1326       }
1327       call_class_initializer(THREAD);
1328     }
1329   }
1330 
1331   // Step 10
1332   if (!HAS_PENDING_EXCEPTION) {
1333     set_initialization_state_and_notify(fully_initialized, CHECK);
1334     debug_only(vtable().verify(tty, true);)
1335   }
1336   else {
1337     // Step 11 and 12
1338     Handle e(THREAD, PENDING_EXCEPTION);
1339     CLEAR_PENDING_EXCEPTION;
1340     // JVMTI has already reported the pending exception
1341     // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1342     JvmtiExport::clear_detected_exception(jt);
1343     {
1344       EXCEPTION_MARK;
1345       add_initialization_error(THREAD, e);
1346       set_initialization_state_and_notify(initialization_error, THREAD);
1347       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below
1348       // JVMTI has already reported the pending exception
1349       // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1350       JvmtiExport::clear_detected_exception(jt);
1351     }
1352     DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1353     if (e->is_a(vmClasses::Error_klass())) {
1354       THROW_OOP(e());
1355     } else {
1356       JavaCallArguments args(e);
1357       THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),

1581               : vmSymbols::java_lang_InstantiationException(), external_name());
1582   }
1583   if (this == vmClasses::Class_klass()) {
1584     ResourceMark rm(THREAD);
1585     THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1586               : vmSymbols::java_lang_IllegalAccessException(), external_name());
1587   }
1588 }
1589 
1590 Klass* InstanceKlass::array_klass(int n, TRAPS) {
1591   // Need load-acquire for lock-free read
1592   if (array_klasses_acquire() == NULL) {
1593     ResourceMark rm(THREAD);
1594     JavaThread *jt = THREAD;
1595     {
1596       // Atomic creation of array_klasses
1597       MutexLocker ma(THREAD, MultiArray_lock);
1598 
1599       // Check if update has already taken place
1600       if (array_klasses() == NULL) {
1601         ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this,
1602                                                                   false, false, CHECK_NULL);
1603         // use 'release' to pair with lock-free load
1604         release_set_array_klasses(k);
1605       }
1606     }
1607   }
1608   // array_klasses() will always be set at this point
1609   ArrayKlass* ak = array_klasses();
1610   return ak->array_klass(n, THREAD);
1611 }
1612 
1613 Klass* InstanceKlass::array_klass_or_null(int n) {
1614   // Need load-acquire for lock-free read
1615   ArrayKlass* ak = array_klasses_acquire();
1616   if (ak == NULL) {
1617     return NULL;
1618   } else {
1619     return ak->array_klass_or_null(n);
1620   }
1621 }
1622 
1623 Klass* InstanceKlass::array_klass(TRAPS) {
1624   return array_klass(1, THREAD);
1625 }
1626 
1627 Klass* InstanceKlass::array_klass_or_null() {
1628   return array_klass_or_null(1);
1629 }
1630 
1631 static int call_class_initializer_counter = 0;   // for debugging
1632 
1633 Method* InstanceKlass::class_initializer() const {
1634   Method* clinit = find_method(
1635       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1636   if (clinit != NULL && clinit->is_class_initializer()) {
1637     return clinit;
1638   }
1639   return NULL;
1640 }
1641 
1642 void InstanceKlass::call_class_initializer(TRAPS) {
1643   if (ReplayCompiles &&
1644       (ReplaySuppressInitializers == 1 ||
1645        (ReplaySuppressInitializers >= 2 && class_loader() != NULL))) {
1646     // Hide the existence of the initializer for the purpose of replaying the compile
1647     return;
1648   }
1649 
1650   methodHandle h_method(THREAD, class_initializer());
1651   assert(!is_initialized(), "we cannot initialize twice");
1652   LogTarget(Info, class, init) lt;
1653   if (lt.is_enabled()) {
1654     ResourceMark rm(THREAD);
1655     LogStream ls(lt);
1656     ls.print("%d Initializing ", call_class_initializer_counter++);
1657     name()->print_value_on(&ls);
1658     ls.print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", p2i(this));
1659   }
1660   if (h_method() != NULL) {
1661     JavaCallArguments args; // No arguments
1662     JavaValue result(T_VOID);
1663     JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1664   }
1665 }
1666 
1667 
1668 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1669   InterpreterOopMap* entry_for) {
1670   // Lazily create the _oop_map_cache at first request
1671   // Lock-free access requires load_acquire.
1672   OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1673   if (oop_map_cache == NULL) {
1674     MutexLocker x(OopMapCacheAlloc_lock,  Mutex::_no_safepoint_check_flag);
1675     // Check if _oop_map_cache was allocated while we were waiting for this lock
1676     if ((oop_map_cache = _oop_map_cache) == NULL) {
1677       oop_map_cache = new OopMapCache();
1678       // Ensure _oop_map_cache is stable, since it is examined without a lock
1679       Atomic::release_store(&_oop_map_cache, oop_map_cache);
1680     }
1681   }
1682   // _oop_map_cache is constant after init; lookup below does its own locking.
1683   oop_map_cache->lookup(method, bci, entry_for);
1684 }
1685 





1686 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1687   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1688     Symbol* f_name = fs.name();
1689     Symbol* f_sig  = fs.signature();
1690     if (f_name == name && f_sig == sig) {
1691       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1692       return true;
1693     }
1694   }
1695   return false;
1696 }
1697 
1698 
1699 Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1700   const int n = local_interfaces()->length();
1701   for (int i = 0; i < n; i++) {
1702     Klass* intf1 = local_interfaces()->at(i);
1703     assert(intf1->is_interface(), "just checking type");
1704     // search for field in current interface
1705     if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) {

1736 
1737 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1738   // search order according to newest JVM spec (5.4.3.2, p.167).
1739   // 1) search for field in current klass
1740   if (find_local_field(name, sig, fd)) {
1741     if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1742   }
1743   // 2) search for field recursively in direct superinterfaces
1744   if (is_static) {
1745     Klass* intf = find_interface_field(name, sig, fd);
1746     if (intf != NULL) return intf;
1747   }
1748   // 3) apply field lookup recursively if superclass exists
1749   { Klass* supr = super();
1750     if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1751   }
1752   // 4) otherwise field lookup fails
1753   return NULL;
1754 }
1755 
1756 bool InstanceKlass::contains_field_offset(int offset) {
1757   if (this->is_inline_klass()) {
1758     InlineKlass* vk = InlineKlass::cast(this);
1759     return offset >= vk->first_field_offset() && offset < (vk->first_field_offset() + vk->get_exact_size_in_bytes());
1760   } else {
1761     fieldDescriptor fd;
1762     return find_field_from_offset(offset, false, &fd);
1763   }
1764 }
1765 
1766 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1767   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1768     if (fs.offset() == offset) {
1769       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1770       if (fd->is_static() == is_static) return true;
1771     }
1772   }
1773   return false;
1774 }
1775 
1776 
1777 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1778   Klass* klass = const_cast<InstanceKlass*>(this);
1779   while (klass != NULL) {
1780     if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1781       return true;
1782     }
1783     klass = klass->super();
1784   }

2146 }
2147 
2148 // uncached_lookup_method searches both the local class methods array and all
2149 // superclasses methods arrays, skipping any overpass methods in superclasses,
2150 // and possibly skipping private methods.
2151 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2152                                               const Symbol* signature,
2153                                               OverpassLookupMode overpass_mode,
2154                                               PrivateLookupMode private_mode) const {
2155   OverpassLookupMode overpass_local_mode = overpass_mode;
2156   const Klass* klass = this;
2157   while (klass != NULL) {
2158     Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2159                                                                         signature,
2160                                                                         overpass_local_mode,
2161                                                                         StaticLookupMode::find,
2162                                                                         private_mode);
2163     if (method != NULL) {
2164       return method;
2165     }
2166     if (name == vmSymbols::object_initializer_name()) {
2167       break;  // <init> is never inherited, not even as a static factory
2168     }
2169     klass = klass->super();
2170     overpass_local_mode = OverpassLookupMode::skip;   // Always ignore overpass methods in superclasses
2171   }
2172   return NULL;
2173 }
2174 
2175 #ifdef ASSERT
2176 // search through class hierarchy and return true if this class or
2177 // one of the superclasses was redefined
2178 bool InstanceKlass::has_redefined_this_or_super() const {
2179   const Klass* klass = this;
2180   while (klass != NULL) {
2181     if (InstanceKlass::cast(klass)->has_been_redefined()) {
2182       return true;
2183     }
2184     klass = klass->super();
2185   }
2186   return false;
2187 }
2188 #endif

2594     itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable();
2595     int method_table_offset_in_words = ioe->offset()/wordSize;
2596     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words())
2597                          / itableOffsetEntry::size();
2598 
2599     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2600       if (ioe->interface_klass() != NULL) {
2601         it->push(ioe->interface_klass_addr());
2602         itableMethodEntry* ime = ioe->first_method_entry(this);
2603         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2604         for (int index = 0; index < n; index ++) {
2605           it->push(ime[index].method_addr());
2606         }
2607       }
2608     }
2609   }
2610 
2611   it->push(&_nest_members);
2612   it->push(&_permitted_subclasses);
2613   it->push(&_record_components);
2614 
2615   if (has_inline_type_fields()) {
2616     for (int i = 0; i < java_fields_count(); i++) {
2617       it->push(&((Klass**)adr_inline_type_field_klasses())[i]);
2618     }
2619   }
2620 }
2621 
2622 void InstanceKlass::remove_unshareable_info() {
2623 
2624   if (is_linked()) {
2625     assert(can_be_verified_at_dumptime(), "must be");
2626     // Remember this so we can avoid walking the hierarchy at runtime.
2627     set_verified_at_dump_time();
2628   }
2629 
2630   Klass::remove_unshareable_info();
2631 
2632   if (SystemDictionaryShared::has_class_failed_verification(this)) {
2633     // Classes are attempted to link during dumping and may fail,
2634     // but these classes are still in the dictionary and class list in CLD.
2635     // If the class has failed verification, there is nothing else to remove.
2636     return;
2637   }
2638 
2639   // Reset to the 'allocated' state to prevent any premature accessing to

2642   // being added to class hierarchy (see SystemDictionary:::add_to_hierarchy()).
2643   _init_state = allocated;
2644 
2645   { // Otherwise this needs to take out the Compile_lock.
2646     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2647     init_implementor();
2648   }
2649 
2650   constants()->remove_unshareable_info();
2651 
2652   for (int i = 0; i < methods()->length(); i++) {
2653     Method* m = methods()->at(i);
2654     m->remove_unshareable_info();
2655   }
2656 
2657   // do array classes also.
2658   if (array_klasses() != NULL) {
2659     array_klasses()->remove_unshareable_info();
2660   }
2661 
2662   if (has_inline_type_fields()) {
2663     for (AllFieldStream fs(fields(), constants()); !fs.done(); fs.next()) {
2664       if (Signature::basic_type(fs.signature()) == T_INLINE_TYPE) {
2665         reset_inline_type_field_klass(fs.index());
2666       }
2667     }
2668   }
2669 
2670   // These are not allocated from metaspace. They are safe to set to NULL.
2671   _source_debug_extension = NULL;
2672   _dep_context = NULL;
2673   _osr_nmethods_head = NULL;
2674 #if INCLUDE_JVMTI
2675   _breakpoints = NULL;
2676   _previous_versions = NULL;
2677   _cached_class_file = NULL;
2678   _jvmti_cached_class_field_map = NULL;
2679 #endif
2680 
2681   _init_thread = NULL;
2682   _methods_jmethod_ids = NULL;
2683   _jni_ids = NULL;
2684   _oop_map_cache = NULL;
2685   // clear _nest_host to ensure re-load at runtime
2686   _nest_host = NULL;
2687   init_shared_package_entry();
2688   _dep_context_last_cleaned = 0;
2689 }

2711     if (is_shared_unregistered_class()) {
2712       _package_entry = NULL;
2713     } else {
2714       _package_entry = PackageEntry::get_archived_entry(_package_entry);
2715     }
2716   }
2717   ArchivePtrMarker::mark_pointer((address**)&_package_entry);
2718 #endif
2719 }
2720 
2721 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2722                                              PackageEntry* pkg_entry, TRAPS) {
2723   // SystemDictionary::add_to_hierarchy() sets the init_state to loaded
2724   // before the InstanceKlass is added to the SystemDictionary. Make
2725   // sure the current state is <loaded.
2726   assert(!is_loaded(), "invalid init state");
2727   assert(!shared_loading_failed(), "Must not try to load failed class again");
2728   set_package(loader_data, pkg_entry, CHECK);
2729   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2730 
2731   if (is_inline_klass()) {
2732     InlineKlass::cast(this)->initialize_calling_convention(CHECK);
2733   }
2734 
2735   Array<Method*>* methods = this->methods();
2736   int num_methods = methods->length();
2737   for (int index = 0; index < num_methods; ++index) {
2738     methods->at(index)->restore_unshareable_info(CHECK);
2739   }
2740 #if INCLUDE_JVMTI
2741   if (JvmtiExport::has_redefined_a_class()) {
2742     // Reinitialize vtable because RedefineClasses may have changed some
2743     // entries in this vtable for super classes so the CDS vtable might
2744     // point to old or obsolete entries.  RedefineClasses doesn't fix up
2745     // vtables in the shared system dictionary, only the main one.
2746     // It also redefines the itable too so fix that too.
2747     // First fix any default methods that point to a super class that may
2748     // have been redefined.
2749     bool trace_name_printed = false;
2750     adjust_default_methods(&trace_name_printed);
2751     vtable().initialize_vtable();
2752     itable().initialize_itable();
2753   }
2754 #endif

2915 
2916 void InstanceKlass::set_source_debug_extension(const char* array, int length) {
2917   if (array == NULL) {
2918     _source_debug_extension = NULL;
2919   } else {
2920     // Adding one to the attribute length in order to store a null terminator
2921     // character could cause an overflow because the attribute length is
2922     // already coded with an u4 in the classfile, but in practice, it's
2923     // unlikely to happen.
2924     assert((length+1) > length, "Overflow checking");
2925     char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
2926     for (int i = 0; i < length; i++) {
2927       sde[i] = array[i];
2928     }
2929     sde[length] = '\0';
2930     _source_debug_extension = sde;
2931   }
2932 }
2933 
2934 const char* InstanceKlass::signature_name() const {
2935   return signature_name_of_carrier(JVM_SIGNATURE_CLASS);
2936 }
2937 
2938 const char* InstanceKlass::signature_name_of_carrier(char c) const {
2939   int hash_len = 0;
2940   char hash_buf[40];
2941 
2942   // Get the internal name as a c string
2943   const char* src = (const char*) (name()->as_C_string());
2944   const int src_length = (int)strlen(src);
2945 
2946   char* dest = NEW_RESOURCE_ARRAY(char, src_length + hash_len + 3);
2947 
2948   // Add L or Q as type indicator
2949   int dest_index = 0;
2950   dest[dest_index++] = c;
2951 
2952   // Add the actual class name
2953   for (int src_index = 0; src_index < src_length; ) {
2954     dest[dest_index++] = src[src_index++];
2955   }
2956 
2957   if (is_hidden()) { // Replace the last '+' with a '.'.
2958     for (int index = (int)src_length; index > 0; index--) {
2959       if (dest[index] == '+') {
2960         dest[index] = JVM_SIGNATURE_DOT;
2961         break;
2962       }
2963     }
2964   }
2965 
2966   // If we have a hash, append it
2967   for (int hash_index = 0; hash_index < hash_len; ) {
2968     dest[dest_index++] = hash_buf[hash_index++];
2969   }
2970 

3524     }
3525     osr = osr->osr_link();
3526   }
3527 
3528   assert(match_level == false || best == NULL, "shouldn't pick up anything if match_level is set");
3529   if (best != NULL && best->comp_level() >= comp_level) {
3530     return best;
3531   }
3532   return NULL;
3533 }
3534 
3535 // -----------------------------------------------------------------------------------------------------
3536 // Printing
3537 
3538 #define BULLET  " - "
3539 
3540 static const char* state_names[] = {
3541   "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3542 };
3543 
3544 static void print_vtable(address self, intptr_t* start, int len, outputStream* st) {
3545   ResourceMark rm;
3546   int* forward_refs = NEW_RESOURCE_ARRAY(int, len);
3547   for (int i = 0; i < len; i++)  forward_refs[i] = 0;
3548   for (int i = 0; i < len; i++) {
3549     intptr_t e = start[i];
3550     st->print("%d : " INTPTR_FORMAT, i, e);
3551     if (forward_refs[i] != 0) {
3552       int from = forward_refs[i];
3553       int off = (int) start[from];
3554       st->print(" (offset %d <= [%d])", off, from);
3555     }
3556     if (MetaspaceObj::is_valid((Metadata*)e)) {
3557       st->print(" ");
3558       ((Metadata*)e)->print_value_on(st);
3559     } else if (self != NULL && e > 0 && e < 0x10000) {
3560       address location = self + e;
3561       int index = (int)((intptr_t*)location - start);
3562       st->print(" (offset %d => [%d])", (int)e, index);
3563       if (index >= 0 && index < len)
3564         forward_refs[index] = i;
3565     }
3566     st->cr();
3567   }
3568 }
3569 
3570 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3571   return print_vtable(NULL, reinterpret_cast<intptr_t*>(start), len, st);
3572 }
3573 
3574 template<typename T>
3575  static void print_array_on(outputStream* st, Array<T>* array) {
3576    if (array == NULL) { st->print_cr("NULL"); return; }
3577    array->print_value_on(st); st->cr();
3578    if (Verbose || WizardMode) {
3579      for (int i = 0; i < array->length(); i++) {
3580        st->print("%d : ", i); array->at(i)->print_value_on(st); st->cr();
3581      }
3582    }
3583  }
3584 
3585 static void print_array_on(outputStream* st, Array<int>* array) {
3586   if (array == NULL) { st->print_cr("NULL"); return; }
3587   array->print_value_on(st); st->cr();
3588   if (Verbose || WizardMode) {
3589     for (int i = 0; i < array->length(); i++) {
3590       st->print("%d : %d", i, array->at(i)); st->cr();
3591     }
3592   }
3593 }
3594 
3595 void InstanceKlass::print_on(outputStream* st) const {
3596   assert(is_klass(), "must be klass");
3597   Klass::print_on(st);
3598 
3599   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
3600   st->print(BULLET"klass size:        %d", size());                               st->cr();
3601   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
3602   st->print(BULLET"misc flags:        0x%x", _misc_flags);                        st->cr();
3603   st->print(BULLET"state:             "); st->print_cr("%s", state_names[_init_state]);
3604   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
3605   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3606   st->print(BULLET"sub:               ");
3607   Klass* sub = subklass();
3608   int n;
3609   for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) {
3610     if (n < MaxSubklassPrintSize) {
3611       sub->print_value_on(st);
3612       st->print("   ");
3613     }
3614   }
3615   if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3616   st->cr();
3617 
3618   if (is_interface()) {
3619     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
3620     if (nof_implementors() == 1) {
3621       st->print_cr(BULLET"implementor:    ");
3622       st->print("   ");
3623       implementor()->print_value_on(st);
3624       st->cr();
3625     }
3626   }
3627 
3628   st->print(BULLET"arrays:            "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3629   st->print(BULLET"methods:           "); print_array_on(st, methods());
3630   st->print(BULLET"method ordering:   "); print_array_on(st, method_ordering());
3631   st->print(BULLET"default_methods:   "); print_array_on(st, default_methods());












3632   if (default_vtable_indices() != NULL) {
3633     st->print(BULLET"default vtable indices:   "); print_array_on(st, default_vtable_indices());
3634   }
3635   st->print(BULLET"local interfaces:  "); print_array_on(st, local_interfaces());
3636   st->print(BULLET"trans. interfaces: "); print_array_on(st, transitive_interfaces());
3637   st->print(BULLET"constants:         "); constants()->print_value_on(st);         st->cr();
3638   if (class_loader_data() != NULL) {
3639     st->print(BULLET"class loader data:  ");
3640     class_loader_data()->print_value_on(st);
3641     st->cr();
3642   }
3643   if (source_file_name() != NULL) {
3644     st->print(BULLET"source file:       ");
3645     source_file_name()->print_value_on(st);
3646     st->cr();
3647   }
3648   if (source_debug_extension() != NULL) {
3649     st->print(BULLET"source debug extension:       ");
3650     st->print("%s", source_debug_extension());
3651     st->cr();
3652   }
3653   st->print(BULLET"class annotations:       "); class_annotations()->print_value_on(st); st->cr();
3654   st->print(BULLET"class type annotations:  "); class_type_annotations()->print_value_on(st); st->cr();
3655   st->print(BULLET"field annotations:       "); fields_annotations()->print_value_on(st); st->cr();
3656   st->print(BULLET"field type annotations:  "); fields_type_annotations()->print_value_on(st); st->cr();

3672     st->print(BULLET"generic signature: ");
3673     generic_signature()->print_value_on(st);
3674     st->cr();
3675   }
3676   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
3677   st->print(BULLET"nest members:     "); nest_members()->print_value_on(st);     st->cr();
3678   if (record_components() != NULL) {
3679     st->print(BULLET"record components:     "); record_components()->print_value_on(st);     st->cr();
3680   }
3681   st->print(BULLET"permitted subclasses:     "); permitted_subclasses()->print_value_on(st);     st->cr();
3682   if (java_mirror() != NULL) {
3683     st->print(BULLET"java mirror:       ");
3684     java_mirror()->print_value_on(st);
3685     st->cr();
3686   } else {
3687     st->print_cr(BULLET"java mirror:       NULL");
3688   }
3689   st->print(BULLET"vtable length      %d  (start addr: " INTPTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3690   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
3691   st->print(BULLET"itable length      %d (start addr: " INTPTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3692   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(NULL, start_of_itable(), itable_length(), st);
3693   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3694   FieldPrinter print_static_field(st);
3695   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3696   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3697   FieldPrinter print_nonstatic_field(st);
3698   InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3699   ik->print_nonstatic_fields(&print_nonstatic_field);
3700 
3701   st->print(BULLET"non-static oop maps: ");
3702   OopMapBlock* map     = start_of_nonstatic_oop_maps();
3703   OopMapBlock* end_map = map + nonstatic_oop_map_count();
3704   while (map < end_map) {
3705     st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3706     map++;
3707   }
3708   st->cr();
3709 }
3710 
3711 void InstanceKlass::print_value_on(outputStream* st) const {
3712   assert(is_klass(), "must be klass");
< prev index next >