< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page

   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "cds/archiveUtils.hpp"
  27 #include "cds/cdsConfig.hpp"

  28 #include "cds/classListWriter.hpp"
  29 #include "cds/heapShared.hpp"
  30 #include "cds/metaspaceShared.hpp"
  31 #include "classfile/classFileParser.hpp"
  32 #include "classfile/classFileStream.hpp"
  33 #include "classfile/classLoader.hpp"
  34 #include "classfile/classLoaderData.inline.hpp"
  35 #include "classfile/javaClasses.hpp"
  36 #include "classfile/moduleEntry.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/systemDictionaryShared.hpp"
  39 #include "classfile/verifier.hpp"
  40 #include "classfile/vmClasses.hpp"
  41 #include "classfile/vmSymbols.hpp"
  42 #include "code/codeCache.hpp"
  43 #include "code/dependencyContext.hpp"
  44 #include "compiler/compilationPolicy.hpp"
  45 #include "compiler/compileBroker.hpp"
  46 #include "gc/shared/collectedHeap.inline.hpp"

  47 #include "interpreter/bytecodeStream.hpp"
  48 #include "interpreter/oopMapCache.hpp"
  49 #include "interpreter/rewriter.hpp"
  50 #include "jvm.h"
  51 #include "jvmtifiles/jvmti.h"
  52 #include "logging/log.hpp"
  53 #include "logging/logMessage.hpp"
  54 #include "logging/logStream.hpp"
  55 #include "memory/allocation.inline.hpp"
  56 #include "memory/iterator.inline.hpp"
  57 #include "memory/metadataFactory.hpp"
  58 #include "memory/metaspaceClosure.hpp"
  59 #include "memory/oopFactory.hpp"
  60 #include "memory/resourceArea.hpp"
  61 #include "memory/universe.hpp"
  62 #include "oops/fieldStreams.inline.hpp"
  63 #include "oops/constantPool.hpp"
  64 #include "oops/instanceClassLoaderKlass.hpp"
  65 #include "oops/instanceKlass.inline.hpp"
  66 #include "oops/instanceMirrorKlass.hpp"
  67 #include "oops/instanceOop.hpp"
  68 #include "oops/instanceStackChunkKlass.hpp"
  69 #include "oops/klass.inline.hpp"
  70 #include "oops/method.hpp"
  71 #include "oops/oop.inline.hpp"
  72 #include "oops/recordComponent.hpp"
  73 #include "oops/symbol.hpp"

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

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

 522 {
 523   set_vtable_length(parser.vtable_size());
 524   set_access_flags(parser.access_flags());
 525   if (parser.is_hidden()) set_is_hidden();
 526   set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
 527                                                     false));
 528 
 529   assert(nullptr == _methods, "underlying memory not zeroed?");
 530   assert(is_instance_klass(), "is layout incorrect?");
 531   assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
 532 }
 533 
 534 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
 535                                        Array<Method*>* methods) {
 536   if (methods != nullptr && methods != Universe::the_empty_method_array() &&
 537       !methods->is_shared()) {
 538     for (int i = 0; i < methods->length(); i++) {
 539       Method* method = methods->at(i);
 540       if (method == nullptr) continue;  // maybe null if error processing
 541       // Only want to delete methods that are not executing for RedefineClasses.

 742 
 743 objArrayOop InstanceKlass::signers() const {
 744   // return the signers from the mirror
 745   return java_lang_Class::signers(java_mirror());
 746 }
 747 
 748 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization
 749 // process. The step comments refers to the procedure described in that section.
 750 // Note: implementation moved to static method to expose the this pointer.
 751 void InstanceKlass::initialize(TRAPS) {
 752   if (this->should_be_initialized()) {
 753     initialize_impl(CHECK);
 754     // Note: at this point the class may be initialized
 755     //       OR it may be in the state of being initialized
 756     //       in case of recursive initialization!
 757   } else {
 758     assert(is_initialized(), "sanity check");
 759   }
 760 }
 761 



























































































 762 
 763 bool InstanceKlass::verify_code(TRAPS) {
 764   // 1) Verify the bytecodes
 765   return Verifier::verify(this, should_verify_class(), THREAD);
 766 }
 767 
 768 void InstanceKlass::link_class(TRAPS) {
 769   assert(is_loaded(), "must be loaded");
 770   if (!is_linked()) {
 771     link_class_impl(CHECK);
 772   }
 773 }
 774 
 775 void InstanceKlass::check_link_state_and_wait(JavaThread* current) {
 776   MonitorLocker ml(current, _init_monitor);
 777 
 778   bool debug_logging_enabled = log_is_enabled(Debug, class, init);
 779 
 780   // Another thread is linking this class, wait.
 781   while (is_being_linked() && !is_init_thread(current)) {

 961   return true;
 962 }
 963 
 964 // Rewrite the byte codes of all of the methods of a class.
 965 // The rewriter must be called exactly once. Rewriting must happen after
 966 // verification but before the first method of the class is executed.
 967 void InstanceKlass::rewrite_class(TRAPS) {
 968   assert(is_loaded(), "must be loaded");
 969   if (is_rewritten()) {
 970     assert(is_shared(), "rewriting an unshared class?");
 971     return;
 972   }
 973   Rewriter::rewrite(this, CHECK);
 974   set_rewritten();
 975 }
 976 
 977 // Now relocate and link method entry points after class is rewritten.
 978 // This is outside is_rewritten flag. In case of an exception, it can be
 979 // executed more than once.
 980 void InstanceKlass::link_methods(TRAPS) {


 981   int len = methods()->length();
 982   for (int i = len-1; i >= 0; i--) {
 983     methodHandle m(THREAD, methods()->at(i));
 984 
 985     // Set up method entry points for compiler and interpreter    .
 986     m->link_method(m, CHECK);
 987   }
 988 }
 989 
 990 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
 991 void InstanceKlass::initialize_super_interfaces(TRAPS) {
 992   assert (has_nonstatic_concrete_methods(), "caller should have checked this");
 993   for (int i = 0; i < local_interfaces()->length(); ++i) {
 994     InstanceKlass* ik = local_interfaces()->at(i);
 995 
 996     // Initialization is depth first search ie. we start with top of the inheritance tree
 997     // has_nonstatic_concrete_methods drives searching superinterfaces since it
 998     // means has_nonstatic_concrete_methods in its superinterface hierarchy
 999     if (ik->has_nonstatic_concrete_methods()) {
1000       ik->initialize_super_interfaces(CHECK);
1001     }
1002 
1003     // Only initialize() interfaces that "declare" concrete methods.
1004     if (ik->should_be_initialized() && ik->declares_nonstatic_concrete_methods()) {







1005       ik->initialize(CHECK);
1006     }
1007   }
1008 }
1009 
1010 using InitializationErrorTable = ResourceHashtable<const InstanceKlass*, OopHandle, 107, AnyObj::C_HEAP, mtClass>;
1011 static InitializationErrorTable* _initialization_error_table;
1012 
1013 void InstanceKlass::add_initialization_error(JavaThread* current, Handle exception) {
1014   // Create the same exception with a message indicating the thread name,
1015   // and the StackTraceElements.
1016   Handle init_error = java_lang_Throwable::create_initialization_error(current, exception);
1017   ResourceMark rm(current);
1018   if (init_error.is_null()) {
1019     log_trace(class, init)("Unable to create the desired initialization error for class %s", external_name());
1020 
1021     // We failed to create the new exception, most likely due to either out-of-memory or
1022     // a stackoverflow error. If the original exception was either of those then we save
1023     // the shared, pre-allocated, stackless, instance of that exception.
1024     if (exception->klass() == vmClasses::StackOverflowError_klass()) {

1069   InitErrorTableCleaner cleaner;
1070   if (_initialization_error_table != nullptr) {
1071     _initialization_error_table->unlink(&cleaner);
1072   }
1073 }
1074 
1075 void InstanceKlass::initialize_impl(TRAPS) {
1076   HandleMark hm(THREAD);
1077 
1078   // Make sure klass is linked (verified) before initialization
1079   // A class could already be verified, since it has been reflected upon.
1080   link_class(CHECK);
1081 
1082   DTRACE_CLASSINIT_PROBE(required, -1);
1083 
1084   bool wait = false;
1085   bool throw_error = false;
1086 
1087   JavaThread* jt = THREAD;
1088 















1089   bool debug_logging_enabled = log_is_enabled(Debug, class, init);
1090 
1091   // refer to the JVM book page 47 for description of steps
1092   // Step 1
1093   {
1094     MonitorLocker ml(jt, _init_monitor);
1095 
1096     // Step 2
1097     while (is_being_initialized() && !is_init_thread(jt)) {
1098       if (debug_logging_enabled) {
1099         ResourceMark rm(jt);
1100         log_debug(class, init)("Thread \"%s\" waiting for initialization of %s by thread \"%s\"",
1101                                jt->name(), external_name(), init_thread_name());
1102       }
1103 
1104       wait = true;
1105       jt->set_class_to_be_initialized(this);
1106       ml.wait();
1107       jt->set_class_to_be_initialized(nullptr);
1108     }

1155     DTRACE_CLASSINIT_PROBE_WAIT(erroneous, -1, wait);
1156     ResourceMark rm(THREAD);
1157     Handle cause(THREAD, get_initialization_error(THREAD));
1158 
1159     stringStream ss;
1160     ss.print("Could not initialize class %s", external_name());
1161     if (cause.is_null()) {
1162       THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1163     } else {
1164       THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1165                       ss.as_string(), cause);
1166     }
1167   }
1168 
1169   // Step 7
1170   // Next, if C is a class rather than an interface, initialize it's super class and super
1171   // interfaces.
1172   if (!is_interface()) {
1173     Klass* super_klass = super();
1174     if (super_klass != nullptr && super_klass->should_be_initialized()) {









1175       super_klass->initialize(THREAD);
1176     }
1177     // If C implements any interface that declares a non-static, concrete method,
1178     // the initialization of C triggers initialization of its super interfaces.
1179     // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1180     // having a superinterface that declares, non-static, concrete methods
1181     if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1182       initialize_super_interfaces(THREAD);


1183     }
1184 
1185     // If any exceptions, complete abruptly, throwing the same exception as above.
1186     if (HAS_PENDING_EXCEPTION) {
1187       Handle e(THREAD, PENDING_EXCEPTION);
1188       CLEAR_PENDING_EXCEPTION;
1189       {
1190         EXCEPTION_MARK;
1191         add_initialization_error(THREAD, e);
1192         // Locks object, set state, and notify all waiting threads
1193         set_initialization_state_and_notify(initialization_error, THREAD);
1194         CLEAR_PENDING_EXCEPTION;
1195       }
1196       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1197       THROW_OOP(e());
1198     }
1199   }
1200 
1201 
1202   // Step 8

1236     {
1237       EXCEPTION_MARK;
1238       add_initialization_error(THREAD, e);
1239       set_initialization_state_and_notify(initialization_error, THREAD);
1240       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below
1241       // JVMTI has already reported the pending exception
1242       // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1243       JvmtiExport::clear_detected_exception(jt);
1244     }
1245     DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1246     if (e->is_a(vmClasses::Error_klass())) {
1247       THROW_OOP(e());
1248     } else {
1249       JavaCallArguments args(e);
1250       THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1251                 vmSymbols::throwable_void_signature(),
1252                 &args);
1253     }
1254   }
1255   DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait);
1256 }
1257 


1258 
1259 void InstanceKlass::set_initialization_state_and_notify(ClassState state, JavaThread* current) {
1260   MonitorLocker ml(current, _init_monitor);
1261 
1262   if (state == linked && UseVtableBasedCHA && Universe::is_fully_initialized()) {
1263     DeoptimizationScope deopt_scope;
1264     {
1265       // Now mark all code that assumes the class is not linked.
1266       // Set state under the Compile_lock also.
1267       MutexLocker ml(current, Compile_lock);
1268 
1269       set_init_thread(nullptr); // reset _init_thread before changing _init_state
1270       set_init_state(state);
1271 
1272       CodeCache::mark_dependents_on(&deopt_scope, this);
1273     }
1274     // Perform the deopt handshake outside Compile_lock.
1275     deopt_scope.deoptimize_marked();
1276   } else {
1277     set_init_thread(nullptr); // reset _init_thread before changing _init_state

1496   JavaCallArguments args(h_i);
1497   methodHandle mh(THREAD, Universe::finalizer_register_method());
1498   JavaCalls::call(&result, mh, &args, CHECK_NULL);
1499   MANAGEMENT_ONLY(FinalizerService::on_register(h_i(), THREAD);)
1500   return h_i();
1501 }
1502 
1503 instanceOop InstanceKlass::allocate_instance(TRAPS) {
1504   bool has_finalizer_flag = has_finalizer(); // Query before possible GC
1505   size_t size = size_helper();  // Query before forming handle.
1506 
1507   instanceOop i;
1508 
1509   i = (instanceOop)Universe::heap()->obj_allocate(this, size, CHECK_NULL);
1510   if (has_finalizer_flag && !RegisterFinalizersAtInit) {
1511     i = register_finalizer(i, CHECK_NULL);
1512   }
1513   return i;
1514 }
1515 
1516 instanceOop InstanceKlass::allocate_instance(oop java_class, TRAPS) {


1517   Klass* k = java_lang_Class::as_Klass(java_class);
1518   if (k == nullptr) {
1519     ResourceMark rm(THREAD);
1520     THROW_(vmSymbols::java_lang_InstantiationException(), nullptr);
1521   }
1522   InstanceKlass* ik = cast(k);
1523   ik->check_valid_for_instantiation(false, CHECK_NULL);



1524   ik->initialize(CHECK_NULL);
1525   return ik->allocate_instance(THREAD);
1526 }
1527 
1528 instanceHandle InstanceKlass::allocate_instance_handle(TRAPS) {
1529   return instanceHandle(THREAD, allocate_instance(THREAD));
1530 }
1531 
1532 void InstanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) {
1533   if (is_interface() || is_abstract()) {
1534     ResourceMark rm(THREAD);
1535     THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1536               : vmSymbols::java_lang_InstantiationException(), external_name());
1537   }
1538   if (this == vmClasses::Class_klass()) {
1539     ResourceMark rm(THREAD);
1540     THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1541               : vmSymbols::java_lang_IllegalAccessException(), external_name());
1542   }
1543 }

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



