46 // The bootstrap loader (represented by NULL) also has a ClassLoaderData,
47 // the singleton class the_null_class_loader_data().
48
49 #include "precompiled.hpp"
50 #include "classfile/classLoaderData.hpp"
51 #include "classfile/classLoaderData.inline.hpp"
52 #include "classfile/dictionary.hpp"
53 #include "classfile/javaClasses.hpp"
54 #include "classfile/metadataOnStackMark.hpp"
55 #include "classfile/moduleEntry.hpp"
56 #include "classfile/packageEntry.hpp"
57 #include "classfile/systemDictionary.hpp"
58 #include "code/codeCache.hpp"
59 #include "gc/shared/gcLocker.hpp"
60 #include "logging/log.hpp"
61 #include "logging/logStream.hpp"
62 #include "memory/metadataFactory.hpp"
63 #include "memory/metaspaceShared.hpp"
64 #include "memory/oopFactory.hpp"
65 #include "memory/resourceArea.hpp"
66 #include "oops/objArrayOop.inline.hpp"
67 #include "oops/oop.inline.hpp"
68 #include "runtime/atomic.hpp"
69 #include "runtime/javaCalls.hpp"
70 #include "runtime/jniHandles.hpp"
71 #include "runtime/mutex.hpp"
72 #include "runtime/orderAccess.hpp"
73 #include "runtime/safepoint.hpp"
74 #include "runtime/synchronizer.hpp"
75 #include "utilities/growableArray.hpp"
76 #include "utilities/macros.hpp"
77 #include "utilities/ostream.hpp"
78 #if INCLUDE_ALL_GCS
79 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
80 #endif // INCLUDE_ALL_GCS
81 #if INCLUDE_TRACE
82 #include "trace/tracing.hpp"
83 #endif
84
85 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
86
87 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
88 _class_loader(h_class_loader()),
89 _is_anonymous(is_anonymous),
90 // An anonymous class loader data doesn't have anything to keep
91 // it from being unloaded during parsing of the anonymous class.
92 // The null-class-loader should always be kept alive.
93 _keep_alive((is_anonymous || h_class_loader.is_null()) ? 1 : 0),
94 _metaspace(NULL), _unloading(false), _klasses(NULL),
95 _modules(NULL), _packages(NULL),
96 _claimed(0), _modified_oops(true), _accumulated_modified_oops(false),
97 _jmethod_ids(NULL), _handles(), _deallocate_list(NULL),
98 _next(NULL), _dependencies(dependencies),
99 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true,
100 Monitor::_safepoint_check_never)) {
741 } else {
742 metaspace = new Metaspace(_metaspace_lock, Metaspace::StandardMetaspaceType);
743 }
744 // Ensure _metaspace is stable, since it is examined without a lock
745 OrderAccess::release_store(&_metaspace, metaspace);
746 }
747 }
748 return metaspace;
749 }
750
751 OopHandle ClassLoaderData::add_handle(Handle h) {
752 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
753 record_modified_oops();
754 return OopHandle(_handles.add(h()));
755 }
756
757 void ClassLoaderData::remove_handle(OopHandle h) {
758 oop* ptr = h.ptr_raw();
759 if (ptr != NULL) {
760 assert(_handles.contains(ptr), "Got unexpected handle " PTR_FORMAT, p2i(ptr));
761 #if INCLUDE_ALL_GCS
762 // This barrier is used by G1 to remember the old oop values, so
763 // that we don't forget any objects that were live at the snapshot at
764 // the beginning.
765 if (UseG1GC) {
766 oop obj = *ptr;
767 if (obj != NULL) {
768 G1SATBCardTableModRefBS::enqueue(obj);
769 }
770 }
771 #endif
772 *ptr = NULL;
773 }
774 }
775
776 void ClassLoaderData::init_handle_locked(OopHandle& dest, Handle h) {
777 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
778 if (dest.resolve() != NULL) {
779 return;
780 } else {
781 dest = _handles.add(h());
782 }
783 }
784
785 // Add this metadata pointer to be freed when it's safe. This is only during
786 // class unloading because Handles might point to this metadata field.
787 void ClassLoaderData::add_to_deallocate_list(Metadata* m) {
788 // Metadata in shared region isn't deleted.
789 if (!m->is_shared()) {
790 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
791 if (_deallocate_list == NULL) {
792 _deallocate_list = new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(100, true);
|
46 // The bootstrap loader (represented by NULL) also has a ClassLoaderData,
47 // the singleton class the_null_class_loader_data().
48
49 #include "precompiled.hpp"
50 #include "classfile/classLoaderData.hpp"
51 #include "classfile/classLoaderData.inline.hpp"
52 #include "classfile/dictionary.hpp"
53 #include "classfile/javaClasses.hpp"
54 #include "classfile/metadataOnStackMark.hpp"
55 #include "classfile/moduleEntry.hpp"
56 #include "classfile/packageEntry.hpp"
57 #include "classfile/systemDictionary.hpp"
58 #include "code/codeCache.hpp"
59 #include "gc/shared/gcLocker.hpp"
60 #include "logging/log.hpp"
61 #include "logging/logStream.hpp"
62 #include "memory/metadataFactory.hpp"
63 #include "memory/metaspaceShared.hpp"
64 #include "memory/oopFactory.hpp"
65 #include "memory/resourceArea.hpp"
66 #include "oops/access.inline.hpp"
67 #include "oops/objArrayOop.inline.hpp"
68 #include "oops/oop.inline.hpp"
69 #include "runtime/atomic.hpp"
70 #include "runtime/javaCalls.hpp"
71 #include "runtime/jniHandles.hpp"
72 #include "runtime/mutex.hpp"
73 #include "runtime/orderAccess.hpp"
74 #include "runtime/safepoint.hpp"
75 #include "runtime/synchronizer.hpp"
76 #include "utilities/growableArray.hpp"
77 #include "utilities/macros.hpp"
78 #include "utilities/ostream.hpp"
79 #if INCLUDE_TRACE
80 #include "trace/tracing.hpp"
81 #endif
82
83 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
84
85 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
86 _class_loader(h_class_loader()),
87 _is_anonymous(is_anonymous),
88 // An anonymous class loader data doesn't have anything to keep
89 // it from being unloaded during parsing of the anonymous class.
90 // The null-class-loader should always be kept alive.
91 _keep_alive((is_anonymous || h_class_loader.is_null()) ? 1 : 0),
92 _metaspace(NULL), _unloading(false), _klasses(NULL),
93 _modules(NULL), _packages(NULL),
94 _claimed(0), _modified_oops(true), _accumulated_modified_oops(false),
95 _jmethod_ids(NULL), _handles(), _deallocate_list(NULL),
96 _next(NULL), _dependencies(dependencies),
97 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true,
98 Monitor::_safepoint_check_never)) {
739 } else {
740 metaspace = new Metaspace(_metaspace_lock, Metaspace::StandardMetaspaceType);
741 }
742 // Ensure _metaspace is stable, since it is examined without a lock
743 OrderAccess::release_store(&_metaspace, metaspace);
744 }
745 }
746 return metaspace;
747 }
748
749 OopHandle ClassLoaderData::add_handle(Handle h) {
750 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
751 record_modified_oops();
752 return OopHandle(_handles.add(h()));
753 }
754
755 void ClassLoaderData::remove_handle(OopHandle h) {
756 oop* ptr = h.ptr_raw();
757 if (ptr != NULL) {
758 assert(_handles.contains(ptr), "Got unexpected handle " PTR_FORMAT, p2i(ptr));
759 // This root is not walked in safepoints, and hence requires an appropriate
760 // decorator that e.g. maintains the SATB invariant in SATB collectors.
761 RootAccess<IN_CONCURRENT_ROOT>::oop_store(ptr, oop(NULL));
762 }
763 }
764
765 void ClassLoaderData::init_handle_locked(OopHandle& dest, Handle h) {
766 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
767 if (dest.resolve() != NULL) {
768 return;
769 } else {
770 dest = _handles.add(h());
771 }
772 }
773
774 // Add this metadata pointer to be freed when it's safe. This is only during
775 // class unloading because Handles might point to this metadata field.
776 void ClassLoaderData::add_to_deallocate_list(Metadata* m) {
777 // Metadata in shared region isn't deleted.
778 if (!m->is_shared()) {
779 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
780 if (_deallocate_list == NULL) {
781 _deallocate_list = new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(100, true);
|