623
624 return alive;
625 }
626
627 class ReleaseKlassClosure: public KlassClosure {
628 private:
629 size_t _instance_class_released;
630 size_t _array_class_released;
631 public:
632 ReleaseKlassClosure() : _instance_class_released(0), _array_class_released(0) { }
633
634 size_t instance_class_released() const { return _instance_class_released; }
635 size_t array_class_released() const { return _array_class_released; }
636
637 void do_klass(Klass* k) {
638 if (k->is_array_klass()) {
639 _array_class_released ++;
640 } else {
641 assert(k->is_instance_klass(), "Must be");
642 _instance_class_released ++;
643 InstanceKlass::release_C_heap_structures(InstanceKlass::cast(k));
644 }
645 }
646 };
647
648 ClassLoaderData::~ClassLoaderData() {
649 // Release C heap structures for all the classes.
650 ReleaseKlassClosure cl;
651 classes_do(&cl);
652
653 ClassLoaderDataGraph::dec_array_classes(cl.array_class_released());
654 ClassLoaderDataGraph::dec_instance_classes(cl.instance_class_released());
655
656 // Release the WeakHandle
657 _holder.release();
658
659 // Release C heap allocated hashtable for all the packages.
660 if (_packages != NULL) {
661 // Destroy the table itself
662 delete _packages;
663 _packages = NULL;
664 }
852 // This is distinct from free_deallocate_list. For class loader data that are
853 // unloading, this frees the C heap memory for items on the list, and unlinks
854 // scratch or error classes so that unloading events aren't triggered for these
855 // classes. The metadata is removed with the unloading metaspace.
856 // There isn't C heap memory allocated for methods, so nothing is done for them.
857 void ClassLoaderData::free_deallocate_list_C_heap_structures() {
858 assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
859 assert(is_unloading(), "only called for ClassLoaderData that are unloading");
860 if (_deallocate_list == NULL) {
861 return;
862 }
863 // Go backwards because this removes entries that are freed.
864 for (int i = _deallocate_list->length() - 1; i >= 0; i--) {
865 Metadata* m = _deallocate_list->at(i);
866 _deallocate_list->remove_at(i);
867 if (m->is_constantPool()) {
868 ((ConstantPool*)m)->release_C_heap_structures();
869 } else if (m->is_klass()) {
870 InstanceKlass* ik = (InstanceKlass*)m;
871 // also releases ik->constants() C heap memory
872 InstanceKlass::release_C_heap_structures(ik);
873 // Remove the class so unloading events aren't triggered for
874 // this class (scratch or error class) in do_unloading().
875 remove_class(ik);
876 }
877 }
878 }
879
880 // These CLDs are to contain non-strong hidden classes or unsafe anonymous classes used for JSR292
881 ClassLoaderData* ClassLoaderData::has_class_mirror_holder_cld(Handle loader) {
882 // Add a new class loader data to the graph.
883 return ClassLoaderDataGraph::add(loader, true);
884 }
885
886 // Caller needs ResourceMark
887 // If the class loader's _name has not been explicitly set, the class loader's
888 // qualified class name is returned.
889 const char* ClassLoaderData::loader_name() const {
890 if (_class_loader_klass == NULL) {
891 return BOOTSTRAP_LOADER_NAME;
892 } else if (_name != NULL) {
|
623
624 return alive;
625 }
626
627 class ReleaseKlassClosure: public KlassClosure {
628 private:
629 size_t _instance_class_released;
630 size_t _array_class_released;
631 public:
632 ReleaseKlassClosure() : _instance_class_released(0), _array_class_released(0) { }
633
634 size_t instance_class_released() const { return _instance_class_released; }
635 size_t array_class_released() const { return _array_class_released; }
636
637 void do_klass(Klass* k) {
638 if (k->is_array_klass()) {
639 _array_class_released ++;
640 } else {
641 assert(k->is_instance_klass(), "Must be");
642 _instance_class_released ++;
643 }
644 k->release_C_heap_structures();
645 }
646 };
647
648 ClassLoaderData::~ClassLoaderData() {
649 // Release C heap structures for all the classes.
650 ReleaseKlassClosure cl;
651 classes_do(&cl);
652
653 ClassLoaderDataGraph::dec_array_classes(cl.array_class_released());
654 ClassLoaderDataGraph::dec_instance_classes(cl.instance_class_released());
655
656 // Release the WeakHandle
657 _holder.release();
658
659 // Release C heap allocated hashtable for all the packages.
660 if (_packages != NULL) {
661 // Destroy the table itself
662 delete _packages;
663 _packages = NULL;
664 }
852 // This is distinct from free_deallocate_list. For class loader data that are
853 // unloading, this frees the C heap memory for items on the list, and unlinks
854 // scratch or error classes so that unloading events aren't triggered for these
855 // classes. The metadata is removed with the unloading metaspace.
856 // There isn't C heap memory allocated for methods, so nothing is done for them.
857 void ClassLoaderData::free_deallocate_list_C_heap_structures() {
858 assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
859 assert(is_unloading(), "only called for ClassLoaderData that are unloading");
860 if (_deallocate_list == NULL) {
861 return;
862 }
863 // Go backwards because this removes entries that are freed.
864 for (int i = _deallocate_list->length() - 1; i >= 0; i--) {
865 Metadata* m = _deallocate_list->at(i);
866 _deallocate_list->remove_at(i);
867 if (m->is_constantPool()) {
868 ((ConstantPool*)m)->release_C_heap_structures();
869 } else if (m->is_klass()) {
870 InstanceKlass* ik = (InstanceKlass*)m;
871 // also releases ik->constants() C heap memory
872 ik->release_C_heap_structures();
873 // Remove the class so unloading events aren't triggered for
874 // this class (scratch or error class) in do_unloading().
875 remove_class(ik);
876 }
877 }
878 }
879
880 // These CLDs are to contain non-strong hidden classes or unsafe anonymous classes used for JSR292
881 ClassLoaderData* ClassLoaderData::has_class_mirror_holder_cld(Handle loader) {
882 // Add a new class loader data to the graph.
883 return ClassLoaderDataGraph::add(loader, true);
884 }
885
886 // Caller needs ResourceMark
887 // If the class loader's _name has not been explicitly set, the class loader's
888 // qualified class name is returned.
889 const char* ClassLoaderData::loader_name() const {
890 if (_class_loader_klass == NULL) {
891 return BOOTSTRAP_LOADER_NAME;
892 } else if (_name != NULL) {
|