1612   }
1613 #endif
1614 
1615   methodHandle h_method(THREAD, class_initializer());
1616   assert(!is_initialized(), "we cannot initialize twice");























































1617   LogTarget(Info, class, init) lt;
1618   if (lt.is_enabled()) {
1619     ResourceMark rm(THREAD);
1620     LogStream ls(lt);
1621     ls.print("%d Initializing ", call_class_initializer_counter++);
1622     name()->print_value_on(&ls);
1623     ls.print_cr("%s (" PTR_FORMAT ") by thread \"%s\"",
1624                 h_method() == nullptr ? "(no method)" : "", p2i(this),
1625                 THREAD->name());
1626   }
1627   if (h_method() != nullptr) {
1628     JavaCallArguments args; // No arguments
1629     JavaValue result(T_VOID);
1630     JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)










1631   }




1632 }
1633 
1634 
















1635 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1636   InterpreterOopMap* entry_for) {
1637   // Lazily create the _oop_map_cache at first request
1638   // Lock-free access requires load_acquire.
1639   OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1640   if (oop_map_cache == nullptr) {
1641     MutexLocker x(OopMapCacheAlloc_lock);
1642     // Check if _oop_map_cache was allocated while we were waiting for this lock
1643     if ((oop_map_cache = _oop_map_cache) == nullptr) {
1644       oop_map_cache = new OopMapCache();
1645       // Ensure _oop_map_cache is stable, since it is examined without a lock
1646       Atomic::release_store(&_oop_map_cache, oop_map_cache);
1647     }
1648   }
1649   // _oop_map_cache is constant after init; lookup below does its own locking.
1650   oop_map_cache->lookup(method, bci, entry_for);
1651 }
1652 
1653 bool InstanceKlass::contains_field_offset(int offset) {
1654   fieldDescriptor fd;

2458 
2459 // Lookup a jmethodID, null if not found.  Do no blocking, no allocations, no handles
2460 jmethodID InstanceKlass::jmethod_id_or_null(Method* method) {
2461   size_t idnum = (size_t)method->method_idnum();
2462   jmethodID* jmeths = methods_jmethod_ids_acquire();
2463   size_t length;                                // length assigned as debugging crumb
2464   jmethodID id = nullptr;
2465   if (jmeths != nullptr &&                      // If there is a cache
2466       (length = (size_t)jmeths[0]) > idnum) {   // and if it is long enough,
2467     id = jmeths[idnum+1];                       // Look up the id (may be null)
2468   }
2469   return id;
2470 }
2471 
2472 inline DependencyContext InstanceKlass::dependencies() {
2473   DependencyContext dep_context(&_dep_context, &_dep_context_last_cleaned);
2474   return dep_context;
2475 }
2476 
2477 void InstanceKlass::mark_dependent_nmethods(DeoptimizationScope* deopt_scope, KlassDepChange& changes) {
2478   dependencies().mark_dependent_nmethods(deopt_scope, changes);
2479 }
2480 
2481 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
2482   dependencies().add_dependent_nmethod(nm);
2483 }
2484 
2485 void InstanceKlass::clean_dependency_context() {
2486   dependencies().clean_unloading_dependents();
2487 }
2488 
2489 #ifndef PRODUCT
2490 void InstanceKlass::print_dependent_nmethods(bool verbose) {
2491   dependencies().print_dependent_nmethods(verbose);
2492 }
2493 
2494 bool InstanceKlass::is_dependent_nmethod(nmethod* nm) {
2495   return dependencies().is_dependent_nmethod(nm);
2496 }
2497 #endif //PRODUCT
2498 

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

