< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page

   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   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 "cds/aotClassInitializer.hpp"

  26 #include "cds/aotMetaspace.hpp"
  27 #include "cds/archiveUtils.hpp"
  28 #include "cds/cdsConfig.hpp"
  29 #include "cds/cdsEnumKlass.hpp"
  30 #include "cds/classListWriter.hpp"
  31 #include "cds/heapShared.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/bytecodeStream.hpp"
  49 #include "interpreter/oopMapCache.hpp"
  50 #include "interpreter/rewriter.hpp"
  51 #include "jvm.h"
  52 #include "jvmtifiles/jvmti.h"
  53 #include "klass.inline.hpp"
  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/constantPool.hpp"
  65 #include "oops/fieldStreams.inline.hpp"
  66 #include "oops/instanceClassLoaderKlass.hpp"
  67 #include "oops/instanceKlass.inline.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 "prims/jvmtiExport.hpp"
  77 #include "prims/jvmtiRedefineClasses.hpp"
  78 #include "prims/jvmtiThreadState.hpp"
  79 #include "prims/methodComparator.hpp"
  80 #include "runtime/arguments.hpp"
  81 #include "runtime/atomicAccess.hpp"
  82 #include "runtime/deoptimization.hpp"
  83 #include "runtime/fieldDescriptor.inline.hpp"
  84 #include "runtime/handles.inline.hpp"
  85 #include "runtime/javaCalls.hpp"
  86 #include "runtime/javaThread.inline.hpp"
  87 #include "runtime/mutexLocker.hpp"
  88 #include "runtime/orderAccess.hpp"
  89 #include "runtime/os.inline.hpp"
  90 #include "runtime/reflection.hpp"

  91 #include "runtime/synchronizer.hpp"
  92 #include "runtime/threads.hpp"
  93 #include "services/classLoadingService.hpp"
  94 #include "services/finalizerService.hpp"
  95 #include "services/threadService.hpp"
  96 #include "utilities/dtrace.hpp"
  97 #include "utilities/events.hpp"
  98 #include "utilities/macros.hpp"
  99 #include "utilities/nativeStackPrinter.hpp"
 100 #include "utilities/stringUtils.hpp"
 101 #ifdef COMPILER1
 102 #include "c1/c1_Compiler.hpp"
 103 #endif
 104 #if INCLUDE_JFR
 105 #include "jfr/jfrEvents.hpp"
 106 #endif
 107 
 108 #ifdef DTRACE_ENABLED
 109 
 110 

 133   {                                                              \
 134     char* data = nullptr;                                        \
 135     int len = 0;                                                 \
 136     Symbol* clss_name = name();                                  \
 137     if (clss_name != nullptr) {                                  \
 138       data = (char*)clss_name->bytes();                          \
 139       len = clss_name->utf8_length();                            \
 140     }                                                            \
 141     HOTSPOT_CLASS_INITIALIZATION_##type(                         \
 142       data, len, (void*)class_loader(), thread_type, wait);      \
 143   }
 144 
 145 #else //  ndef DTRACE_ENABLED
 146 
 147 #define DTRACE_CLASSINIT_PROBE(type, thread_type)
 148 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait)
 149 
 150 #endif //  ndef DTRACE_ENABLED
 151 
 152 bool InstanceKlass::_finalization_enabled = true;

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

 867   }
 868 
 869   Array<InstanceKlass*>* interfaces = local_interfaces();
 870   int len = interfaces->length();
 871   for (int i = 0; i < len; i++) {
 872     InstanceKlass* intf = interfaces->at(i);
 873     if (!intf->is_initialized()) {
 874       ResourceMark rm;
 875       // Note: an interface needs to be marked as is_initialized() only if
 876       // - it has a <clinit>
 877       // - it has declared a default method.
 878       assert(!intf->interface_needs_clinit_execution_as_super(/*also_check_supers*/false),
 879              "uninitialized super interface %s of aot-inited class %s must not have <clinit>",
 880              intf->external_name(), external_name());
 881     }
 882   }
 883 }
 884 #endif
 885 
 886 #if INCLUDE_CDS
 887 void InstanceKlass::initialize_with_aot_initialized_mirror(TRAPS) {


 888   assert(has_aot_initialized_mirror(), "must be");
 889   assert(CDSConfig::is_loading_heap(), "must be");
 890   assert(CDSConfig::is_using_aot_linked_classes(), "must be");
 891   assert_no_clinit_will_run_for_aot_initialized_class();
 892 
 893   if (is_initialized()) {
 894     return;
 895   }
 896 





 897   if (is_runtime_setup_required()) {

 898     // Need to take the slow path, which will call the runtimeSetup() function instead
 899     // of <clinit>
 900     initialize(CHECK);
 901     return;
 902   }
 903   if (log_is_enabled(Info, aot, init)) {
 904     ResourceMark rm;
 905     log_info(aot, init)("%s (aot-inited)", external_name());















 906   }
 907 
 908   link_class(CHECK);
 909 
 910 #ifdef ASSERT
 911   {
 912     Handle h_init_lock(THREAD, init_lock());
 913     ObjectLocker ol(h_init_lock, THREAD);
 914     assert(!is_initialized(), "sanity");
 915     assert(!is_being_initialized(), "sanity");
 916     assert(!is_in_error_state(), "sanity");
 917   }
 918 #endif
 919 
 920   set_init_thread(THREAD);
 921   set_initialization_state_and_notify(fully_initialized, CHECK);
 922 }
 923 #endif
 924 
 925 bool InstanceKlass::verify_code(TRAPS) {

1101   return true;
1102 }
1103 
1104 // Rewrite the byte codes of all of the methods of a class.
1105 // The rewriter must be called exactly once. Rewriting must happen after
1106 // verification but before the first method of the class is executed.
1107 void InstanceKlass::rewrite_class(TRAPS) {
1108   assert(is_loaded(), "must be loaded");
1109   if (is_rewritten()) {
1110     assert(in_aot_cache(), "rewriting an unshared class?");
1111     return;
1112   }
1113   Rewriter::rewrite(this, CHECK);
1114   set_rewritten();
1115 }
1116 
1117 // Now relocate and link method entry points after class is rewritten.
1118 // This is outside is_rewritten flag. In case of an exception, it can be
1119 // executed more than once.
1120 void InstanceKlass::link_methods(TRAPS) {
1121   PerfTraceTime timer(ClassLoader::perf_ik_link_methods_time());
1122 
1123   int len = methods()->length();
1124   for (int i = len-1; i >= 0; i--) {
1125     methodHandle m(THREAD, methods()->at(i));

1126 
1127     // Set up method entry points for compiler and interpreter    .
1128     m->link_method(m, CHECK);
1129   }
1130 }
1131 
1132 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
1133 void InstanceKlass::initialize_super_interfaces(TRAPS) {
1134   assert (has_nonstatic_concrete_methods(), "caller should have checked this");
1135   for (int i = 0; i < local_interfaces()->length(); ++i) {
1136     InstanceKlass* ik = local_interfaces()->at(i);
1137 
1138     // Initialization is depth first search ie. we start with top of the inheritance tree
1139     // has_nonstatic_concrete_methods drives searching superinterfaces since it
1140     // means has_nonstatic_concrete_methods in its superinterface hierarchy
1141     if (ik->has_nonstatic_concrete_methods()) {
1142       ik->initialize_super_interfaces(CHECK);
1143     }
1144 
1145     // Only initialize() interfaces that "declare" concrete methods.

1221     _thread->set_class_to_be_initialized(ik);
1222   }
1223   ~ThreadWaitingForClassInit() {
1224     _thread->set_class_to_be_initialized(nullptr);
1225   }
1226 };
1227 
1228 void InstanceKlass::initialize_impl(TRAPS) {
1229   HandleMark hm(THREAD);
1230 
1231   // Make sure klass is linked (verified) before initialization
1232   // A class could already be verified, since it has been reflected upon.
1233   link_class(CHECK);
1234 
1235   DTRACE_CLASSINIT_PROBE(required, -1);
1236 
1237   bool wait = false;
1238 
1239   JavaThread* jt = THREAD;
1240 















1241   bool debug_logging_enabled = log_is_enabled(Debug, class, init);
1242 
1243   // refer to the JVM book page 47 for description of steps
1244   // Step 1
1245   {
1246     Handle h_init_lock(THREAD, init_lock());
1247     ObjectLocker ol(h_init_lock, CHECK_PREEMPTABLE);
1248 
1249     // Step 2
1250     // If we were to use wait() instead of waitInterruptibly() then
1251     // we might end up throwing IE from link/symbol resolution sites
1252     // that aren't expected to throw.  This would wreak havoc.  See 6320309.
1253     while (is_being_initialized() && !is_reentrant_initialization(jt)) {
1254       if (debug_logging_enabled) {
1255         ResourceMark rm(jt);
1256         log_debug(class, init)("Thread \"%s\" waiting for initialization of %s by thread \"%s\"",
1257                                jt->name(), external_name(), init_thread_name());
1258       }
1259       wait = true;
1260       ThreadWaitingForClassInit twcl(THREAD, this);

1614     tty->print("Registered ");
1615     i->print_value_on(tty);
1616     tty->print_cr(" (" PTR_FORMAT ") as finalizable", p2i(i));
1617   }
1618   instanceHandle h_i(THREAD, i);
1619   // Pass the handle as argument, JavaCalls::call expects oop as jobjects
1620   JavaValue result(T_VOID);
1621   JavaCallArguments args(h_i);
1622   methodHandle mh(THREAD, Universe::finalizer_register_method());
1623   JavaCalls::call(&result, mh, &args, CHECK_NULL);
1624   MANAGEMENT_ONLY(FinalizerService::on_register(h_i(), THREAD);)
1625   return h_i();
1626 }
1627 
1628 instanceOop InstanceKlass::allocate_instance(TRAPS) {
1629   assert(!is_abstract() && !is_interface(), "Should not create this object");
1630   size_t size = size_helper();  // Query before forming handle.
1631   return (instanceOop)Universe::heap()->obj_allocate(this, size, CHECK_NULL);
1632 }
1633 
1634 instanceOop InstanceKlass::allocate_instance(oop java_class, TRAPS) {


1635   Klass* k = java_lang_Class::as_Klass(java_class);
1636   if (k == nullptr) {
1637     ResourceMark rm(THREAD);
1638     THROW_(vmSymbols::java_lang_InstantiationException(), nullptr);
1639   }
1640   InstanceKlass* ik = cast(k);
1641   ik->check_valid_for_instantiation(false, CHECK_NULL);
1642   ik->initialize(CHECK_NULL);
1643   return ik->allocate_instance(THREAD);
1644 }
1645 
1646 instanceHandle InstanceKlass::allocate_instance_handle(TRAPS) {
1647   return instanceHandle(THREAD, allocate_instance(THREAD));
1648 }
1649 
1650 void InstanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) {
1651   if (is_interface() || is_abstract()) {
1652     ResourceMark rm(THREAD);
1653     THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1654               : vmSymbols::java_lang_InstantiationException(), external_name());

1682 }
1683 
1684 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1685   // Need load-acquire for lock-free read
1686   ObjArrayKlass* oak = array_klasses_acquire();
1687   if (oak == nullptr) {
1688     return nullptr;
1689   } else {
1690     return oak->array_klass_or_null(n);
1691   }
1692 }
1693 
1694 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1695   return array_klass(1, THREAD);
1696 }
1697 
1698 ArrayKlass* InstanceKlass::array_klass_or_null() {
1699   return array_klass_or_null(1);
1700 }
1701 
1702 static int call_class_initializer_counter = 0;   // for debugging
1703 
1704 Method* InstanceKlass::class_initializer() const {
1705   Method* clinit = find_method(
1706       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1707   if (clinit != nullptr && clinit->has_valid_initializer_flags()) {
1708     return clinit;
1709   }
1710   return nullptr;
1711 }
1712 
1713 void InstanceKlass::call_class_initializer(TRAPS) {
1714   if (ReplayCompiles &&
1715       (ReplaySuppressInitializers == 1 ||
1716        (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1717     // Hide the existence of the initializer for the purpose of replaying the compile
1718     return;
1719   }
1720 
1721 #if INCLUDE_CDS
1722   // This is needed to ensure the consistency of the archived heap objects.
1723   if (has_aot_initialized_mirror() && CDSConfig::is_loading_heap()) {
1724     AOTClassInitializer::call_runtime_setup(THREAD, this);
1725     return;
1726   } else if (has_archived_enum_objs()) {
1727     assert(in_aot_cache(), "must be");
1728     bool initialized = CDSEnumKlass::initialize_enum_klass(this, CHECK);
1729     if (initialized) {
1730       return;
1731     }
1732   }
1733 #endif
1734 
1735   methodHandle h_method(THREAD, class_initializer());
1736   assert(!is_initialized(), "we cannot initialize twice");






















































1737   LogTarget(Info, class, init) lt;
1738   if (lt.is_enabled()) {
1739     ResourceMark rm(THREAD);
1740     LogStream ls(lt);
1741     ls.print("%d Initializing ", call_class_initializer_counter++);
1742     name()->print_value_on(&ls);
1743     ls.print_cr("%s (" PTR_FORMAT ") by thread \"%s\"",
1744                 h_method() == nullptr ? "(no method)" : "", p2i(this),
1745                 THREAD->name());
1746   }
1747   if (h_method() != nullptr) {
1748     ThreadInClassInitializer ticl(THREAD, this); // Track class being initialized
1749     JavaCallArguments args; // No arguments
1750     JavaValue result(T_VOID);
1751     JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1752   }

1753 }
1754 
1755 // If a class that implements this interface is initialized, is the JVM required
1756 // to first execute a <clinit> method declared in this interface,
1757 // or (if also_check_supers==true) any of the super types of this interface?
1758 //
1759 // JVMS 5.5. Initialization, step 7: Next, if C is a class rather than
1760 // an interface, then let SC be its superclass and let SI1, ..., SIn
1761 // be all superinterfaces of C (whether direct or indirect) that
1762 // declare at least one non-abstract, non-static method.
1763 //
1764 // So when an interface is initialized, it does not look at its
1765 // supers. But a proper class will ensure that all of its supers have
1766 // run their <clinit> methods, except that it disregards interfaces
1767 // that lack a non-static concrete method (i.e., a default method).
1768 // Therefore, you should probably call this method only when the
1769 // current class is a super of some proper class, not an interface.
1770 bool InstanceKlass::interface_needs_clinit_execution_as_super(bool also_check_supers) const {
1771   assert(is_interface(), "must be");
1772 

2541         id == nullptr) {
2542       id = Method::make_jmethod_id(class_loader_data(), m);
2543       AtomicAccess::release_store(&jmeths[idnum + 1], id);
2544     }
2545   }
2546 }
2547 
2548 // Lookup a jmethodID, null if not found.  Do no blocking, no allocations, no handles
2549 jmethodID InstanceKlass::jmethod_id_or_null(Method* method) {
2550   int idnum = method->method_idnum();
2551   jmethodID* jmeths = methods_jmethod_ids_acquire();
2552   return (jmeths != nullptr) ? jmeths[idnum + 1] : nullptr;
2553 }
2554 
2555 inline DependencyContext InstanceKlass::dependencies() {
2556   DependencyContext dep_context(&_dep_context, &_dep_context_last_cleaned);
2557   return dep_context;
2558 }
2559 
2560 void InstanceKlass::mark_dependent_nmethods(DeoptimizationScope* deopt_scope, KlassDepChange& changes) {
2561   dependencies().mark_dependent_nmethods(deopt_scope, changes);
2562 }
2563 
2564 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
2565   assert_lock_strong(CodeCache_lock);
2566   dependencies().add_dependent_nmethod(nm);
2567 }
2568 
2569 void InstanceKlass::clean_dependency_context() {
2570   dependencies().clean_unloading_dependents();
2571 }
2572 
2573 #ifndef PRODUCT
2574 void InstanceKlass::print_dependent_nmethods(bool verbose) {
2575   dependencies().print_dependent_nmethods(verbose);
2576 }
2577 
2578 bool InstanceKlass::is_dependent_nmethod(nmethod* nm) {
2579   return dependencies().is_dependent_nmethod(nm);
2580 }
2581 #endif //PRODUCT

