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/bytecodeStream.hpp"
49 #include "interpreter/oopMapCache.hpp"
50 #include "interpreter/rewriter.hpp"
51 #include "jvm.h"
52 #include "jvmtifiles/jvmti.h"
53 #include "logging/log.hpp"
54 #include "klass.inline.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"
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/deoptimization.hpp"
82 #include "runtime/atomic.hpp"
83 #include "runtime/fieldDescriptor.inline.hpp"
84 #include "runtime/handles.inline.hpp"
85 #include "runtime/javaCalls.hpp"
86 #include "runtime/javaThread.inline.hpp"
87 #include "runtime/mutexLocker.hpp"
88 #include "runtime/orderAccess.hpp"
89 #include "runtime/os.inline.hpp"
90 #include "runtime/reflection.hpp"
91 #include "runtime/synchronizer.hpp"
92 #include "runtime/threads.hpp"
93 #include "services/classLoadingService.hpp"
94 #include "services/finalizerService.hpp"
95 #include "services/threadService.hpp"
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
868 }
869 if (log_is_enabled(Info, aot, init)) {
870 ResourceMark rm;
871 log_info(aot, init)("%s (aot-inited)", external_name());
872 }
873
874 link_class(CHECK);
875
876 #ifdef ASSERT
877 {
878 Handle h_init_lock(THREAD, init_lock());
879 ObjectLocker ol(h_init_lock, THREAD);
880 assert(!is_initialized(), "sanity");
881 assert(!is_being_initialized(), "sanity");
882 assert(!is_in_error_state(), "sanity");
883 }
884 #endif
885
886 set_init_thread(THREAD);
887 set_initialization_state_and_notify(fully_initialized, CHECK);
888 }
889 #endif
890
891 bool InstanceKlass::verify_code(TRAPS) {
892 // 1) Verify the bytecodes
893 return Verifier::verify(this, should_verify_class(), THREAD);
894 }
895
896 void InstanceKlass::link_class(TRAPS) {
897 assert(is_loaded(), "must be loaded");
898 if (!is_linked()) {
899 link_class_impl(CHECK);
900 }
901 }
902
903 // Called to verify that a class can link during initialization, without
904 // throwing a VerifyError.
905 bool InstanceKlass::link_class_or_fail(TRAPS) {
906 assert(is_loaded(), "must be loaded");
907 if (!is_linked()) {
1063 return true;
1064 }
1065
1066 // Rewrite the byte codes of all of the methods of a class.
1067 // The rewriter must be called exactly once. Rewriting must happen after
1068 // verification but before the first method of the class is executed.
1069 void InstanceKlass::rewrite_class(TRAPS) {
1070 assert(is_loaded(), "must be loaded");
1071 if (is_rewritten()) {
1072 assert(is_shared(), "rewriting an unshared class?");
1073 return;
1074 }
1075 Rewriter::rewrite(this, CHECK);
1076 set_rewritten();
1077 }
1078
1079 // Now relocate and link method entry points after class is rewritten.
1080 // This is outside is_rewritten flag. In case of an exception, it can be
1081 // executed more than once.
1082 void InstanceKlass::link_methods(TRAPS) {
1083 PerfTraceTime timer(ClassLoader::perf_ik_link_methods_time());
1084
1085 int len = methods()->length();
1086 for (int i = len-1; i >= 0; i--) {
1087 methodHandle m(THREAD, methods()->at(i));
1088
1089 // Set up method entry points for compiler and interpreter .
1090 m->link_method(m, CHECK);
1091 }
1092 }
1093
1094 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
1095 void InstanceKlass::initialize_super_interfaces(TRAPS) {
1096 assert (has_nonstatic_concrete_methods(), "caller should have checked this");
1097 for (int i = 0; i < local_interfaces()->length(); ++i) {
1098 InstanceKlass* ik = local_interfaces()->at(i);
1099
1100 // Initialization is depth first search ie. we start with top of the inheritance tree
1101 // has_nonstatic_concrete_methods drives searching superinterfaces since it
1102 // means has_nonstatic_concrete_methods in its superinterface hierarchy
1103 if (ik->has_nonstatic_concrete_methods()) {
1104 ik->initialize_super_interfaces(CHECK);
1105 }
1106
1107 // Only initialize() interfaces that "declare" concrete methods.
1172 assert_locked_or_safepoint(ClassInitError_lock);
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
1190 JavaThread* jt = THREAD;
1191
1192 bool debug_logging_enabled = log_is_enabled(Debug, class, init);
1193
1194 // refer to the JVM book page 47 for description of steps
1195 // Step 1
1196 {
1197 Handle h_init_lock(THREAD, init_lock());
1198 ObjectLocker ol(h_init_lock, jt);
1199
1200 // Step 2
1201 // If we were to use wait() instead of waitInterruptibly() then
1202 // we might end up throwing IE from link/symbol resolution sites
1203 // that aren't expected to throw. This would wreak havoc. See 6320309.
1204 while (is_being_initialized() && !is_reentrant_initialization(jt)) {
1205 if (debug_logging_enabled) {
1206 ResourceMark rm(jt);
1207 log_debug(class, init)("Thread \"%s\" waiting for initialization of %s by thread \"%s\"",
1208 jt->name(), external_name(), init_thread_name());
1209 }
1210 wait = true;
1211 jt->set_class_to_be_initialized(this);
1341 add_initialization_error(THREAD, e);
1342 set_initialization_state_and_notify(initialization_error, THREAD);
1343 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
1344 // JVMTI has already reported the pending exception
1345 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1346 JvmtiExport::clear_detected_exception(jt);
1347 }
1348 DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1349 if (e->is_a(vmClasses::Error_klass())) {
1350 THROW_OOP(e());
1351 } else {
1352 JavaCallArguments args(e);
1353 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1354 vmSymbols::throwable_void_signature(),
1355 &args);
1356 }
1357 }
1358 DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait);
1359 }
1360
1361
1362 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
1363 Handle h_init_lock(THREAD, init_lock());
1364 if (h_init_lock() != nullptr) {
1365 ObjectLocker ol(h_init_lock, THREAD);
1366 set_init_thread(nullptr); // reset _init_thread before changing _init_state
1367 set_init_state(state);
1368 fence_and_clear_init_lock();
1369 ol.notify_all(CHECK);
1370 } else {
1371 assert(h_init_lock() != nullptr, "The initialization state should never be set twice");
1372 set_init_thread(nullptr); // reset _init_thread before changing _init_state
1373 set_init_state(state);
1374 }
1375 }
1376
1377 // Update hierarchy. This is done before the new klass has been added to the SystemDictionary. The Compile_lock
1378 // is grabbed, to ensure that the compiler is not using the class hierarchy.
1379 void InstanceKlass::add_to_hierarchy(JavaThread* current) {
1380 assert(!SafepointSynchronize::is_at_safepoint(), "must NOT be at safepoint");
1381
1571 tty->print("Registered ");
1572 i->print_value_on(tty);
1573 tty->print_cr(" (" PTR_FORMAT ") as finalizable", p2i(i));
1574 }
1575 instanceHandle h_i(THREAD, i);
1576 // Pass the handle as argument, JavaCalls::call expects oop as jobjects
1577 JavaValue result(T_VOID);
1578 JavaCallArguments args(h_i);
1579 methodHandle mh(THREAD, Universe::finalizer_register_method());
1580 JavaCalls::call(&result, mh, &args, CHECK_NULL);
1581 MANAGEMENT_ONLY(FinalizerService::on_register(h_i(), THREAD);)
1582 return h_i();
1583 }
1584
1585 instanceOop InstanceKlass::allocate_instance(TRAPS) {
1586 assert(!is_abstract() && !is_interface(), "Should not create this object");
1587 size_t size = size_helper(); // Query before forming handle.
1588 return (instanceOop)Universe::heap()->obj_allocate(this, size, CHECK_NULL);
1589 }
1590
1591 instanceOop InstanceKlass::allocate_instance(oop java_class, TRAPS) {
1592 Klass* k = java_lang_Class::as_Klass(java_class);
1593 if (k == nullptr) {
1594 ResourceMark rm(THREAD);
1595 THROW_(vmSymbols::java_lang_InstantiationException(), nullptr);
1596 }
1597 InstanceKlass* ik = cast(k);
1598 ik->check_valid_for_instantiation(false, CHECK_NULL);
1599 ik->initialize(CHECK_NULL);
1600 return ik->allocate_instance(THREAD);
1601 }
1602
1603 instanceHandle InstanceKlass::allocate_instance_handle(TRAPS) {
1604 return instanceHandle(THREAD, allocate_instance(THREAD));
1605 }
1606
1607 void InstanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) {
1608 if (is_interface() || is_abstract()) {
1609 ResourceMark rm(THREAD);
1610 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1611 : vmSymbols::java_lang_InstantiationException(), external_name());
1674 // Hide the existence of the initializer for the purpose of replaying the compile
1675 return;
1676 }
1677
1678 #if INCLUDE_CDS
1679 // This is needed to ensure the consistency of the archived heap objects.
1680 if (has_aot_initialized_mirror() && CDSConfig::is_loading_heap()) {
1681 AOTClassInitializer::call_runtime_setup(THREAD, this);
1682 return;
1683 } else if (has_archived_enum_objs()) {
1684 assert(is_shared(), "must be");
1685 bool initialized = CDSEnumKlass::initialize_enum_klass(this, CHECK);
1686 if (initialized) {
1687 return;
1688 }
1689 }
1690 #endif
1691
1692 methodHandle h_method(THREAD, class_initializer());
1693 assert(!is_initialized(), "we cannot initialize twice");
1694 LogTarget(Info, class, init) lt;
1695 if (lt.is_enabled()) {
1696 ResourceMark rm(THREAD);
1697 LogStream ls(lt);
1698 ls.print("%d Initializing ", call_class_initializer_counter++);
1699 name()->print_value_on(&ls);
1700 ls.print_cr("%s (" PTR_FORMAT ") by thread \"%s\"",
1701 h_method() == nullptr ? "(no method)" : "", p2i(this),
1702 THREAD->name());
1703 }
1704 if (h_method() != nullptr) {
1705 ThreadInClassInitializer ticl(THREAD, this); // Track class being initialized
1706 JavaCallArguments args; // No arguments
1707 JavaValue result(T_VOID);
1708 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1709 }
1710 }
1711
1712 // If a class that implements this interface is initialized, is the JVM required
1713 // to first execute a <clinit> method declared in this interface,
1714 // or (if also_check_supers==true) any of the super types of this interface?
1715 //
1716 // JVMS 5.5. Initialization, step 7: Next, if C is a class rather than
1717 // an interface, then let SC be its superclass and let SI1, ..., SIn
1718 // be all superinterfaces of C (whether direct or indirect) that
1719 // declare at least one non-abstract, non-static method.
1720 //
1721 // So when an interface is initialized, it does not look at its
1722 // supers. But a proper class will ensure that all of its supers have
1723 // run their <clinit> methods, except that it disregards interfaces
1724 // that lack a non-static concrete method (i.e., a default method).
1725 // Therefore, you should probably call this method only when the
1726 // current class is a super of some proper class, not an interface.
1727 bool InstanceKlass::interface_needs_clinit_execution_as_super(bool also_check_supers) const {
1728 assert(is_interface(), "must be");
1729
2486 }
2487 }
2488 if (new_jmeths != 0) {
2489 Method::ensure_jmethod_ids(class_loader_data(), new_jmeths);
2490 }
2491 }
2492
2493 // Lookup a jmethodID, null if not found. Do no blocking, no allocations, no handles
2494 jmethodID InstanceKlass::jmethod_id_or_null(Method* method) {
2495 int idnum = method->method_idnum();
2496 jmethodID* jmeths = methods_jmethod_ids_acquire();
2497 return (jmeths != nullptr) ? jmeths[idnum + 1] : nullptr;
2498 }
2499
2500 inline DependencyContext InstanceKlass::dependencies() {
2501 DependencyContext dep_context(&_dep_context, &_dep_context_last_cleaned);
2502 return dep_context;
2503 }
2504
2505 void InstanceKlass::mark_dependent_nmethods(DeoptimizationScope* deopt_scope, KlassDepChange& changes) {
2506 dependencies().mark_dependent_nmethods(deopt_scope, changes);
2507 }
2508
2509 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
2510 assert_lock_strong(CodeCache_lock);
2511 dependencies().add_dependent_nmethod(nm);
2512 }
2513
2514 void InstanceKlass::clean_dependency_context() {
2515 dependencies().clean_unloading_dependents();
2516 }
2517
2518 #ifndef PRODUCT
2519 void InstanceKlass::print_dependent_nmethods(bool verbose) {
2520 dependencies().print_dependent_nmethods(verbose);
2521 }
2522
2523 bool InstanceKlass::is_dependent_nmethod(nmethod* nm) {
2524 return dependencies().is_dependent_nmethod(nm);
2525 }
2526 #endif //PRODUCT
2624 for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2625 if (ioe->interface_klass() != nullptr) {
2626 it->push(ioe->interface_klass_addr());
2627 itableMethodEntry* ime = ioe->first_method_entry(this);
2628 int n = klassItable::method_count_for_interface(ioe->interface_klass());
2629 for (int index = 0; index < n; index ++) {
2630 it->push(ime[index].method_addr());
2631 }
2632 }
2633 }
2634 }
2635
2636 it->push(&_nest_host);
2637 it->push(&_nest_members);
2638 it->push(&_permitted_subclasses);
2639 it->push(&_record_components);
2640 }
2641
2642 #if INCLUDE_CDS
2643 void InstanceKlass::remove_unshareable_info() {
2644
2645 if (is_linked()) {
2646 assert(can_be_verified_at_dumptime(), "must be");
2647 // Remember this so we can avoid walking the hierarchy at runtime.
2648 set_verified_at_dump_time();
2649 }
2650
2651 _misc_flags.set_has_init_deps_processed(false);
2652
2653 Klass::remove_unshareable_info();
2654
2655 if (SystemDictionaryShared::has_class_failed_verification(this)) {
2656 // Classes are attempted to link during dumping and may fail,
2657 // but these classes are still in the dictionary and class list in CLD.
2658 // If the class has failed verification, there is nothing else to remove.
2659 return;
2660 }
2661
2662 // Reset to the 'allocated' state to prevent any premature accessing to
2663 // a shared class at runtime while the class is still being loaded and
2664 // restored. A class' init_state is set to 'loaded' at runtime when it's
2665 // being added to class hierarchy (see InstanceKlass:::add_to_hierarchy()).
2666 _init_state = allocated;
2667
2668 { // Otherwise this needs to take out the Compile_lock.
2669 assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2801
2802 // restore constant pool resolved references
2803 constants()->restore_unshareable_info(CHECK);
2804
2805 if (array_klasses() != nullptr) {
2806 // To get a consistent list of classes we need MultiArray_lock to ensure
2807 // array classes aren't observed while they are being restored.
2808 RecursiveLocker rl(MultiArray_lock, THREAD);
2809 assert(this == array_klasses()->bottom_klass(), "sanity");
2810 // Array classes have null protection domain.
2811 // --> see ArrayKlass::complete_create_array_klass()
2812 array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2813 }
2814
2815 // Initialize @ValueBased class annotation if not already set in the archived klass.
2816 if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
2817 set_is_value_based();
2818 }
2819 }
2820
2821 // Check if a class or any of its supertypes has a version older than 50.
2822 // CDS will not perform verification of old classes during dump time because
2823 // without changing the old verifier, the verification constraint cannot be
2824 // retrieved during dump time.
2825 // Verification of archived old classes will be performed during run time.
2826 bool InstanceKlass::can_be_verified_at_dumptime() const {
2827 if (MetaspaceShared::is_in_shared_metaspace(this)) {
2828 // This is a class that was dumped into the base archive, so we know
2829 // it was verified at dump time.
2830 return true;
2831 }
2832 if (major_version() < 50 /*JAVA_6_VERSION*/) {
2833 return false;
2834 }
2835 if (java_super() != nullptr && !java_super()->can_be_verified_at_dumptime()) {
2836 return false;
2837 }
2838 Array<InstanceKlass*>* interfaces = local_interfaces();
2839 int len = interfaces->length();
2840 for (int i = 0; i < len; i++) {
2841 if (!interfaces->at(i)->can_be_verified_at_dumptime()) {
2842 return false;
2843 }
2844 }
2845 return true;
2846 }
2847
2848 #endif // INCLUDE_CDS
2849
2850 #if INCLUDE_JVMTI
2851 static void clear_all_breakpoints(Method* m) {
3606 static void print_vtable(intptr_t* start, int len, outputStream* st) {
3607 for (int i = 0; i < len; i++) {
3608 intptr_t e = start[i];
3609 st->print("%d : " INTPTR_FORMAT, i, e);
3610 if (MetaspaceObj::is_valid((Metadata*)e)) {
3611 st->print(" ");
3612 ((Metadata*)e)->print_value_on(st);
3613 }
3614 st->cr();
3615 }
3616 }
3617
3618 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3619 return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
3620 }
3621
3622 const char* InstanceKlass::init_state_name() const {
3623 return state_names[init_state()];
3624 }
3625
3626 void InstanceKlass::print_on(outputStream* st) const {
3627 assert(is_klass(), "must be klass");
3628 Klass::print_on(st);
3629
3630 st->print(BULLET"instance size: %d", size_helper()); st->cr();
3631 st->print(BULLET"klass size: %d", size()); st->cr();
3632 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
3633 st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
3634 st->print(BULLET"state: "); st->print_cr("%s", init_state_name());
3635 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3636 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3637 st->print(BULLET"sub: ");
3638 Klass* sub = subklass();
3639 int n;
3640 for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3641 if (n < MaxSubklassPrintSize) {
3642 sub->print_value_on(st);
3643 st->print(" ");
3644 }
3645 }
3935 nullptr;
3936 // caller can be null, for example, during a JVMTI VM_Init hook
3937 if (caller != nullptr) {
3938 info_stream.print(" source: instance of %s", caller->external_name());
3939 } else {
3940 // source is unknown
3941 }
3942 } else {
3943 oop class_loader = loader_data->class_loader();
3944 info_stream.print(" source: %s", class_loader->klass()->external_name());
3945 }
3946 } else {
3947 assert(this->is_shared(), "must be");
3948 if (MetaspaceShared::is_shared_dynamic((void*)this)) {
3949 info_stream.print(" source: shared objects file (top)");
3950 } else {
3951 info_stream.print(" source: shared objects file");
3952 }
3953 }
3954
3955 msg.info("%s", info_stream.as_string());
3956
3957 if (log_is_enabled(Debug, class, load)) {
3958 stringStream debug_stream;
3959
3960 // Class hierarchy info
3961 debug_stream.print(" klass: " PTR_FORMAT " super: " PTR_FORMAT,
3962 p2i(this), p2i(superklass()));
3963
3964 // Interfaces
3965 if (local_interfaces() != nullptr && local_interfaces()->length() > 0) {
3966 debug_stream.print(" interfaces:");
3967 int length = local_interfaces()->length();
3968 for (int i = 0; i < length; i++) {
3969 debug_stream.print(" " PTR_FORMAT,
3970 p2i(InstanceKlass::cast(local_interfaces()->at(i))));
3971 }
3972 }
3973
3974 // Class loader
|
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 "klass.inline.hpp"
56 #include "logging/logMessage.hpp"
57 #include "logging/logStream.hpp"
58 #include "memory/allocation.inline.hpp"
59 #include "memory/iterator.inline.hpp"
60 #include "memory/metadataFactory.hpp"
61 #include "memory/metaspaceClosure.hpp"
62 #include "memory/oopFactory.hpp"
63 #include "memory/resourceArea.hpp"
64 #include "memory/universe.hpp"
65 #include "oops/fieldStreams.inline.hpp"
66 #include "oops/constantPool.hpp"
67 #include "oops/instanceClassLoaderKlass.hpp"
68 #include "oops/instanceKlass.inline.hpp"
72 #include "oops/klass.inline.hpp"
73 #include "oops/method.hpp"
74 #include "oops/oop.inline.hpp"
75 #include "oops/recordComponent.hpp"
76 #include "oops/symbol.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/runtimeUpcalls.hpp"
93 #include "runtime/synchronizer.hpp"
94 #include "runtime/threads.hpp"
95 #include "services/classLoadingService.hpp"
96 #include "services/finalizerService.hpp"
97 #include "services/threadService.hpp"
98 #include "utilities/dtrace.hpp"
99 #include "utilities/events.hpp"
100 #include "utilities/macros.hpp"
101 #include "utilities/nativeStackPrinter.hpp"
102 #include "utilities/stringUtils.hpp"
103 #ifdef COMPILER1
104 #include "c1/c1_Compiler.hpp"
105 #endif
106 #if INCLUDE_JFR
107 #include "jfr/jfrEvents.hpp"
108 #endif
109
110 #ifdef DTRACE_ENABLED
111
112
870 }
871 if (log_is_enabled(Info, aot, init)) {
872 ResourceMark rm;
873 log_info(aot, init)("%s (aot-inited)", external_name());
874 }
875
876 link_class(CHECK);
877
878 #ifdef ASSERT
879 {
880 Handle h_init_lock(THREAD, init_lock());
881 ObjectLocker ol(h_init_lock, THREAD);
882 assert(!is_initialized(), "sanity");
883 assert(!is_being_initialized(), "sanity");
884 assert(!is_in_error_state(), "sanity");
885 }
886 #endif
887
888 set_init_thread(THREAD);
889 set_initialization_state_and_notify(fully_initialized, CHECK);
890 AOTClassInitializer::call_runtime_setup(THREAD, this);
891 }
892 #endif
893
894 bool InstanceKlass::verify_code(TRAPS) {
895 // 1) Verify the bytecodes
896 return Verifier::verify(this, should_verify_class(), THREAD);
897 }
898
899 void InstanceKlass::link_class(TRAPS) {
900 assert(is_loaded(), "must be loaded");
901 if (!is_linked()) {
902 link_class_impl(CHECK);
903 }
904 }
905
906 // Called to verify that a class can link during initialization, without
907 // throwing a VerifyError.
908 bool InstanceKlass::link_class_or_fail(TRAPS) {
909 assert(is_loaded(), "must be loaded");
910 if (!is_linked()) {
1066 return true;
1067 }
1068
1069 // Rewrite the byte codes of all of the methods of a class.
1070 // The rewriter must be called exactly once. Rewriting must happen after
1071 // verification but before the first method of the class is executed.
1072 void InstanceKlass::rewrite_class(TRAPS) {
1073 assert(is_loaded(), "must be loaded");
1074 if (is_rewritten()) {
1075 assert(is_shared(), "rewriting an unshared class?");
1076 return;
1077 }
1078 Rewriter::rewrite(this, CHECK);
1079 set_rewritten();
1080 }
1081
1082 // Now relocate and link method entry points after class is rewritten.
1083 // This is outside is_rewritten flag. In case of an exception, it can be
1084 // executed more than once.
1085 void InstanceKlass::link_methods(TRAPS) {
1086 PerfTraceElapsedTime timer(ClassLoader::perf_ik_link_methods_time());
1087
1088 int len = methods()->length();
1089 for (int i = len-1; i >= 0; i--) {
1090 methodHandle m(THREAD, methods()->at(i));
1091 RuntimeUpcalls::install_upcalls(m);
1092
1093 // Set up method entry points for compiler and interpreter .
1094 m->link_method(m, CHECK);
1095 }
1096 }
1097
1098 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
1099 void InstanceKlass::initialize_super_interfaces(TRAPS) {
1100 assert (has_nonstatic_concrete_methods(), "caller should have checked this");
1101 for (int i = 0; i < local_interfaces()->length(); ++i) {
1102 InstanceKlass* ik = local_interfaces()->at(i);
1103
1104 // Initialization is depth first search ie. we start with top of the inheritance tree
1105 // has_nonstatic_concrete_methods drives searching superinterfaces since it
1106 // means has_nonstatic_concrete_methods in its superinterface hierarchy
1107 if (ik->has_nonstatic_concrete_methods()) {
1108 ik->initialize_super_interfaces(CHECK);
1109 }
1110
1111 // Only initialize() interfaces that "declare" concrete methods.
1176 assert_locked_or_safepoint(ClassInitError_lock);
1177 InitErrorTableCleaner cleaner;
1178 if (_initialization_error_table != nullptr) {
1179 _initialization_error_table->unlink(&cleaner);
1180 }
1181 }
1182
1183 void InstanceKlass::initialize_impl(TRAPS) {
1184 HandleMark hm(THREAD);
1185
1186 // Make sure klass is linked (verified) before initialization
1187 // A class could already be verified, since it has been reflected upon.
1188 link_class(CHECK);
1189
1190 DTRACE_CLASSINIT_PROBE(required, -1);
1191
1192 bool wait = false;
1193
1194 JavaThread* jt = THREAD;
1195
1196 if (ForceProfiling) {
1197 // Preallocate MDOs.
1198 for (int i = 0; i < methods()->length(); i++) {
1199 assert(!HAS_PENDING_EXCEPTION, "");
1200 methodHandle m(THREAD, methods()->at(i));
1201 Method::build_profiling_method_data(m, THREAD);
1202 if (HAS_PENDING_EXCEPTION) {
1203 ResourceMark rm;
1204 log_warning(cds)("MDO preallocation failed for %s", external_name());
1205 CLEAR_PENDING_EXCEPTION;
1206 break;
1207 }
1208 }
1209 }
1210
1211 bool debug_logging_enabled = log_is_enabled(Debug, class, init);
1212
1213 // refer to the JVM book page 47 for description of steps
1214 // Step 1
1215 {
1216 Handle h_init_lock(THREAD, init_lock());
1217 ObjectLocker ol(h_init_lock, jt);
1218
1219 // Step 2
1220 // If we were to use wait() instead of waitInterruptibly() then
1221 // we might end up throwing IE from link/symbol resolution sites
1222 // that aren't expected to throw. This would wreak havoc. See 6320309.
1223 while (is_being_initialized() && !is_reentrant_initialization(jt)) {
1224 if (debug_logging_enabled) {
1225 ResourceMark rm(jt);
1226 log_debug(class, init)("Thread \"%s\" waiting for initialization of %s by thread \"%s\"",
1227 jt->name(), external_name(), init_thread_name());
1228 }
1229 wait = true;
1230 jt->set_class_to_be_initialized(this);
1360 add_initialization_error(THREAD, e);
1361 set_initialization_state_and_notify(initialization_error, THREAD);
1362 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
1363 // JVMTI has already reported the pending exception
1364 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1365 JvmtiExport::clear_detected_exception(jt);
1366 }
1367 DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1368 if (e->is_a(vmClasses::Error_klass())) {
1369 THROW_OOP(e());
1370 } else {
1371 JavaCallArguments args(e);
1372 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1373 vmSymbols::throwable_void_signature(),
1374 &args);
1375 }
1376 }
1377 DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait);
1378 }
1379
1380 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
1381 Handle h_init_lock(THREAD, init_lock());
1382 if (h_init_lock() != nullptr) {
1383 ObjectLocker ol(h_init_lock, THREAD);
1384 set_init_thread(nullptr); // reset _init_thread before changing _init_state
1385 set_init_state(state);
1386 fence_and_clear_init_lock();
1387 ol.notify_all(CHECK);
1388 } else {
1389 assert(h_init_lock() != nullptr, "The initialization state should never be set twice");
1390 set_init_thread(nullptr); // reset _init_thread before changing _init_state
1391 set_init_state(state);
1392 }
1393 }
1394
1395 // Update hierarchy. This is done before the new klass has been added to the SystemDictionary. The Compile_lock
1396 // is grabbed, to ensure that the compiler is not using the class hierarchy.
1397 void InstanceKlass::add_to_hierarchy(JavaThread* current) {
1398 assert(!SafepointSynchronize::is_at_safepoint(), "must NOT be at safepoint");
1399
1589 tty->print("Registered ");
1590 i->print_value_on(tty);
1591 tty->print_cr(" (" PTR_FORMAT ") as finalizable", p2i(i));
1592 }
1593 instanceHandle h_i(THREAD, i);
1594 // Pass the handle as argument, JavaCalls::call expects oop as jobjects
1595 JavaValue result(T_VOID);
1596 JavaCallArguments args(h_i);
1597 methodHandle mh(THREAD, Universe::finalizer_register_method());
1598 JavaCalls::call(&result, mh, &args, CHECK_NULL);
1599 MANAGEMENT_ONLY(FinalizerService::on_register(h_i(), THREAD);)
1600 return h_i();
1601 }
1602
1603 instanceOop InstanceKlass::allocate_instance(TRAPS) {
1604 assert(!is_abstract() && !is_interface(), "Should not create this object");
1605 size_t size = size_helper(); // Query before forming handle.
1606 return (instanceOop)Universe::heap()->obj_allocate(this, size, CHECK_NULL);
1607 }
1608
1609 instanceOop InstanceKlass::allocate_instance(oop java_class,
1610 const char* who,
1611 TRAPS) {
1612 Klass* k = java_lang_Class::as_Klass(java_class);
1613 if (k == nullptr) {
1614 ResourceMark rm(THREAD);
1615 THROW_(vmSymbols::java_lang_InstantiationException(), nullptr);
1616 }
1617 InstanceKlass* ik = cast(k);
1618 ik->check_valid_for_instantiation(false, CHECK_NULL);
1619 ik->initialize(CHECK_NULL);
1620 return ik->allocate_instance(THREAD);
1621 }
1622
1623 instanceHandle InstanceKlass::allocate_instance_handle(TRAPS) {
1624 return instanceHandle(THREAD, allocate_instance(THREAD));
1625 }
1626
1627 void InstanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) {
1628 if (is_interface() || is_abstract()) {
1629 ResourceMark rm(THREAD);
1630 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
1631 : vmSymbols::java_lang_InstantiationException(), external_name());
1694 // Hide the existence of the initializer for the purpose of replaying the compile
1695 return;
1696 }
1697
1698 #if INCLUDE_CDS
1699 // This is needed to ensure the consistency of the archived heap objects.
1700 if (has_aot_initialized_mirror() && CDSConfig::is_loading_heap()) {
1701 AOTClassInitializer::call_runtime_setup(THREAD, this);
1702 return;
1703 } else if (has_archived_enum_objs()) {
1704 assert(is_shared(), "must be");
1705 bool initialized = CDSEnumKlass::initialize_enum_klass(this, CHECK);
1706 if (initialized) {
1707 return;
1708 }
1709 }
1710 #endif
1711
1712 methodHandle h_method(THREAD, class_initializer());
1713 assert(!is_initialized(), "we cannot initialize twice");
1714
1715 #if 0
1716 // FIXME -- revive this code added to leyden/premain for <clinit> profiling
1717 int init_id = log_class_init(THREAD, this);
1718 if (h_method() != nullptr) {
1719 JavaCallArguments args; // No arguments
1720 JavaValue result(T_VOID);
1721 InstanceKlass* outer = THREAD->set_class_being_initialized(this);
1722 jlong bc_start = (CountBytecodesPerThread ? THREAD->bc_counter_value() : BytecodeCounter::counter_value());
1723
1724 elapsedTimer timer;
1725 {
1726 PerfPauseTimer pt(THREAD->current_rt_call_timer(), THREAD->profile_rt_calls());
1727 PauseRuntimeCallProfiling prcp(THREAD, THREAD->profile_rt_calls());
1728
1729 timer.start();
1730 JavaCalls::call(&result, h_method, &args, THREAD); // Static call (no args)
1731 timer.stop();
1732 }
1733
1734 jlong bc_end = (CountBytecodesPerThread ? THREAD->bc_counter_value() : BytecodeCounter::counter_value());
1735
1736 jlong bc_executed = (bc_end - bc_start);
1737 if (UsePerfData && outer == nullptr) { // outermost clinit
1738 THREAD->inc_clinit_bc_counter_value(bc_executed);
1739 ClassLoader::perf_class_init_bytecodes_count()->inc(bc_executed);
1740 }
1741
1742 THREAD->set_class_being_initialized(outer);
1743
1744 LogStreamHandle(Debug, init) log;
1745 if (log.is_enabled()) {
1746 ResourceMark rm(THREAD);
1747 log.print("%d Initialized in %.3fms (total: " JLONG_FORMAT "ms); ",
1748 init_id, timer.seconds() * 1000.0, ClassLoader::class_init_time_ms());
1749 if (CountBytecodes || CountBytecodesPerThread) {
1750 log.print("executed " JLONG_FORMAT " bytecodes; ", bc_executed);
1751 }
1752 name()->print_value_on(&log);
1753 log.print_cr(" by thread " PTR_FORMAT " \"%s\" (" PTR_FORMAT ")",
1754 p2i(THREAD), THREAD->name(), p2i(this));
1755 }
1756 }
1757 LogTarget(Info, class, init) lt;
1758 if (lt.is_enabled()) {
1759 ResourceMark rm(THREAD);
1760 LogStream ls(lt);
1761 ls.print("%d Initialized ", init_id);
1762 name()->print_value_on(&ls);
1763 ls.print_cr("%s (" PTR_FORMAT ") by thread \"%s\"",
1764 h_method() == nullptr ? "(no method)" : "", p2i(this),
1765 THREAD->name());
1766 }
1767 #else
1768 LogTarget(Info, class, init) lt;
1769 if (lt.is_enabled()) {
1770 ResourceMark rm(THREAD);
1771 LogStream ls(lt);
1772 ls.print("%d Initializing ", call_class_initializer_counter++);
1773 name()->print_value_on(&ls);
1774 ls.print_cr("%s (" PTR_FORMAT ") by thread \"%s\"",
1775 h_method() == nullptr ? "(no method)" : "", p2i(this),
1776 THREAD->name());
1777 }
1778 if (h_method() != nullptr) {
1779 ThreadInClassInitializer ticl(THREAD, this); // Track class being initialized
1780 JavaCallArguments args; // No arguments
1781 JavaValue result(T_VOID);
1782 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1783 }
1784 #endif
1785 }
1786
1787 // If a class that implements this interface is initialized, is the JVM required
1788 // to first execute a <clinit> method declared in this interface,
1789 // or (if also_check_supers==true) any of the super types of this interface?
1790 //
1791 // JVMS 5.5. Initialization, step 7: Next, if C is a class rather than
1792 // an interface, then let SC be its superclass and let SI1, ..., SIn
1793 // be all superinterfaces of C (whether direct or indirect) that
1794 // declare at least one non-abstract, non-static method.
1795 //
1796 // So when an interface is initialized, it does not look at its
1797 // supers. But a proper class will ensure that all of its supers have
1798 // run their <clinit> methods, except that it disregards interfaces
1799 // that lack a non-static concrete method (i.e., a default method).
1800 // Therefore, you should probably call this method only when the
1801 // current class is a super of some proper class, not an interface.
1802 bool InstanceKlass::interface_needs_clinit_execution_as_super(bool also_check_supers) const {
1803 assert(is_interface(), "must be");
1804
2561 }
2562 }
2563 if (new_jmeths != 0) {
2564 Method::ensure_jmethod_ids(class_loader_data(), new_jmeths);
2565 }
2566 }
2567
2568 // Lookup a jmethodID, null if not found. Do no blocking, no allocations, no handles
2569 jmethodID InstanceKlass::jmethod_id_or_null(Method* method) {
2570 int idnum = method->method_idnum();
2571 jmethodID* jmeths = methods_jmethod_ids_acquire();
2572 return (jmeths != nullptr) ? jmeths[idnum + 1] : nullptr;
2573 }
2574
2575 inline DependencyContext InstanceKlass::dependencies() {
2576 DependencyContext dep_context(&_dep_context, &_dep_context_last_cleaned);
2577 return dep_context;
2578 }
2579
2580 void InstanceKlass::mark_dependent_nmethods(DeoptimizationScope* deopt_scope, KlassDepChange& changes) {
2581 dependencies().mark_dependent_nmethods(deopt_scope, changes, this);
2582 }
2583
2584 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
2585 assert_lock_strong(CodeCache_lock);
2586 dependencies().add_dependent_nmethod(nm);
2587 }
2588
2589 void InstanceKlass::clean_dependency_context() {
2590 dependencies().clean_unloading_dependents();
2591 }
2592
2593 #ifndef PRODUCT
2594 void InstanceKlass::print_dependent_nmethods(bool verbose) {
2595 dependencies().print_dependent_nmethods(verbose);
2596 }
2597
2598 bool InstanceKlass::is_dependent_nmethod(nmethod* nm) {
2599 return dependencies().is_dependent_nmethod(nm);
2600 }
2601 #endif //PRODUCT
2699 for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2700 if (ioe->interface_klass() != nullptr) {
2701 it->push(ioe->interface_klass_addr());
2702 itableMethodEntry* ime = ioe->first_method_entry(this);
2703 int n = klassItable::method_count_for_interface(ioe->interface_klass());
2704 for (int index = 0; index < n; index ++) {
2705 it->push(ime[index].method_addr());
2706 }
2707 }
2708 }
2709 }
2710
2711 it->push(&_nest_host);
2712 it->push(&_nest_members);
2713 it->push(&_permitted_subclasses);
2714 it->push(&_record_components);
2715 }
2716
2717 #if INCLUDE_CDS
2718 void InstanceKlass::remove_unshareable_info() {
2719 if (is_linked()) {
2720 assert(can_be_verified_at_dumptime(), "must be");
2721 // Remember this so we can avoid walking the hierarchy at runtime.
2722 set_verified_at_dump_time();
2723 }
2724 _misc_flags.set_has_init_deps_processed(false);
2725
2726 _misc_flags.set_has_init_deps_processed(false);
2727
2728 Klass::remove_unshareable_info();
2729
2730 if (SystemDictionaryShared::has_class_failed_verification(this)) {
2731 // Classes are attempted to link during dumping and may fail,
2732 // but these classes are still in the dictionary and class list in CLD.
2733 // If the class has failed verification, there is nothing else to remove.
2734 return;
2735 }
2736
2737 // Reset to the 'allocated' state to prevent any premature accessing to
2738 // a shared class at runtime while the class is still being loaded and
2739 // restored. A class' init_state is set to 'loaded' at runtime when it's
2740 // being added to class hierarchy (see InstanceKlass:::add_to_hierarchy()).
2741 _init_state = allocated;
2742
2743 { // Otherwise this needs to take out the Compile_lock.
2744 assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2876
2877 // restore constant pool resolved references
2878 constants()->restore_unshareable_info(CHECK);
2879
2880 if (array_klasses() != nullptr) {
2881 // To get a consistent list of classes we need MultiArray_lock to ensure
2882 // array classes aren't observed while they are being restored.
2883 RecursiveLocker rl(MultiArray_lock, THREAD);
2884 assert(this == array_klasses()->bottom_klass(), "sanity");
2885 // Array classes have null protection domain.
2886 // --> see ArrayKlass::complete_create_array_klass()
2887 array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2888 }
2889
2890 // Initialize @ValueBased class annotation if not already set in the archived klass.
2891 if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation() && !is_value_based()) {
2892 set_is_value_based();
2893 }
2894 }
2895
2896 bool InstanceKlass::can_be_verified_at_dumptime() const {
2897 if (CDSConfig::preserve_all_dumptime_verification_states(this)) {
2898 return true;
2899 }
2900
2901 if (MetaspaceShared::is_in_shared_metaspace(this)) {
2902 // This is a class that was dumped into the base archive, so we know
2903 // it was verified at dump time.
2904 return true;
2905 }
2906
2907 // Check if a class or any of its supertypes has a version older than 50.
2908 // CDS will not perform verification of old classes during dump time because
2909 // without changing the old verifier, the verification constraint cannot be
2910 // retrieved during dump time.
2911 // Verification of archived old classes will be performed during run time.
2912 if (major_version() < 50 /*JAVA_6_VERSION*/) {
2913 return false;
2914 }
2915 if (java_super() != nullptr && !java_super()->can_be_verified_at_dumptime()) {
2916 return false;
2917 }
2918 Array<InstanceKlass*>* interfaces = local_interfaces();
2919 int len = interfaces->length();
2920 for (int i = 0; i < len; i++) {
2921 if (!interfaces->at(i)->can_be_verified_at_dumptime()) {
2922 return false;
2923 }
2924 }
2925 return true;
2926 }
2927
2928 #endif // INCLUDE_CDS
2929
2930 #if INCLUDE_JVMTI
2931 static void clear_all_breakpoints(Method* m) {
3686 static void print_vtable(intptr_t* start, int len, outputStream* st) {
3687 for (int i = 0; i < len; i++) {
3688 intptr_t e = start[i];
3689 st->print("%d : " INTPTR_FORMAT, i, e);
3690 if (MetaspaceObj::is_valid((Metadata*)e)) {
3691 st->print(" ");
3692 ((Metadata*)e)->print_value_on(st);
3693 }
3694 st->cr();
3695 }
3696 }
3697
3698 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3699 return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
3700 }
3701
3702 const char* InstanceKlass::init_state_name() const {
3703 return state_names[init_state()];
3704 }
3705
3706 const char* InstanceKlass::state2name(ClassState s) {
3707 return state_names[s];
3708 }
3709
3710 void InstanceKlass::print_on(outputStream* st) const {
3711 assert(is_klass(), "must be klass");
3712 Klass::print_on(st);
3713
3714 st->print(BULLET"instance size: %d", size_helper()); st->cr();
3715 st->print(BULLET"klass size: %d", size()); st->cr();
3716 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
3717 st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
3718 st->print(BULLET"state: "); st->print_cr("%s", init_state_name());
3719 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3720 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3721 st->print(BULLET"sub: ");
3722 Klass* sub = subklass();
3723 int n;
3724 for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3725 if (n < MaxSubklassPrintSize) {
3726 sub->print_value_on(st);
3727 st->print(" ");
3728 }
3729 }
4019 nullptr;
4020 // caller can be null, for example, during a JVMTI VM_Init hook
4021 if (caller != nullptr) {
4022 info_stream.print(" source: instance of %s", caller->external_name());
4023 } else {
4024 // source is unknown
4025 }
4026 } else {
4027 oop class_loader = loader_data->class_loader();
4028 info_stream.print(" source: %s", class_loader->klass()->external_name());
4029 }
4030 } else {
4031 assert(this->is_shared(), "must be");
4032 if (MetaspaceShared::is_shared_dynamic((void*)this)) {
4033 info_stream.print(" source: shared objects file (top)");
4034 } else {
4035 info_stream.print(" source: shared objects file");
4036 }
4037 }
4038
4039 info_stream.print(" loader:");
4040 if (is_shared()) {
4041 info_stream.print(" %s", SystemDictionaryShared::loader_type_for_shared_class((Klass*)this));
4042 } else if (loader_data == ClassLoaderData::the_null_class_loader_data()) {
4043 info_stream.print(" boot_loader");
4044 } else {
4045 oop class_loader = loader_data->class_loader();
4046 if (class_loader != nullptr) {
4047 info_stream.print(" %s", class_loader->klass()->external_name());
4048 oop cl_name_and_id = java_lang_ClassLoader::nameAndId(class_loader);
4049 if (cl_name_and_id != nullptr) {
4050 info_stream.print(" %s", java_lang_String::as_utf8_string(cl_name_and_id));
4051 }
4052 } else {
4053 info_stream.print(" null");
4054 }
4055 }
4056 msg.info("%s", info_stream.as_string());
4057
4058 if (log_is_enabled(Debug, class, load)) {
4059 stringStream debug_stream;
4060
4061 // Class hierarchy info
4062 debug_stream.print(" klass: " PTR_FORMAT " super: " PTR_FORMAT,
4063 p2i(this), p2i(superklass()));
4064
4065 // Interfaces
4066 if (local_interfaces() != nullptr && local_interfaces()->length() > 0) {
4067 debug_stream.print(" interfaces:");
4068 int length = local_interfaces()->length();
4069 for (int i = 0; i < length; i++) {
4070 debug_stream.print(" " PTR_FORMAT,
4071 p2i(InstanceKlass::cast(local_interfaces()->at(i))));
4072 }
4073 }
4074
4075 // Class loader
|