2607   it->push(&_nest_members);
2608   it->push(&_permitted_subclasses);
2609   it->push(&_record_components);
2610 }
2611 
2612 #if INCLUDE_CDS
2613 void InstanceKlass::remove_unshareable_info() {
2614 
2615   if (is_linked()) {
2616     assert(can_be_verified_at_dumptime(), "must be");
2617     // Remember this so we can avoid walking the hierarchy at runtime.
2618     set_verified_at_dump_time();
2619   }
2620 
2621   Klass::remove_unshareable_info();
2622 
2623   if (SystemDictionaryShared::has_class_failed_verification(this)) {
2624     // Classes are attempted to link during dumping and may fail,
2625     // but these classes are still in the dictionary and class list in CLD.
2626     // If the class has failed verification, there is nothing else to remove.
2627     return;
2628   }
2629 
2630   // Reset to the 'allocated' state to prevent any premature accessing to
2631   // a shared class at runtime while the class is still being loaded and
2632   // restored. A class' init_state is set to 'loaded' at runtime when it's
2633   // being added to class hierarchy (see InstanceKlass:::add_to_hierarchy()).
2634   _init_state = allocated;
2635 
2636   { // Otherwise this needs to take out the Compile_lock.
2637     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2638     init_implementor();
2639   }
2640 
2641   constants()->remove_unshareable_info();

2642 
2643   for (int i = 0; i < methods()->length(); i++) {
2644     Method* m = methods()->at(i);
2645     m->remove_unshareable_info();
2646   }
2647 
2648   // do array classes also.
2649   if (array_klasses() != nullptr) {
2650     array_klasses()->remove_unshareable_info();
2651   }
2652 
2653   // These are not allocated from metaspace. They are safe to set to null.
2654   _source_debug_extension = nullptr;
2655   _dep_context = nullptr;
2656   _osr_nmethods_head = nullptr;
2657 #if INCLUDE_JVMTI
2658   _breakpoints = nullptr;
2659   _previous_versions = nullptr;
2660   _cached_class_file = nullptr;
2661   _jvmti_cached_class_field_map = nullptr;
2662 #endif
2663 
2664   _init_thread = nullptr;
2665   _methods_jmethod_ids = nullptr;
2666   _jni_ids = nullptr;
2667   _oop_map_cache = nullptr;
2668   // clear _nest_host to ensure re-load at runtime
2669   _nest_host = nullptr;




2670   init_shared_package_entry();
2671   _dep_context_last_cleaned = 0;
2672   _init_monitor = nullptr;

2673 

2674   remove_unshareable_flags();
2675 }
2676 
2677 void InstanceKlass::remove_unshareable_flags() {
2678   // clear all the flags/stats that shouldn't be in the archived version
2679   assert(!is_scratch_class(), "must be");
2680   assert(!has_been_redefined(), "must be");
2681 #if INCLUDE_JVMTI
2682   set_is_being_redefined(false);
2683 #endif
2684   set_has_resolved_methods(false);
2685 }
2686 
2687 void InstanceKlass::remove_java_mirror() {
2688   Klass::remove_java_mirror();
2689 
2690   // do array classes also.
2691   if (array_klasses() != nullptr) {
2692     array_klasses()->remove_java_mirror();
2693   }

2759   // restore constant pool resolved references
2760   constants()->restore_unshareable_info(CHECK);
2761 
2762   if (array_klasses() != nullptr) {
2763     // To get a consistent list of classes we need MultiArray_lock to ensure
2764     // array classes aren't observed while they are being restored.
2765     MutexLocker ml(MultiArray_lock);
2766     assert(this == array_klasses()->bottom_klass(), "sanity");
2767     // Array classes have null protection domain.
2768     // --> see ArrayKlass::complete_create_array_klass()
2769     array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2770   }
2771 
2772   // Initialize @ValueBased class annotation
2773   if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation()) {
2774     set_is_value_based();
2775   }
2776 
2777   // restore the monitor
2778   _init_monitor = create_init_monitor("InstanceKlassInitMonitorRestored_lock");




2779 }
2780 
2781 // Check if a class or any of its supertypes has a version older than 50.
2782 // CDS will not perform verification of old classes during dump time because
2783 // without changing the old verifier, the verification constraint cannot be
2784 // retrieved during dump time.
2785 // Verification of archived old classes will be performed during run time.
2786 bool InstanceKlass::can_be_verified_at_dumptime() const {




2787   if (MetaspaceShared::is_in_shared_metaspace(this)) {
2788     // This is a class that was dumped into the base archive, so we know
2789     // it was verified at dump time.
2790     return true;
2791   }











2792   if (major_version() < 50 /*JAVA_6_VERSION*/) {
2793     return false;
2794   }
2795   if (java_super() != nullptr && !java_super()->can_be_verified_at_dumptime()) {
2796     return false;
2797   }
2798   Array<InstanceKlass*>* interfaces = local_interfaces();
2799   int len = interfaces->length();
2800   for (int i = 0; i < len; i++) {
2801     if (!interfaces->at(i)->can_be_verified_at_dumptime()) {
2802       return false;
2803     }
2804   }
2805   return true;
2806 }
2807 
2808 bool InstanceKlass::methods_contain_jsr_bytecode() const {
2809   Thread* thread = Thread::current();
2810   for (int i = 0; i < _methods->length(); i++) {
2811     methodHandle m(thread, _methods->at(i));
2812     BytecodeStream bcs(m);
2813     while (!bcs.is_last_bytecode()) {
2814       Bytecodes::Code opcode = bcs.next();
2815       if (opcode == Bytecodes::_jsr || opcode == Bytecodes::_jsr_w) {
2816         return true;
2817       }
2818     }
2819   }
2820   return false;
2821 }












2822 #endif // INCLUDE_CDS
2823 
2824 #if INCLUDE_JVMTI
2825 static void clear_all_breakpoints(Method* m) {
2826   m->clear_all_breakpoints();
2827 }
2828 #endif
2829 
2830 void InstanceKlass::unload_class(InstanceKlass* ik) {
2831   // Release dependencies.
2832   ik->dependencies().remove_all_dependents();
2833 
2834   // notify the debugger
2835   if (JvmtiExport::should_post_class_unload()) {
2836     JvmtiExport::post_class_unload(ik);
2837   }
2838 
2839   // notify ClassLoadingService of class unload
2840   ClassLoadingService::notify_class_unloaded(ik);
2841 

3571 static void print_vtable(intptr_t* start, int len, outputStream* st) {
3572   for (int i = 0; i < len; i++) {
3573     intptr_t e = start[i];
3574     st->print("%d : " INTPTR_FORMAT, i, e);
3575     if (MetaspaceObj::is_valid((Metadata*)e)) {
3576       st->print(" ");
3577       ((Metadata*)e)->print_value_on(st);
3578     }
3579     st->cr();
3580   }
3581 }
3582 
3583 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3584   return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
3585 }
3586 
3587 const char* InstanceKlass::init_state_name() const {
3588   return state_names[init_state()];
3589 }
3590 




3591 void InstanceKlass::print_on(outputStream* st) const {
3592   assert(is_klass(), "must be klass");
3593   Klass::print_on(st);
3594 
3595   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
3596   st->print(BULLET"klass size:        %d", size());                               st->cr();
3597   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
3598   st->print(BULLET"flags:             "); _misc_flags.print_on(st);               st->cr();
3599   st->print(BULLET"state:             "); st->print_cr("%s", init_state_name());
3600   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
3601   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3602   st->print(BULLET"sub:               ");
3603   Klass* sub = subklass();
3604   int n;
3605   for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3606     if (n < MaxSubklassPrintSize) {
3607       sub->print_value_on(st);
3608       st->print("   ");
3609     }
3610   }

3889         nullptr;
3890       // caller can be null, for example, during a JVMTI VM_Init hook
3891       if (caller != nullptr) {
3892         info_stream.print(" source: instance of %s", caller->external_name());
3893       } else {
3894         // source is unknown
3895       }
3896     } else {
3897       oop class_loader = loader_data->class_loader();
3898       info_stream.print(" source: %s", class_loader->klass()->external_name());
3899     }
3900   } else {
3901     assert(this->is_shared(), "must be");
3902     if (MetaspaceShared::is_shared_dynamic((void*)this)) {
3903       info_stream.print(" source: shared objects file (top)");
3904     } else {
3905       info_stream.print(" source: shared objects file");
3906     }
3907   }
3908 

















