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 // helper function to avoid in-line casts
86 template <typename T> static T* load_ptr_acquire(T* volatile *p) {
87 return static_cast<T*>(OrderAccess::load_ptr_acquire(p));
88 }
89
90 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
91
92 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
93 _class_loader(h_class_loader()),
94 _is_anonymous(is_anonymous),
95 // An anonymous class loader data doesn't have anything to keep
96 // it from being unloaded during parsing of the anonymous class.
97 // The null-class-loader should always be kept alive.
98 _keep_alive((is_anonymous || h_class_loader.is_null()) ? 1 : 0),
99 _metaspace(NULL), _unloading(false), _klasses(NULL),
761 }
762 return metaspace;
763 }
764
765 OopHandle ClassLoaderData::add_handle(Handle h) {
766 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
767 return OopHandle(_handles.add(h()));
768 }
769
770 void ClassLoaderData::remove_handle(OopHandle h) {
771 oop* ptr = h.ptr_raw();
772 if (ptr != NULL) {
773 assert(_handles.contains(ptr), "Got unexpected handle " PTR_FORMAT, p2i(ptr));
774 #if INCLUDE_ALL_GCS
775 // This barrier is used by G1 to remember the old oop values, so
776 // that we don't forget any objects that were live at the snapshot at
777 // the beginning.
778 if (UseG1GC) {
779 oop obj = *ptr;
780 if (obj != NULL) {
781 G1SATBCardTableModRefBS::enqueue(obj);
782 }
783 }
784 #endif
785 *ptr = NULL;
786 }
787 }
788
789 void ClassLoaderData::init_handle_locked(OopHandle& dest, Handle h) {
790 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
791 if (dest.resolve() != NULL) {
792 return;
793 } else {
794 dest = _handles.add(h());
795 }
796 }
797
798 // Add this metadata pointer to be freed when it's safe. This is only during
799 // class unloading because Handles might point to this metadata field.
800 void ClassLoaderData::add_to_deallocate_list(Metadata* m) {
801 // Metadata in shared region isn't deleted.
|
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/g1BarrierSet.hpp"
80 #endif // INCLUDE_ALL_GCS
81 #if INCLUDE_TRACE
82 #include "trace/tracing.hpp"
83 #endif
84
85 // helper function to avoid in-line casts
86 template <typename T> static T* load_ptr_acquire(T* volatile *p) {
87 return static_cast<T*>(OrderAccess::load_ptr_acquire(p));
88 }
89
90 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
91
92 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
93 _class_loader(h_class_loader()),
94 _is_anonymous(is_anonymous),
95 // An anonymous class loader data doesn't have anything to keep
96 // it from being unloaded during parsing of the anonymous class.
97 // The null-class-loader should always be kept alive.
98 _keep_alive((is_anonymous || h_class_loader.is_null()) ? 1 : 0),
99 _metaspace(NULL), _unloading(false), _klasses(NULL),
761 }
762 return metaspace;
763 }
764
765 OopHandle ClassLoaderData::add_handle(Handle h) {
766 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
767 return OopHandle(_handles.add(h()));
768 }
769
770 void ClassLoaderData::remove_handle(OopHandle h) {
771 oop* ptr = h.ptr_raw();
772 if (ptr != NULL) {
773 assert(_handles.contains(ptr), "Got unexpected handle " PTR_FORMAT, p2i(ptr));
774 #if INCLUDE_ALL_GCS
775 // This barrier is used by G1 to remember the old oop values, so
776 // that we don't forget any objects that were live at the snapshot at
777 // the beginning.
778 if (UseG1GC) {
779 oop obj = *ptr;
780 if (obj != NULL) {
781 G1BarrierSet::satb_enqueue(obj);
782 }
783 }
784 #endif
785 *ptr = NULL;
786 }
787 }
788
789 void ClassLoaderData::init_handle_locked(OopHandle& dest, Handle h) {
790 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
791 if (dest.resolve() != NULL) {
792 return;
793 } else {
794 dest = _handles.add(h());
795 }
796 }
797
798 // Add this metadata pointer to be freed when it's safe. This is only during
799 // class unloading because Handles might point to this metadata field.
800 void ClassLoaderData::add_to_deallocate_list(Metadata* m) {
801 // Metadata in shared region isn't deleted.
|