3657 static void print_vtable(intptr_t* start, int len, outputStream* st) {
3658   for (int i = 0; i < len; i++) {
3659     intptr_t e = start[i];
3660     st->print("%d : " INTPTR_FORMAT, i, e);
3661     if (MetaspaceObj::is_valid((Metadata*)e)) {
3662       st->print(" ");
3663       ((Metadata*)e)->print_value_on(st);
3664     }
3665     st->cr();
3666   }
3667 }
3668 
3669 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3670   return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
3671 }
3672 
3673 const char* InstanceKlass::init_state_name() const {
3674   return state_names[init_state()];
3675 }
3676 




3677 void InstanceKlass::print_on(outputStream* st) const {
3678   assert(is_klass(), "must be klass");
3679   Klass::print_on(st);
3680 
3681   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
3682   st->print(BULLET"klass size:        %d", size());                               st->cr();
3683   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
3684   st->print(BULLET"flags:             "); _misc_flags.print_on(st);               st->cr();
3685   st->print(BULLET"state:             "); st->print_cr("%s", init_state_name());
3686   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
3687   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3688   st->print(BULLET"sub:               ");
3689   Klass* sub = subklass();
3690   int n;
3691   for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3692     if (n < MaxSubklassPrintSize) {
3693       sub->print_value_on(st);
3694       st->print("   ");
3695     }
3696   }