3909   msg.info("%s", info_stream.as_string());
3910 
3911   if (log_is_enabled(Debug, class, load)) {
3912     stringStream debug_stream;
3913 
3914     // Class hierarchy info
3915     debug_stream.print(" klass: " PTR_FORMAT " super: " PTR_FORMAT,
3916                        p2i(this),  p2i(superklass()));
3917 
3918     // Interfaces
3919     if (local_interfaces() != nullptr && local_interfaces()->length() > 0) {
3920       debug_stream.print(" interfaces:");
3921       int length = local_interfaces()->length();
3922       for (int i = 0; i < length; i++) {
3923         debug_stream.print(" " PTR_FORMAT,
3924                            p2i(InstanceKlass::cast(local_interfaces()->at(i))));
3925       }
3926     }
3927 
3928     // Class loader

   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "cds/archiveUtils.hpp"
  27 #include "cds/cdsConfig.hpp"
  28 #include "cds/cdsEnumKlass.hpp"
  29 #include "cds/classListWriter.hpp"
  30 #include "cds/heapShared.hpp"
  31 #include "cds/metaspaceShared.hpp"
  32 #include "classfile/classFileParser.hpp"
  33 #include "classfile/classFileStream.hpp"
  34 #include "classfile/classLoader.hpp"
  35 #include "classfile/classLoaderData.inline.hpp"
  36 #include "classfile/javaClasses.hpp"
  37 #include "classfile/moduleEntry.hpp"
  38 #include "classfile/systemDictionary.hpp"
  39 #include "classfile/systemDictionaryShared.hpp"
  40 #include "classfile/verifier.hpp"
  41 #include "classfile/vmClasses.hpp"
  42 #include "classfile/vmSymbols.hpp"
  43 #include "code/codeCache.hpp"
  44 #include "code/dependencyContext.hpp"
  45 #include "compiler/compilationPolicy.hpp"
  46 #include "compiler/compileBroker.hpp"
  47 #include "gc/shared/collectedHeap.inline.hpp"
  48 #include "interpreter/bytecodeHistogram.hpp"
  49 #include "interpreter/bytecodeStream.hpp"
  50 #include "interpreter/oopMapCache.hpp"
  51 #include "interpreter/rewriter.hpp"
  52 #include "jvm.h"
  53 #include "jvmtifiles/jvmti.h"
  54 #include "logging/log.hpp"
  55 #include "logging/logMessage.hpp"
  56 #include "logging/logStream.hpp"
  57 #include "memory/allocation.inline.hpp"
  58 #include "memory/iterator.inline.hpp"
  59 #include "memory/metadataFactory.hpp"
  60 #include "memory/metaspaceClosure.hpp"
  61 #include "memory/oopFactory.hpp"
  62 #include "memory/resourceArea.hpp"
  63 #include "memory/universe.hpp"
  64 #include "oops/fieldStreams.inline.hpp"
  65 #include "oops/constantPool.hpp"
  66 #include "oops/instanceClassLoaderKlass.hpp"
  67 #include "oops/instanceKlass.inline.hpp"
  68 #include "oops/instanceMirrorKlass.hpp"
  69 #include "oops/instanceOop.hpp"
  70 #include "oops/instanceStackChunkKlass.hpp"
  71 #include "oops/klass.inline.hpp"
  72 #include "oops/method.hpp"
  73 #include "oops/oop.inline.hpp"
  74 #include "oops/recordComponent.hpp"
  75 #include "oops/symbol.hpp"
  76 #include "oops/trainingData.hpp"
  77 #include "prims/jvmtiExport.hpp"
  78 #include "prims/jvmtiRedefineClasses.hpp"
  79 #include "prims/jvmtiThreadState.hpp"
  80 #include "prims/methodComparator.hpp"
  81 #include "runtime/arguments.hpp"
  82 #include "runtime/deoptimization.hpp"
  83 #include "runtime/atomic.hpp"
  84 #include "runtime/fieldDescriptor.inline.hpp"
  85 #include "runtime/handles.inline.hpp"
  86 #include "runtime/javaCalls.hpp"
  87 #include "runtime/javaThread.inline.hpp"
  88 #include "runtime/mutexLocker.hpp"
  89 #include "runtime/orderAccess.hpp"
  90 #include "runtime/os.inline.hpp"
  91 #include "runtime/reflection.hpp"
  92 #include "runtime/threads.hpp"
  93 #include "services/classLoadingService.hpp"
  94 #include "services/finalizerService.hpp"
  95 #include "services/threadService.hpp"
  96 #include "utilities/dtrace.hpp"

 504   return new Monitor(Mutex::safepoint, name);
 505 }
 506 
 507 InstanceKlass::InstanceKlass() {
 508   assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS");
 509 }
 510 
 511 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) :
 512   Klass(kind),
 513   _nest_members(nullptr),
 514   _nest_host(nullptr),
 515   _permitted_subclasses(nullptr),
 516   _record_components(nullptr),
 517   _static_field_size(parser.static_field_size()),
 518   _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
 519   _itable_len(parser.itable_size()),
 520   _nest_host_index(0),
 521   _init_state(allocated),
 522   _reference_type(reference_type),
 523   _init_monitor(create_init_monitor("InstanceKlassInitMonitor_lock")),
 524   _init_thread(nullptr),
 525   _training_data(nullptr)
 526 {
 527   set_vtable_length(parser.vtable_size());
 528   set_access_flags(parser.access_flags());
 529   if (parser.is_hidden()) set_is_hidden();
 530   set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
 531                                                     false));
 532 
 533   assert(nullptr == _methods, "underlying memory not zeroed?");
 534   assert(is_instance_klass(), "is layout incorrect?");
 535   assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
 536 }
 537 
 538 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
 539                                        Array<Method*>* methods) {
 540   if (methods != nullptr && methods != Universe::the_empty_method_array() &&
 541       !methods->is_shared()) {
 542     for (int i = 0; i < methods->length(); i++) {
 543       Method* method = methods->at(i);
 544       if (method == nullptr) continue;  // maybe null if error processing
 545       // Only want to delete methods that are not executing for RedefineClasses.

 746 
 747 objArrayOop InstanceKlass::signers() const {
 748   // return the signers from the mirror
 749   return java_lang_Class::signers(java_mirror());
 750 }
 751 
 752 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization
 753 // process. The step comments refers to the procedure described in that section.
 754 // Note: implementation moved to static method to expose the this pointer.
 755 void InstanceKlass::initialize(TRAPS) {
 756   if (this->should_be_initialized()) {
 757     initialize_impl(CHECK);
 758     // Note: at this point the class may be initialized
 759     //       OR it may be in the state of being initialized
 760     //       in case of recursive initialization!
 761   } else {
 762     assert(is_initialized(), "sanity check");
 763   }
 764 }
 765 
 766 static bool are_super_types_initialized(InstanceKlass* ik) {
 767   InstanceKlass* s = ik->java_super();
 768   if (s != nullptr && !s->is_initialized()) {
 769     return false;
 770   }
 771 
 772   if (ik->has_nonstatic_concrete_methods()) {
 773     // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
 774     // having a superinterface that declares, non-static, concrete methods
 775     Array<InstanceKlass*>* interfaces = ik->local_interfaces();
 776     int len = interfaces->length();
 777     for (int i = 0; i < len; i++) {
 778       InstanceKlass* intf = interfaces->at(i);
 779       if (!intf->is_initialized()) {
 780         return false;
 781       }
 782     }
 783   }
 784 
 785   return true;
 786 }
 787 
 788 static void log_class_init_start(outputStream* st, JavaThread* current, InstanceKlass* ik, int init_id) {
 789   ResourceMark rm;
 790   const char* info = "";
 791   if (ik->has_preinitialized_mirror() && CDSConfig::is_loading_heap()) {
 792     info = " (preinitialized)";
 793   } else if (ik->class_initializer() == nullptr) {
 794     info = " (no method)";
 795   }
 796   st->print("%d Initializing ", init_id);
 797   ik->name()->print_value_on(st);
 798   st->print_cr("%s (" PTR_FORMAT ") by thread " PTR_FORMAT " \"%s\"", info, p2i(ik), p2i(current), current->name());
 799 }
 800 
 801 static int log_class_init(JavaThread* current, InstanceKlass* ik) {
 802   int init_id = -1;
 803   LogStreamHandle(Info,  init, class) lsh1;
 804   LogStreamHandle(Debug, init)        lsh2;
 805   if (lsh1.is_enabled() || lsh2.is_enabled()) {
 806     static int call_class_initializer_counter = 0;  // for debugging
 807     init_id = Atomic::fetch_then_add(&call_class_initializer_counter, 1);
 808     if (lsh1.is_enabled()) {
 809       log_class_init_start(&lsh1, current, ik, init_id);
 810     }
 811     if (lsh2.is_enabled() && ik->class_initializer() != nullptr && !ik->has_preinitialized_mirror()) {
 812       log_class_init_start(&lsh2, current, ik, init_id);
 813     }
 814   }
 815   return init_id;
 816 }
 817 
 818 void InstanceKlass::initialize_from_cds(TRAPS) {
 819   if (is_initialized()) {
 820     return;
 821   }
 822 
 823   if (has_preinitialized_mirror() && CDSConfig::is_loading_heap() &&
 824       !ForceProfiling &&
 825       !RecordTraining &&
 826       are_super_types_initialized(this)) {
 827     // FIXME: also check for events listeners such as JVMTI, JFR, etc
 828     if (log_is_enabled(Info, cds, init)) {
 829       ResourceMark rm;
 830       log_info(cds, init)("%s (quickest)", external_name());
 831     }
 832 
 833     link_class(CHECK);
 834 
 835 #ifdef AZZERT
 836     {
 837       MonitorLocker ml(THREAD, _init_monitor);
 838       assert(!initialized(), "sanity");
 839       assert(!is_being_initialized(), "sanity");
 840       assert(!is_in_error_state(), "sanity");
 841     }
 842 #endif
 843 
 844     log_class_init(THREAD, this);
 845     set_init_thread(THREAD);
 846     set_initialization_state_and_notify(fully_initialized, CHECK);
 847     return;
 848   }
 849 
 850   if (log_is_enabled(Info, cds, init)) {
 851     ResourceMark rm;
 852     log_info(cds, init)("%s%s", external_name(),
 853                         (has_preinitialized_mirror() && CDSConfig::is_loading_heap()) ? " (quicker)" : "");
 854   }
 855   initialize(THREAD);
 856 }
 857 
 858 bool InstanceKlass::verify_code(TRAPS) {
 859   // 1) Verify the bytecodes
 860   return Verifier::verify(this, should_verify_class(), THREAD);
 861 }
 862 
 863 void InstanceKlass::link_class(TRAPS) {
 864   assert(is_loaded(), "must be loaded");
 865   if (!is_linked()) {
 866     link_class_impl(CHECK);
 867   }
 868 }
 869 
 870 void InstanceKlass::check_link_state_and_wait(JavaThread* current) {
 871   MonitorLocker ml(current, _init_monitor);
 872 
 873   bool debug_logging_enabled = log_is_enabled(Debug, class, init);
 874 
 875   // Another thread is linking this class, wait.
 876   while (is_being_linked() && !is_init_thread(current)) {

1056   return true;
1057 }
1058 
1059 // Rewrite the byte codes of all of the methods of a class.
1060 // The rewriter must be called exactly once. Rewriting must happen after
1061 // verification but before the first method of the class is executed.
1062 void InstanceKlass::rewrite_class(TRAPS) {
1063   assert(is_loaded(), "must be loaded");
1064   if (is_rewritten()) {
1065     assert(is_shared(), "rewriting an unshared class?");
1066     return;
1067   }
1068   Rewriter::rewrite(this, CHECK);
1069   set_rewritten();
1070 }
1071 
1072 // Now relocate and link method entry points after class is rewritten.
1073 // This is outside is_rewritten flag. In case of an exception, it can be
1074 // executed more than once.
1075 void InstanceKlass::link_methods(TRAPS) {
1076   PerfTraceElapsedTime timer(ClassLoader::perf_ik_link_methods_time());
1077 
1078   int len = methods()->length();
1079   for (int i = len-1; i >= 0; i--) {
1080     methodHandle m(THREAD, methods()->at(i));
1081 
1082     // Set up method entry points for compiler and interpreter    .
1083     m->link_method(m, CHECK);
1084   }
1085 }
1086 
1087 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
1088 void InstanceKlass::initialize_super_interfaces(Klass* requester, TRAPS) {
1089   assert (has_nonstatic_concrete_methods(), "caller should have checked this");
1090   for (int i = 0; i < local_interfaces()->length(); ++i) {
1091     InstanceKlass* ik = local_interfaces()->at(i);
1092 
1093     // Initialization is depth first search ie. we start with top of the inheritance tree
1094     // has_nonstatic_concrete_methods drives searching superinterfaces since it
1095     // means has_nonstatic_concrete_methods in its superinterface hierarchy
1096     if (ik->has_nonstatic_concrete_methods()) {
1097       ik->initialize_super_interfaces(requester, CHECK);
1098     }
1099 
1100     // Only initialize() interfaces that "declare" concrete methods.
1101     if (ik->should_be_initialized() && ik->declares_nonstatic_concrete_methods()) {
1102       if (RecordTraining && requester != nullptr) {
1103         ik->record_initialization_touch("super", nullptr, nullptr, requester,
1104                                         nullptr, THREAD);
1105         if (HAS_PENDING_EXCEPTION) {
1106           CLEAR_PENDING_EXCEPTION;  // could not allocate training data
1107         }
1108       }
1109       ik->initialize(CHECK);
1110     }
1111   }
1112 }
1113 
1114 using InitializationErrorTable = ResourceHashtable<const InstanceKlass*, OopHandle, 107, AnyObj::C_HEAP, mtClass>;
1115 static InitializationErrorTable* _initialization_error_table;
1116 
1117 void InstanceKlass::add_initialization_error(JavaThread* current, Handle exception) {
1118   // Create the same exception with a message indicating the thread name,
1119   // and the StackTraceElements.
1120   Handle init_error = java_lang_Throwable::create_initialization_error(current, exception);
1121   ResourceMark rm(current);
1122   if (init_error.is_null()) {
1123     log_trace(class, init)("Unable to create the desired initialization error for class %s", external_name());
1124 
1125     // We failed to create the new exception, most likely due to either out-of-memory or
1126     // a stackoverflow error. If the original exception was either of those then we save
1127     // the shared, pre-allocated, stackless, instance of that exception.
1128     if (exception->klass() == vmClasses::StackOverflowError_klass()) {

1173   InitErrorTableCleaner cleaner;
1174   if (_initialization_error_table != nullptr) {
1175     _initialization_error_table->unlink(&cleaner);
1176   }
1177 }
1178 
1179 void InstanceKlass::initialize_impl(TRAPS) {
1180   HandleMark hm(THREAD);
1181 
1182   // Make sure klass is linked (verified) before initialization
1183   // A class could already be verified, since it has been reflected upon.
1184   link_class(CHECK);
1185 
1186   DTRACE_CLASSINIT_PROBE(required, -1);
1187 
1188   bool wait = false;
1189   bool throw_error = false;
1190 
1191   JavaThread* jt = THREAD;
1192 
1193   if (ForceProfiling) {
1194     // Preallocate MDOs.
1195     for (int i = 0; i < methods()->length(); i++) {
1196       assert(!HAS_PENDING_EXCEPTION, "");
1197       methodHandle m(THREAD, methods()->at(i));
1198       Method::build_profiling_method_data(m, THREAD);
1199       if (HAS_PENDING_EXCEPTION) {
1200         ResourceMark rm;
1201         log_warning(cds)("MDO preallocation failed for %s", external_name());
1202         CLEAR_PENDING_EXCEPTION;
1203         break;
1204       }
1205     }
1206   }
1207 
1208   bool debug_logging_enabled = log_is_enabled(Debug, class, init);
1209 
1210   // refer to the JVM book page 47 for description of steps
1211   // Step 1
1212   {
1213     MonitorLocker ml(jt, _init_monitor);
1214 
1215     // Step 2
1216     while (is_being_initialized() && !is_init_thread(jt)) {
1217       if (debug_logging_enabled) {
1218         ResourceMark rm(jt);
1219         log_debug(class, init)("Thread \"%s\" waiting for initialization of %s by thread \"%s\"",
1220                                jt->name(), external_name(), init_thread_name());
1221       }
1222 
1223       wait = true;
1224       jt->set_class_to_be_initialized(this);
1225       ml.wait();
1226       jt->set_class_to_be_initialized(nullptr);
1227     }

1274     DTRACE_CLASSINIT_PROBE_WAIT(erroneous, -1, wait);
1275     ResourceMark rm(THREAD);
1276     Handle cause(THREAD, get_initialization_error(THREAD));
1277 
1278     stringStream ss;
1279     ss.print("Could not initialize class %s", external_name());
1280     if (cause.is_null()) {
1281       THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1282     } else {
1283       THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1284                       ss.as_string(), cause);
1285     }
1286   }
1287 
1288   // Step 7
1289   // Next, if C is a class rather than an interface, initialize it's super class and super
1290   // interfaces.
1291   if (!is_interface()) {
1292     Klass* super_klass = super();
1293     if (super_klass != nullptr && super_klass->should_be_initialized()) {
1294       // do not bother to report touches from an untouched subclass
1295       if (RecordTraining && has_initialization_touch()) {
1296         InstanceKlass::cast(super_klass)
1297           ->record_initialization_touch("super", nullptr, nullptr, this,
1298                                         nullptr, THREAD);
1299         if (HAS_PENDING_EXCEPTION) {
1300           CLEAR_PENDING_EXCEPTION;  // could not allocate training data
1301         }
1302       }
1303       super_klass->initialize(THREAD);
1304     }
1305     // If C implements any interface that declares a non-static, concrete method,
1306     // the initialization of C triggers initialization of its super interfaces.
1307     // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1308     // having a superinterface that declares, non-static, concrete methods
1309     if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1310       // do not bother to report touches from an untouched implementer
1311       Klass* requester = has_initialization_touch() ? this : nullptr;
1312       initialize_super_interfaces(requester, THREAD);
1313     }
1314 
1315     // If any exceptions, complete abruptly, throwing the same exception as above.
1316     if (HAS_PENDING_EXCEPTION) {
1317       Handle e(THREAD, PENDING_EXCEPTION);
1318       CLEAR_PENDING_EXCEPTION;
1319       {
1320         EXCEPTION_MARK;
1321         add_initialization_error(THREAD, e);
1322         // Locks object, set state, and notify all waiting threads
1323         set_initialization_state_and_notify(initialization_error, THREAD);
1324         CLEAR_PENDING_EXCEPTION;
1325       }
1326       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1327       THROW_OOP(e());
1328     }
1329   }
1330 
1331 
1332   // Step 8

1366     {
1367       EXCEPTION_MARK;
1368       add_initialization_error(THREAD, e);
1369       set_initialization_state_and_notify(initialization_error, THREAD);
1370       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below
1371       // JVMTI has already reported the pending exception
1372       // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1373       JvmtiExport::clear_detected_exception(jt);
1374     }
1375     DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1376     if (e->is_a(vmClasses::Error_klass())) {
1377       THROW_OOP(e());
1378     } else {
1379       JavaCallArguments args(e);
1380       THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1381                 vmSymbols::throwable_void_signature(),
1382                 &args);
1383     }
1384   }
1385   DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait);

1386 
1387   CompilationPolicy::replay_training_at_init(this, THREAD);
1388 }
1389 
1390 void InstanceKlass::set_initialization_state_and_notify(ClassState state, JavaThread* current) {
1391   MonitorLocker ml(current, _init_monitor);
1392 
1393   if (state == linked && UseVtableBasedCHA && Universe::is_fully_initialized()) {
1394     DeoptimizationScope deopt_scope;
1395     {
1396       // Now mark all code that assumes the class is not linked.
1397       // Set state under the Compile_lock also.
1398       MutexLocker ml(current, Compile_lock);
1399 
1400       set_init_thread(nullptr); // reset _init_thread before changing _init_state
1401       set_init_state(state);
1402 
1403       CodeCache::mark_dependents_on(&deopt_scope, this);
1404     }
1405     // Perform the deopt handshake outside Compile_lock.
1406     deopt_scope.deoptimize_marked();
1407   } else {
1408     set_init_thread(nullptr); // reset _init_thread before changing _init_state

1627   JavaCallArguments args(h_i);
1628   methodHandle mh(THREAD, Universe::finalizer_register_method());
1629   JavaCalls::call(&result, mh, &args, CHECK_NULL);
1630   MANAGEMENT_ONLY(FinalizerService::on_register(h_i(), THREAD);)
1631   return h_i();
1632 }
1633 
1634 instanceOop InstanceKlass::allocate_instance(TRAPS) {
1635   bool has_finalizer_flag = has_finalizer(); // Query before possible GC
1636   size_t size = size_helper();  // Query before forming handle.
1637 
1638   instanceOop i;
1639 
1640   i = (instanceOop)Universe::heap()->obj_allocate(this, size, CHECK_NULL);
1641   if (has_finalizer_flag && !RegisterFinalizersAtInit) {
1642     i = register_finalizer(i, CHECK_NULL);
1643   }
1644   return i;
1645 }
1646 
1647 instanceOop InstanceKlass::allocate_instance(oop java_class,
1648                                              const char* who,
1649                                              TRAPS) {
1650   Klass* k = java_lang_Class::as_Klass(java_class);
1651   if (k == nullptr) {
1652     ResourceMark rm(THREAD);
1653     THROW_(vmSymbols::java_lang_InstantiationException(), nullptr);
1654   }
1655   InstanceKlass* ik = cast(k);
1656   ik->check_valid_for_instantiation(false, CHECK_NULL);
1657   if (RecordTraining) {
1658     ik->record_initialization_touch("new", nullptr, nullptr, nullptr, who, CHECK_NULL);
1659   }
1660   ik->initialize(CHECK_NULL);
1661   return ik->allocate_instance(THREAD);
1662 }
1663 
1664 instanceHandle InstanceKlass::allocate_instance_handle(TRAPS) {
1665   return instanceHandle(THREAD, allocate_instance(THREAD));
1666 }
1667 
1668 void InstanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) {
1669   if (is_interface() || is_abstract()) {
1670     ResourceMark rm(THREAD);
1671     THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1672               : vmSymbols::java_lang_InstantiationException(), external_name());
1673   }
1674   if (this == vmClasses::Class_klass()) {
1675     ResourceMark rm(THREAD);
1676     THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1677               : vmSymbols::java_lang_IllegalAccessException(), external_name());
1678   }
1679 }

