Mercurial > hg > graal-jvmci-8
comparison src/share/vm/classfile/classLoaderData.cpp @ 10408:836a62f43af9
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 19 Jun 2013 10:45:56 +0200 |
parents | f2110083203d |
children | 190899198332 |
comparison
equal
deleted
inserted
replaced
10086:e0fb8a213650 | 10408:836a62f43af9 |
---|---|
51 #include "classfile/classLoaderData.inline.hpp" | 51 #include "classfile/classLoaderData.inline.hpp" |
52 #include "classfile/javaClasses.hpp" | 52 #include "classfile/javaClasses.hpp" |
53 #include "classfile/metadataOnStackMark.hpp" | 53 #include "classfile/metadataOnStackMark.hpp" |
54 #include "classfile/systemDictionary.hpp" | 54 #include "classfile/systemDictionary.hpp" |
55 #include "code/codeCache.hpp" | 55 #include "code/codeCache.hpp" |
56 #include "memory/gcLocker.hpp" | |
56 #include "memory/metadataFactory.hpp" | 57 #include "memory/metadataFactory.hpp" |
57 #include "memory/metaspaceShared.hpp" | 58 #include "memory/metaspaceShared.hpp" |
58 #include "memory/oopFactory.hpp" | 59 #include "memory/oopFactory.hpp" |
59 #include "runtime/jniHandles.hpp" | 60 #include "runtime/jniHandles.hpp" |
60 #include "runtime/mutex.hpp" | 61 #include "runtime/mutex.hpp" |
61 #include "runtime/safepoint.hpp" | 62 #include "runtime/safepoint.hpp" |
62 #include "runtime/synchronizer.hpp" | 63 #include "runtime/synchronizer.hpp" |
63 #include "utilities/growableArray.hpp" | 64 #include "utilities/growableArray.hpp" |
64 #include "utilities/ostream.hpp" | 65 #include "utilities/ostream.hpp" |
65 | 66 |
67 #if INCLUDE_TRACE | |
68 #include "trace/tracing.hpp" | |
69 #endif | |
70 | |
71 | |
66 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL; | 72 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL; |
67 | 73 |
68 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous) : | 74 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) : |
69 _class_loader(h_class_loader()), | 75 _class_loader(h_class_loader()), |
70 _is_anonymous(is_anonymous), _keep_alive(is_anonymous), // initially | 76 _is_anonymous(is_anonymous), _keep_alive(is_anonymous), // initially |
71 _metaspace(NULL), _unloading(false), _klasses(NULL), | 77 _metaspace(NULL), _unloading(false), _klasses(NULL), |
72 _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL), | 78 _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL), |
73 _next(NULL), _dependencies(), | 79 _next(NULL), _dependencies(dependencies), |
74 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { | 80 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { |
75 // empty | 81 // empty |
76 } | 82 } |
77 | 83 |
78 void ClassLoaderData::init_dependencies(TRAPS) { | 84 void ClassLoaderData::init_dependencies(TRAPS) { |
85 assert(!Universe::is_fully_initialized(), "should only be called when initializing"); | |
86 assert(is_the_null_class_loader_data(), "should only call this for the null class loader"); | |
79 _dependencies.init(CHECK); | 87 _dependencies.init(CHECK); |
80 } | 88 } |
81 | 89 |
82 void ClassLoaderData::Dependencies::init(TRAPS) { | 90 void ClassLoaderData::Dependencies::init(TRAPS) { |
83 // Create empty dependencies array to add to. CMS requires this to be | 91 // Create empty dependencies array to add to. CMS requires this to be |
112 | 120 |
113 void ClassLoaderData::classes_do(KlassClosure* klass_closure) { | 121 void ClassLoaderData::classes_do(KlassClosure* klass_closure) { |
114 for (Klass* k = _klasses; k != NULL; k = k->next_link()) { | 122 for (Klass* k = _klasses; k != NULL; k = k->next_link()) { |
115 klass_closure->do_klass(k); | 123 klass_closure->do_klass(k); |
116 assert(k != k->next_link(), "no loops!"); | 124 assert(k != k->next_link(), "no loops!"); |
125 } | |
126 } | |
127 | |
128 void ClassLoaderData::classes_do(void f(Klass * const)) { | |
129 for (Klass* k = _klasses; k != NULL; k = k->next_link()) { | |
130 f(k); | |
117 } | 131 } |
118 } | 132 } |
119 | 133 |
120 void ClassLoaderData::classes_do(void f(InstanceKlass*)) { | 134 void ClassLoaderData::classes_do(void f(InstanceKlass*)) { |
121 for (Klass* k = _klasses; k != NULL; k = k->next_link()) { | 135 for (Klass* k = _klasses; k != NULL; k = k->next_link()) { |
275 } | 289 } |
276 | 290 |
277 void ClassLoaderData::unload() { | 291 void ClassLoaderData::unload() { |
278 _unloading = true; | 292 _unloading = true; |
279 | 293 |
294 // Tell serviceability tools these classes are unloading | |
295 classes_do(InstanceKlass::notify_unload_class); | |
296 | |
280 if (TraceClassLoaderData) { | 297 if (TraceClassLoaderData) { |
281 ResourceMark rm; | 298 ResourceMark rm; |
282 tty->print("[ClassLoaderData: unload loader data "PTR_FORMAT, this); | 299 tty->print("[ClassLoaderData: unload loader data "PTR_FORMAT, this); |
283 tty->print(" for instance "PTR_FORMAT" of %s", class_loader(), | 300 tty->print(" for instance "PTR_FORMAT" of %s", class_loader(), |
284 loader_name()); | 301 loader_name()); |
298 return alive; | 315 return alive; |
299 } | 316 } |
300 | 317 |
301 | 318 |
302 ClassLoaderData::~ClassLoaderData() { | 319 ClassLoaderData::~ClassLoaderData() { |
320 // Release C heap structures for all the classes. | |
321 classes_do(InstanceKlass::release_C_heap_structures); | |
322 | |
303 Metaspace *m = _metaspace; | 323 Metaspace *m = _metaspace; |
304 if (m != NULL) { | 324 if (m != NULL) { |
305 _metaspace = NULL; | 325 _metaspace = NULL; |
306 // release the metaspace | 326 // release the metaspace |
307 delete m; | 327 delete m; |
421 } | 441 } |
422 | 442 |
423 // These anonymous class loaders are to contain classes used for JSR292 | 443 // These anonymous class loaders are to contain classes used for JSR292 |
424 ClassLoaderData* ClassLoaderData::anonymous_class_loader_data(oop loader, TRAPS) { | 444 ClassLoaderData* ClassLoaderData::anonymous_class_loader_data(oop loader, TRAPS) { |
425 // Add a new class loader data to the graph. | 445 // Add a new class loader data to the graph. |
426 return ClassLoaderDataGraph::add(NULL, loader, CHECK_NULL); | 446 return ClassLoaderDataGraph::add(loader, true, CHECK_NULL); |
427 } | 447 } |
428 | 448 |
429 const char* ClassLoaderData::loader_name() { | 449 const char* ClassLoaderData::loader_name() { |
430 // Handles null class loader | 450 // Handles null class loader |
431 return SystemDictionary::loader_name(class_loader()); | 451 return SystemDictionary::loader_name(class_loader()); |
493 // GC root of class loader data created. | 513 // GC root of class loader data created. |
494 ClassLoaderData* ClassLoaderDataGraph::_head = NULL; | 514 ClassLoaderData* ClassLoaderDataGraph::_head = NULL; |
495 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL; | 515 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL; |
496 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL; | 516 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL; |
497 | 517 |
498 | |
499 // Add a new class loader data node to the list. Assign the newly created | 518 // Add a new class loader data node to the list. Assign the newly created |
500 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field | 519 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field |
501 ClassLoaderData* ClassLoaderDataGraph::add(ClassLoaderData** cld_addr, Handle loader, TRAPS) { | 520 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous, TRAPS) { |
502 // Not assigned a class loader data yet. | 521 // We need to allocate all the oops for the ClassLoaderData before allocating the |
503 // Create one. | 522 // actual ClassLoaderData object. |
504 ClassLoaderData* *list_head = &_head; | 523 ClassLoaderData::Dependencies dependencies(CHECK_NULL); |
505 ClassLoaderData* next = _head; | 524 |
506 | 525 No_Safepoint_Verifier no_safepoints; // we mustn't GC until we've installed the |
507 bool is_anonymous = (cld_addr == NULL); | 526 // ClassLoaderData in the graph since the CLD |
508 ClassLoaderData* cld = new ClassLoaderData(loader, is_anonymous); | 527 // contains unhandled oops |
509 | 528 |
510 if (cld_addr != NULL) { | 529 ClassLoaderData* cld = new ClassLoaderData(loader, is_anonymous, dependencies); |
530 | |
531 | |
532 if (!is_anonymous) { | |
533 ClassLoaderData** cld_addr = java_lang_ClassLoader::loader_data_addr(loader()); | |
511 // First, Atomically set it | 534 // First, Atomically set it |
512 ClassLoaderData* old = (ClassLoaderData*) Atomic::cmpxchg_ptr(cld, cld_addr, NULL); | 535 ClassLoaderData* old = (ClassLoaderData*) Atomic::cmpxchg_ptr(cld, cld_addr, NULL); |
513 if (old != NULL) { | 536 if (old != NULL) { |
514 delete cld; | 537 delete cld; |
515 // Returns the data. | 538 // Returns the data. |
517 } | 540 } |
518 } | 541 } |
519 | 542 |
520 // We won the race, and therefore the task of adding the data to the list of | 543 // We won the race, and therefore the task of adding the data to the list of |
521 // class loader data | 544 // class loader data |
545 ClassLoaderData** list_head = &_head; | |
546 ClassLoaderData* next = _head; | |
547 | |
522 do { | 548 do { |
523 cld->set_next(next); | 549 cld->set_next(next); |
524 ClassLoaderData* exchanged = (ClassLoaderData*)Atomic::cmpxchg_ptr(cld, list_head, next); | 550 ClassLoaderData* exchanged = (ClassLoaderData*)Atomic::cmpxchg_ptr(cld, list_head, next); |
525 if (exchanged == next) { | 551 if (exchanged == next) { |
526 if (TraceClassLoaderData) { | 552 if (TraceClassLoaderData) { |
529 tty->print("create class loader data "PTR_FORMAT, cld); | 555 tty->print("create class loader data "PTR_FORMAT, cld); |
530 tty->print(" for instance "PTR_FORMAT" of %s", cld->class_loader(), | 556 tty->print(" for instance "PTR_FORMAT" of %s", cld->class_loader(), |
531 cld->loader_name()); | 557 cld->loader_name()); |
532 tty->print_cr("]"); | 558 tty->print_cr("]"); |
533 } | 559 } |
534 // Create dependencies after the CLD is added to the list. Otherwise, | |
535 // the GC GC will not find the CLD and the _class_loader field will | |
536 // not be updated. | |
537 cld->init_dependencies(CHECK_NULL); | |
538 return cld; | 560 return cld; |
539 } | 561 } |
540 next = exchanged; | 562 next = exchanged; |
541 } while (true); | 563 } while (true); |
542 | 564 |
567 } | 589 } |
568 | 590 |
569 void ClassLoaderDataGraph::classes_do(KlassClosure* klass_closure) { | 591 void ClassLoaderDataGraph::classes_do(KlassClosure* klass_closure) { |
570 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) { | 592 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) { |
571 cld->classes_do(klass_closure); | 593 cld->classes_do(klass_closure); |
594 } | |
595 } | |
596 | |
597 void ClassLoaderDataGraph::classes_do(void f(Klass* const)) { | |
598 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) { | |
599 cld->classes_do(f); | |
600 } | |
601 } | |
602 | |
603 void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) { | |
604 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); | |
605 for (ClassLoaderData* cld = _unloading; cld != NULL; cld = cld->next()) { | |
606 cld->classes_do(f); | |
572 } | 607 } |
573 } | 608 } |
574 | 609 |
575 GrowableArray<ClassLoaderData*>* ClassLoaderDataGraph::new_clds() { | 610 GrowableArray<ClassLoaderData*>* ClassLoaderDataGraph::new_clds() { |
576 assert(_head == NULL || _saved_head != NULL, "remember_new_clds(true) not called?"); | 611 assert(_head == NULL || _saved_head != NULL, "remember_new_clds(true) not called?"); |
663 seen_dead_loader = true; | 698 seen_dead_loader = true; |
664 ClassLoaderData* dead = data; | 699 ClassLoaderData* dead = data; |
665 dead->unload(); | 700 dead->unload(); |
666 data = data->next(); | 701 data = data->next(); |
667 // Remove from loader list. | 702 // Remove from loader list. |
703 // This class loader data will no longer be found | |
704 // in the ClassLoaderDataGraph. | |
668 if (prev != NULL) { | 705 if (prev != NULL) { |
669 prev->set_next(data); | 706 prev->set_next(data); |
670 } else { | 707 } else { |
671 assert(dead == _head, "sanity check"); | 708 assert(dead == _head, "sanity check"); |
672 _head = data; | 709 _head = data; |
673 } | 710 } |
674 dead->set_next(_unloading); | 711 dead->set_next(_unloading); |
675 _unloading = dead; | 712 _unloading = dead; |
676 } | 713 } |
714 | |
715 if (seen_dead_loader) { | |
716 post_class_unload_events(); | |
717 } | |
718 | |
677 return seen_dead_loader; | 719 return seen_dead_loader; |
678 } | 720 } |
679 | 721 |
680 void ClassLoaderDataGraph::purge() { | 722 void ClassLoaderDataGraph::purge() { |
681 ClassLoaderData* list = _unloading; | 723 ClassLoaderData* list = _unloading; |
684 while (next != NULL) { | 726 while (next != NULL) { |
685 ClassLoaderData* purge_me = next; | 727 ClassLoaderData* purge_me = next; |
686 next = purge_me->next(); | 728 next = purge_me->next(); |
687 delete purge_me; | 729 delete purge_me; |
688 } | 730 } |
731 Metaspace::purge(); | |
732 } | |
733 | |
734 void ClassLoaderDataGraph::post_class_unload_events(void) { | |
735 #if INCLUDE_TRACE | |
736 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); | |
737 if (Tracing::enabled()) { | |
738 if (Tracing::is_event_enabled(TraceClassUnloadEvent)) { | |
739 assert(_unloading != NULL, "need class loader data unload list!"); | |
740 _class_unload_time = Tracing::time(); | |
741 classes_unloading_do(&class_unload_event); | |
742 } | |
743 Tracing::on_unloading_classes(); | |
744 } | |
745 #endif | |
689 } | 746 } |
690 | 747 |
691 // CDS support | 748 // CDS support |
692 | 749 |
693 // Global metaspaces for writing information to the shared archive. When | 750 // Global metaspaces for writing information to the shared archive. When |
753 } else { | 810 } else { |
754 out->print("class loader "PTR_FORMAT, this); | 811 out->print("class loader "PTR_FORMAT, this); |
755 class_loader()->print_value_on(out); | 812 class_loader()->print_value_on(out); |
756 } | 813 } |
757 } | 814 } |
815 | |
816 #if INCLUDE_TRACE | |
817 | |
818 TracingTime ClassLoaderDataGraph::_class_unload_time; | |
819 | |
820 void ClassLoaderDataGraph::class_unload_event(Klass* const k) { | |
821 | |
822 // post class unload event | |
823 EventClassUnload event(UNTIMED); | |
824 event.set_endtime(_class_unload_time); | |
825 event.set_unloadedClass(k); | |
826 oop defining_class_loader = k->class_loader(); | |
827 event.set_definingClassLoader(defining_class_loader != NULL ? | |
828 defining_class_loader->klass() : (Klass*)NULL); | |
829 event.commit(); | |
830 } | |
831 | |
832 #endif /* INCLUDE_TRACE */ |