3991         nullptr;
3992       // caller can be null, for example, during a JVMTI VM_Init hook
3993       if (caller != nullptr) {
3994         info_stream.print(" source: instance of %s", caller->external_name());
3995       } else {
3996         // source is unknown
3997       }
3998     } else {
3999       oop class_loader = loader_data->class_loader();
4000       info_stream.print(" source: %s", class_loader->klass()->external_name());
4001     }
4002   } else {
4003     assert(this->in_aot_cache(), "must be");
4004     if (AOTMetaspace::in_aot_cache_dynamic_region((void*)this)) {
4005       info_stream.print(" source: shared objects file (top)");
4006     } else {
4007       info_stream.print(" source: shared objects file");
4008     }
4009   }
4010 




















4011   msg.info("%s", info_stream.as_string());
4012 
4013   if (log_is_enabled(Debug, class, load)) {
4014     stringStream debug_stream;
4015 
4016     // Class hierarchy info
4017     debug_stream.print(" klass: " PTR_FORMAT " super: " PTR_FORMAT,
4018                        p2i(this),  p2i(super()));
4019 
4020     // Interfaces
4021     if (local_interfaces() != nullptr && local_interfaces()->length() > 0) {
4022       debug_stream.print(" interfaces:");
4023       int length = local_interfaces()->length();
4024       for (int i = 0; i < length; i++) {
4025         debug_stream.print(" " PTR_FORMAT,
4026                            p2i(local_interfaces()->at(i)));
4027       }
4028     }
4029 
4030     // Class loader

   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   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 "cds/aotClassInitializer.hpp"
  26 #include "cds/aotLinkedClassBulkLoader.hpp"
  27 #include "cds/aotMetaspace.hpp"
  28 #include "cds/archiveUtils.hpp"
  29 #include "cds/cdsConfig.hpp"
  30 #include "cds/cdsEnumKlass.hpp"
  31 #include "cds/classListWriter.hpp"
  32 #include "cds/heapShared.hpp"
  33 #include "classfile/classFileParser.hpp"
  34 #include "classfile/classFileStream.hpp"
  35 #include "classfile/classLoader.hpp"
  36 #include "classfile/classLoaderData.inline.hpp"
  37 #include "classfile/javaClasses.hpp"
  38 #include "classfile/moduleEntry.hpp"
  39 #include "classfile/systemDictionary.hpp"
  40 #include "classfile/systemDictionaryShared.hpp"
  41 #include "classfile/verifier.hpp"
  42 #include "classfile/vmClasses.hpp"
  43 #include "classfile/vmSymbols.hpp"
  44 #include "code/codeCache.hpp"
  45 #include "code/dependencyContext.hpp"
  46 #include "compiler/compilationPolicy.hpp"
  47 #include "compiler/compileBroker.hpp"
  48 #include "gc/shared/collectedHeap.inline.hpp"
  49 #include "interpreter/bytecodeHistogram.hpp"
  50 #include "interpreter/bytecodeStream.hpp"
  51 #include "interpreter/oopMapCache.hpp"
  52 #include "interpreter/rewriter.hpp"
  53 #include "jvm.h"
  54 #include "jvmtifiles/jvmti.h"
  55 #include "klass.inline.hpp"
  56 #include "logging/log.hpp"
  57 #include "logging/logMessage.hpp"
  58 #include "logging/logStream.hpp"
  59 #include "memory/allocation.inline.hpp"
  60 #include "memory/iterator.inline.hpp"
  61 #include "memory/metadataFactory.hpp"
  62 #include "memory/metaspaceClosure.hpp"
  63 #include "memory/oopFactory.hpp"
  64 #include "memory/resourceArea.hpp"
  65 #include "memory/universe.hpp"
  66 #include "oops/constantPool.hpp"
  67 #include "oops/fieldStreams.inline.hpp"
  68 #include "oops/instanceClassLoaderKlass.hpp"
  69 #include "oops/instanceKlass.inline.hpp"

  73 #include "oops/klass.inline.hpp"
  74 #include "oops/method.hpp"
  75 #include "oops/oop.inline.hpp"
  76 #include "oops/recordComponent.hpp"
  77 #include "oops/symbol.hpp"
  78 #include "prims/jvmtiExport.hpp"
  79 #include "prims/jvmtiRedefineClasses.hpp"
  80 #include "prims/jvmtiThreadState.hpp"
  81 #include "prims/methodComparator.hpp"
  82 #include "runtime/arguments.hpp"
  83 #include "runtime/atomicAccess.hpp"
  84 #include "runtime/deoptimization.hpp"
  85 #include "runtime/fieldDescriptor.inline.hpp"
  86 #include "runtime/handles.inline.hpp"
  87 #include "runtime/javaCalls.hpp"
  88 #include "runtime/javaThread.inline.hpp"
  89 #include "runtime/mutexLocker.hpp"
  90 #include "runtime/orderAccess.hpp"
  91 #include "runtime/os.inline.hpp"
  92 #include "runtime/reflection.hpp"
  93 #include "runtime/runtimeUpcalls.hpp"
  94 #include "runtime/synchronizer.hpp"
  95 #include "runtime/threads.hpp"
  96 #include "services/classLoadingService.hpp"
  97 #include "services/finalizerService.hpp"
  98 #include "services/threadService.hpp"
  99 #include "utilities/dtrace.hpp"
 100 #include "utilities/events.hpp"
 101 #include "utilities/macros.hpp"
 102 #include "utilities/nativeStackPrinter.hpp"
 103 #include "utilities/stringUtils.hpp"
 104 #ifdef COMPILER1
 105 #include "c1/c1_Compiler.hpp"
 106 #endif
 107 #if INCLUDE_JFR
 108 #include "jfr/jfrEvents.hpp"
 109 #endif
 110 
 111 #ifdef DTRACE_ENABLED
 112 
 113 

 136   {                                                              \
 137     char* data = nullptr;                                        \
 138     int len = 0;                                                 \
 139     Symbol* clss_name = name();                                  \
 140     if (clss_name != nullptr) {                                  \
 141       data = (char*)clss_name->bytes();                          \
 142       len = clss_name->utf8_length();                            \
 143     }                                                            \
 144     HOTSPOT_CLASS_INITIALIZATION_##type(                         \
 145       data, len, (void*)class_loader(), thread_type, wait);      \
 146   }
 147 
 148 #else //  ndef DTRACE_ENABLED
 149 
 150 #define DTRACE_CLASSINIT_PROBE(type, thread_type)
 151 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait)
 152 
 153 #endif //  ndef DTRACE_ENABLED
 154 
 155 bool InstanceKlass::_finalization_enabled = true;
 156 static int call_class_initializer_counter = 0;   // for debugging
 157 
 158 static inline bool is_class_loader(const Symbol* class_name,
 159                                    const ClassFileParser& parser) {
 160   assert(class_name != nullptr, "invariant");
 161 
 162   if (class_name == vmSymbols::java_lang_ClassLoader()) {
 163     return true;
 164   }
 165 
 166   if (vmClasses::ClassLoader_klass_is_loaded()) {
 167     const Klass* const super_klass = parser.super_klass();
 168     if (super_klass != nullptr) {
 169       if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
 170         return true;
 171       }
 172     }
 173   }
 174   return false;
 175 }
 176 

 871   }
 872 
 873   Array<InstanceKlass*>* interfaces = local_interfaces();
 874   int len = interfaces->length();
 875   for (int i = 0; i < len; i++) {
 876     InstanceKlass* intf = interfaces->at(i);
 877     if (!intf->is_initialized()) {
 878       ResourceMark rm;
 879       // Note: an interface needs to be marked as is_initialized() only if
 880       // - it has a <clinit>
 881       // - it has declared a default method.
 882       assert(!intf->interface_needs_clinit_execution_as_super(/*also_check_supers*/false),
 883              "uninitialized super interface %s of aot-inited class %s must not have <clinit>",
 884              intf->external_name(), external_name());
 885     }
 886   }
 887 }
 888 #endif
 889 
 890 #if INCLUDE_CDS
 891 // early_init -- we are moving this class into the fully_initialized state before the
 892 // JVM is able to execute any bytecodes. See AOTLinkedClassBulkLoader::is_initializing_classes_early().
 893 void InstanceKlass::initialize_with_aot_initialized_mirror(bool early_init, TRAPS) {
 894   assert(has_aot_initialized_mirror(), "must be");
 895   assert(CDSConfig::is_loading_heap(), "must be");
 896   assert(CDSConfig::is_using_aot_linked_classes(), "must be");
 897   assert_no_clinit_will_run_for_aot_initialized_class();
 898 
 899   if (is_initialized()) {
 900     return;
 901   }
 902 
 903   if (log_is_enabled(Info, aot, init)) {
 904     ResourceMark rm;
 905     log_info(aot, init)("%s (aot-inited%s)", external_name(), early_init ? ", early" : "");
 906   }
 907 
 908   if (is_runtime_setup_required()) {
 909     assert(!early_init, "must not call");
 910     // Need to take the slow path, which will call the runtimeSetup() function instead
 911     // of <clinit>
 912     initialize(CHECK);
 913     return;
 914   }
 915 
 916   LogTarget(Info, class, init) lt;
 917   if (lt.is_enabled()) {
 918     ResourceMark rm(THREAD);
 919     LogStream ls(lt);
 920     ls.print("%d Initializing ", call_class_initializer_counter++);
 921     name()->print_value_on(&ls);
 922     ls.print_cr("(aot-inited) (" PTR_FORMAT ") by thread \"%s\"",
 923                 p2i(this), THREAD->name());
 924   }
 925 
 926   if (early_init) {
 927     precond(AOTLinkedClassBulkLoader::is_initializing_classes_early());
 928     precond(is_linked());
 929     precond(init_thread() == nullptr);
 930     set_init_state(fully_initialized);
 931     fence_and_clear_init_lock();
 932     return;
 933   }
 934 
 935   link_class(CHECK);
 936 
 937 #ifdef ASSERT
 938   {
 939     Handle h_init_lock(THREAD, init_lock());
 940     ObjectLocker ol(h_init_lock, THREAD);
 941     assert(!is_initialized(), "sanity");
 942     assert(!is_being_initialized(), "sanity");
 943     assert(!is_in_error_state(), "sanity");
 944   }
 945 #endif
 946 
 947   set_init_thread(THREAD);
 948   set_initialization_state_and_notify(fully_initialized, CHECK);
 949 }
 950 #endif
 951 
 952 bool InstanceKlass::verify_code(TRAPS) {

1128   return true;
1129 }
1130 
1131 // Rewrite the byte codes of all of the methods of a class.
1132 // The rewriter must be called exactly once. Rewriting must happen after
1133 // verification but before the first method of the class is executed.
1134 void InstanceKlass::rewrite_class(TRAPS) {
1135   assert(is_loaded(), "must be loaded");
1136   if (is_rewritten()) {
1137     assert(in_aot_cache(), "rewriting an unshared class?");
1138     return;
1139   }
1140   Rewriter::rewrite(this, CHECK);
1141   set_rewritten();
1142 }
1143 
1144 // Now relocate and link method entry points after class is rewritten.
1145 // This is outside is_rewritten flag. In case of an exception, it can be
1146 // executed more than once.
1147 void InstanceKlass::link_methods(TRAPS) {
1148   PerfTraceElapsedTime timer(ClassLoader::perf_ik_link_methods_time());
1149 
1150   int len = methods()->length();
1151   for (int i = len-1; i >= 0; i--) {
1152     methodHandle m(THREAD, methods()->at(i));
1153     RuntimeUpcalls::install_upcalls(m);
1154 
1155     // Set up method entry points for compiler and interpreter    .
1156     m->link_method(m, CHECK);
1157   }
1158 }
1159 
1160 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
1161 void InstanceKlass::initialize_super_interfaces(TRAPS) {
1162   assert (has_nonstatic_concrete_methods(), "caller should have checked this");
1163   for (int i = 0; i < local_interfaces()->length(); ++i) {
1164     InstanceKlass* ik = local_interfaces()->at(i);
1165 
1166     // Initialization is depth first search ie. we start with top of the inheritance tree
1167     // has_nonstatic_concrete_methods drives searching superinterfaces since it
1168     // means has_nonstatic_concrete_methods in its superinterface hierarchy
1169     if (ik->has_nonstatic_concrete_methods()) {
1170       ik->initialize_super_interfaces(CHECK);
1171     }
1172 
1173     // Only initialize() interfaces that "declare" concrete methods.

1249     _thread->set_class_to_be_initialized(ik);
1250   }
1251   ~ThreadWaitingForClassInit() {
1252     _thread->set_class_to_be_initialized(nullptr);
1253   }
1254 };
1255 
1256 void InstanceKlass::initialize_impl(TRAPS) {
1257   HandleMark hm(THREAD);
1258 
1259   // Make sure klass is linked (verified) before initialization
1260   // A class could already be verified, since it has been reflected upon.
1261   link_class(CHECK);
1262 
1263   DTRACE_CLASSINIT_PROBE(required, -1);
1264 
1265   bool wait = false;
1266 
1267   JavaThread* jt = THREAD;
1268 
1269   if (ForceProfiling) {
1270     // Preallocate MDOs.
1271     for (int i = 0; i < methods()->length(); i++) {
1272       assert(!HAS_PENDING_EXCEPTION, "");
1273       methodHandle m(THREAD, methods()->at(i));
1274       Method::build_profiling_method_data(m, THREAD);
1275       if (HAS_PENDING_EXCEPTION) {
1276         ResourceMark rm;
1277         log_warning(cds)("MDO preallocation failed for %s", external_name());
1278         CLEAR_PENDING_EXCEPTION;
1279         break;
1280       }
1281     }
1282   }
1283 
1284   bool debug_logging_enabled = log_is_enabled(Debug, class, init);
1285 
1286   // refer to the JVM book page 47 for description of steps
1287   // Step 1
1288   {
1289     Handle h_init_lock(THREAD, init_lock());
1290     ObjectLocker ol(h_init_lock, CHECK_PREEMPTABLE);
1291 
1292     // Step 2
1293     // If we were to use wait() instead of waitInterruptibly() then
1294     // we might end up throwing IE from link/symbol resolution sites
1295     // that aren't expected to throw.  This would wreak havoc.  See 6320309.
1296     while (is_being_initialized() && !is_reentrant_initialization(jt)) {
1297       if (debug_logging_enabled) {
1298         ResourceMark rm(jt);
1299         log_debug(class, init)("Thread \"%s\" waiting for initialization of %s by thread \"%s\"",
1300                                jt->name(), external_name(), init_thread_name());
1301       }
1302       wait = true;
1303       ThreadWaitingForClassInit twcl(THREAD, this);

1657     tty->print("Registered ");
1658     i->print_value_on(tty);
1659     tty->print_cr(" (" PTR_FORMAT ") as finalizable", p2i(i));
1660   }
1661   instanceHandle h_i(THREAD, i);
1662   // Pass the handle as argument, JavaCalls::call expects oop as jobjects
1663   JavaValue result(T_VOID);
1664   JavaCallArguments args(h_i);
1665   methodHandle mh(THREAD, Universe::finalizer_register_method());
1666   JavaCalls::call(&result, mh, &args, CHECK_NULL);
1667   MANAGEMENT_ONLY(FinalizerService::on_register(h_i(), THREAD);)
1668   return h_i();
1669 }
1670 
1671 instanceOop InstanceKlass::allocate_instance(TRAPS) {
1672   assert(!is_abstract() && !is_interface(), "Should not create this object");
1673   size_t size = size_helper();  // Query before forming handle.
1674   return (instanceOop)Universe::heap()->obj_allocate(this, size, CHECK_NULL);
1675 }
1676 
1677 instanceOop InstanceKlass::allocate_instance(oop java_class,
1678                                              const char* who,
1679                                              TRAPS) {
1680   Klass* k = java_lang_Class::as_Klass(java_class);
1681   if (k == nullptr) {
1682     ResourceMark rm(THREAD);
1683     THROW_(vmSymbols::java_lang_InstantiationException(), nullptr);
1684   }
1685   InstanceKlass* ik = cast(k);
1686   ik->check_valid_for_instantiation(false, CHECK_NULL);
1687   ik->initialize(CHECK_NULL);
1688   return ik->allocate_instance(THREAD);
1689 }
1690 
1691 instanceHandle InstanceKlass::allocate_instance_handle(TRAPS) {
1692   return instanceHandle(THREAD, allocate_instance(THREAD));
1693 }
1694 
1695 void InstanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) {
1696   if (is_interface() || is_abstract()) {
1697     ResourceMark rm(THREAD);
1698     THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1699               : vmSymbols::java_lang_InstantiationException(), external_name());

1727 }
1728 
1729 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1730   // Need load-acquire for lock-free read
1731   ObjArrayKlass* oak = array_klasses_acquire();
1732   if (oak == nullptr) {
1733     return nullptr;
1734   } else {
1735     return oak->array_klass_or_null(n);
1736   }
1737 }
1738 
1739 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1740   return array_klass(1, THREAD);
1741 }
1742 
1743 ArrayKlass* InstanceKlass::array_klass_or_null() {
1744   return array_klass_or_null(1);
1745 }
1746 