1701 }
1702 
1703 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1704   // Need load-acquire for lock-free read
1705   ObjArrayKlass* oak = array_klasses_acquire();
1706   if (oak == nullptr) {
1707     return nullptr;
1708   } else {
1709     return oak->array_klass_or_null(n);
1710   }
1711 }
1712 
1713 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1714   return array_klass(1, THREAD);
1715 }
1716 
1717 ArrayKlass* InstanceKlass::array_klass_or_null() {
1718   return array_klass_or_null(1);
1719 }
1720 


1721 Method* InstanceKlass::class_initializer() const {
1722   Method* clinit = find_method(
1723       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1724   if (clinit != nullptr && clinit->has_valid_initializer_flags()) {
1725     return clinit;
1726   }
1727   return nullptr;
1728 }
1729 
1730 void InstanceKlass::call_class_initializer(TRAPS) {
1731   if (ReplayCompiles &&
1732       (ReplaySuppressInitializers == 1 ||
1733        (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1734     // Hide the existence of the initializer for the purpose of replaying the compile
1735     return;
1736   }
1737 
1738 #if INCLUDE_CDS
1739   // This is needed to ensure the consistency of the archived heap objects.
1740   if (has_archived_enum_objs()) {
1741     assert(is_shared(), "must be");
1742     bool initialized = CDSEnumKlass::initialize_enum_klass(this, CHECK);
1743     if (initialized) {
1744       return;
1745     }
1746   } else if (has_preinitialized_mirror() && CDSConfig::is_loading_heap()) {
1747     log_class_init(THREAD, this);
1748     return;
1749   }
1750 #endif
1751 
1752   methodHandle h_method(THREAD, class_initializer());
1753   assert(!is_initialized(), "we cannot initialize twice");
1754   int init_id = log_class_init(THREAD, this);
1755   if (h_method() != nullptr) {
1756     JavaCallArguments args; // No arguments
1757     JavaValue result(T_VOID);
1758     KlassTrainingData* tdata = nullptr;
1759     if (RecordTraining) {
1760       tdata = alloc_training_data(CHECK);
1761       if (HAS_PENDING_EXCEPTION) {
1762         CLEAR_PENDING_EXCEPTION;  // could not allocate training data
1763       }
1764     }
1765     InstanceKlass* outer = THREAD->set_class_being_initialized(this);
1766     if (tdata != nullptr) {
1767       tdata->record_initialization_start();
1768     }
1769 
1770     jlong bc_start = (CountBytecodesPerThread ? THREAD->bc_counter_value() : BytecodeCounter::counter_value());
1771 
1772     elapsedTimer timer;
1773     {
1774       PerfPauseTimer pt(THREAD->current_rt_call_timer(), THREAD->profile_rt_calls());
1775       PauseRuntimeCallProfiling prcp(THREAD, THREAD->profile_rt_calls());
1776 
1777       timer.start();
1778       JavaCalls::call(&result, h_method, &args, THREAD); // Static call (no args)
1779       timer.stop();
1780     }
1781 
1782     jlong bc_end = (CountBytecodesPerThread ? THREAD->bc_counter_value() : BytecodeCounter::counter_value());
1783 
1784     jlong bc_executed = (bc_end - bc_start);
1785     if (UsePerfData && outer == nullptr) { // outermost clinit
1786       THREAD->inc_clinit_bc_counter_value(bc_executed);
1787       ClassLoader::perf_class_init_bytecodes_count()->inc(bc_executed);
1788     }
1789 
1790     THREAD->set_class_being_initialized(outer);
1791 
1792     if (tdata != nullptr) {
1793       tdata->record_initialization_end();
1794     }
1795 
1796     LogStreamHandle(Debug, init) log;
1797     if (log.is_enabled()) {
1798       ResourceMark rm(THREAD);
1799       log.print("%d Initialized in %.3fms (total: %ldms); ",
1800                 init_id, timer.seconds() * 1000.0, ClassLoader::class_init_time_ms());
1801       if (CountBytecodes || CountBytecodesPerThread) {
1802         log.print("executed %ld bytecodes; ", bc_executed);
1803       }
1804       name()->print_value_on(&log);
1805       log.print_cr(" by thread " PTR_FORMAT " \"%s\" (" PTR_FORMAT ")",
1806                    p2i(THREAD), THREAD->name(), p2i(this));
1807     }
1808   }
1809   LogTarget(Info, class, init) lt;
1810   if (lt.is_enabled()) {
1811     ResourceMark rm(THREAD);
1812     LogStream ls(lt);
1813     ls.print("%d Initialized ", init_id);
1814     name()->print_value_on(&ls);
1815     ls.print_cr("%s (" PTR_FORMAT ")", h_method() == nullptr ? "(no method)" : "", p2i(this));


1816   }
1817 }
1818 
1819 void InstanceKlass::record_initialization_touch(const char* reason,
1820                                                 Symbol* name,
1821                                                 Symbol* sig,
1822                                                 Klass* requesting_klass,
1823                                                 const char* context,
1824                                                 TRAPS) {
1825   if (requesting_klass == this) {
1826     return;  // self-initialization is never interesting
1827   }
1828   if (is_initialized() && !has_initialization_touch()) {
1829     // initialized by some hardwired JVM logic; not interesting
1830     return;
1831   }
1832   KlassTrainingData* tdata = alloc_training_data(CHECK);
1833   if (tdata == nullptr)  return;
1834   tdata->record_initialization_touch(reason, name, sig,
1835                                      requesting_klass, context, THREAD);
1836 }
1837 
1838 
1839 bool InstanceKlass::has_initialization_touch() const {
1840   KlassTrainingData* tdata = training_data_or_null();
1841   if (tdata == nullptr)  return false;
1842   return tdata->has_initialization_touch();
1843 }
1844 
1845 KlassTrainingData* InstanceKlass::alloc_training_data(TRAPS) {
1846   guarantee(RecordTraining || ReplayTraining, "caller resp.");
1847   KlassTrainingData* tdata = training_data_or_null();
1848   if (tdata == nullptr) {
1849     tdata = KlassTrainingData::make(this);
1850     assert(tdata == training_data_or_null(), "");
1851   }
1852   return tdata;
1853 }
1854 
1855 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1856   InterpreterOopMap* entry_for) {
1857   // Lazily create the _oop_map_cache at first request
1858   // Lock-free access requires load_acquire.
1859   OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1860   if (oop_map_cache == nullptr) {
1861     MutexLocker x(OopMapCacheAlloc_lock);
1862     // Check if _oop_map_cache was allocated while we were waiting for this lock
1863     if ((oop_map_cache = _oop_map_cache) == nullptr) {
1864       oop_map_cache = new OopMapCache();
1865       // Ensure _oop_map_cache is stable, since it is examined without a lock
1866       Atomic::release_store(&_oop_map_cache, oop_map_cache);
1867     }
1868   }
1869   // _oop_map_cache is constant after init; lookup below does its own locking.
1870   oop_map_cache->lookup(method, bci, entry_for);
1871 }
1872 
1873 bool InstanceKlass::contains_field_offset(int offset) {
1874   fieldDescriptor fd;

2678 
2679 // Lookup a jmethodID, null if not found.  Do no blocking, no allocations, no handles
2680 jmethodID InstanceKlass::jmethod_id_or_null(Method* method) {
2681   size_t idnum = (size_t)method->method_idnum();
2682   jmethodID* jmeths = methods_jmethod_ids_acquire();
2683   size_t length;                                // length assigned as debugging crumb
2684   jmethodID id = nullptr;
2685   if (jmeths != nullptr &&                      // If there is a cache
2686       (length = (size_t)jmeths[0]) > idnum) {   // and if it is long enough,
2687     id = jmeths[idnum+1];                       // Look up the id (may be null)
2688   }
2689   return id;
2690 }
2691 
2692 inline DependencyContext InstanceKlass::dependencies() {
2693   DependencyContext dep_context(&_dep_context, &_dep_context_last_cleaned);
2694   return dep_context;
2695 }
2696 
2697 void InstanceKlass::mark_dependent_nmethods(DeoptimizationScope* deopt_scope, KlassDepChange& changes) {
2698   dependencies().mark_dependent_nmethods(deopt_scope, changes, this);
2699 }
2700 
2701 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
2702   dependencies().add_dependent_nmethod(nm);
2703 }
2704 
2705 void InstanceKlass::clean_dependency_context() {
2706   dependencies().clean_unloading_dependents();
2707 }
2708 
2709 #ifndef PRODUCT
2710 void InstanceKlass::print_dependent_nmethods(bool verbose) {
2711   dependencies().print_dependent_nmethods(verbose);
2712 }
2713 
2714 bool InstanceKlass::is_dependent_nmethod(nmethod* nm) {
2715   return dependencies().is_dependent_nmethod(nm);
2716 }
2717 #endif //PRODUCT
2718 

2807   if (itable_length() > 0) {
2808     itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable();
2809     int method_table_offset_in_words = ioe->offset()/wordSize;
2810     int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2811 
2812     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2813                          / itableOffsetEntry::size();
2814 
2815     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2816       if (ioe->interface_klass() != nullptr) {
2817         it->push(ioe->interface_klass_addr());
2818         itableMethodEntry* ime = ioe->first_method_entry(this);
2819         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2820         for (int index = 0; index < n; index ++) {
2821           it->push(ime[index].method_addr());
2822         }
2823       }
2824     }
2825   }
2826 
2827   it->push(&_nest_host);
2828   it->push(&_nest_members);
2829   it->push(&_permitted_subclasses);
2830   it->push(&_record_components);
2831 }
2832 
2833 #if INCLUDE_CDS
2834 void InstanceKlass::remove_unshareable_info() {
2835 
2836   if (is_linked()) {
2837     assert(can_be_verified_at_dumptime(), "must be");
2838     // Remember this so we can avoid walking the hierarchy at runtime.
2839     set_verified_at_dump_time();
2840   }
2841 
2842   Klass::remove_unshareable_info();
2843 
2844   if (SystemDictionaryShared::has_class_failed_verification(this)) {
2845     // Classes are attempted to link during dumping and may fail,
2846     // but these classes are still in the dictionary and class list in CLD.
2847     // If the class has failed verification, there is nothing else to remove.
2848     return;
2849   }
2850 
2851   // Reset to the 'allocated' state to prevent any premature accessing to
2852   // a shared class at runtime while the class is still being loaded and
2853   // restored. A class' init_state is set to 'loaded' at runtime when it's
2854   // being added to class hierarchy (see InstanceKlass:::add_to_hierarchy()).
2855   _init_state = allocated;
2856 
2857   { // Otherwise this needs to take out the Compile_lock.
2858     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2859     init_implementor();
2860   }
2861 
2862   // ConstantPool is cleaned separately. See ArchiveBuilder::make_klasses_shareable()
2863   // constants()->remove_unshareable_info();
2864 
2865   for (int i = 0; i < methods()->length(); i++) {
2866     Method* m = methods()->at(i);
2867     m->remove_unshareable_info();
2868   }
2869 
2870   // do array classes also.
2871   if (array_klasses() != nullptr) {
2872     array_klasses()->remove_unshareable_info();
2873   }
2874 
2875   // These are not allocated from metaspace. They are safe to set to null.
2876   _source_debug_extension = nullptr;
2877   _dep_context = nullptr;
2878   _osr_nmethods_head = nullptr;
2879 #if INCLUDE_JVMTI
2880   _breakpoints = nullptr;
2881   _previous_versions = nullptr;
2882   _cached_class_file = nullptr;
2883   _jvmti_cached_class_field_map = nullptr;
2884 #endif
2885 
2886   _init_thread = nullptr;
2887   _methods_jmethod_ids = nullptr;
2888   _jni_ids = nullptr;
2889   _oop_map_cache = nullptr;
2890   if (ArchiveInvokeDynamic && HeapShared::is_lambda_proxy_klass(this)) {
2891     // keep _nest_host
2892   } else {
2893     // clear _nest_host to ensure re-load at runtime
2894     _nest_host = nullptr;
2895   }
2896   init_shared_package_entry();
2897   _dep_context_last_cleaned = 0;
2898   _init_monitor = nullptr;
2899   DEBUG_ONLY(_shared_class_load_count = 0);
2900 
2901   _training_data = nullptr;
2902   remove_unshareable_flags();
2903 }
2904 
2905 void InstanceKlass::remove_unshareable_flags() {
2906   // clear all the flags/stats that shouldn't be in the archived version
2907   assert(!is_scratch_class(), "must be");
2908   assert(!has_been_redefined(), "must be");
2909 #if INCLUDE_JVMTI
2910   set_is_being_redefined(false);
2911 #endif
2912   set_has_resolved_methods(false);
2913 }
2914 
2915 void InstanceKlass::remove_java_mirror() {
2916   Klass::remove_java_mirror();
2917 
2918   // do array classes also.
2919   if (array_klasses() != nullptr) {
2920     array_klasses()->remove_java_mirror();
2921   }

2987   // restore constant pool resolved references
2988   constants()->restore_unshareable_info(CHECK);
2989 
2990   if (array_klasses() != nullptr) {
2991     // To get a consistent list of classes we need MultiArray_lock to ensure
2992     // array classes aren't observed while they are being restored.
2993     MutexLocker ml(MultiArray_lock);
2994     assert(this == array_klasses()->bottom_klass(), "sanity");
2995     // Array classes have null protection domain.
2996     // --> see ArrayKlass::complete_create_array_klass()
2997     array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2998   }
2999 
3000   // Initialize @ValueBased class annotation
3001   if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation()) {
3002     set_is_value_based();
3003   }
3004 
3005   // restore the monitor
3006   _init_monitor = create_init_monitor("InstanceKlassInitMonitorRestored_lock");
3007 
3008   if (_training_data != nullptr) {
3009     _training_data->restore_unshareable_info(CHECK);
3010   }
3011 }
3012 





