49
#include "precompiled.hpp"
50
#include "classfile/classLoaderData.inline.hpp"
51
#include "classfile/classLoaderDataGraph.inline.hpp"
52
#include "classfile/dictionary.hpp"
53
#include "classfile/javaClasses.inline.hpp"
54
#include "classfile/moduleEntry.hpp"
55
#include "classfile/packageEntry.hpp"
56
#include "classfile/symbolTable.hpp"
57
#include "classfile/systemDictionary.hpp"
58
#include "classfile/systemDictionaryShared.hpp"
59
#include "classfile/vmClasses.hpp"
60
#include "logging/log.hpp"
61
#include "logging/logStream.hpp"
62
#include "memory/allocation.inline.hpp"
63
#include "memory/classLoaderMetaspace.hpp"
64
#include "memory/metadataFactory.hpp"
65
#include "memory/metaspace.hpp"
66
#include "memory/resourceArea.hpp"
67
#include "memory/universe.hpp"
68
#include "oops/access.inline.hpp"
69
#include "oops/klass.inline.hpp"
70
#include "oops/oop.inline.hpp"
71
#include "oops/oopHandle.inline.hpp"
72
#include "oops/verifyOopClosure.hpp"
73
#include "oops/weakHandle.inline.hpp"
74
#include "runtime/arguments.hpp"
75
#include "runtime/atomic.hpp"
76
#include "runtime/handles.inline.hpp"
77
#include "runtime/mutex.hpp"
78
#include "runtime/safepoint.hpp"
79
#include "utilities/growableArray.hpp"
80
#include "utilities/macros.hpp"
81
#include "utilities/ostream.hpp"
83
ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = nullptr;
85
void ClassLoaderData::init_null_class_loader_data() {
86
assert(_the_null_class_loader_data == nullptr, "cannot initialize twice");
87
assert(ClassLoaderDataGraph::_head == nullptr, "cannot initialize twice");
89
_the_null_class_loader_data = new ClassLoaderData(Handle(), false);
90
ClassLoaderDataGraph::_head = _the_null_class_loader_data;
91
assert(_the_null_class_loader_data->is_the_null_class_loader_data(), "Must be");
93
LogTarget(Trace, class, loader, data) lt;
94
if (lt.is_enabled()) {
98
_the_null_class_loader_data->print_value_on(&ls);
107
void ClassLoaderData::initialize_name(Handle class_loader) {
112
oop cl_name = java_lang_ClassLoader::name(class_loader());
113
if (cl_name != nullptr) {
114
const char* cl_instance_name = java_lang_String::as_utf8_string(cl_name);
116
if (cl_instance_name != nullptr && cl_instance_name[0] != '\0') {
117
_name = SymbolTable::new_symbol(cl_instance_name);
128
oop cl_name_and_id = java_lang_ClassLoader::nameAndId(class_loader());
129
const char* cl_instance_name_and_id =
130
(cl_name_and_id == nullptr) ? _class_loader_klass->external_name() :
131
java_lang_String::as_utf8_string(cl_name_and_id);
132
assert(cl_instance_name_and_id != nullptr && cl_instance_name_and_id[0] != '\0', "class loader has no name and id");
133
_name_and_id = SymbolTable::new_symbol(cl_instance_name_and_id);
136
ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool has_class_mirror_holder) :
138
_metaspace_lock(new Mutex(Mutex::nosafepoint-2, "MetaspaceAllocation_lock")),
139
_unloading(false), _has_class_mirror_holder(has_class_mirror_holder),
140
_modified_oops(true),
144
_keep_alive((has_class_mirror_holder || h_class_loader.is_null()) ? 1 : 0),
147
_klasses(nullptr), _packages(nullptr), _modules(nullptr), _unnamed_module(nullptr), _dictionary(nullptr),
148
_jmethod_ids(nullptr),
149
_deallocate_list(nullptr),
151
_unloading_next(nullptr),
152
_class_loader_klass(nullptr), _name(nullptr), _name_and_id(nullptr) {
154
if (!h_class_loader.is_null()) {
155
_class_loader = _handles.add(h_class_loader());
156
_class_loader_klass = h_class_loader->klass();
157
initialize_name(h_class_loader);
160
if (!has_class_mirror_holder) {
163
initialize_holder(h_class_loader);
167
_packages = new PackageEntryTable();
168
if (h_class_loader.is_null()) {
170
_unnamed_module = ModuleEntry::create_boot_unnamed_module(this);
173
_unnamed_module = ModuleEntry::create_unnamed_module(this);
175
_dictionary = create_dictionary();
178
NOT_PRODUCT(_dependency_count = 0);
180
JFR_ONLY(INIT_ID(this);)
183
ClassLoaderData::ChunkedHandleList::~ChunkedHandleList() {
185
while (c != nullptr) {
186
Chunk* next = c->_next;
192
OopHandle ClassLoaderData::ChunkedHandleList::add(oop o) {
193
if (_head == nullptr || _head->_size == Chunk::CAPACITY) {
194
Chunk* next = new Chunk(_head);
195
Atomic::release_store(&_head, next);
197
oop* handle = &_head->_data[_head->_size];
198
NativeAccess<IS_DEST_UNINITIALIZED>::oop_store(handle, o);
199
Atomic::release_store(&_head->_size, _head->_size + 1);
200
return OopHandle(handle);
203
int ClassLoaderData::ChunkedHandleList::count() const {
205
Chunk* chunk = Atomic::load_acquire(&_head);
206
while (chunk != nullptr) {
207
count += Atomic::load(&chunk->_size);
208
chunk = chunk->_next;
213
inline void ClassLoaderData::ChunkedHandleList::oops_do_chunk(OopClosure* f, Chunk* c, const juint size) {
214
for (juint i = 0; i < size; i++) {
215
f->do_oop(&c->_data[i]);
219
void ClassLoaderData::ChunkedHandleList::oops_do(OopClosure* f) {
220
Chunk* head = Atomic::load_acquire(&_head);
221
if (head != nullptr) {
223
oops_do_chunk(f, head, Atomic::load_acquire(&head->_size));
224
for (Chunk* c = head->_next; c != nullptr; c = c->_next) {
225
oops_do_chunk(f, c, c->_size);
230
class VerifyContainsOopClosure : public OopClosure {
235
VerifyContainsOopClosure(oop target) : _target(target), _found(false) {}
237
void do_oop(oop* p) {
238
if (p != nullptr && NativeAccess<AS_NO_KEEPALIVE>::oop_load(p) == _target) {
243
void do_oop(narrowOop* p) {
245
ShouldNotReachHere();
253
bool ClassLoaderData::ChunkedHandleList::contains(oop p) {
254
VerifyContainsOopClosure cl(p);
260
bool ClassLoaderData::ChunkedHandleList::owner_of(oop* oop_handle) {
261
Chunk* chunk = Atomic::load_acquire(&_head);
262
while (chunk != nullptr) {
263
if (&(chunk->_data[0]) <= oop_handle && oop_handle < &(chunk->_data[Atomic::load(&chunk->_size)])) {
266
chunk = chunk->_next;
272
void ClassLoaderData::clear_claim(int claim) {
274
int old_claim = Atomic::load(&_claim);
275
if ((old_claim & claim) == 0) {
278
int new_claim = old_claim & ~claim;
279
if (Atomic::cmpxchg(&_claim, old_claim, new_claim) == old_claim) {
286
void ClassLoaderData::verify_not_claimed(int claim) {
287
assert((_claim & claim) == 0, "Found claim: %d bits in _claim: %d", claim, _claim);
291
bool ClassLoaderData::try_claim(int claim) {
293
int old_claim = Atomic::load(&_claim);
294
if ((old_claim & claim) == claim) {
297
int new_claim = old_claim | claim;
298
if (Atomic::cmpxchg(&_claim, old_claim, new_claim) == old_claim) {
304
void ClassLoaderData::demote_strong_roots() {
322
class TransitionRootsOopClosure : public OopClosure {
324
virtual void do_oop(oop* p) {
333
oop obj = NativeAccess<>::oop_load(p);
334
NativeAccess<>::oop_store(p, obj);
337
virtual void do_oop(narrowOop* p) {
338
ShouldNotReachHere();
341
oops_do(&cl, ClassLoaderData::_claim_none, false );
349
void ClassLoaderData::inc_keep_alive() {
350
if (has_class_mirror_holder()) {
351
assert(_keep_alive > 0, "Invalid keep alive increment count");
356
void ClassLoaderData::dec_keep_alive() {
357
if (has_class_mirror_holder()) {
358
assert(_keep_alive > 0, "Invalid keep alive decrement count");
359
if (_keep_alive == 1) {
365
demote_strong_roots();
371
void ClassLoaderData::oops_do(OopClosure* f, int claim_value, bool clear_mod_oops) {
372
if (claim_value != ClassLoaderData::_claim_none && !try_claim(claim_value)) {
377
if (clear_mod_oops) {
378
clear_modified_oops();
384
void ClassLoaderData::classes_do(KlassClosure* klass_closure) {
386
for (Klass* k = Atomic::load_acquire(&_klasses); k != nullptr; k = k->next_link()) {
387
klass_closure->do_klass(k);
388
assert(k != k->next_link(), "no loops!");
392
void ClassLoaderData::classes_do(void f(Klass * const)) {
394
for (Klass* k = Atomic::load_acquire(&_klasses); k != nullptr; k = k->next_link()) {
396
assert(k != k->next_link(), "no loops!");
400
void ClassLoaderData::methods_do(void f(Method*)) {
402
for (Klass* k = Atomic::load_acquire(&_klasses); k != nullptr; k = k->next_link()) {
403
if (k->is_instance_klass() && InstanceKlass::cast(k)->is_loaded()) {
404
InstanceKlass::cast(k)->methods_do(f);
409
void ClassLoaderData::loaded_classes_do(KlassClosure* klass_closure) {
411
for (Klass* k = Atomic::load_acquire(&_klasses); k != nullptr; k = k->next_link()) {
414
if (k->is_instance_klass()) {
415
if (!InstanceKlass::cast(k)->is_loaded()) {
418
} else if (k->is_shared() && k->is_objArray_klass()) {
419
Klass* bottom = ObjArrayKlass::cast(k)->bottom_klass();
420
if (bottom->is_instance_klass() && !InstanceKlass::cast(bottom)->is_loaded()) {
429
oop m = k->java_mirror();
430
assert(m != nullptr, "nullptr mirror");
431
assert(m->is_a(vmClasses::Class_klass()), "invalid mirror");
433
klass_closure->do_klass(k);
437
void ClassLoaderData::classes_do(void f(InstanceKlass*)) {
439
for (Klass* k = Atomic::load_acquire(&_klasses); k != nullptr; k = k->next_link()) {
440
if (k->is_instance_klass()) {
441
f(InstanceKlass::cast(k));
443
assert(k != k->next_link(), "no loops!");
447
void ClassLoaderData::modules_do(void f(ModuleEntry*)) {
448
assert_locked_or_safepoint(Module_lock);
449
if (_unnamed_module != nullptr) {
452
if (_modules != nullptr) {
453
_modules->modules_do(f);
457
void ClassLoaderData::packages_do(void f(PackageEntry*)) {
458
assert_locked_or_safepoint(Module_lock);
459
if (_packages != nullptr) {
460
_packages->packages_do(f);
464
void ClassLoaderData::record_dependency(const Klass* k) {
465
assert(k != nullptr, "invariant");
467
ClassLoaderData * const from_cld = this;
468
ClassLoaderData * const to_cld = k->class_loader_data();
474
if (to_cld->is_permanent_class_loader_data()) {
479
if (to_cld->has_class_mirror_holder()) {
483
if (to_cld == from_cld) {
487
to = k->java_mirror();
489
to = to_cld->class_loader();
490
oop from = from_cld->class_loader();
494
if (from == to || java_lang_ClassLoader::isAncestor(from, to)) {
500
if (!_handles.contains(to)) {
501
NOT_PRODUCT(Atomic::inc(&_dependency_count));
502
LogTarget(Trace, class, loader, data) lt;
503
if (lt.is_enabled()) {
506
ls.print("adding dependency from ");
509
to_cld->print_value_on(&ls);
512
Handle dependency(Thread::current(), to);
513
add_handle(dependency);
515
record_modified_oops();
519
void ClassLoaderData::add_class(Klass* k, bool publicize ) {
521
MutexLocker ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
522
Klass* old_value = _klasses;
523
k->set_next_link(old_value);
526
Atomic::release_store(&_klasses, k);
527
if (k->is_array_klass()) {
528
ClassLoaderDataGraph::inc_array_classes(1);
530
ClassLoaderDataGraph::inc_instance_classes(1);
535
LogTarget(Trace, class, loader, data) lt;
536
if (lt.is_enabled()) {
539
ls.print("Adding k: " PTR_FORMAT " %s to ", p2i(k), k->external_name());
546
void ClassLoaderData::initialize_holder(Handle loader_or_mirror) {
547
if (loader_or_mirror() != nullptr) {
548
assert(_holder.is_null(), "never replace holders");
549
_holder = WeakHandle(Universe::vm_weak(), loader_or_mirror);
555
void ClassLoaderData::remove_class(Klass* scratch_class) {
556
assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
558
Klass* prev = nullptr;
559
for (Klass* k = _klasses; k != nullptr; k = k->next_link()) {
560
if (k == scratch_class) {
561
if (prev == nullptr) {
562
_klasses = k->next_link();
564
Klass* next = k->next_link();
565
prev->set_next_link(next);
568
if (k->is_array_klass()) {
569
ClassLoaderDataGraph::dec_array_classes(1);
571
ClassLoaderDataGraph::dec_instance_classes(1);
577
assert(k != k->next_link(), "no loops!");
579
ShouldNotReachHere();
582
void ClassLoaderData::unload() {
585
LogTarget(Trace, class, loader, data) lt;
586
if (lt.is_enabled()) {
596
free_deallocate_list_C_heap_structures();
601
classes_do(InstanceKlass::unload_class);
614
if (_jmethod_ids != nullptr) {
615
Method::clear_jmethod_ids(this);
619
ModuleEntryTable* ClassLoaderData::modules() {
622
ModuleEntryTable* modules = Atomic::load_acquire(&_modules);
623
if (modules == nullptr) {
624
MutexLocker m1(Module_lock);
626
if ((modules = _modules) == nullptr) {
627
modules = new ModuleEntryTable();
630
MutexLocker m1(metaspace_lock(), Mutex::_no_safepoint_check_flag);
632
Atomic::release_store(&_modules, modules);
639
const int _boot_loader_dictionary_size = 1009;
640
const int _default_loader_dictionary_size = 107;
642
Dictionary* ClassLoaderData::create_dictionary() {
643
assert(!has_class_mirror_holder(), "class mirror holder cld does not have a dictionary");
645
if (_the_null_class_loader_data == nullptr) {
646
size = _boot_loader_dictionary_size;
647
} else if (class_loader()->is_a(vmClasses::reflect_DelegatingClassLoader_klass())) {
649
} else if (is_system_class_loader_data()) {
650
size = _boot_loader_dictionary_size;
652
size = _default_loader_dictionary_size;
654
return new Dictionary(this, size);
659
oop ClassLoaderData::holder() const {
665
if (!_holder.is_null()) {
666
return _holder.resolve();
673
oop ClassLoaderData::holder_no_keepalive() const {
674
if (!_holder.is_null()) {
675
return _holder.peek();
682
bool ClassLoaderData::is_alive() const {
683
bool alive = keep_alive()
684
|| (_holder.peek() != nullptr);
689
class ReleaseKlassClosure: public KlassClosure {
691
size_t _instance_class_released;
692
size_t _array_class_released;
694
ReleaseKlassClosure() : _instance_class_released(0), _array_class_released(0) { }
696
size_t instance_class_released() const { return _instance_class_released; }
697
size_t array_class_released() const { return _array_class_released; }
699
void do_klass(Klass* k) {
700
if (k->is_array_klass()) {
701
_array_class_released ++;
703
assert(k->is_instance_klass(), "Must be");
704
_instance_class_released ++;
706
k->release_C_heap_structures();
710
ClassLoaderData::~ClassLoaderData() {
712
ReleaseKlassClosure cl;
715
ClassLoaderDataGraph::dec_array_classes(cl.array_class_released());
716
ClassLoaderDataGraph::dec_instance_classes(cl.instance_class_released());
719
_holder.release(Universe::vm_weak());
722
if (_packages != nullptr) {
729
if (_modules != nullptr) {
736
if (_dictionary != nullptr) {
739
_dictionary = nullptr;
742
if (_unnamed_module != nullptr) {
743
delete _unnamed_module;
744
_unnamed_module = nullptr;
748
ClassLoaderMetaspace *m = _metaspace;
750
_metaspace = nullptr;
755
delete _metaspace_lock;
758
if (_deallocate_list != nullptr) {
759
delete _deallocate_list;
763
if (_name != nullptr) {
764
_name->decrement_refcount();
766
if (_name_and_id != nullptr) {
767
_name_and_id->decrement_refcount();
774
bool ClassLoaderData::is_system_class_loader_data() const {
775
return SystemDictionary::is_system_class_loader(class_loader());
780
bool ClassLoaderData::is_platform_class_loader_data() const {
781
return SystemDictionary::is_platform_class_loader(class_loader());
789
bool ClassLoaderData::is_builtin_class_loader_data() const {
790
return (is_boot_class_loader_data() ||
791
SystemDictionary::is_system_class_loader(class_loader()) ||
792
SystemDictionary::is_platform_class_loader(class_loader()));
798
bool ClassLoaderData::is_permanent_class_loader_data() const {
799
return is_builtin_class_loader_data() && !has_class_mirror_holder();
802
ClassLoaderMetaspace* ClassLoaderData::metaspace_non_null() {
808
ClassLoaderMetaspace* metaspace = Atomic::load_acquire(&_metaspace);
809
if (metaspace == nullptr) {
810
MutexLocker ml(_metaspace_lock, Mutex::_no_safepoint_check_flag);
812
if ((metaspace = _metaspace) == nullptr) {
813
if (this == the_null_class_loader_data()) {
814
assert (class_loader() == nullptr, "Must be");
815
metaspace = new ClassLoaderMetaspace(_metaspace_lock, Metaspace::BootMetaspaceType);
816
} else if (has_class_mirror_holder()) {
817
metaspace = new ClassLoaderMetaspace(_metaspace_lock, Metaspace::ClassMirrorHolderMetaspaceType);
818
} else if (class_loader()->is_a(vmClasses::reflect_DelegatingClassLoader_klass())) {
819
metaspace = new ClassLoaderMetaspace(_metaspace_lock, Metaspace::ReflectionMetaspaceType);
821
metaspace = new ClassLoaderMetaspace(_metaspace_lock, Metaspace::StandardMetaspaceType);
824
Atomic::release_store(&_metaspace, metaspace);
830
OopHandle ClassLoaderData::add_handle(Handle h) {
831
MutexLocker ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
832
record_modified_oops();
833
return _handles.add(h());
836
void ClassLoaderData::remove_handle(OopHandle h) {
837
assert(!is_unloading(), "Do not remove a handle for a CLD that is unloading");
839
assert(_handles.owner_of(h.ptr_raw()),
840
"Got unexpected handle " PTR_FORMAT, p2i(h.ptr_raw()));
841
h.replace(oop(nullptr));
845
void ClassLoaderData::init_handle_locked(OopHandle& dest, Handle h) {
846
MutexLocker ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
847
if (dest.resolve() != nullptr) {
850
record_modified_oops();
851
dest = _handles.add(h());
857
void ClassLoaderData::add_to_deallocate_list(Metadata* m) {
859
if (!m->is_shared()) {
860
MutexLocker ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
861
if (_deallocate_list == nullptr) {
862
_deallocate_list = new (mtClass) GrowableArray<Metadata*>(100, mtClass);
864
_deallocate_list->append_if_missing(m);
866
log_debug(class, loader, data)("deallocate added for %s", m->print_value_string());
867
ClassLoaderDataGraph::set_should_clean_deallocate_lists();
872
void ClassLoaderData::free_deallocate_list() {
875
assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
876
assert(!is_unloading(), "only called for ClassLoaderData that are not unloading");
877
if (_deallocate_list == nullptr) {
881
for (int i = _deallocate_list->length() - 1; i >= 0; i--) {
882
Metadata* m = _deallocate_list->at(i);
883
if (!m->on_stack()) {
884
_deallocate_list->remove_at(i);
887
if (m->is_method()) {
888
MetadataFactory::free_metadata(this, (Method*)m);
889
} else if (m->is_constantPool()) {
890
MetadataFactory::free_metadata(this, (ConstantPool*)m);
891
} else if (m->is_klass()) {
892
MetadataFactory::free_metadata(this, (InstanceKlass*)m);
894
ShouldNotReachHere();
899
assert(!m->is_klass() || !((InstanceKlass*)m)->is_scratch_class(),
900
"scratch classes on this list should be dead");
903
ClassLoaderDataGraph::set_should_clean_deallocate_lists();
913
void ClassLoaderData::free_deallocate_list_C_heap_structures() {
914
assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
915
assert(is_unloading(), "only called for ClassLoaderData that are unloading");
916
if (_deallocate_list == nullptr) {
920
for (int i = _deallocate_list->length() - 1; i >= 0; i--) {
921
Metadata* m = _deallocate_list->at(i);
922
_deallocate_list->remove_at(i);
923
if (m->is_constantPool()) {
924
((ConstantPool*)m)->release_C_heap_structures();
925
} else if (m->is_klass()) {
926
InstanceKlass* ik = (InstanceKlass*)m;
928
ik->release_C_heap_structures();
933
SystemDictionaryShared::handle_class_unloading(ik);
941
const char* ClassLoaderData::loader_name() const {
942
if (_class_loader_klass == nullptr) {
943
return BOOTSTRAP_LOADER_NAME;
944
} else if (_name != nullptr) {
945
return _name->as_C_string();
947
return _class_loader_klass->external_name();
956
const char* ClassLoaderData::loader_name_and_id() const {
957
if (_class_loader_klass == nullptr) {
958
return "'" BOOTSTRAP_LOADER_NAME "'";
959
} else if (_name_and_id != nullptr) {
960
return _name_and_id->as_C_string();
963
return _class_loader_klass->external_name();
967
void ClassLoaderData::print_value_on(outputStream* out) const {
968
if (!is_unloading() && class_loader() != nullptr) {
969
out->print("loader data: " INTPTR_FORMAT " for instance ", p2i(this));
970
class_loader()->print_value_on(out);
973
out->print("loader data: " INTPTR_FORMAT " of %s", p2i(this), loader_name_and_id());
975
if (_has_class_mirror_holder) {
976
out->print(" has a class holder");
980
void ClassLoaderData::print_value() const { print_value_on(tty); }
983
class PrintKlassClosure: public KlassClosure {
986
PrintKlassClosure(outputStream* out): _out(out) { }
988
void do_klass(Klass* k) {
990
_out->print("%s,", k->external_name());
994
void ClassLoaderData::print_on(outputStream* out) const {
996
out->print_cr("ClassLoaderData(" INTPTR_FORMAT ")", p2i(this));
997
out->print_cr(" - name %s", loader_name_and_id());
998
if (!_holder.is_null()) {
999
out->print (" - holder ");
1000
_holder.print_on(out);
1004
out->print_cr(" - class loader " INTPTR_FORMAT, p2i(_class_loader.peek()));
1006
out->print_cr(" - class loader <unloading, oop is bad>");
1008
out->print_cr(" - metaspace " INTPTR_FORMAT, p2i(_metaspace));
1009
out->print_cr(" - unloading %s", _unloading ? "true" : "false");
1010
out->print_cr(" - class mirror holder %s", _has_class_mirror_holder ? "true" : "false");
1011
out->print_cr(" - modified oops %s", _modified_oops ? "true" : "false");
1012
out->print_cr(" - keep alive %d", _keep_alive);
1013
out->print (" - claim ");
1015
case _claim_none: out->print_cr("none"); break;
1016
case _claim_finalizable: out->print_cr("finalizable"); break;
1017
case _claim_strong: out->print_cr("strong"); break;
1018
case _claim_stw_fullgc_mark: out->print_cr("stw full gc mark"); break;
1019
case _claim_stw_fullgc_adjust: out->print_cr("stw full gc adjust"); break;
1020
case _claim_other: out->print_cr("other"); break;
1021
case _claim_other | _claim_finalizable: out->print_cr("other and finalizable"); break;
1022
case _claim_other | _claim_strong: out->print_cr("other and strong"); break;
1023
default: ShouldNotReachHere();
1025
out->print_cr(" - handles %d", _handles.count());
1026
out->print_cr(" - dependency count %d", _dependency_count);
1027
out->print (" - klasses { ");
1029
PrintKlassClosure closure(out);
1030
((ClassLoaderData*)this)->classes_do(&closure);
1034
out->print_cr(" }");
1035
out->print_cr(" - packages " INTPTR_FORMAT, p2i(_packages));
1036
out->print_cr(" - module " INTPTR_FORMAT, p2i(_modules));
1037
out->print_cr(" - unnamed module " INTPTR_FORMAT, p2i(_unnamed_module));
1038
if (_dictionary != nullptr) {
1039
out->print (" - dictionary " INTPTR_FORMAT " ", p2i(_dictionary));
1040
_dictionary->print_size(out);
1042
out->print_cr(" - dictionary " INTPTR_FORMAT, p2i(_dictionary));
1044
if (_jmethod_ids != nullptr) {
1045
out->print (" - jmethod count ");
1046
Method::print_jmethod_ids_count(this, out);
1049
out->print_cr(" - deallocate list " INTPTR_FORMAT, p2i(_deallocate_list));
1050
out->print_cr(" - next CLD " INTPTR_FORMAT, p2i(_next));
1054
void ClassLoaderData::print() const { print_on(tty); }
1056
class VerifyHandleOops : public OopClosure {
1057
VerifyOopClosure vc;
1059
virtual void do_oop(oop* p) {
1060
if (p != nullptr && *p != nullptr) {
1062
if (!java_lang_Class::is_instance(o)) {
1066
o->oop_iterate(&vc);
1070
virtual void do_oop(narrowOop* o) { ShouldNotReachHere(); }
1073
void ClassLoaderData::verify() {
1074
assert_locked_or_safepoint(_metaspace_lock);
1075
oop cl = class_loader();
1077
guarantee(this == class_loader_data(cl) || has_class_mirror_holder(), "Must be the same");
1078
guarantee(cl != nullptr || this == ClassLoaderData::the_null_class_loader_data() || has_class_mirror_holder(), "must be");
1082
if (metaspace_or_null() != nullptr) {
1083
metaspace_or_null()->verify();
1087
for (Klass* k = _klasses; k != nullptr; k = k->next_link()) {
1088
guarantee(k->class_loader_data() == this, "Must be the same");
1090
assert(k != k->next_link(), "no loops!");
1093
if (_modules != nullptr) {
1097
if (_deallocate_list != nullptr) {
1098
for (int i = _deallocate_list->length() - 1; i >= 0; i--) {
1099
Metadata* m = _deallocate_list->at(i);
1100
if (m->is_klass()) {
1101
((Klass*)m)->verify();
1107
VerifyHandleOops vho;
1108
oops_do(&vho, _claim_none, false);
1111
bool ClassLoaderData::contains_klass(Klass* klass) {
1113
for (Klass* k = Atomic::load_acquire(&_klasses); k != nullptr; k = k->next_link()) {
1114
if (k == klass) return true;