1747 Method* InstanceKlass::class_initializer() const {
1748   Method* clinit = find_method(
1749       vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1750   if (clinit != nullptr && clinit->has_valid_initializer_flags()) {
1751     return clinit;
1752   }
1753   return nullptr;
1754 }
1755 
1756 void InstanceKlass::call_class_initializer(TRAPS) {
1757   if (ReplayCompiles &&
1758       (ReplaySuppressInitializers == 1 ||
1759        (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1760     // Hide the existence of the initializer for the purpose of replaying the compile
1761     return;
1762   }
1763 
1764 #if INCLUDE_CDS
1765   // This is needed to ensure the consistency of the archived heap objects.
1766   if (has_aot_initialized_mirror() && CDSConfig::is_loading_heap()) {
1767     AOTClassInitializer::call_runtime_setup(THREAD, this);
1768     return;
1769   } else if (has_archived_enum_objs()) {
1770     assert(in_aot_cache(), "must be");
1771     bool initialized = CDSEnumKlass::initialize_enum_klass(this, CHECK);
1772     if (initialized) {
1773       return;
1774     }
1775   }
1776 #endif
1777 
1778   methodHandle h_method(THREAD, class_initializer());
1779   assert(!is_initialized(), "we cannot initialize twice");
1780 
1781 #if 0
1782   // FIXME -- revive this code added to leyden/premain for <clinit> profiling
1783   int init_id = log_class_init(THREAD, this);
1784   if (h_method() != nullptr) {
1785     JavaCallArguments args; // No arguments
1786     JavaValue result(T_VOID);
1787     InstanceKlass* outer = THREAD->set_class_being_initialized(this);
1788     jlong bc_start = (CountBytecodesPerThread ? THREAD->bc_counter_value() : BytecodeCounter::counter_value());
1789 
1790     elapsedTimer timer;
1791     {
1792       PerfPauseTimer pt(THREAD->current_rt_call_timer(), THREAD->profile_rt_calls());
1793       PauseRuntimeCallProfiling prcp(THREAD, THREAD->profile_rt_calls());
1794 
1795       timer.start();
1796       JavaCalls::call(&result, h_method, &args, THREAD); // Static call (no args)
1797       timer.stop();
1798     }
1799 
1800     jlong bc_end = (CountBytecodesPerThread ? THREAD->bc_counter_value() : BytecodeCounter::counter_value());
1801 
1802     jlong bc_executed = (bc_end - bc_start);
1803     if (UsePerfData && outer == nullptr) { // outermost clinit
1804       THREAD->inc_clinit_bc_counter_value(bc_executed);
1805       ClassLoader::perf_class_init_bytecodes_count()->inc(bc_executed);
1806     }
1807 
1808     THREAD->set_class_being_initialized(outer);
1809 
1810     LogStreamHandle(Debug, init) log;
1811     if (log.is_enabled()) {
1812       ResourceMark rm(THREAD);
1813       log.print("%d Initialized in %.3fms (total: " JLONG_FORMAT "ms); ",
1814                 init_id, timer.seconds() * 1000.0, ClassLoader::class_init_time_ms());
1815       if (CountBytecodes || CountBytecodesPerThread) {
1816         log.print("executed " JLONG_FORMAT " bytecodes; ", bc_executed);
1817       }
1818       name()->print_value_on(&log);
1819       log.print_cr(" by thread " PTR_FORMAT " \"%s\" (" PTR_FORMAT ")",
1820                    p2i(THREAD), THREAD->name(), p2i(this));
1821     }
1822   }
1823   LogTarget(Info, class, init) lt;
1824   if (lt.is_enabled()) {
1825     ResourceMark rm(THREAD);
1826     LogStream ls(lt);
1827     ls.print("%d Initialized ", init_id);
1828     name()->print_value_on(&ls);
1829     ls.print_cr("%s (" PTR_FORMAT ") by thread \"%s\"",
1830                 h_method() == nullptr ? "(no method)" : "", p2i(this),
1831                 THREAD->name());
1832   }
1833 #else
1834   LogTarget(Info, class, init) lt;
1835   if (lt.is_enabled()) {
1836     ResourceMark rm(THREAD);
1837     LogStream ls(lt);
1838     ls.print("%d Initializing ", call_class_initializer_counter++);
1839     name()->print_value_on(&ls);
1840     ls.print_cr("%s (" PTR_FORMAT ") by thread \"%s\"",
1841                 h_method() == nullptr ? "(no method)" : "", p2i(this),
1842                 THREAD->name());
1843   }
1844   if (h_method() != nullptr) {
1845     ThreadInClassInitializer ticl(THREAD, this); // Track class being initialized
1846     JavaCallArguments args; // No arguments
1847     JavaValue result(T_VOID);
1848     JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1849   }
1850 #endif
1851 }
1852 
1853 // If a class that implements this interface is initialized, is the JVM required
1854 // to first execute a <clinit> method declared in this interface,
1855 // or (if also_check_supers==true) any of the super types of this interface?
1856 //
1857 // JVMS 5.5. Initialization, step 7: Next, if C is a class rather than
1858 // an interface, then let SC be its superclass and let SI1, ..., SIn
1859 // be all superinterfaces of C (whether direct or indirect) that
1860 // declare at least one non-abstract, non-static method.
1861 //
1862 // So when an interface is initialized, it does not look at its
1863 // supers. But a proper class will ensure that all of its supers have
1864 // run their <clinit> methods, except that it disregards interfaces
1865 // that lack a non-static concrete method (i.e., a default method).
1866 // Therefore, you should probably call this method only when the
1867 // current class is a super of some proper class, not an interface.
1868 bool InstanceKlass::interface_needs_clinit_execution_as_super(bool also_check_supers) const {
1869   assert(is_interface(), "must be");
1870 

2639         id == nullptr) {
2640       id = Method::make_jmethod_id(class_loader_data(), m);
2641       AtomicAccess::release_store(&jmeths[idnum + 1], id);
2642     }
2643   }
2644 }
2645 
2646 // Lookup a jmethodID, null if not found.  Do no blocking, no allocations, no handles
2647 jmethodID InstanceKlass::jmethod_id_or_null(Method* method) {
2648   int idnum = method->method_idnum();
2649   jmethodID* jmeths = methods_jmethod_ids_acquire();
2650   return (jmeths != nullptr) ? jmeths[idnum + 1] : nullptr;
2651 }
2652 
2653 inline DependencyContext InstanceKlass::dependencies() {
2654   DependencyContext dep_context(&_dep_context, &_dep_context_last_cleaned);
2655   return dep_context;
2656 }
2657 
2658 void InstanceKlass::mark_dependent_nmethods(DeoptimizationScope* deopt_scope, KlassDepChange& changes) {
2659   dependencies().mark_dependent_nmethods(deopt_scope, changes, this);
2660 }
2661 
2662 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
2663   assert_lock_strong(CodeCache_lock);
2664   dependencies().add_dependent_nmethod(nm);
2665 }
2666 
2667 void InstanceKlass::clean_dependency_context() {
2668   dependencies().clean_unloading_dependents();
2669 }
2670 
2671 #ifndef PRODUCT
2672 void InstanceKlass::print_dependent_nmethods(bool verbose) {
2673   dependencies().print_dependent_nmethods(verbose);
2674 }
2675 
2676 bool InstanceKlass::is_dependent_nmethod(nmethod* nm) {
2677   return dependencies().is_dependent_nmethod(nm);
2678 }
2679 #endif //PRODUCT