3013 bool InstanceKlass::can_be_verified_at_dumptime() const {
3014   if (CDSConfig::preserve_all_dumptime_verification_states(this)) {
3015     return true;
3016   }
3017 
3018   if (MetaspaceShared::is_in_shared_metaspace(this)) {
3019     // This is a class that was dumped into the base archive, so we know
3020     // it was verified at dump time.
3021     return true;
3022   }
3023 
3024   if (ArchiveInvokeDynamic) {
3025     // FIXME: this works around JDK-8315719
3026     return true;
3027   }
3028 
3029   // Check if a class or any of its supertypes has a version older than 50.
3030   // CDS will not perform verification of old classes during dump time because
3031   // without changing the old verifier, the verification constraint cannot be
3032   // retrieved during dump time.
3033   // Verification of archived old classes will be performed during run time.
3034   if (major_version() < 50 /*JAVA_6_VERSION*/) {
3035     return false;
3036   }
3037   if (java_super() != nullptr && !java_super()->can_be_verified_at_dumptime()) {
3038     return false;
3039   }
3040   Array<InstanceKlass*>* interfaces = local_interfaces();
3041   int len = interfaces->length();
3042   for (int i = 0; i < len; i++) {
3043     if (!interfaces->at(i)->can_be_verified_at_dumptime()) {
3044       return false;
3045     }
3046   }
3047   return true;
3048 }
3049 
3050 bool InstanceKlass::methods_contain_jsr_bytecode() const {
3051   Thread* thread = Thread::current();
3052   for (int i = 0; i < _methods->length(); i++) {
3053     methodHandle m(thread, _methods->at(i));
3054     BytecodeStream bcs(m);
3055     while (!bcs.is_last_bytecode()) {
3056       Bytecodes::Code opcode = bcs.next();
3057       if (opcode == Bytecodes::_jsr || opcode == Bytecodes::_jsr_w) {
3058         return true;
3059       }
3060     }
3061   }
3062   return false;
3063 }
3064 
3065 int InstanceKlass::shared_class_loader_type() const {
3066   if (is_shared_boot_class()) {
3067     return ClassLoader::BOOT_LOADER;
3068   } else if (is_shared_platform_class()) {
3069     return ClassLoader::PLATFORM_LOADER;
3070   } else if (is_shared_app_class()) {
3071     return ClassLoader::APP_LOADER;
3072   } else {
3073     return ClassLoader::OTHER;
3074   }
3075 }
3076 #endif // INCLUDE_CDS
3077 
3078 #if INCLUDE_JVMTI
3079 static void clear_all_breakpoints(Method* m) {
3080   m->clear_all_breakpoints();
3081 }
3082 #endif
3083 
3084 void InstanceKlass::unload_class(InstanceKlass* ik) {
3085   // Release dependencies.
3086   ik->dependencies().remove_all_dependents();
3087 
3088   // notify the debugger
3089   if (JvmtiExport::should_post_class_unload()) {
3090     JvmtiExport::post_class_unload(ik);
3091   }
3092 
3093   // notify ClassLoadingService of class unload
3094   ClassLoadingService::notify_class_unloaded(ik);
3095 

3825 static void print_vtable(intptr_t* start, int len, outputStream* st) {
3826   for (int i = 0; i < len; i++) {
3827     intptr_t e = start[i];
3828     st->print("%d : " INTPTR_FORMAT, i, e);
3829     if (MetaspaceObj::is_valid((Metadata*)e)) {
3830       st->print(" ");
3831       ((Metadata*)e)->print_value_on(st);
3832     }
3833     st->cr();
3834   }
3835 }
3836 
3837 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3838   return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
3839 }
3840 
3841 const char* InstanceKlass::init_state_name() const {
3842   return state_names[init_state()];
3843 }
3844 
3845 const char* InstanceKlass::state2name(ClassState s) {
3846   return state_names[s];
3847 }
3848 
3849 void InstanceKlass::print_on(outputStream* st) const {
3850   assert(is_klass(), "must be klass");
3851   Klass::print_on(st);
3852 
3853   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
3854   st->print(BULLET"klass size:        %d", size());                               st->cr();
3855   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
3856   st->print(BULLET"flags:             "); _misc_flags.print_on(st);               st->cr();
3857   st->print(BULLET"state:             "); st->print_cr("%s", init_state_name());
3858   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
3859   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3860   st->print(BULLET"sub:               ");
3861   Klass* sub = subklass();
3862   int n;
3863   for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3864     if (n < MaxSubklassPrintSize) {
3865       sub->print_value_on(st);
3866       st->print("   ");
3867     }
3868   }

