< prev index next >

src/hotspot/share/classfile/classLoaderData.cpp

Print this page




  92   assert(ClassLoaderDataGraph::_head == NULL, "cannot initialize twice");
  93 
  94   _the_null_class_loader_data = new ClassLoaderData(Handle(), false);
  95   ClassLoaderDataGraph::_head = _the_null_class_loader_data;
  96   assert(_the_null_class_loader_data->is_the_null_class_loader_data(), "Must be");
  97 
  98   LogTarget(Debug, class, loader, data) lt;
  99   if (lt.is_enabled()) {
 100     ResourceMark rm;
 101     LogStream ls(lt);
 102     ls.print("create ");
 103     _the_null_class_loader_data->print_value_on(&ls);
 104     ls.cr();
 105   }
 106 }
 107 
 108 // JFR and logging support so that the name and klass are available after the
 109 // class_loader oop is no longer alive, during unloading.
 110 void ClassLoaderData::initialize_name_and_klass(Handle class_loader) {
 111   _class_loader_klass = class_loader->klass();
 112   oop class_loader_name = java_lang_ClassLoader::name(class_loader());
 113   if (class_loader_name != NULL) {
 114     Thread* THREAD = Thread::current();
 115     ResourceMark rm(THREAD);
 116     const char* class_loader_instance_name =
 117       java_lang_String::as_utf8_string(class_loader_name);
 118 
 119     if (class_loader_instance_name != NULL && class_loader_instance_name[0] != '\0') {
 120       // Can't throw InternalError and SymbolTable doesn't throw OOM anymore.
 121       _class_loader_name = SymbolTable::new_symbol(class_loader_instance_name, CATCH);
 122     }
 123   }







 124 }
 125 
 126 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous) :
 127   _is_anonymous(is_anonymous),
 128   // An anonymous class loader data doesn't have anything to keep
 129   // it from being unloaded during parsing of the anonymous class.
 130   // The null-class-loader should always be kept alive.
 131   _keep_alive((is_anonymous || h_class_loader.is_null()) ? 1 : 0),
 132   _metaspace(NULL), _unloading(false), _klasses(NULL),
 133   _modules(NULL), _packages(NULL), _unnamed_module(NULL), _dictionary(NULL),
 134   _claimed(0), _modified_oops(true), _accumulated_modified_oops(false),
 135   _jmethod_ids(NULL), _handles(), _deallocate_list(NULL),
 136   _next(NULL),
 137   _class_loader_klass(NULL), _class_loader_name(NULL),
 138   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true,
 139                             Monitor::_safepoint_check_never)) {
 140 
 141   if (!h_class_loader.is_null()) {
 142     _class_loader = _handles.add(h_class_loader());
 143   }
 144 
 145   if (!is_anonymous) {
 146     // The holder is initialized later for anonymous classes, and before calling anything
 147     // that call class_loader().
 148     initialize_holder(h_class_loader);
 149 
 150     // A ClassLoaderData created solely for an anonymous class should never have a
 151     // ModuleEntryTable or PackageEntryTable created for it. The defining package
 152     // and module for an anonymous class will be found in its host class.
 153     _packages = new PackageEntryTable(PackageEntryTable::_packagetable_entry_size);
 154     if (h_class_loader.is_null()) {
 155       // Create unnamed module for boot loader
 156       _unnamed_module = ModuleEntry::create_boot_unnamed_module(this);
 157     } else {


 894     _deallocate_list->remove_at(i);
 895     if (m->is_constantPool()) {
 896       ((ConstantPool*)m)->release_C_heap_structures();
 897     } else if (m->is_klass()) {
 898       InstanceKlass* ik = (InstanceKlass*)m;
 899       // also releases ik->constants() C heap memory
 900       InstanceKlass::release_C_heap_structures(ik);
 901       // Remove the class so unloading events aren't triggered for
 902       // this class (scratch or error class) in do_unloading().
 903       remove_class(ik);
 904     }
 905   }
 906 }
 907 
 908 // These anonymous class loaders are to contain classes used for JSR292
 909 ClassLoaderData* ClassLoaderData::anonymous_class_loader_data(Handle loader) {
 910   // Add a new class loader data to the graph.
 911   return ClassLoaderDataGraph::add(loader, true);
 912 }
 913 




 914 const char* ClassLoaderData::loader_name() const {
 915   if (is_unloading()) {
 916     if (_class_loader_klass == NULL) {
 917       return "<bootloader>";
 918     } else if (_class_loader_name != NULL) {
 919       return _class_loader_name->as_C_string();
 920     } else {
 921       return _class_loader_klass->name()->as_C_string();
 922     }
 923   } else {
 924     // Handles null class loader
 925     return SystemDictionary::loader_name(class_loader());
 926   }
 927 }
 928 
 929 
 930 void ClassLoaderData::print_value_on(outputStream* out) const {
 931   if (!is_unloading() && class_loader() != NULL) {
 932     out->print("loader data: " INTPTR_FORMAT " for instance ", p2i(this));
 933     class_loader()->print_value_on(out);  // includes loader_name() and address of class loader instance
 934   } else {
 935     // loader data: 0xsomeaddr of <bootloader>
 936     out->print("loader data: " INTPTR_FORMAT " of %s", p2i(this), loader_name());
 937   }
 938   if (is_anonymous()) {
 939     out->print(" anonymous");
 940   }
 941 }
 942 
 943 #ifndef PRODUCT
 944 void ClassLoaderData::print_on(outputStream* out) const {
 945   out->print("ClassLoaderData CLD: " PTR_FORMAT ", loader: " PTR_FORMAT ", loader_klass: %s {",
 946               p2i(this), p2i(_class_loader.ptr_raw()), loader_name());
 947   if (is_anonymous()) out->print(" anonymous");
 948   if (claimed()) out->print(" claimed");
 949   if (is_unloading()) out->print(" unloading");
 950   out->print(" metaspace: " INTPTR_FORMAT, p2i(metaspace_or_null()));
 951 
 952   if (_jmethod_ids != NULL) {
 953     Method::print_jmethod_ids(this, out);
 954   }
 955   out->print(" handles count %d", _handles.count());


1220 void ClassLoaderDataGraph::verify_dictionary() {
1221   FOR_ALL_DICTIONARY(cld) {
1222     cld->dictionary()->verify();
1223   }
1224 }
1225 
1226 void ClassLoaderDataGraph::print_dictionary(outputStream* st) {
1227   FOR_ALL_DICTIONARY(cld) {
1228     st->print("Dictionary for ");
1229     cld->print_value_on(st);
1230     st->cr();
1231     cld->dictionary()->print_on(st);
1232     st->cr();
1233   }
1234 }
1235 
1236 void ClassLoaderDataGraph::print_dictionary_statistics(outputStream* st) {
1237   FOR_ALL_DICTIONARY(cld) {
1238     ResourceMark rm;
1239     stringStream tempst;
1240     tempst.print("System Dictionary for %s", cld->loader_name());
1241     cld->dictionary()->print_table_statistics(st, tempst.as_string());
1242   }
1243 }
1244 
1245 GrowableArray<ClassLoaderData*>* ClassLoaderDataGraph::new_clds() {
1246   assert(_head == NULL || _saved_head != NULL, "remember_new_clds(true) not called?");
1247 
1248   GrowableArray<ClassLoaderData*>* array = new GrowableArray<ClassLoaderData*>();
1249 
1250   // The CLDs in [_head, _saved_head] were all added during last call to remember_new_clds(true);
1251   ClassLoaderData* curr = _head;
1252   while (curr != _saved_head) {
1253     if (!curr->claimed()) {
1254       array->push(curr);
1255       LogTarget(Debug, class, loader, data) lt;
1256       if (lt.is_enabled()) {
1257         LogStream ls(lt);
1258         ls.print("found new CLD: ");
1259         curr->print_value_on(&ls);
1260         ls.cr();




  92   assert(ClassLoaderDataGraph::_head == NULL, "cannot initialize twice");
  93 
  94   _the_null_class_loader_data = new ClassLoaderData(Handle(), false);
  95   ClassLoaderDataGraph::_head = _the_null_class_loader_data;
  96   assert(_the_null_class_loader_data->is_the_null_class_loader_data(), "Must be");
  97 
  98   LogTarget(Debug, class, loader, data) lt;
  99   if (lt.is_enabled()) {
 100     ResourceMark rm;
 101     LogStream ls(lt);
 102     ls.print("create ");
 103     _the_null_class_loader_data->print_value_on(&ls);
 104     ls.cr();
 105   }
 106 }
 107 
 108 // JFR and logging support so that the name and klass are available after the
 109 // class_loader oop is no longer alive, during unloading.
 110 void ClassLoaderData::initialize_name_and_klass(Handle class_loader) {
 111   _class_loader_klass = class_loader->klass();
 112   oop class_loader_name = java_lang_ClassLoader::nameAndId(class_loader());
 113   if (class_loader_name != NULL) {
 114     Thread* THREAD = Thread::current();
 115     ResourceMark rm(THREAD);
 116     const char* class_loader_instance_name =
 117       java_lang_String::as_utf8_string(class_loader_name);
 118 
 119     if (class_loader_instance_name != NULL && class_loader_instance_name[0] != '\0') {
 120       // Can't throw InternalError and SymbolTable doesn't throw OOM anymore.
 121       _class_loader_name_id = SymbolTable::new_symbol(class_loader_instance_name, CATCH);
 122     }
 123   }
 124 
 125   // The class loader's nameAndId should be set in ClassLoader's constructor.
 126   // If for some reason the constructor is not run, instead of leaving the name set
 127   // to null, fallback to the <qualified-class-name>.
 128   if (_class_loader_name_id == NULL) {
 129     _class_loader_name_id = _class_loader_klass->name();
 130   }
 131 }
 132 
 133 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous) :
 134   _is_anonymous(is_anonymous),
 135   // An anonymous class loader data doesn't have anything to keep
 136   // it from being unloaded during parsing of the anonymous class.
 137   // The null-class-loader should always be kept alive.
 138   _keep_alive((is_anonymous || h_class_loader.is_null()) ? 1 : 0),
 139   _metaspace(NULL), _unloading(false), _klasses(NULL),
 140   _modules(NULL), _packages(NULL), _unnamed_module(NULL), _dictionary(NULL),
 141   _claimed(0), _modified_oops(true), _accumulated_modified_oops(false),
 142   _jmethod_ids(NULL), _handles(), _deallocate_list(NULL),
 143   _next(NULL),
 144   _class_loader_klass(NULL), _class_loader_name_id(NULL),
 145   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true,
 146                             Monitor::_safepoint_check_never)) {
 147 
 148   if (!h_class_loader.is_null()) {
 149     _class_loader = _handles.add(h_class_loader());
 150   }
 151 
 152   if (!is_anonymous) {
 153     // The holder is initialized later for anonymous classes, and before calling anything
 154     // that call class_loader().
 155     initialize_holder(h_class_loader);
 156 
 157     // A ClassLoaderData created solely for an anonymous class should never have a
 158     // ModuleEntryTable or PackageEntryTable created for it. The defining package
 159     // and module for an anonymous class will be found in its host class.
 160     _packages = new PackageEntryTable(PackageEntryTable::_packagetable_entry_size);
 161     if (h_class_loader.is_null()) {
 162       // Create unnamed module for boot loader
 163       _unnamed_module = ModuleEntry::create_boot_unnamed_module(this);
 164     } else {


 901     _deallocate_list->remove_at(i);
 902     if (m->is_constantPool()) {
 903       ((ConstantPool*)m)->release_C_heap_structures();
 904     } else if (m->is_klass()) {
 905       InstanceKlass* ik = (InstanceKlass*)m;
 906       // also releases ik->constants() C heap memory
 907       InstanceKlass::release_C_heap_structures(ik);
 908       // Remove the class so unloading events aren't triggered for
 909       // this class (scratch or error class) in do_unloading().
 910       remove_class(ik);
 911     }
 912   }
 913 }
 914 
 915 // These anonymous class loaders are to contain classes used for JSR292
 916 ClassLoaderData* ClassLoaderData::anonymous_class_loader_data(Handle loader) {
 917   // Add a new class loader data to the graph.
 918   return ClassLoaderDataGraph::add(loader, true);
 919 }
 920 
 921 // Caller needs ResourceMark
 922 // If the defining loader has a name explicitly set then '<loader-name>' @<id>
 923 // If the defining loader has no name then <qualified-class-name> @<id>
 924 // If built-in loader, then omit '@<id>' as there is only one instance.
 925 const char* ClassLoaderData::loader_name() const {

 926   if (_class_loader_klass == NULL) {
 927     return "'bootstrap'";


 928   } else {
 929     assert(_class_loader_name_id != NULL, "encountered a null class loader name");
 930     return _class_loader_name_id->as_C_string();



 931   }
 932 }
 933 

 934 void ClassLoaderData::print_value_on(outputStream* out) const {
 935   if (!is_unloading() && class_loader() != NULL) {
 936     out->print("loader data: " INTPTR_FORMAT " for instance ", p2i(this));
 937     class_loader()->print_value_on(out);  // includes loader_name() and address of class loader instance
 938   } else {
 939     // loader data: 0xsomeaddr of 'bootstrap'
 940     out->print("loader data: " INTPTR_FORMAT " of %s", p2i(this), loader_name());
 941   }
 942   if (is_anonymous()) {
 943     out->print(" anonymous");
 944   }
 945 }
 946 
 947 #ifndef PRODUCT
 948 void ClassLoaderData::print_on(outputStream* out) const {
 949   out->print("ClassLoaderData CLD: " PTR_FORMAT ", loader: " PTR_FORMAT ", loader_klass: %s {",
 950               p2i(this), p2i(_class_loader.ptr_raw()), loader_name());
 951   if (is_anonymous()) out->print(" anonymous");
 952   if (claimed()) out->print(" claimed");
 953   if (is_unloading()) out->print(" unloading");
 954   out->print(" metaspace: " INTPTR_FORMAT, p2i(metaspace_or_null()));
 955 
 956   if (_jmethod_ids != NULL) {
 957     Method::print_jmethod_ids(this, out);
 958   }
 959   out->print(" handles count %d", _handles.count());


1224 void ClassLoaderDataGraph::verify_dictionary() {
1225   FOR_ALL_DICTIONARY(cld) {
1226     cld->dictionary()->verify();
1227   }
1228 }
1229 
1230 void ClassLoaderDataGraph::print_dictionary(outputStream* st) {
1231   FOR_ALL_DICTIONARY(cld) {
1232     st->print("Dictionary for ");
1233     cld->print_value_on(st);
1234     st->cr();
1235     cld->dictionary()->print_on(st);
1236     st->cr();
1237   }
1238 }
1239 
1240 void ClassLoaderDataGraph::print_dictionary_statistics(outputStream* st) {
1241   FOR_ALL_DICTIONARY(cld) {
1242     ResourceMark rm;
1243     stringStream tempst;
1244     tempst.print("System Dictionary for %s class loader", cld->loader_name());
1245     cld->dictionary()->print_table_statistics(st, tempst.as_string());
1246   }
1247 }
1248 
1249 GrowableArray<ClassLoaderData*>* ClassLoaderDataGraph::new_clds() {
1250   assert(_head == NULL || _saved_head != NULL, "remember_new_clds(true) not called?");
1251 
1252   GrowableArray<ClassLoaderData*>* array = new GrowableArray<ClassLoaderData*>();
1253 
1254   // The CLDs in [_head, _saved_head] were all added during last call to remember_new_clds(true);
1255   ClassLoaderData* curr = _head;
1256   while (curr != _saved_head) {
1257     if (!curr->claimed()) {
1258       array->push(curr);
1259       LogTarget(Debug, class, loader, data) lt;
1260       if (lt.is_enabled()) {
1261         LogStream ls(lt);
1262         ls.print("found new CLD: ");
1263         curr->print_value_on(&ls);
1264         ls.cr();


< prev index next >