3755 static void print_vtable(intptr_t* start, int len, outputStream* st) {
3756   for (int i = 0; i < len; i++) {
3757     intptr_t e = start[i];
3758     st->print("%d : " INTPTR_FORMAT, i, e);
3759     if (MetaspaceObj::is_valid((Metadata*)e)) {
3760       st->print(" ");
3761       ((Metadata*)e)->print_value_on(st);
3762     }
3763     st->cr();
3764   }
3765 }
3766 
3767 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3768   return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
3769 }
3770 
3771 const char* InstanceKlass::init_state_name() const {
3772   return state_names[init_state()];
3773 }
3774 
3775 const char* InstanceKlass::state2name(ClassState s) {
3776   return state_names[s];
3777 }
3778 
3779 void InstanceKlass::print_on(outputStream* st) const {
3780   assert(is_klass(), "must be klass");
3781   Klass::print_on(st);
3782 
3783   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
3784   st->print(BULLET"klass size:        %d", size());                               st->cr();
3785   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
3786   st->print(BULLET"flags:             "); _misc_flags.print_on(st);               st->cr();
3787   st->print(BULLET"state:             "); st->print_cr("%s", init_state_name());
3788   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
3789   st->print(BULLET"super:             "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3790   st->print(BULLET"sub:               ");
3791   Klass* sub = subklass();
3792   int n;
3793   for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3794     if (n < MaxSubklassPrintSize) {
3795       sub->print_value_on(st);
3796       st->print("   ");
3797     }
3798   }

4093         nullptr;
4094       // caller can be null, for example, during a JVMTI VM_Init hook
4095       if (caller != nullptr) {
4096         info_stream.print(" source: instance of %s", caller->external_name());
4097       } else {
4098         // source is unknown
4099       }
4100     } else {
4101       oop class_loader = loader_data->class_loader();
4102       info_stream.print(" source: %s", class_loader->klass()->external_name());
4103     }
4104   } else {
4105     assert(this->in_aot_cache(), "must be");
4106     if (AOTMetaspace::in_aot_cache_dynamic_region((void*)this)) {
4107       info_stream.print(" source: shared objects file (top)");
4108     } else {
4109       info_stream.print(" source: shared objects file");
4110     }
4111   }
4112 
4113   info_stream.print(" loader:");
4114 #if INCLUDE_CDS
4115   if (in_aot_cache()) {
4116     info_stream.print(" %s", SystemDictionaryShared::loader_type_for_shared_class((Klass*)this));
4117   } else
4118 #endif
4119   if (loader_data == ClassLoaderData::the_null_class_loader_data()) {
4120     info_stream.print(" boot_loader");
4121   } else {
4122     oop class_loader = loader_data->class_loader();
4123     if (class_loader != nullptr) {
4124       info_stream.print(" %s", class_loader->klass()->external_name());
4125       oop cl_name_and_id = java_lang_ClassLoader::nameAndId(class_loader);
4126       if (cl_name_and_id != nullptr) {
4127         info_stream.print(" %s", java_lang_String::as_utf8_string(cl_name_and_id));
4128       }
4129     } else {
4130       info_stream.print(" null");
4131     }
4132   }
4133   msg.info("%s", info_stream.as_string());
4134 
4135   if (log_is_enabled(Debug, class, load)) {
4136     stringStream debug_stream;
4137 
4138     // Class hierarchy info
4139     debug_stream.print(" klass: " PTR_FORMAT " super: " PTR_FORMAT,
4140                        p2i(this),  p2i(super()));
4141 
4142     // Interfaces
4143     if (local_interfaces() != nullptr && local_interfaces()->length() > 0) {
4144       debug_stream.print(" interfaces:");
4145       int length = local_interfaces()->length();
4146       for (int i = 0; i < length; i++) {
4147         debug_stream.print(" " PTR_FORMAT,
4148                            p2i(local_interfaces()->at(i)));
4149       }
4150     }
4151 
4152     // Class loader
< prev index next >