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/javaClasses.hpp"
53 #include "classfile/metadataOnStackMark.hpp"
54 #include "classfile/systemDictionary.hpp"
55 #include "code/codeCache.hpp"
56 #include "memory/gcLocker.hpp"
57 #include "memory/metadataFactory.hpp"
58 #include "memory/metaspaceShared.hpp"
59 #include "memory/oopFactory.hpp"
60 #include "runtime/jniHandles.hpp"
61 #include "runtime/mutex.hpp"
62 #include "runtime/safepoint.hpp"
63 #include "runtime/synchronizer.hpp"
64 #include "utilities/growableArray.hpp"
65 #include "utilities/macros.hpp"
66 #include "utilities/ostream.hpp"
67 #if INCLUDE_TRACE
68 #include "trace/tracing.hpp"
69 #endif
70
71 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
72
73 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
74 _class_loader(h_class_loader()),
75 _is_anonymous(is_anonymous),
76 // An anonymous class loader data doesn't have anything to keep
77 // it from being unloaded during parsing of the anonymous class.
78 // The null-class-loader should always be kept alive.
79 _keep_alive(is_anonymous || h_class_loader.is_null()),
80 _metaspace(NULL), _unloading(false), _klasses(NULL),
81 _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL),
82 _next(NULL), _dependencies(dependencies),
83 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) {
84 // empty
85 }
86
289 for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
290 if (k == scratch_class) {
291 if (prev == NULL) {
292 _klasses = k->next_link();
293 } else {
294 Klass* next = k->next_link();
295 prev->set_next_link(next);
296 }
297 return;
298 }
299 prev = k;
300 assert(k != k->next_link(), "no loops!");
301 }
302 ShouldNotReachHere(); // should have found this class!!
303 }
304
305 void ClassLoaderData::unload() {
306 _unloading = true;
307
308 // Tell serviceability tools these classes are unloading
309 classes_do(InstanceKlass::notify_unload_class);
310
311 if (TraceClassLoaderData) {
312 ResourceMark rm;
313 tty->print("[ClassLoaderData: unload loader data " INTPTR_FORMAT, p2i(this));
314 tty->print(" for instance " INTPTR_FORMAT " of %s", p2i((void *)class_loader()),
315 loader_name());
316 if (is_anonymous()) {
317 tty->print(" for anonymous class " INTPTR_FORMAT " ", p2i(_klasses));
318 }
319 tty->print_cr("]");
320 }
321 }
322
323 oop ClassLoaderData::keep_alive_object() const {
324 assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
325 return is_anonymous() ? _klasses->java_mirror() : class_loader();
326 }
327
328 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
|
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/javaClasses.hpp"
53 #include "classfile/metadataOnStackMark.hpp"
54 #include "classfile/systemDictionary.hpp"
55 #include "code/codeCache.hpp"
56 #include "memory/gcLocker.hpp"
57 #include "memory/metadataFactory.hpp"
58 #include "memory/metaspaceShared.hpp"
59 #include "memory/oopFactory.hpp"
60 #include "runtime/jniHandles.hpp"
61 #include "runtime/mutex.hpp"
62 #include "runtime/safepoint.hpp"
63 #include "runtime/synchronizer.hpp"
64 #include "utilities/growableArray.hpp"
65 #include "utilities/macros.hpp"
66 #include "utilities/ostream.hpp"
67 #include "evtrace/traceEvents.hpp"
68 #if INCLUDE_TRACE
69 #include "trace/tracing.hpp"
70 #endif
71
72 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
73
74 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
75 _class_loader(h_class_loader()),
76 _is_anonymous(is_anonymous),
77 // An anonymous class loader data doesn't have anything to keep
78 // it from being unloaded during parsing of the anonymous class.
79 // The null-class-loader should always be kept alive.
80 _keep_alive(is_anonymous || h_class_loader.is_null()),
81 _metaspace(NULL), _unloading(false), _klasses(NULL),
82 _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL),
83 _next(NULL), _dependencies(dependencies),
84 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) {
85 // empty
86 }
87
290 for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
291 if (k == scratch_class) {
292 if (prev == NULL) {
293 _klasses = k->next_link();
294 } else {
295 Klass* next = k->next_link();
296 prev->set_next_link(next);
297 }
298 return;
299 }
300 prev = k;
301 assert(k != k->next_link(), "no loops!");
302 }
303 ShouldNotReachHere(); // should have found this class!!
304 }
305
306 void ClassLoaderData::unload() {
307 _unloading = true;
308
309 // Tell serviceability tools these classes are unloading
310 if (EnableEventTracing) {
311 TraceManager::class_loader_is_unloading(this); // also writes an event
312 }
313 classes_do(InstanceKlass::notify_unload_class);
314
315 if (TraceClassLoaderData) {
316 ResourceMark rm;
317 tty->print("[ClassLoaderData: unload loader data " INTPTR_FORMAT, p2i(this));
318 tty->print(" for instance " INTPTR_FORMAT " of %s", p2i((void *)class_loader()),
319 loader_name());
320 if (is_anonymous()) {
321 tty->print(" for anonymous class " INTPTR_FORMAT " ", p2i(_klasses));
322 }
323 tty->print_cr("]");
324 }
325 }
326
327 oop ClassLoaderData::keep_alive_object() const {
328 assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
329 return is_anonymous() ? _klasses->java_mirror() : class_loader();
330 }
331
332 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
|