4147         nullptr;
4148       // caller can be null, for example, during a JVMTI VM_Init hook
4149       if (caller != nullptr) {
4150         info_stream.print(" source: instance of %s", caller->external_name());
4151       } else {
4152         // source is unknown
4153       }
4154     } else {
4155       oop class_loader = loader_data->class_loader();
4156       info_stream.print(" source: %s", class_loader->klass()->external_name());
4157     }
4158   } else {
4159     assert(this->is_shared(), "must be");
4160     if (MetaspaceShared::is_shared_dynamic((void*)this)) {
4161       info_stream.print(" source: shared objects file (top)");
4162     } else {
4163       info_stream.print(" source: shared objects file");
4164     }
4165   }
4166 
4167   info_stream.print(" loader:");
4168   if (is_shared()) {
4169     info_stream.print(" %s", SystemDictionaryShared::class_loader_name_for_shared((Klass*)this));
4170   } else if (loader_data == ClassLoaderData::the_null_class_loader_data()) {
4171     info_stream.print(" boot_loader");
4172   } else {
4173     oop class_loader = loader_data->class_loader();
4174     if (class_loader != nullptr) {
4175       info_stream.print(" %s", class_loader->klass()->external_name());
4176       oop cl_name_and_id = java_lang_ClassLoader::nameAndId(class_loader);
4177       if (cl_name_and_id != nullptr) {
4178         info_stream.print(" %s", java_lang_String::as_utf8_string(cl_name_and_id));
4179       }
4180     } else {
4181       info_stream.print(" null");
4182     }
4183   }
4184   msg.info("%s", info_stream.as_string());
4185 
4186   if (log_is_enabled(Debug, class, load)) {
4187     stringStream debug_stream;
4188 
4189     // Class hierarchy info
4190     debug_stream.print(" klass: " PTR_FORMAT " super: " PTR_FORMAT,
4191                        p2i(this),  p2i(superklass()));
4192 
4193     // Interfaces
4194     if (local_interfaces() != nullptr && local_interfaces()->length() > 0) {
4195       debug_stream.print(" interfaces:");
4196       int length = local_interfaces()->length();
4197       for (int i = 0; i < length; i++) {
4198         debug_stream.print(" " PTR_FORMAT,
4199                            p2i(InstanceKlass::cast(local_interfaces()->at(i))));
4200       }
4201     }
4202 
4203     // Class loader
< prev index next >