1 /*
2 * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
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 *
54 #include "logging/logStream.hpp"
55 #include "memory/allocation.inline.hpp"
56 #include "memory/iterator.inline.hpp"
57 #include "memory/metadataFactory.hpp"
58 #include "memory/metaspaceClosure.hpp"
59 #include "memory/oopFactory.hpp"
60 #include "memory/resourceArea.hpp"
61 #include "memory/universe.hpp"
62 #include "oops/fieldStreams.inline.hpp"
63 #include "oops/constantPool.hpp"
64 #include "oops/instanceClassLoaderKlass.hpp"
65 #include "oops/instanceKlass.inline.hpp"
66 #include "oops/instanceMirrorKlass.hpp"
67 #include "oops/instanceOop.hpp"
68 #include "oops/instanceStackChunkKlass.hpp"
69 #include "oops/klass.inline.hpp"
70 #include "oops/method.hpp"
71 #include "oops/oop.inline.hpp"
72 #include "oops/recordComponent.hpp"
73 #include "oops/symbol.hpp"
74 #include "prims/jvmtiExport.hpp"
75 #include "prims/jvmtiRedefineClasses.hpp"
76 #include "prims/jvmtiThreadState.hpp"
77 #include "prims/methodComparator.hpp"
78 #include "runtime/arguments.hpp"
79 #include "runtime/deoptimization.hpp"
80 #include "runtime/atomic.hpp"
81 #include "runtime/fieldDescriptor.inline.hpp"
82 #include "runtime/handles.inline.hpp"
83 #include "runtime/javaCalls.hpp"
84 #include "runtime/javaThread.inline.hpp"
85 #include "runtime/mutexLocker.hpp"
86 #include "runtime/orderAccess.hpp"
87 #include "runtime/os.inline.hpp"
88 #include "runtime/reflectionUtils.hpp"
89 #include "runtime/threads.hpp"
90 #include "services/classLoadingService.hpp"
91 #include "services/finalizerService.hpp"
92 #include "services/threadService.hpp"
93 #include "utilities/dtrace.hpp"
150
151 static inline bool is_class_loader(const Symbol* class_name,
152 const ClassFileParser& parser) {
153 assert(class_name != nullptr, "invariant");
154
155 if (class_name == vmSymbols::java_lang_ClassLoader()) {
156 return true;
157 }
158
159 if (vmClasses::ClassLoader_klass_loaded()) {
160 const Klass* const super_klass = parser.super_klass();
161 if (super_klass != nullptr) {
162 if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
163 return true;
164 }
165 }
166 }
167 return false;
168 }
169
170 static inline bool is_stack_chunk_class(const Symbol* class_name,
171 const ClassLoaderData* loader_data) {
172 return (class_name == vmSymbols::jdk_internal_vm_StackChunk() &&
173 loader_data->is_the_null_class_loader_data());
174 }
175
176 // private: called to verify that k is a static member of this nest.
177 // We know that k is an instance class in the same package and hence the
178 // same classloader.
179 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
180 assert(!is_hidden(), "unexpected hidden class");
181 if (_nest_members == nullptr || _nest_members == Universe::the_empty_short_array()) {
182 if (log_is_enabled(Trace, class, nestmates)) {
183 ResourceMark rm(current);
184 log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
185 k->external_name(), this->external_name());
186 }
187 return false;
188 }
189
422 log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
423 this->external_name(),
424 access ? "" : "NOT ",
425 k->external_name());
426 return access;
427 }
428
429 const char* InstanceKlass::nest_host_error() {
430 if (_nest_host_index == 0) {
431 return nullptr;
432 } else {
433 constantPoolHandle cph(Thread::current(), constants());
434 return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
435 }
436 }
437
438 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
439 const int size = InstanceKlass::size(parser.vtable_size(),
440 parser.itable_size(),
441 nonstatic_oop_map_size(parser.total_oop_map_count()),
442 parser.is_interface());
443
444 const Symbol* const class_name = parser.class_name();
445 assert(class_name != nullptr, "invariant");
446 ClassLoaderData* loader_data = parser.loader_data();
447 assert(loader_data != nullptr, "invariant");
448
449 InstanceKlass* ik;
450
451 // Allocation
452 if (parser.is_instance_ref_klass()) {
453 // java.lang.ref.Reference
454 ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
455 } else if (class_name == vmSymbols::java_lang_Class()) {
456 // mirror - java.lang.Class
457 ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
458 } else if (is_stack_chunk_class(class_name, loader_data)) {
459 // stack chunk
460 ik = new (loader_data, size, THREAD) InstanceStackChunkKlass(parser);
461 } else if (is_class_loader(class_name, parser)) {
462 // class loader - java.lang.ClassLoader
463 ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
464 } else {
465 // normal
466 ik = new (loader_data, size, THREAD) InstanceKlass(parser);
467 }
468
469 // Check for pending exception before adding to the loader data and incrementing
470 // class count. Can get OOM here.
471 if (HAS_PENDING_EXCEPTION) {
472 return nullptr;
473 }
474
475 return ik;
476 }
477
478
479 // copy method ordering from resource area to Metaspace
480 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
481 if (m != nullptr) {
482 // allocate a new array and copy contents (memcpy?)
483 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
484 for (int i = 0; i < m->length(); i++) {
485 _method_ordering->at_put(i, m->at(i));
486 }
487 } else {
488 _method_ordering = Universe::the_empty_int_array();
489 }
490 }
491
492 // create a new array of vtable_indices for default methods
493 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
494 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
495 assert(default_vtable_indices() == nullptr, "only create once");
496 set_default_vtable_indices(vtable_indices);
497 return vtable_indices;
501 return new Monitor(Mutex::safepoint, name);
502 }
503
504 InstanceKlass::InstanceKlass() {
505 assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS");
506 }
507
508 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) :
509 Klass(kind),
510 _nest_members(nullptr),
511 _nest_host(nullptr),
512 _permitted_subclasses(nullptr),
513 _record_components(nullptr),
514 _static_field_size(parser.static_field_size()),
515 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
516 _itable_len(parser.itable_size()),
517 _nest_host_index(0),
518 _init_state(allocated),
519 _reference_type(reference_type),
520 _init_monitor(create_init_monitor("InstanceKlassInitMonitor_lock")),
521 _init_thread(nullptr)
522 {
523 set_vtable_length(parser.vtable_size());
524 set_access_flags(parser.access_flags());
525 if (parser.is_hidden()) set_is_hidden();
526 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
527 false));
528
529 assert(nullptr == _methods, "underlying memory not zeroed?");
530 assert(is_instance_klass(), "is layout incorrect?");
531 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
532 }
533
534 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
535 Array<Method*>* methods) {
536 if (methods != nullptr && methods != Universe::the_empty_method_array() &&
537 !methods->is_shared()) {
538 for (int i = 0; i < methods->length(); i++) {
539 Method* method = methods->at(i);
540 if (method == nullptr) continue; // maybe null if error processing
541 // Only want to delete methods that are not executing for RedefineClasses.
542 // The previous version will point to them so they're not totally dangling
543 assert (!method->on_stack(), "shouldn't be called with methods on stack");
544 MetadataFactory::free_metadata(loader_data, method);
545 }
546 MetadataFactory::free_array<Method*>(loader_data, methods);
547 }
647 (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
648 !secondary_supers()->is_shared()) {
649 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
650 }
651 set_secondary_supers(nullptr);
652
653 deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
654 set_transitive_interfaces(nullptr);
655 set_local_interfaces(nullptr);
656
657 if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->is_shared()) {
658 MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
659 }
660 set_fieldinfo_stream(nullptr);
661
662 if (fields_status() != nullptr && !fields_status()->is_shared()) {
663 MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
664 }
665 set_fields_status(nullptr);
666
667 // If a method from a redefined class is using this constant pool, don't
668 // delete it, yet. The new class's previous version will point to this.
669 if (constants() != nullptr) {
670 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
671 if (!constants()->is_shared()) {
672 MetadataFactory::free_metadata(loader_data, constants());
673 }
674 // Delete any cached resolution errors for the constant pool
675 SystemDictionary::delete_resolution_error(constants());
676
677 set_constants(nullptr);
678 }
679
680 if (inner_classes() != nullptr &&
681 inner_classes() != Universe::the_empty_short_array() &&
682 !inner_classes()->is_shared()) {
683 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
684 }
685 set_inner_classes(nullptr);
686
687 if (nest_members() != nullptr &&
688 nest_members() != Universe::the_empty_short_array() &&
689 !nest_members()->is_shared()) {
690 MetadataFactory::free_array<jushort>(loader_data, nest_members());
691 }
692 set_nest_members(nullptr);
693
694 if (permitted_subclasses() != nullptr &&
695 permitted_subclasses() != Universe::the_empty_short_array() &&
696 !permitted_subclasses()->is_shared()) {
697 MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
698 }
699 set_permitted_subclasses(nullptr);
700
701 // We should deallocate the Annotations instance if it's not in shared spaces.
702 if (annotations() != nullptr && !annotations()->is_shared()) {
703 MetadataFactory::free_metadata(loader_data, annotations());
704 }
705 set_annotations(nullptr);
706
707 SystemDictionaryShared::handle_class_unloading(this);
708
709 #if INCLUDE_CDS_JAVA_HEAP
710 if (CDSConfig::is_dumping_heap()) {
711 HeapShared::remove_scratch_objects(this);
712 }
713 #endif
714 }
715
716 bool InstanceKlass::is_record() const {
717 return _record_components != nullptr &&
718 is_final() &&
719 java_super() == vmClasses::Record_klass();
720 }
860 vmSymbols::java_lang_IncompatibleClassChangeError(),
861 "class %s has interface %s as super class",
862 external_name(),
863 super_klass->external_name()
864 );
865 return false;
866 }
867
868 InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
869 ik_super->link_class_impl(CHECK_false);
870 }
871
872 // link all interfaces implemented by this class before linking this class
873 Array<InstanceKlass*>* interfaces = local_interfaces();
874 int num_interfaces = interfaces->length();
875 for (int index = 0; index < num_interfaces; index++) {
876 InstanceKlass* interk = interfaces->at(index);
877 interk->link_class_impl(CHECK_false);
878 }
879
880 // in case the class is linked in the process of linking its superclasses
881 if (is_linked()) {
882 return true;
883 }
884
885 // trace only the link time for this klass that includes
886 // the verification time
887 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
888 ClassLoader::perf_class_link_selftime(),
889 ClassLoader::perf_classes_linked(),
890 jt->get_thread_stat()->perf_recursion_counts_addr(),
891 jt->get_thread_stat()->perf_timers_addr(),
892 PerfClassTraceTime::CLASS_LINK);
893
894 // verification & rewriting
895 {
896 LockLinkState init_lock(this, jt);
897
898 // rewritten will have been set if loader constraint error found
899 // on an earlier link attempt
1149 }
1150 }
1151 }
1152
1153 // Throw error outside lock
1154 if (throw_error) {
1155 DTRACE_CLASSINIT_PROBE_WAIT(erroneous, -1, wait);
1156 ResourceMark rm(THREAD);
1157 Handle cause(THREAD, get_initialization_error(THREAD));
1158
1159 stringStream ss;
1160 ss.print("Could not initialize class %s", external_name());
1161 if (cause.is_null()) {
1162 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1163 } else {
1164 THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1165 ss.as_string(), cause);
1166 }
1167 }
1168
1169 // Step 7
1170 // Next, if C is a class rather than an interface, initialize it's super class and super
1171 // interfaces.
1172 if (!is_interface()) {
1173 Klass* super_klass = super();
1174 if (super_klass != nullptr && super_klass->should_be_initialized()) {
1175 super_klass->initialize(THREAD);
1176 }
1177 // If C implements any interface that declares a non-static, concrete method,
1178 // the initialization of C triggers initialization of its super interfaces.
1179 // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1180 // having a superinterface that declares, non-static, concrete methods
1181 if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1182 initialize_super_interfaces(THREAD);
1183 }
1184
1185 // If any exceptions, complete abruptly, throwing the same exception as above.
1186 if (HAS_PENDING_EXCEPTION) {
1187 Handle e(THREAD, PENDING_EXCEPTION);
1188 CLEAR_PENDING_EXCEPTION;
1189 {
1190 EXCEPTION_MARK;
1191 add_initialization_error(THREAD, e);
1192 // Locks object, set state, and notify all waiting threads
1193 set_initialization_state_and_notify(initialization_error, THREAD);
1194 CLEAR_PENDING_EXCEPTION;
1195 }
1196 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1197 THROW_OOP(e());
1198 }
1199 }
1200
1201
1202 // Step 8
1203 {
1204 DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1205 if (class_initializer() != nullptr) {
1206 // Timer includes any side effects of class initialization (resolution,
1207 // etc), but not recursive entry into call_class_initializer().
1208 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1209 ClassLoader::perf_class_init_selftime(),
1210 ClassLoader::perf_classes_inited(),
1211 jt->get_thread_stat()->perf_recursion_counts_addr(),
1212 jt->get_thread_stat()->perf_timers_addr(),
1213 PerfClassTraceTime::CLASS_CLINIT);
1214 call_class_initializer(THREAD);
1215 } else {
1216 // The elapsed time is so small it's not worth counting.
1217 if (UsePerfData) {
1218 ClassLoader::perf_classes_inited()->inc();
1219 }
1220 call_class_initializer(THREAD);
1221 }
1222 }
1223
1224 // Step 9
1225 if (!HAS_PENDING_EXCEPTION) {
1226 set_initialization_state_and_notify(fully_initialized, THREAD);
1227 debug_only(vtable().verify(tty, true);)
1228 }
1229 else {
1230 // Step 10 and 11
1231 Handle e(THREAD, PENDING_EXCEPTION);
1232 CLEAR_PENDING_EXCEPTION;
1233 // JVMTI has already reported the pending exception
1234 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1235 JvmtiExport::clear_detected_exception(jt);
1236 {
1237 EXCEPTION_MARK;
1238 add_initialization_error(THREAD, e);
1239 set_initialization_state_and_notify(initialization_error, THREAD);
1240 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
1241 // JVMTI has already reported the pending exception
1242 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1243 JvmtiExport::clear_detected_exception(jt);
1244 }
1245 DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1246 if (e->is_a(vmClasses::Error_klass())) {
1247 THROW_OOP(e());
1248 } else {
1249 JavaCallArguments args(e);
1250 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1536 : vmSymbols::java_lang_InstantiationException(), external_name());
1537 }
1538 if (this == vmClasses::Class_klass()) {
1539 ResourceMark rm(THREAD);
1540 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1541 : vmSymbols::java_lang_IllegalAccessException(), external_name());
1542 }
1543 }
1544
1545 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1546 // Need load-acquire for lock-free read
1547 if (array_klasses_acquire() == nullptr) {
1548 ResourceMark rm(THREAD);
1549 JavaThread *jt = THREAD;
1550 {
1551 // Atomic creation of array_klasses
1552 MutexLocker ma(THREAD, MultiArray_lock);
1553
1554 // Check if update has already taken place
1555 if (array_klasses() == nullptr) {
1556 ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);
1557 // use 'release' to pair with lock-free load
1558 release_set_array_klasses(k);
1559 }
1560 }
1561 }
1562 // array_klasses() will always be set at this point
1563 ObjArrayKlass* oak = array_klasses();
1564 return oak->array_klass(n, THREAD);
1565 }
1566
1567 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1568 // Need load-acquire for lock-free read
1569 ObjArrayKlass* oak = array_klasses_acquire();
1570 if (oak == nullptr) {
1571 return nullptr;
1572 } else {
1573 return oak->array_klass_or_null(n);
1574 }
1575 }
1576
1577 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1578 return array_klass(1, THREAD);
1579 }
1580
1581 ArrayKlass* InstanceKlass::array_klass_or_null() {
1582 return array_klass_or_null(1);
1583 }
1584
1585 static int call_class_initializer_counter = 0; // for debugging
1586
1587 Method* InstanceKlass::class_initializer() const {
1588 Method* clinit = find_method(
1589 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1590 if (clinit != nullptr && clinit->has_valid_initializer_flags()) {
1591 return clinit;
1592 }
1593 return nullptr;
1594 }
1595
1596 void InstanceKlass::call_class_initializer(TRAPS) {
1597 if (ReplayCompiles &&
1598 (ReplaySuppressInitializers == 1 ||
1599 (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1600 // Hide the existence of the initializer for the purpose of replaying the compile
1601 return;
1602 }
1603
1604 #if INCLUDE_CDS
1605 // This is needed to ensure the consistency of the archived heap objects.
1606 if (has_archived_enum_objs()) {
1607 assert(is_shared(), "must be");
1608 bool initialized = HeapShared::initialize_enum_klass(this, CHECK);
1609 if (initialized) {
1610 return;
1621 ls.print("%d Initializing ", call_class_initializer_counter++);
1622 name()->print_value_on(&ls);
1623 ls.print_cr("%s (" PTR_FORMAT ") by thread \"%s\"",
1624 h_method() == nullptr ? "(no method)" : "", p2i(this),
1625 THREAD->name());
1626 }
1627 if (h_method() != nullptr) {
1628 JavaCallArguments args; // No arguments
1629 JavaValue result(T_VOID);
1630 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1631 }
1632 }
1633
1634
1635 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1636 InterpreterOopMap* entry_for) {
1637 // Lazily create the _oop_map_cache at first request
1638 // Lock-free access requires load_acquire.
1639 OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1640 if (oop_map_cache == nullptr) {
1641 MutexLocker x(OopMapCacheAlloc_lock);
1642 // Check if _oop_map_cache was allocated while we were waiting for this lock
1643 if ((oop_map_cache = _oop_map_cache) == nullptr) {
1644 oop_map_cache = new OopMapCache();
1645 // Ensure _oop_map_cache is stable, since it is examined without a lock
1646 Atomic::release_store(&_oop_map_cache, oop_map_cache);
1647 }
1648 }
1649 // _oop_map_cache is constant after init; lookup below does its own locking.
1650 oop_map_cache->lookup(method, bci, entry_for);
1651 }
1652
1653 bool InstanceKlass::contains_field_offset(int offset) {
1654 fieldDescriptor fd;
1655 return find_field_from_offset(offset, false, &fd);
1656 }
1657
1658 FieldInfo InstanceKlass::field(int index) const {
1659 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1660 if (fs.index() == index) {
1661 return fs.to_FieldInfo();
1662 }
1663 }
1664 fatal("Field not found");
1665 return FieldInfo();
1666 }
1667
1668 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1669 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1670 Symbol* f_name = fs.name();
1671 Symbol* f_sig = fs.signature();
1672 if (f_name == name && f_sig == sig) {
1673 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1674 return true;
1675 }
1676 }
1718
1719 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1720 // search order according to newest JVM spec (5.4.3.2, p.167).
1721 // 1) search for field in current klass
1722 if (find_local_field(name, sig, fd)) {
1723 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1724 }
1725 // 2) search for field recursively in direct superinterfaces
1726 if (is_static) {
1727 Klass* intf = find_interface_field(name, sig, fd);
1728 if (intf != nullptr) return intf;
1729 }
1730 // 3) apply field lookup recursively if superclass exists
1731 { Klass* supr = super();
1732 if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1733 }
1734 // 4) otherwise field lookup fails
1735 return nullptr;
1736 }
1737
1738
1739 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1740 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1741 if (fs.offset() == offset) {
1742 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1743 if (fd->is_static() == is_static) return true;
1744 }
1745 }
1746 return false;
1747 }
1748
1749
1750 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1751 Klass* klass = const_cast<InstanceKlass*>(this);
1752 while (klass != nullptr) {
1753 if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1754 return true;
1755 }
1756 klass = klass->super();
1757 }
2109 }
2110
2111 // uncached_lookup_method searches both the local class methods array and all
2112 // superclasses methods arrays, skipping any overpass methods in superclasses,
2113 // and possibly skipping private methods.
2114 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2115 const Symbol* signature,
2116 OverpassLookupMode overpass_mode,
2117 PrivateLookupMode private_mode) const {
2118 OverpassLookupMode overpass_local_mode = overpass_mode;
2119 const Klass* klass = this;
2120 while (klass != nullptr) {
2121 Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2122 signature,
2123 overpass_local_mode,
2124 StaticLookupMode::find,
2125 private_mode);
2126 if (method != nullptr) {
2127 return method;
2128 }
2129 klass = klass->super();
2130 overpass_local_mode = OverpassLookupMode::skip; // Always ignore overpass methods in superclasses
2131 }
2132 return nullptr;
2133 }
2134
2135 #ifdef ASSERT
2136 // search through class hierarchy and return true if this class or
2137 // one of the superclasses was redefined
2138 bool InstanceKlass::has_redefined_this_or_super() const {
2139 const Klass* klass = this;
2140 while (klass != nullptr) {
2141 if (InstanceKlass::cast(klass)->has_been_redefined()) {
2142 return true;
2143 }
2144 klass = klass->super();
2145 }
2146 return false;
2147 }
2148 #endif
2590 int method_table_offset_in_words = ioe->offset()/wordSize;
2591 int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2592
2593 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2594 / itableOffsetEntry::size();
2595
2596 for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2597 if (ioe->interface_klass() != nullptr) {
2598 it->push(ioe->interface_klass_addr());
2599 itableMethodEntry* ime = ioe->first_method_entry(this);
2600 int n = klassItable::method_count_for_interface(ioe->interface_klass());
2601 for (int index = 0; index < n; index ++) {
2602 it->push(ime[index].method_addr());
2603 }
2604 }
2605 }
2606 }
2607
2608 it->push(&_nest_members);
2609 it->push(&_permitted_subclasses);
2610 it->push(&_record_components);
2611 }
2612
2613 #if INCLUDE_CDS
2614 void InstanceKlass::remove_unshareable_info() {
2615
2616 if (is_linked()) {
2617 assert(can_be_verified_at_dumptime(), "must be");
2618 // Remember this so we can avoid walking the hierarchy at runtime.
2619 set_verified_at_dump_time();
2620 }
2621
2622 Klass::remove_unshareable_info();
2623
2624 if (SystemDictionaryShared::has_class_failed_verification(this)) {
2625 // Classes are attempted to link during dumping and may fail,
2626 // but these classes are still in the dictionary and class list in CLD.
2627 // If the class has failed verification, there is nothing else to remove.
2628 return;
2629 }
2630
2634 // being added to class hierarchy (see InstanceKlass:::add_to_hierarchy()).
2635 _init_state = allocated;
2636
2637 { // Otherwise this needs to take out the Compile_lock.
2638 assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2639 init_implementor();
2640 }
2641
2642 constants()->remove_unshareable_info();
2643
2644 for (int i = 0; i < methods()->length(); i++) {
2645 Method* m = methods()->at(i);
2646 m->remove_unshareable_info();
2647 }
2648
2649 // do array classes also.
2650 if (array_klasses() != nullptr) {
2651 array_klasses()->remove_unshareable_info();
2652 }
2653
2654 // These are not allocated from metaspace. They are safe to set to null.
2655 _source_debug_extension = nullptr;
2656 _dep_context = nullptr;
2657 _osr_nmethods_head = nullptr;
2658 #if INCLUDE_JVMTI
2659 _breakpoints = nullptr;
2660 _previous_versions = nullptr;
2661 _cached_class_file = nullptr;
2662 _jvmti_cached_class_field_map = nullptr;
2663 #endif
2664
2665 _init_thread = nullptr;
2666 _methods_jmethod_ids = nullptr;
2667 _jni_ids = nullptr;
2668 _oop_map_cache = nullptr;
2669 // clear _nest_host to ensure re-load at runtime
2670 _nest_host = nullptr;
2671 init_shared_package_entry();
2672 _dep_context_last_cleaned = 0;
2673 _init_monitor = nullptr;
2674
2719 void InstanceKlass::compute_has_loops_flag_for_methods() {
2720 Array<Method*>* methods = this->methods();
2721 for (int index = 0; index < methods->length(); ++index) {
2722 Method* m = methods->at(index);
2723 if (!m->is_overpass()) { // work around JDK-8305771
2724 m->compute_has_loops_flag();
2725 }
2726 }
2727 }
2728
2729 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2730 PackageEntry* pkg_entry, TRAPS) {
2731 // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2732 // before the InstanceKlass is added to the SystemDictionary. Make
2733 // sure the current state is <loaded.
2734 assert(!is_loaded(), "invalid init state");
2735 assert(!shared_loading_failed(), "Must not try to load failed class again");
2736 set_package(loader_data, pkg_entry, CHECK);
2737 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2738
2739 Array<Method*>* methods = this->methods();
2740 int num_methods = methods->length();
2741 for (int index = 0; index < num_methods; ++index) {
2742 methods->at(index)->restore_unshareable_info(CHECK);
2743 }
2744 #if INCLUDE_JVMTI
2745 if (JvmtiExport::has_redefined_a_class()) {
2746 // Reinitialize vtable because RedefineClasses may have changed some
2747 // entries in this vtable for super classes so the CDS vtable might
2748 // point to old or obsolete entries. RedefineClasses doesn't fix up
2749 // vtables in the shared system dictionary, only the main one.
2750 // It also redefines the itable too so fix that too.
2751 // First fix any default methods that point to a super class that may
2752 // have been redefined.
2753 bool trace_name_printed = false;
2754 adjust_default_methods(&trace_name_printed);
2755 vtable().initialize_vtable();
2756 itable().initialize_itable();
2757 }
2758 #endif
2759
2760 // restore constant pool resolved references
2761 constants()->restore_unshareable_info(CHECK);
2762
2763 if (array_klasses() != nullptr) {
2764 // To get a consistent list of classes we need MultiArray_lock to ensure
2765 // array classes aren't observed while they are being restored.
2766 MutexLocker ml(MultiArray_lock);
2767 assert(this == array_klasses()->bottom_klass(), "sanity");
2768 // Array classes have null protection domain.
2769 // --> see ArrayKlass::complete_create_array_klass()
2770 array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
2771 }
2772
2773 // Initialize @ValueBased class annotation
2774 if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation()) {
2775 set_is_value_based();
2776 }
2777
2778 // restore the monitor
2779 _init_monitor = create_init_monitor("InstanceKlassInitMonitorRestored_lock");
2780 }
2781
2782 // Check if a class or any of its supertypes has a version older than 50.
2783 // CDS will not perform verification of old classes during dump time because
2784 // without changing the old verifier, the verification constraint cannot be
2785 // retrieved during dump time.
2786 // Verification of archived old classes will be performed during run time.
2787 bool InstanceKlass::can_be_verified_at_dumptime() const {
2946 } else {
2947 // Adding one to the attribute length in order to store a null terminator
2948 // character could cause an overflow because the attribute length is
2949 // already coded with an u4 in the classfile, but in practice, it's
2950 // unlikely to happen.
2951 assert((length+1) > length, "Overflow checking");
2952 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
2953 for (int i = 0; i < length; i++) {
2954 sde[i] = array[i];
2955 }
2956 sde[length] = '\0';
2957 _source_debug_extension = sde;
2958 }
2959 }
2960
2961 Symbol* InstanceKlass::generic_signature() const { return _constants->generic_signature(); }
2962 u2 InstanceKlass::generic_signature_index() const { return _constants->generic_signature_index(); }
2963 void InstanceKlass::set_generic_signature_index(u2 sig_index) { _constants->set_generic_signature_index(sig_index); }
2964
2965 const char* InstanceKlass::signature_name() const {
2966
2967 // Get the internal name as a c string
2968 const char* src = (const char*) (name()->as_C_string());
2969 const int src_length = (int)strlen(src);
2970
2971 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
2972
2973 // Add L as type indicator
2974 int dest_index = 0;
2975 dest[dest_index++] = JVM_SIGNATURE_CLASS;
2976
2977 // Add the actual class name
2978 for (int src_index = 0; src_index < src_length; ) {
2979 dest[dest_index++] = src[src_index++];
2980 }
2981
2982 if (is_hidden()) { // Replace the last '+' with a '.'.
2983 for (int index = (int)src_length; index > 0; index--) {
2984 if (dest[index] == '+') {
2985 dest[index] = JVM_SIGNATURE_DOT;
2986 break;
2987 }
2988 }
2989 }
2990
2991 // Add the semicolon and the null
2992 dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
2993 dest[dest_index] = '\0';
2994 return dest;
2995 }
3297 jint InstanceKlass::compute_modifier_flags() const {
3298 jint access = access_flags().as_int();
3299
3300 // But check if it happens to be member class.
3301 InnerClassesIterator iter(this);
3302 for (; !iter.done(); iter.next()) {
3303 int ioff = iter.inner_class_info_index();
3304 // Inner class attribute can be zero, skip it.
3305 // Strange but true: JVM spec. allows null inner class refs.
3306 if (ioff == 0) continue;
3307
3308 // only look at classes that are already loaded
3309 // since we are looking for the flags for our self.
3310 Symbol* inner_name = constants()->klass_name_at(ioff);
3311 if (name() == inner_name) {
3312 // This is really a member class.
3313 access = iter.inner_access_flags();
3314 break;
3315 }
3316 }
3317 // Remember to strip ACC_SUPER bit
3318 return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
3319 }
3320
3321 jint InstanceKlass::jvmti_class_status() const {
3322 jint result = 0;
3323
3324 if (is_linked()) {
3325 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3326 }
3327
3328 if (is_initialized()) {
3329 assert(is_linked(), "Class status is not consistent");
3330 result |= JVMTI_CLASS_STATUS_INITIALIZED;
3331 }
3332 if (is_in_error_state()) {
3333 result |= JVMTI_CLASS_STATUS_ERROR;
3334 }
3335 return result;
3336 }
3337
3338 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {
3552 }
3553 osr = osr->osr_link();
3554 }
3555
3556 assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3557 if (best != nullptr && best->comp_level() >= comp_level) {
3558 return best;
3559 }
3560 return nullptr;
3561 }
3562
3563 // -----------------------------------------------------------------------------------------------------
3564 // Printing
3565
3566 #define BULLET " - "
3567
3568 static const char* state_names[] = {
3569 "allocated", "loaded", "being_linked", "linked", "being_initialized", "fully_initialized", "initialization_error"
3570 };
3571
3572 static void print_vtable(intptr_t* start, int len, outputStream* st) {
3573 for (int i = 0; i < len; i++) {
3574 intptr_t e = start[i];
3575 st->print("%d : " INTPTR_FORMAT, i, e);
3576 if (MetaspaceObj::is_valid((Metadata*)e)) {
3577 st->print(" ");
3578 ((Metadata*)e)->print_value_on(st);
3579 }
3580 st->cr();
3581 }
3582 }
3583
3584 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3585 return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
3586 }
3587
3588 const char* InstanceKlass::init_state_name() const {
3589 return state_names[init_state()];
3590 }
3591
3592 void InstanceKlass::print_on(outputStream* st) const {
3593 assert(is_klass(), "must be klass");
3594 Klass::print_on(st);
3595
3596 st->print(BULLET"instance size: %d", size_helper()); st->cr();
3597 st->print(BULLET"klass size: %d", size()); st->cr();
3598 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
3599 st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
3600 st->print(BULLET"state: "); st->print_cr("%s", init_state_name());
3601 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3602 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3603 st->print(BULLET"sub: ");
3604 Klass* sub = subklass();
3605 int n;
3606 for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3607 if (n < MaxSubklassPrintSize) {
3608 sub->print_value_on(st);
3609 st->print(" ");
3610 }
3611 }
3612 if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3613 st->cr();
3614
3615 if (is_interface()) {
3616 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
3617 if (nof_implementors() == 1) {
3618 st->print_cr(BULLET"implementor: ");
3619 st->print(" ");
3620 implementor()->print_value_on(st);
3621 st->cr();
3622 }
3623 }
3624
3625 st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3626 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr();
3627 if (Verbose || WizardMode) {
3628 Array<Method*>* method_array = methods();
3629 for (int i = 0; i < method_array->length(); i++) {
3630 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3631 }
3632 }
3633 st->print(BULLET"method ordering: "); method_ordering()->print_value_on(st); st->cr();
3634 st->print(BULLET"default_methods: "); default_methods()->print_value_on(st); st->cr();
3635 if (Verbose && default_methods() != nullptr) {
3636 Array<Method*>* method_array = default_methods();
3637 for (int i = 0; i < method_array->length(); i++) {
3638 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3639 }
3640 }
3641 if (default_vtable_indices() != nullptr) {
3642 st->print(BULLET"default vtable indices: "); default_vtable_indices()->print_value_on(st); st->cr();
3643 }
3644 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr();
3645 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3646 st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr();
3647 if (class_loader_data() != nullptr) {
3648 st->print(BULLET"class loader data: ");
3649 class_loader_data()->print_value_on(st);
3650 st->cr();
3651 }
3652 if (source_file_name() != nullptr) {
3653 st->print(BULLET"source file: ");
3654 source_file_name()->print_value_on(st);
3655 st->cr();
3656 }
3657 if (source_debug_extension() != nullptr) {
3658 st->print(BULLET"source debug extension: ");
3659 st->print("%s", source_debug_extension());
3660 st->cr();
3661 }
3662 st->print(BULLET"class annotations: "); class_annotations()->print_value_on(st); st->cr();
3663 st->print(BULLET"class type annotations: "); class_type_annotations()->print_value_on(st); st->cr();
3664 st->print(BULLET"field annotations: "); fields_annotations()->print_value_on(st); st->cr();
3665 st->print(BULLET"field type annotations: "); fields_type_annotations()->print_value_on(st); st->cr();
3671 pv_node = pv_node->previous_versions()) {
3672 if (!have_pv)
3673 st->print(BULLET"previous version: ");
3674 have_pv = true;
3675 pv_node->constants()->print_value_on(st);
3676 }
3677 if (have_pv) st->cr();
3678 }
3679
3680 if (generic_signature() != nullptr) {
3681 st->print(BULLET"generic signature: ");
3682 generic_signature()->print_value_on(st);
3683 st->cr();
3684 }
3685 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
3686 st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr();
3687 if (record_components() != nullptr) {
3688 st->print(BULLET"record components: "); record_components()->print_value_on(st); st->cr();
3689 }
3690 st->print(BULLET"permitted subclasses: "); permitted_subclasses()->print_value_on(st); st->cr();
3691 if (java_mirror() != nullptr) {
3692 st->print(BULLET"java mirror: ");
3693 java_mirror()->print_value_on(st);
3694 st->cr();
3695 } else {
3696 st->print_cr(BULLET"java mirror: null");
3697 }
3698 st->print(BULLET"vtable length %d (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3699 if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
3700 st->print(BULLET"itable length %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3701 if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_itable(), itable_length(), st);
3702 st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3703 FieldPrinter print_static_field(st);
3704 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3705 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3706 FieldPrinter print_nonstatic_field(st);
3707 InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3708 ik->print_nonstatic_fields(&print_nonstatic_field);
3709
3710 st->print(BULLET"non-static oop maps: ");
3711 OopMapBlock* map = start_of_nonstatic_oop_maps();
3712 OopMapBlock* end_map = map + nonstatic_oop_map_count();
3713 while (map < end_map) {
3714 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3715 map++;
3716 }
3717 st->cr();
3718 }
3719
3720 void InstanceKlass::print_value_on(outputStream* st) const {
3721 assert(is_klass(), "must be klass");
|
1 /*
2 * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
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 *
54 #include "logging/logStream.hpp"
55 #include "memory/allocation.inline.hpp"
56 #include "memory/iterator.inline.hpp"
57 #include "memory/metadataFactory.hpp"
58 #include "memory/metaspaceClosure.hpp"
59 #include "memory/oopFactory.hpp"
60 #include "memory/resourceArea.hpp"
61 #include "memory/universe.hpp"
62 #include "oops/fieldStreams.inline.hpp"
63 #include "oops/constantPool.hpp"
64 #include "oops/instanceClassLoaderKlass.hpp"
65 #include "oops/instanceKlass.inline.hpp"
66 #include "oops/instanceMirrorKlass.hpp"
67 #include "oops/instanceOop.hpp"
68 #include "oops/instanceStackChunkKlass.hpp"
69 #include "oops/klass.inline.hpp"
70 #include "oops/method.hpp"
71 #include "oops/oop.inline.hpp"
72 #include "oops/recordComponent.hpp"
73 #include "oops/symbol.hpp"
74 #include "oops/inlineKlass.hpp"
75 #include "prims/jvmtiExport.hpp"
76 #include "prims/jvmtiRedefineClasses.hpp"
77 #include "prims/jvmtiThreadState.hpp"
78 #include "prims/methodComparator.hpp"
79 #include "runtime/arguments.hpp"
80 #include "runtime/deoptimization.hpp"
81 #include "runtime/atomic.hpp"
82 #include "runtime/fieldDescriptor.inline.hpp"
83 #include "runtime/handles.inline.hpp"
84 #include "runtime/javaCalls.hpp"
85 #include "runtime/javaThread.inline.hpp"
86 #include "runtime/mutexLocker.hpp"
87 #include "runtime/orderAccess.hpp"
88 #include "runtime/os.inline.hpp"
89 #include "runtime/reflectionUtils.hpp"
90 #include "runtime/threads.hpp"
91 #include "services/classLoadingService.hpp"
92 #include "services/finalizerService.hpp"
93 #include "services/threadService.hpp"
94 #include "utilities/dtrace.hpp"
151
152 static inline bool is_class_loader(const Symbol* class_name,
153 const ClassFileParser& parser) {
154 assert(class_name != nullptr, "invariant");
155
156 if (class_name == vmSymbols::java_lang_ClassLoader()) {
157 return true;
158 }
159
160 if (vmClasses::ClassLoader_klass_loaded()) {
161 const Klass* const super_klass = parser.super_klass();
162 if (super_klass != nullptr) {
163 if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) {
164 return true;
165 }
166 }
167 }
168 return false;
169 }
170
171 bool InstanceKlass::field_is_null_free_inline_type(int index) const {
172 return field(index).field_flags().is_null_free_inline_type();
173 }
174
175 bool InstanceKlass::is_class_in_preload_attribute(Symbol* name) const {
176 if (_preload_classes == nullptr) return false;
177 for (int i = 0; i < _preload_classes->length(); i++) {
178 Symbol* class_name = _constants->klass_at_noresolve(_preload_classes->at(i));
179 if (class_name == name) return true;
180 }
181 return false;
182 }
183
184 static inline bool is_stack_chunk_class(const Symbol* class_name,
185 const ClassLoaderData* loader_data) {
186 return (class_name == vmSymbols::jdk_internal_vm_StackChunk() &&
187 loader_data->is_the_null_class_loader_data());
188 }
189
190 // private: called to verify that k is a static member of this nest.
191 // We know that k is an instance class in the same package and hence the
192 // same classloader.
193 bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const {
194 assert(!is_hidden(), "unexpected hidden class");
195 if (_nest_members == nullptr || _nest_members == Universe::the_empty_short_array()) {
196 if (log_is_enabled(Trace, class, nestmates)) {
197 ResourceMark rm(current);
198 log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
199 k->external_name(), this->external_name());
200 }
201 return false;
202 }
203
436 log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
437 this->external_name(),
438 access ? "" : "NOT ",
439 k->external_name());
440 return access;
441 }
442
443 const char* InstanceKlass::nest_host_error() {
444 if (_nest_host_index == 0) {
445 return nullptr;
446 } else {
447 constantPoolHandle cph(Thread::current(), constants());
448 return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index);
449 }
450 }
451
452 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
453 const int size = InstanceKlass::size(parser.vtable_size(),
454 parser.itable_size(),
455 nonstatic_oop_map_size(parser.total_oop_map_count()),
456 parser.is_interface(),
457 parser.is_inline_type());
458
459 const Symbol* const class_name = parser.class_name();
460 assert(class_name != nullptr, "invariant");
461 ClassLoaderData* loader_data = parser.loader_data();
462 assert(loader_data != nullptr, "invariant");
463
464 InstanceKlass* ik;
465
466 // Allocation
467 if (parser.is_instance_ref_klass()) {
468 // java.lang.ref.Reference
469 ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
470 } else if (class_name == vmSymbols::java_lang_Class()) {
471 // mirror - java.lang.Class
472 ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
473 } else if (is_stack_chunk_class(class_name, loader_data)) {
474 // stack chunk
475 ik = new (loader_data, size, THREAD) InstanceStackChunkKlass(parser);
476 } else if (is_class_loader(class_name, parser)) {
477 // class loader - java.lang.ClassLoader
478 ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
479 } else if (parser.is_inline_type()) {
480 // inline type
481 ik = new (loader_data, size, THREAD) InlineKlass(parser);
482 } else {
483 // normal
484 ik = new (loader_data, size, THREAD) InstanceKlass(parser);
485 }
486
487 // Check for pending exception before adding to the loader data and incrementing
488 // class count. Can get OOM here.
489 if (HAS_PENDING_EXCEPTION) {
490 return nullptr;
491 }
492
493 #ifdef ASSERT
494 ik->bounds_check((address) ik->start_of_vtable(), false, size);
495 ik->bounds_check((address) ik->start_of_itable(), false, size);
496 ik->bounds_check((address) ik->end_of_itable(), true, size);
497 ik->bounds_check((address) ik->end_of_nonstatic_oop_maps(), true, size);
498 #endif //ASSERT
499 return ik;
500 }
501
502 #ifndef PRODUCT
503 bool InstanceKlass::bounds_check(address addr, bool edge_ok, intptr_t size_in_bytes) const {
504 const char* bad = nullptr;
505 address end = nullptr;
506 if (addr < (address)this) {
507 bad = "before";
508 } else if (addr == (address)this) {
509 if (edge_ok) return true;
510 bad = "just before";
511 } else if (addr == (end = (address)this + sizeof(intptr_t) * (size_in_bytes < 0 ? size() : size_in_bytes))) {
512 if (edge_ok) return true;
513 bad = "just after";
514 } else if (addr > end) {
515 bad = "after";
516 } else {
517 return true;
518 }
519 tty->print_cr("%s object bounds: " INTPTR_FORMAT " [" INTPTR_FORMAT ".." INTPTR_FORMAT "]",
520 bad, (intptr_t)addr, (intptr_t)this, (intptr_t)end);
521 Verbose = WizardMode = true; this->print(); //@@
522 return false;
523 }
524 #endif //PRODUCT
525
526 // copy method ordering from resource area to Metaspace
527 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
528 if (m != nullptr) {
529 // allocate a new array and copy contents (memcpy?)
530 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
531 for (int i = 0; i < m->length(); i++) {
532 _method_ordering->at_put(i, m->at(i));
533 }
534 } else {
535 _method_ordering = Universe::the_empty_int_array();
536 }
537 }
538
539 // create a new array of vtable_indices for default methods
540 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
541 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
542 assert(default_vtable_indices() == nullptr, "only create once");
543 set_default_vtable_indices(vtable_indices);
544 return vtable_indices;
548 return new Monitor(Mutex::safepoint, name);
549 }
550
551 InstanceKlass::InstanceKlass() {
552 assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS");
553 }
554
555 InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) :
556 Klass(kind),
557 _nest_members(nullptr),
558 _nest_host(nullptr),
559 _permitted_subclasses(nullptr),
560 _record_components(nullptr),
561 _static_field_size(parser.static_field_size()),
562 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
563 _itable_len(parser.itable_size()),
564 _nest_host_index(0),
565 _init_state(allocated),
566 _reference_type(reference_type),
567 _init_monitor(create_init_monitor("InstanceKlassInitMonitor_lock")),
568 _init_thread(nullptr),
569 _inline_type_field_klasses(nullptr),
570 _preload_classes(nullptr),
571 _adr_inlineklass_fixed_block(nullptr)
572 {
573 set_vtable_length(parser.vtable_size());
574 set_access_flags(parser.access_flags());
575 if (parser.is_hidden()) set_is_hidden();
576 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
577 false));
578 if (parser.has_inline_fields()) {
579 set_has_inline_type_fields();
580 }
581
582 assert(nullptr == _methods, "underlying memory not zeroed?");
583 assert(is_instance_klass(), "is layout incorrect?");
584 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
585 }
586
587 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
588 Array<Method*>* methods) {
589 if (methods != nullptr && methods != Universe::the_empty_method_array() &&
590 !methods->is_shared()) {
591 for (int i = 0; i < methods->length(); i++) {
592 Method* method = methods->at(i);
593 if (method == nullptr) continue; // maybe null if error processing
594 // Only want to delete methods that are not executing for RedefineClasses.
595 // The previous version will point to them so they're not totally dangling
596 assert (!method->on_stack(), "shouldn't be called with methods on stack");
597 MetadataFactory::free_metadata(loader_data, method);
598 }
599 MetadataFactory::free_array<Method*>(loader_data, methods);
600 }
700 (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
701 !secondary_supers()->is_shared()) {
702 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
703 }
704 set_secondary_supers(nullptr);
705
706 deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
707 set_transitive_interfaces(nullptr);
708 set_local_interfaces(nullptr);
709
710 if (fieldinfo_stream() != nullptr && !fieldinfo_stream()->is_shared()) {
711 MetadataFactory::free_array<u1>(loader_data, fieldinfo_stream());
712 }
713 set_fieldinfo_stream(nullptr);
714
715 if (fields_status() != nullptr && !fields_status()->is_shared()) {
716 MetadataFactory::free_array<FieldStatus>(loader_data, fields_status());
717 }
718 set_fields_status(nullptr);
719
720 if (inline_type_field_klasses_array() != nullptr) {
721 MetadataFactory::free_array<InlineKlass*>(loader_data, inline_type_field_klasses_array());
722 }
723 set_inline_type_field_klasses_array(nullptr);
724
725 // If a method from a redefined class is using this constant pool, don't
726 // delete it, yet. The new class's previous version will point to this.
727 if (constants() != nullptr) {
728 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
729 if (!constants()->is_shared()) {
730 MetadataFactory::free_metadata(loader_data, constants());
731 }
732 // Delete any cached resolution errors for the constant pool
733 SystemDictionary::delete_resolution_error(constants());
734
735 set_constants(nullptr);
736 }
737
738 if (inner_classes() != nullptr &&
739 inner_classes() != Universe::the_empty_short_array() &&
740 !inner_classes()->is_shared()) {
741 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
742 }
743 set_inner_classes(nullptr);
744
745 if (nest_members() != nullptr &&
746 nest_members() != Universe::the_empty_short_array() &&
747 !nest_members()->is_shared()) {
748 MetadataFactory::free_array<jushort>(loader_data, nest_members());
749 }
750 set_nest_members(nullptr);
751
752 if (permitted_subclasses() != nullptr &&
753 permitted_subclasses() != Universe::the_empty_short_array() &&
754 !permitted_subclasses()->is_shared()) {
755 MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses());
756 }
757 set_permitted_subclasses(nullptr);
758
759 if (preload_classes() != nullptr &&
760 preload_classes() != Universe::the_empty_short_array() &&
761 !preload_classes()->is_shared()) {
762 MetadataFactory::free_array<jushort>(loader_data, preload_classes());
763 }
764
765 // We should deallocate the Annotations instance if it's not in shared spaces.
766 if (annotations() != nullptr && !annotations()->is_shared()) {
767 MetadataFactory::free_metadata(loader_data, annotations());
768 }
769 set_annotations(nullptr);
770
771 SystemDictionaryShared::handle_class_unloading(this);
772
773 #if INCLUDE_CDS_JAVA_HEAP
774 if (CDSConfig::is_dumping_heap()) {
775 HeapShared::remove_scratch_objects(this);
776 }
777 #endif
778 }
779
780 bool InstanceKlass::is_record() const {
781 return _record_components != nullptr &&
782 is_final() &&
783 java_super() == vmClasses::Record_klass();
784 }
924 vmSymbols::java_lang_IncompatibleClassChangeError(),
925 "class %s has interface %s as super class",
926 external_name(),
927 super_klass->external_name()
928 );
929 return false;
930 }
931
932 InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
933 ik_super->link_class_impl(CHECK_false);
934 }
935
936 // link all interfaces implemented by this class before linking this class
937 Array<InstanceKlass*>* interfaces = local_interfaces();
938 int num_interfaces = interfaces->length();
939 for (int index = 0; index < num_interfaces; index++) {
940 InstanceKlass* interk = interfaces->at(index);
941 interk->link_class_impl(CHECK_false);
942 }
943
944
945 // If a class declares a method that uses an inline class as an argument
946 // type or return inline type, this inline class must be loaded during the
947 // linking of this class because size and properties of the inline class
948 // must be known in order to be able to perform inline type optimizations.
949 // The implementation below is an approximation of this rule, the code
950 // iterates over all methods of the current class (including overridden
951 // methods), not only the methods declared by this class. This
952 // approximation makes the code simpler, and doesn't change the semantic
953 // because classes declaring methods overridden by the current class are
954 // linked (and have performed their own pre-loading) before the linking
955 // of the current class.
956
957
958 // Note:
959 // Inline class types are loaded during
960 // the loading phase (see ClassFileParser::post_process_parsed_stream()).
961 // Inline class types used as element types for array creation
962 // are not pre-loaded. Their loading is triggered by either anewarray
963 // or multianewarray bytecodes.
964
965 // Could it be possible to do the following processing only if the
966 // class uses inline types?
967 if (EnableValhalla) {
968 ResourceMark rm(THREAD);
969 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
970 if (fs.is_null_free_inline_type() && fs.access_flags().is_static()) {
971 Symbol* sig = fs.signature();
972 TempNewSymbol s = Signature::strip_envelope(sig);
973 if (s != name()) {
974 log_info(class, preload)("Preloading class %s during linking of class %s. Cause: a null-free static field is declared with this type", s->as_C_string(), name()->as_C_string());
975 Klass* klass = SystemDictionary::resolve_or_fail(s,
976 Handle(THREAD, class_loader()), Handle(THREAD, protection_domain()), true,
977 CHECK_false);
978 if (HAS_PENDING_EXCEPTION) {
979 log_warning(class, preload)("Preloading of class %s during linking of class %s (cause: null-free static field) failed: %s",
980 s->as_C_string(), name()->as_C_string(), PENDING_EXCEPTION->klass()->name()->as_C_string());
981 return false; // Exception is still pending
982 }
983 log_info(class, preload)("Preloading of class %s during linking of class %s (cause: null-free static field) succeeded",
984 s->as_C_string(), name()->as_C_string());
985 assert(klass != nullptr, "Sanity check");
986 if (!klass->is_inline_klass()) {
987 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
988 err_msg("class %s expects class %s to be a value class but it is an identity class",
989 name()->as_C_string(), klass->external_name()), false);
990 }
991 if (klass->is_abstract()) {
992 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
993 err_msg("Class %s expects class %s to be concrete value class, but it is an abstract class",
994 name()->as_C_string(),
995 InstanceKlass::cast(klass)->external_name()), false);
996 }
997 InstanceKlass* ik = InstanceKlass::cast(klass);
998 if (!ik->is_implicitly_constructible()) {
999 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(),
1000 err_msg("class %s is not implicitly constructible and it is used in a null restricted static field (not supported)",
1001 klass->external_name()), false);
1002 }
1003 // the inline_type_field_klass_array is not updated because of CDS (see verifications in SystemDictionary::load_shared_class())
1004 }
1005 }
1006 }
1007 // Aggressively preloading all classes from the Preload attribute
1008 if (preload_classes() != nullptr) {
1009 HandleMark hm(THREAD);
1010 for (int i = 0; i < preload_classes()->length(); i++) {
1011 if (constants()->tag_at(preload_classes()->at(i)).is_klass()) continue;
1012 Symbol* class_name = constants()->klass_at_noresolve(preload_classes()->at(i));
1013 if (class_name == name()) continue;
1014 log_info(class, preload)("Preloading class %s during linking of class %s because of the class is listed in the Preload attribute", class_name->as_C_string(), name()->as_C_string());
1015 oop loader = class_loader();
1016 oop protection_domain = this->protection_domain();
1017 Klass* klass = SystemDictionary::resolve_or_null(class_name,
1018 Handle(THREAD, loader), Handle(THREAD, protection_domain), THREAD);
1019 if (HAS_PENDING_EXCEPTION) {
1020 CLEAR_PENDING_EXCEPTION;
1021 }
1022 if (klass != nullptr) {
1023 log_info(class, preload)("Preloading of class %s during linking of class %s (cause: Preload attribute) succeeded", class_name->as_C_string(), name()->as_C_string());
1024 if (!klass->is_inline_klass()) {
1025 // Non value class are allowed by the current spec, but it could be an indication of an issue so let's log a warning
1026 log_warning(class, preload)("Preloading class %s during linking of class %s (cause: Preload attribute) but loaded class is not a value class", class_name->as_C_string(), name()->as_C_string());
1027 }
1028 } else {
1029 log_warning(class, preload)("Preloading of class %s during linking of class %s (cause: Preload attribute) failed", class_name->as_C_string(), name()->as_C_string());
1030 }
1031 }
1032 }
1033 }
1034
1035 // in case the class is linked in the process of linking its superclasses
1036 if (is_linked()) {
1037 return true;
1038 }
1039
1040 // trace only the link time for this klass that includes
1041 // the verification time
1042 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
1043 ClassLoader::perf_class_link_selftime(),
1044 ClassLoader::perf_classes_linked(),
1045 jt->get_thread_stat()->perf_recursion_counts_addr(),
1046 jt->get_thread_stat()->perf_timers_addr(),
1047 PerfClassTraceTime::CLASS_LINK);
1048
1049 // verification & rewriting
1050 {
1051 LockLinkState init_lock(this, jt);
1052
1053 // rewritten will have been set if loader constraint error found
1054 // on an earlier link attempt
1304 }
1305 }
1306 }
1307
1308 // Throw error outside lock
1309 if (throw_error) {
1310 DTRACE_CLASSINIT_PROBE_WAIT(erroneous, -1, wait);
1311 ResourceMark rm(THREAD);
1312 Handle cause(THREAD, get_initialization_error(THREAD));
1313
1314 stringStream ss;
1315 ss.print("Could not initialize class %s", external_name());
1316 if (cause.is_null()) {
1317 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string());
1318 } else {
1319 THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),
1320 ss.as_string(), cause);
1321 }
1322 }
1323
1324 // Pre-allocating an instance of the default value
1325 if (is_inline_klass()) {
1326 InlineKlass* vk = InlineKlass::cast(this);
1327 oop val = vk->allocate_instance(THREAD);
1328 if (HAS_PENDING_EXCEPTION) {
1329 Handle e(THREAD, PENDING_EXCEPTION);
1330 CLEAR_PENDING_EXCEPTION;
1331 {
1332 EXCEPTION_MARK;
1333 add_initialization_error(THREAD, e);
1334 // Locks object, set state, and notify all waiting threads
1335 set_initialization_state_and_notify(initialization_error, THREAD);
1336 CLEAR_PENDING_EXCEPTION;
1337 }
1338 THROW_OOP(e());
1339 }
1340 vk->set_default_value(val);
1341 }
1342
1343 // Step 7
1344 // Next, if C is a class rather than an interface, initialize it's super class and super
1345 // interfaces.
1346 if (!is_interface()) {
1347 Klass* super_klass = super();
1348 if (super_klass != nullptr && super_klass->should_be_initialized()) {
1349 super_klass->initialize(THREAD);
1350 }
1351 // If C implements any interface that declares a non-static, concrete method,
1352 // the initialization of C triggers initialization of its super interfaces.
1353 // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
1354 // having a superinterface that declares, non-static, concrete methods
1355 if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1356 initialize_super_interfaces(THREAD);
1357 }
1358
1359 // If any exceptions, complete abruptly, throwing the same exception as above.
1360 if (HAS_PENDING_EXCEPTION) {
1361 Handle e(THREAD, PENDING_EXCEPTION);
1362 CLEAR_PENDING_EXCEPTION;
1363 {
1364 EXCEPTION_MARK;
1365 add_initialization_error(THREAD, e);
1366 // Locks object, set state, and notify all waiting threads
1367 set_initialization_state_and_notify(initialization_error, THREAD);
1368 CLEAR_PENDING_EXCEPTION;
1369 }
1370 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1371 THROW_OOP(e());
1372 }
1373 }
1374
1375 // Step 8
1376 // Initialize classes of inline fields
1377 if (EnableValhalla) {
1378 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1379 if (fs.is_null_free_inline_type()) {
1380 Klass* klass = get_inline_type_field_klass_or_null(fs.index());
1381 if (fs.access_flags().is_static() && klass == nullptr) {
1382 klass = SystemDictionary::resolve_or_fail(field_signature(fs.index())->fundamental_name(THREAD),
1383 Handle(THREAD, class_loader()),
1384 Handle(THREAD, protection_domain()),
1385 true, THREAD);
1386 assert(klass->is_inline_klass(), "Must be");
1387 set_inline_type_field_klass(fs.index(), InlineKlass::cast(klass));
1388 }
1389
1390 if (!HAS_PENDING_EXCEPTION) {
1391 assert(klass != nullptr, "Must be");
1392 InstanceKlass::cast(klass)->initialize(THREAD);
1393 if (fs.access_flags().is_static()) {
1394 if (java_mirror()->obj_field(fs.offset()) == nullptr) {
1395 java_mirror()->obj_field_put(fs.offset(), InlineKlass::cast(klass)->default_value());
1396 }
1397 }
1398 }
1399
1400 if (HAS_PENDING_EXCEPTION) {
1401 Handle e(THREAD, PENDING_EXCEPTION);
1402 CLEAR_PENDING_EXCEPTION;
1403 {
1404 EXCEPTION_MARK;
1405 add_initialization_error(THREAD, e);
1406 // Locks object, set state, and notify all waiting threads
1407 set_initialization_state_and_notify(initialization_error, THREAD);
1408 CLEAR_PENDING_EXCEPTION;
1409 }
1410 THROW_OOP(e());
1411 }
1412 }
1413 }
1414 }
1415
1416
1417 // Step 9
1418 {
1419 DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1420 if (class_initializer() != nullptr) {
1421 // Timer includes any side effects of class initialization (resolution,
1422 // etc), but not recursive entry into call_class_initializer().
1423 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1424 ClassLoader::perf_class_init_selftime(),
1425 ClassLoader::perf_classes_inited(),
1426 jt->get_thread_stat()->perf_recursion_counts_addr(),
1427 jt->get_thread_stat()->perf_timers_addr(),
1428 PerfClassTraceTime::CLASS_CLINIT);
1429 call_class_initializer(THREAD);
1430 } else {
1431 // The elapsed time is so small it's not worth counting.
1432 if (UsePerfData) {
1433 ClassLoader::perf_classes_inited()->inc();
1434 }
1435 call_class_initializer(THREAD);
1436 }
1437 }
1438
1439 // Step 10
1440 if (!HAS_PENDING_EXCEPTION) {
1441 set_initialization_state_and_notify(fully_initialized, THREAD);
1442 debug_only(vtable().verify(tty, true);)
1443 }
1444 else {
1445 // Step 11 and 12
1446 Handle e(THREAD, PENDING_EXCEPTION);
1447 CLEAR_PENDING_EXCEPTION;
1448 // JVMTI has already reported the pending exception
1449 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1450 JvmtiExport::clear_detected_exception(jt);
1451 {
1452 EXCEPTION_MARK;
1453 add_initialization_error(THREAD, e);
1454 set_initialization_state_and_notify(initialization_error, THREAD);
1455 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
1456 // JVMTI has already reported the pending exception
1457 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1458 JvmtiExport::clear_detected_exception(jt);
1459 }
1460 DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1461 if (e->is_a(vmClasses::Error_klass())) {
1462 THROW_OOP(e());
1463 } else {
1464 JavaCallArguments args(e);
1465 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1751 : vmSymbols::java_lang_InstantiationException(), external_name());
1752 }
1753 if (this == vmClasses::Class_klass()) {
1754 ResourceMark rm(THREAD);
1755 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
1756 : vmSymbols::java_lang_IllegalAccessException(), external_name());
1757 }
1758 }
1759
1760 ArrayKlass* InstanceKlass::array_klass(int n, TRAPS) {
1761 // Need load-acquire for lock-free read
1762 if (array_klasses_acquire() == nullptr) {
1763 ResourceMark rm(THREAD);
1764 JavaThread *jt = THREAD;
1765 {
1766 // Atomic creation of array_klasses
1767 MutexLocker ma(THREAD, MultiArray_lock);
1768
1769 // Check if update has already taken place
1770 if (array_klasses() == nullptr) {
1771 ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this,
1772 false, CHECK_NULL);
1773 // use 'release' to pair with lock-free load
1774 release_set_array_klasses(k);
1775 }
1776 }
1777 }
1778 // array_klasses() will always be set at this point
1779 ArrayKlass* ak = array_klasses();
1780 return ak->array_klass(n, THREAD);
1781 }
1782
1783 ArrayKlass* InstanceKlass::array_klass_or_null(int n) {
1784 // Need load-acquire for lock-free read
1785 ArrayKlass* ak = array_klasses_acquire();
1786 if (ak == nullptr) {
1787 return nullptr;
1788 } else {
1789 return ak->array_klass_or_null(n);
1790 }
1791 }
1792
1793 ArrayKlass* InstanceKlass::array_klass(TRAPS) {
1794 return array_klass(1, THREAD);
1795 }
1796
1797 ArrayKlass* InstanceKlass::array_klass_or_null() {
1798 return array_klass_or_null(1);
1799 }
1800
1801 static int call_class_initializer_counter = 0; // for debugging
1802
1803 Method* InstanceKlass::class_initializer() const {
1804 Method* clinit = find_method(
1805 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
1806 if (clinit != nullptr && clinit->is_class_initializer()) {
1807 return clinit;
1808 }
1809 return nullptr;
1810 }
1811
1812 void InstanceKlass::call_class_initializer(TRAPS) {
1813 if (ReplayCompiles &&
1814 (ReplaySuppressInitializers == 1 ||
1815 (ReplaySuppressInitializers >= 2 && class_loader() != nullptr))) {
1816 // Hide the existence of the initializer for the purpose of replaying the compile
1817 return;
1818 }
1819
1820 #if INCLUDE_CDS
1821 // This is needed to ensure the consistency of the archived heap objects.
1822 if (has_archived_enum_objs()) {
1823 assert(is_shared(), "must be");
1824 bool initialized = HeapShared::initialize_enum_klass(this, CHECK);
1825 if (initialized) {
1826 return;
1837 ls.print("%d Initializing ", call_class_initializer_counter++);
1838 name()->print_value_on(&ls);
1839 ls.print_cr("%s (" PTR_FORMAT ") by thread \"%s\"",
1840 h_method() == nullptr ? "(no method)" : "", p2i(this),
1841 THREAD->name());
1842 }
1843 if (h_method() != nullptr) {
1844 JavaCallArguments args; // No arguments
1845 JavaValue result(T_VOID);
1846 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1847 }
1848 }
1849
1850
1851 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1852 InterpreterOopMap* entry_for) {
1853 // Lazily create the _oop_map_cache at first request
1854 // Lock-free access requires load_acquire.
1855 OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
1856 if (oop_map_cache == nullptr) {
1857 MutexLocker x(OopMapCacheAlloc_lock, Mutex::_no_safepoint_check_flag);
1858 // Check if _oop_map_cache was allocated while we were waiting for this lock
1859 if ((oop_map_cache = _oop_map_cache) == nullptr) {
1860 oop_map_cache = new OopMapCache();
1861 // Ensure _oop_map_cache is stable, since it is examined without a lock
1862 Atomic::release_store(&_oop_map_cache, oop_map_cache);
1863 }
1864 }
1865 // _oop_map_cache is constant after init; lookup below does its own locking.
1866 oop_map_cache->lookup(method, bci, entry_for);
1867 }
1868
1869
1870 FieldInfo InstanceKlass::field(int index) const {
1871 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1872 if (fs.index() == index) {
1873 return fs.to_FieldInfo();
1874 }
1875 }
1876 fatal("Field not found");
1877 return FieldInfo();
1878 }
1879
1880 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1881 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1882 Symbol* f_name = fs.name();
1883 Symbol* f_sig = fs.signature();
1884 if (f_name == name && f_sig == sig) {
1885 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1886 return true;
1887 }
1888 }
1930
1931 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
1932 // search order according to newest JVM spec (5.4.3.2, p.167).
1933 // 1) search for field in current klass
1934 if (find_local_field(name, sig, fd)) {
1935 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1936 }
1937 // 2) search for field recursively in direct superinterfaces
1938 if (is_static) {
1939 Klass* intf = find_interface_field(name, sig, fd);
1940 if (intf != nullptr) return intf;
1941 }
1942 // 3) apply field lookup recursively if superclass exists
1943 { Klass* supr = super();
1944 if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1945 }
1946 // 4) otherwise field lookup fails
1947 return nullptr;
1948 }
1949
1950 bool InstanceKlass::contains_field_offset(int offset) {
1951 if (this->is_inline_klass()) {
1952 InlineKlass* vk = InlineKlass::cast(this);
1953 return offset >= vk->first_field_offset() && offset < (vk->first_field_offset() + vk->get_exact_size_in_bytes());
1954 } else {
1955 fieldDescriptor fd;
1956 return find_field_from_offset(offset, false, &fd);
1957 }
1958 }
1959
1960 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1961 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1962 if (fs.offset() == offset) {
1963 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1964 if (fd->is_static() == is_static) return true;
1965 }
1966 }
1967 return false;
1968 }
1969
1970
1971 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1972 Klass* klass = const_cast<InstanceKlass*>(this);
1973 while (klass != nullptr) {
1974 if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1975 return true;
1976 }
1977 klass = klass->super();
1978 }
2330 }
2331
2332 // uncached_lookup_method searches both the local class methods array and all
2333 // superclasses methods arrays, skipping any overpass methods in superclasses,
2334 // and possibly skipping private methods.
2335 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
2336 const Symbol* signature,
2337 OverpassLookupMode overpass_mode,
2338 PrivateLookupMode private_mode) const {
2339 OverpassLookupMode overpass_local_mode = overpass_mode;
2340 const Klass* klass = this;
2341 while (klass != nullptr) {
2342 Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2343 signature,
2344 overpass_local_mode,
2345 StaticLookupMode::find,
2346 private_mode);
2347 if (method != nullptr) {
2348 return method;
2349 }
2350 if (name == vmSymbols::object_initializer_name()) {
2351 break; // <init> is never inherited
2352 }
2353 klass = klass->super();
2354 overpass_local_mode = OverpassLookupMode::skip; // Always ignore overpass methods in superclasses
2355 }
2356 return nullptr;
2357 }
2358
2359 #ifdef ASSERT
2360 // search through class hierarchy and return true if this class or
2361 // one of the superclasses was redefined
2362 bool InstanceKlass::has_redefined_this_or_super() const {
2363 const Klass* klass = this;
2364 while (klass != nullptr) {
2365 if (InstanceKlass::cast(klass)->has_been_redefined()) {
2366 return true;
2367 }
2368 klass = klass->super();
2369 }
2370 return false;
2371 }
2372 #endif
2814 int method_table_offset_in_words = ioe->offset()/wordSize;
2815 int itable_offset_in_words = (int)(start_of_itable() - (intptr_t*)this);
2816
2817 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words)
2818 / itableOffsetEntry::size();
2819
2820 for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2821 if (ioe->interface_klass() != nullptr) {
2822 it->push(ioe->interface_klass_addr());
2823 itableMethodEntry* ime = ioe->first_method_entry(this);
2824 int n = klassItable::method_count_for_interface(ioe->interface_klass());
2825 for (int index = 0; index < n; index ++) {
2826 it->push(ime[index].method_addr());
2827 }
2828 }
2829 }
2830 }
2831
2832 it->push(&_nest_members);
2833 it->push(&_permitted_subclasses);
2834 it->push(&_preload_classes);
2835 it->push(&_record_components);
2836
2837 it->push(&_inline_type_field_klasses, MetaspaceClosure::_writable);
2838 }
2839
2840 #if INCLUDE_CDS
2841 void InstanceKlass::remove_unshareable_info() {
2842
2843 if (is_linked()) {
2844 assert(can_be_verified_at_dumptime(), "must be");
2845 // Remember this so we can avoid walking the hierarchy at runtime.
2846 set_verified_at_dump_time();
2847 }
2848
2849 Klass::remove_unshareable_info();
2850
2851 if (SystemDictionaryShared::has_class_failed_verification(this)) {
2852 // Classes are attempted to link during dumping and may fail,
2853 // but these classes are still in the dictionary and class list in CLD.
2854 // If the class has failed verification, there is nothing else to remove.
2855 return;
2856 }
2857
2861 // being added to class hierarchy (see InstanceKlass:::add_to_hierarchy()).
2862 _init_state = allocated;
2863
2864 { // Otherwise this needs to take out the Compile_lock.
2865 assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
2866 init_implementor();
2867 }
2868
2869 constants()->remove_unshareable_info();
2870
2871 for (int i = 0; i < methods()->length(); i++) {
2872 Method* m = methods()->at(i);
2873 m->remove_unshareable_info();
2874 }
2875
2876 // do array classes also.
2877 if (array_klasses() != nullptr) {
2878 array_klasses()->remove_unshareable_info();
2879 }
2880
2881 // These are not allocated from metaspace. They are safe to set to nullptr.
2882 _source_debug_extension = nullptr;
2883 _dep_context = nullptr;
2884 _osr_nmethods_head = nullptr;
2885 #if INCLUDE_JVMTI
2886 _breakpoints = nullptr;
2887 _previous_versions = nullptr;
2888 _cached_class_file = nullptr;
2889 _jvmti_cached_class_field_map = nullptr;
2890 #endif
2891
2892 _init_thread = nullptr;
2893 _methods_jmethod_ids = nullptr;
2894 _jni_ids = nullptr;
2895 _oop_map_cache = nullptr;
2896 // clear _nest_host to ensure re-load at runtime
2897 _nest_host = nullptr;
2898 init_shared_package_entry();
2899 _dep_context_last_cleaned = 0;
2900 _init_monitor = nullptr;
2901
2946 void InstanceKlass::compute_has_loops_flag_for_methods() {
2947 Array<Method*>* methods = this->methods();
2948 for (int index = 0; index < methods->length(); ++index) {
2949 Method* m = methods->at(index);
2950 if (!m->is_overpass()) { // work around JDK-8305771
2951 m->compute_has_loops_flag();
2952 }
2953 }
2954 }
2955
2956 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
2957 PackageEntry* pkg_entry, TRAPS) {
2958 // InstanceKlass::add_to_hierarchy() sets the init_state to loaded
2959 // before the InstanceKlass is added to the SystemDictionary. Make
2960 // sure the current state is <loaded.
2961 assert(!is_loaded(), "invalid init state");
2962 assert(!shared_loading_failed(), "Must not try to load failed class again");
2963 set_package(loader_data, pkg_entry, CHECK);
2964 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2965
2966 if (is_inline_klass()) {
2967 InlineKlass::cast(this)->initialize_calling_convention(CHECK);
2968 }
2969
2970 Array<Method*>* methods = this->methods();
2971 int num_methods = methods->length();
2972 for (int index = 0; index < num_methods; ++index) {
2973 methods->at(index)->restore_unshareable_info(CHECK);
2974 }
2975 #if INCLUDE_JVMTI
2976 if (JvmtiExport::has_redefined_a_class()) {
2977 // Reinitialize vtable because RedefineClasses may have changed some
2978 // entries in this vtable for super classes so the CDS vtable might
2979 // point to old or obsolete entries. RedefineClasses doesn't fix up
2980 // vtables in the shared system dictionary, only the main one.
2981 // It also redefines the itable too so fix that too.
2982 // First fix any default methods that point to a super class that may
2983 // have been redefined.
2984 bool trace_name_printed = false;
2985 adjust_default_methods(&trace_name_printed);
2986 vtable().initialize_vtable();
2987 itable().initialize_itable();
2988 }
2989 #endif
2990
2991 // restore constant pool resolved references
2992 constants()->restore_unshareable_info(CHECK);
2993
2994 if (array_klasses() != nullptr) {
2995 // To get a consistent list of classes we need MultiArray_lock to ensure
2996 // array classes aren't observed while they are being restored.
2997 MutexLocker ml(MultiArray_lock);
2998 assert(this == ObjArrayKlass::cast(array_klasses())->bottom_klass(), "sanity");
2999 // Array classes have null protection domain.
3000 // --> see ArrayKlass::complete_create_array_klass()
3001 array_klasses()->restore_unshareable_info(class_loader_data(), Handle(), CHECK);
3002 }
3003
3004 // Initialize @ValueBased class annotation
3005 if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation()) {
3006 set_is_value_based();
3007 }
3008
3009 // restore the monitor
3010 _init_monitor = create_init_monitor("InstanceKlassInitMonitorRestored_lock");
3011 }
3012
3013 // Check if a class or any of its supertypes has a version older than 50.
3014 // CDS will not perform verification of old classes during dump time because
3015 // without changing the old verifier, the verification constraint cannot be
3016 // retrieved during dump time.
3017 // Verification of archived old classes will be performed during run time.
3018 bool InstanceKlass::can_be_verified_at_dumptime() const {
3177 } else {
3178 // Adding one to the attribute length in order to store a null terminator
3179 // character could cause an overflow because the attribute length is
3180 // already coded with an u4 in the classfile, but in practice, it's
3181 // unlikely to happen.
3182 assert((length+1) > length, "Overflow checking");
3183 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
3184 for (int i = 0; i < length; i++) {
3185 sde[i] = array[i];
3186 }
3187 sde[length] = '\0';
3188 _source_debug_extension = sde;
3189 }
3190 }
3191
3192 Symbol* InstanceKlass::generic_signature() const { return _constants->generic_signature(); }
3193 u2 InstanceKlass::generic_signature_index() const { return _constants->generic_signature_index(); }
3194 void InstanceKlass::set_generic_signature_index(u2 sig_index) { _constants->set_generic_signature_index(sig_index); }
3195
3196 const char* InstanceKlass::signature_name() const {
3197 return signature_name_of_carrier(JVM_SIGNATURE_CLASS);
3198 }
3199
3200 const char* InstanceKlass::signature_name_of_carrier(char c) const {
3201 // Get the internal name as a c string
3202 const char* src = (const char*) (name()->as_C_string());
3203 const int src_length = (int)strlen(src);
3204
3205 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
3206
3207 // Add L or Q as type indicator
3208 int dest_index = 0;
3209 dest[dest_index++] = c;
3210
3211 // Add the actual class name
3212 for (int src_index = 0; src_index < src_length; ) {
3213 dest[dest_index++] = src[src_index++];
3214 }
3215
3216 if (is_hidden()) { // Replace the last '+' with a '.'.
3217 for (int index = (int)src_length; index > 0; index--) {
3218 if (dest[index] == '+') {
3219 dest[index] = JVM_SIGNATURE_DOT;
3220 break;
3221 }
3222 }
3223 }
3224
3225 // Add the semicolon and the null
3226 dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
3227 dest[dest_index] = '\0';
3228 return dest;
3229 }
3531 jint InstanceKlass::compute_modifier_flags() const {
3532 jint access = access_flags().as_int();
3533
3534 // But check if it happens to be member class.
3535 InnerClassesIterator iter(this);
3536 for (; !iter.done(); iter.next()) {
3537 int ioff = iter.inner_class_info_index();
3538 // Inner class attribute can be zero, skip it.
3539 // Strange but true: JVM spec. allows null inner class refs.
3540 if (ioff == 0) continue;
3541
3542 // only look at classes that are already loaded
3543 // since we are looking for the flags for our self.
3544 Symbol* inner_name = constants()->klass_name_at(ioff);
3545 if (name() == inner_name) {
3546 // This is really a member class.
3547 access = iter.inner_access_flags();
3548 break;
3549 }
3550 }
3551 return (access & JVM_ACC_WRITTEN_FLAGS);
3552 }
3553
3554 jint InstanceKlass::jvmti_class_status() const {
3555 jint result = 0;
3556
3557 if (is_linked()) {
3558 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
3559 }
3560
3561 if (is_initialized()) {
3562 assert(is_linked(), "Class status is not consistent");
3563 result |= JVMTI_CLASS_STATUS_INITIALIZED;
3564 }
3565 if (is_in_error_state()) {
3566 result |= JVMTI_CLASS_STATUS_ERROR;
3567 }
3568 return result;
3569 }
3570
3571 Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPS) {
3785 }
3786 osr = osr->osr_link();
3787 }
3788
3789 assert(match_level == false || best == nullptr, "shouldn't pick up anything if match_level is set");
3790 if (best != nullptr && best->comp_level() >= comp_level) {
3791 return best;
3792 }
3793 return nullptr;
3794 }
3795
3796 // -----------------------------------------------------------------------------------------------------
3797 // Printing
3798
3799 #define BULLET " - "
3800
3801 static const char* state_names[] = {
3802 "allocated", "loaded", "being_linked", "linked", "being_initialized", "fully_initialized", "initialization_error"
3803 };
3804
3805 static void print_vtable(address self, intptr_t* start, int len, outputStream* st) {
3806 ResourceMark rm;
3807 int* forward_refs = NEW_RESOURCE_ARRAY(int, len);
3808 for (int i = 0; i < len; i++) forward_refs[i] = 0;
3809 for (int i = 0; i < len; i++) {
3810 intptr_t e = start[i];
3811 st->print("%d : " INTPTR_FORMAT, i, e);
3812 if (forward_refs[i] != 0) {
3813 int from = forward_refs[i];
3814 int off = (int) start[from];
3815 st->print(" (offset %d <= [%d])", off, from);
3816 }
3817 if (MetaspaceObj::is_valid((Metadata*)e)) {
3818 st->print(" ");
3819 ((Metadata*)e)->print_value_on(st);
3820 } else if (self != nullptr && e > 0 && e < 0x10000) {
3821 address location = self + e;
3822 int index = (int)((intptr_t*)location - start);
3823 st->print(" (offset %d => [%d])", (int)e, index);
3824 if (index >= 0 && index < len)
3825 forward_refs[index] = i;
3826 }
3827 st->cr();
3828 }
3829 }
3830
3831 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3832 return print_vtable(nullptr, reinterpret_cast<intptr_t*>(start), len, st);
3833 }
3834
3835 template<typename T>
3836 static void print_array_on(outputStream* st, Array<T>* array) {
3837 if (array == nullptr) { st->print_cr("nullptr"); return; }
3838 array->print_value_on(st); st->cr();
3839 if (Verbose || WizardMode) {
3840 for (int i = 0; i < array->length(); i++) {
3841 st->print("%d : ", i); array->at(i)->print_value_on(st); st->cr();
3842 }
3843 }
3844 }
3845
3846 static void print_array_on(outputStream* st, Array<int>* array) {
3847 if (array == nullptr) { st->print_cr("nullptr"); return; }
3848 array->print_value_on(st); st->cr();
3849 if (Verbose || WizardMode) {
3850 for (int i = 0; i < array->length(); i++) {
3851 st->print("%d : %d", i, array->at(i)); st->cr();
3852 }
3853 }
3854 }
3855
3856 const char* InstanceKlass::init_state_name() const {
3857 return state_names[init_state()];
3858 }
3859
3860 void InstanceKlass::print_on(outputStream* st) const {
3861 assert(is_klass(), "must be klass");
3862 Klass::print_on(st);
3863
3864 st->print(BULLET"instance size: %d", size_helper()); st->cr();
3865 st->print(BULLET"klass size: %d", size()); st->cr();
3866 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
3867 st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
3868 st->print(BULLET"state: "); st->print_cr("%s", init_state_name());
3869 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3870 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3871 st->print(BULLET"sub: ");
3872 Klass* sub = subklass();
3873 int n;
3874 for (n = 0; sub != nullptr; n++, sub = sub->next_sibling()) {
3875 if (n < MaxSubklassPrintSize) {
3876 sub->print_value_on(st);
3877 st->print(" ");
3878 }
3879 }
3880 if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3881 st->cr();
3882
3883 if (is_interface()) {
3884 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
3885 if (nof_implementors() == 1) {
3886 st->print_cr(BULLET"implementor: ");
3887 st->print(" ");
3888 implementor()->print_value_on(st);
3889 st->cr();
3890 }
3891 }
3892
3893 st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3894 st->print(BULLET"methods: "); print_array_on(st, methods());
3895 st->print(BULLET"method ordering: "); print_array_on(st, method_ordering());
3896 st->print(BULLET"default_methods: "); print_array_on(st, default_methods());
3897 if (default_vtable_indices() != nullptr) {
3898 st->print(BULLET"default vtable indices: "); print_array_on(st, default_vtable_indices());
3899 }
3900 st->print(BULLET"local interfaces: "); print_array_on(st, local_interfaces());
3901 st->print(BULLET"trans. interfaces: "); print_array_on(st, transitive_interfaces());
3902 st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr();
3903 if (class_loader_data() != nullptr) {
3904 st->print(BULLET"class loader data: ");
3905 class_loader_data()->print_value_on(st);
3906 st->cr();
3907 }
3908 if (source_file_name() != nullptr) {
3909 st->print(BULLET"source file: ");
3910 source_file_name()->print_value_on(st);
3911 st->cr();
3912 }
3913 if (source_debug_extension() != nullptr) {
3914 st->print(BULLET"source debug extension: ");
3915 st->print("%s", source_debug_extension());
3916 st->cr();
3917 }
3918 st->print(BULLET"class annotations: "); class_annotations()->print_value_on(st); st->cr();
3919 st->print(BULLET"class type annotations: "); class_type_annotations()->print_value_on(st); st->cr();
3920 st->print(BULLET"field annotations: "); fields_annotations()->print_value_on(st); st->cr();
3921 st->print(BULLET"field type annotations: "); fields_type_annotations()->print_value_on(st); st->cr();
3927 pv_node = pv_node->previous_versions()) {
3928 if (!have_pv)
3929 st->print(BULLET"previous version: ");
3930 have_pv = true;
3931 pv_node->constants()->print_value_on(st);
3932 }
3933 if (have_pv) st->cr();
3934 }
3935
3936 if (generic_signature() != nullptr) {
3937 st->print(BULLET"generic signature: ");
3938 generic_signature()->print_value_on(st);
3939 st->cr();
3940 }
3941 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
3942 st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr();
3943 if (record_components() != nullptr) {
3944 st->print(BULLET"record components: "); record_components()->print_value_on(st); st->cr();
3945 }
3946 st->print(BULLET"permitted subclasses: "); permitted_subclasses()->print_value_on(st); st->cr();
3947 st->print(BULLET"preload classes: "); preload_classes()->print_value_on(st); st->cr();
3948 if (java_mirror() != nullptr) {
3949 st->print(BULLET"java mirror: ");
3950 java_mirror()->print_value_on(st);
3951 st->cr();
3952 } else {
3953 st->print_cr(BULLET"java mirror: null");
3954 }
3955 st->print(BULLET"vtable length %d (start addr: " PTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3956 if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
3957 st->print(BULLET"itable length %d (start addr: " PTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3958 if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(nullptr, start_of_itable(), itable_length(), st);
3959 st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3960 FieldPrinter print_static_field(st);
3961 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3962 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3963 FieldPrinter print_nonstatic_field(st);
3964 InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3965 ik->print_nonstatic_fields(&print_nonstatic_field);
3966
3967 st->print(BULLET"non-static oop maps: ");
3968 OopMapBlock* map = start_of_nonstatic_oop_maps();
3969 OopMapBlock* end_map = map + nonstatic_oop_map_count();
3970 while (map < end_map) {
3971 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3972 map++;
3973 }
3974 st->cr();
3975 }
3976
3977 void InstanceKlass::print_value_on(outputStream* st) const {
3978 assert(is_klass(), "must be klass");
|