< 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 // Obtain and set the class loader's name within the ClassLoaderData so
 109 // it will be available for error messages, logging, JFR, etc.  The name
 110 // and klass are available after the class_loader oop is no longer alive,
 111 // during unloading.
 112 void ClassLoaderData::initialize_name_and_klass(Handle class_loader) {
 113   Thread* THREAD = Thread::current();
 114   ResourceMark rm(THREAD);
 115   _class_loader_klass = class_loader->klass();
 116 
 117   // Obtain the class loader's name.  If the class loader's name was not
 118   // explicitly set during construction, the CLD's _name field will be null.
 119   oop cl_name = java_lang_ClassLoader::name(class_loader());
 120   if (cl_name != NULL) {
 121     const char* cl_instance_name = java_lang_String::as_utf8_string(cl_name);
 122 
 123     if (cl_instance_name != NULL && cl_instance_name[0] != '\0') {
 124       // Can't throw InternalError and SymbolTable doesn't throw OOM anymore.
 125       _name = SymbolTable::new_symbol(cl_instance_name, CATCH);
 126     }
 127   }
 128 
 129   // Obtain the class loader's name and identity hash.  If the class loader's
 130   // name was not explicitly set during construction, the class loader's name and id
 131   // will be set to the qualified class name of the class loader along with its
 132   // identity hash.
 133   // If for some reason the ClassLoader's constructor has not been run, instead of
 134   // leaving the _name_and_id field null, fall back to the external qualified class
 135   // name.  Thus CLD's _name_and_id field should never have a null value.


 144 
 145 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous) :
 146   _is_anonymous(is_anonymous),
 147   // An anonymous class loader data doesn't have anything to keep
 148   // it from being unloaded during parsing of the anonymous class.
 149   // The null-class-loader should always be kept alive.
 150   _keep_alive((is_anonymous || h_class_loader.is_null()) ? 1 : 0),
 151   _metaspace(NULL), _unloading(false), _klasses(NULL),
 152   _modules(NULL), _packages(NULL), _unnamed_module(NULL), _dictionary(NULL),
 153   _claimed(0), _modified_oops(true), _accumulated_modified_oops(false),
 154   _jmethod_ids(NULL), _handles(), _deallocate_list(NULL),
 155   _next(NULL),
 156   _class_loader_klass(NULL), _name(NULL), _name_and_id(NULL),
 157   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true,
 158                             Monitor::_safepoint_check_never)) {
 159 
 160   if (!h_class_loader.is_null()) {
 161     _class_loader = _handles.add(h_class_loader());
 162   }
 163 




 164   if (!is_anonymous) {
 165     // The holder is initialized later for anonymous classes, and before calling anything
 166     // that call class_loader().
 167     initialize_holder(h_class_loader);
 168 
 169     // A ClassLoaderData created solely for an anonymous class should never have a
 170     // ModuleEntryTable or PackageEntryTable created for it. The defining package
 171     // and module for an anonymous class will be found in its host class.
 172     _packages = new PackageEntryTable(PackageEntryTable::_packagetable_entry_size);
 173     if (h_class_loader.is_null()) {
 174       // Create unnamed module for boot loader
 175       _unnamed_module = ModuleEntry::create_boot_unnamed_module(this);
 176     } else {
 177       // Create unnamed module for all other loaders
 178       _unnamed_module = ModuleEntry::create_unnamed_module(this);
 179     }
 180     _dictionary = create_dictionary();
 181   }
 182 
 183   NOT_PRODUCT(_dependency_count = 0); // number of class loader dependencies


 934 // If the class loader's _name has not been explicitly set, the class loader's
 935 // qualified class name is returned.
 936 const char* ClassLoaderData::loader_name() const {
 937    if (_class_loader_klass == NULL) {
 938      return BOOTSTRAP_LOADER_NAME;
 939    } else if (_name != NULL) {
 940      return _name->as_C_string();
 941    } else {
 942      return _class_loader_klass->external_name();
 943    }
 944 }
 945 
 946 // Caller needs ResourceMark
 947 // Format of the _name_and_id is as follows:
 948 //   If the defining loader has a name explicitly set then '<loader-name>' @<id>
 949 //   If the defining loader has no name then <qualified-class-name> @<id>
 950 //   If built-in loader, then omit '@<id>' as there is only one instance.
 951 const char* ClassLoaderData::loader_name_and_id() const {
 952   if (_class_loader_klass == NULL) {
 953     return "'" BOOTSTRAP_LOADER_NAME "'";
 954   } else {
 955     assert(_name_and_id != NULL, "encountered a class loader null name and id");
 956     return _name_and_id->as_C_string();


 957   }
 958 }
 959 
 960 void ClassLoaderData::print_value_on(outputStream* out) const {
 961   if (!is_unloading() && class_loader() != NULL) {
 962     out->print("loader data: " INTPTR_FORMAT " for instance ", p2i(this));
 963     class_loader()->print_value_on(out);  // includes loader_name_and_id() and address of class loader instance
 964   } else {
 965     // loader data: 0xsomeaddr of 'bootstrap'
 966     out->print("loader data: " INTPTR_FORMAT " of %s", p2i(this), loader_name_and_id());
 967   }
 968   if (is_anonymous()) {
 969     out->print(" anonymous");
 970   }
 971 }
 972 
 973 #ifndef PRODUCT
 974 void ClassLoaderData::print_on(outputStream* out) const {
 975   out->print("ClassLoaderData CLD: " PTR_FORMAT ", loader: " PTR_FORMAT ", loader_klass: %s {",
 976               p2i(this), p2i(_class_loader.ptr_raw()), loader_name_and_id());


1055     if (exchanged == next) {
1056       LogTarget(Debug, class, loader, data) lt;
1057       if (lt.is_enabled()) {
1058         ResourceMark rm;
1059         LogStream ls(lt);
1060         ls.print("create ");
1061         cld->print_value_on(&ls);
1062         ls.cr();
1063       }
1064       return cld;
1065     }
1066     next = exchanged;
1067   } while (true);
1068 }
1069 
1070 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous) {
1071   ClassLoaderData* loader_data = add_to_graph(loader, is_anonymous);
1072   // Initialize name and class after the loader data is added to the CLDG
1073   // because adding the Symbol for the name might safepoint.
1074   if (loader.not_null()) {
1075     loader_data->initialize_name_and_klass(loader);
1076   }
1077   return loader_data;
1078 }
1079 
1080 void ClassLoaderDataGraph::oops_do(OopClosure* f, bool must_claim) {
1081   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1082     cld->oops_do(f, must_claim);
1083   }
1084 }
1085 
1086 void ClassLoaderDataGraph::keep_alive_oops_do(OopClosure* f, bool must_claim) {
1087   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1088     if (cld->keep_alive()) {
1089       cld->oops_do(f, must_claim);
1090     }
1091   }
1092 }
1093 
1094 void ClassLoaderDataGraph::always_strong_oops_do(OopClosure* f, bool must_claim) {
1095   if (ClassUnloading) {




  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 // Obtain and set the class loader's name within the ClassLoaderData so
 109 // it will be available for error messages, logging, JFR, etc.  The name
 110 // and klass are available after the class_loader oop is no longer alive,
 111 // during unloading.
 112 void ClassLoaderData::initialize_name(Handle class_loader) {
 113   Thread* THREAD = Thread::current();
 114   ResourceMark rm(THREAD);

 115 
 116   // Obtain the class loader's name.  If the class loader's name was not
 117   // explicitly set during construction, the CLD's _name field will be null.
 118   oop cl_name = java_lang_ClassLoader::name(class_loader());
 119   if (cl_name != NULL) {
 120     const char* cl_instance_name = java_lang_String::as_utf8_string(cl_name);
 121 
 122     if (cl_instance_name != NULL && cl_instance_name[0] != '\0') {
 123       // Can't throw InternalError and SymbolTable doesn't throw OOM anymore.
 124       _name = SymbolTable::new_symbol(cl_instance_name, CATCH);
 125     }
 126   }
 127 
 128   // Obtain the class loader's name and identity hash.  If the class loader's
 129   // name was not explicitly set during construction, the class loader's name and id
 130   // will be set to the qualified class name of the class loader along with its
 131   // identity hash.
 132   // If for some reason the ClassLoader's constructor has not been run, instead of
 133   // leaving the _name_and_id field null, fall back to the external qualified class
 134   // name.  Thus CLD's _name_and_id field should never have a null value.


 143 
 144 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous) :
 145   _is_anonymous(is_anonymous),
 146   // An anonymous class loader data doesn't have anything to keep
 147   // it from being unloaded during parsing of the anonymous class.
 148   // The null-class-loader should always be kept alive.
 149   _keep_alive((is_anonymous || h_class_loader.is_null()) ? 1 : 0),
 150   _metaspace(NULL), _unloading(false), _klasses(NULL),
 151   _modules(NULL), _packages(NULL), _unnamed_module(NULL), _dictionary(NULL),
 152   _claimed(0), _modified_oops(true), _accumulated_modified_oops(false),
 153   _jmethod_ids(NULL), _handles(), _deallocate_list(NULL),
 154   _next(NULL),
 155   _class_loader_klass(NULL), _name(NULL), _name_and_id(NULL),
 156   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true,
 157                             Monitor::_safepoint_check_never)) {
 158 
 159   if (!h_class_loader.is_null()) {
 160     _class_loader = _handles.add(h_class_loader());
 161   }
 162 
 163   if (!h_class_loader.is_null()) {
 164     _class_loader_klass = h_class_loader->klass();
 165   }
 166 
 167   if (!is_anonymous) {
 168     // The holder is initialized later for anonymous classes, and before calling anything
 169     // that call class_loader().
 170     initialize_holder(h_class_loader);
 171 
 172     // A ClassLoaderData created solely for an anonymous class should never have a
 173     // ModuleEntryTable or PackageEntryTable created for it. The defining package
 174     // and module for an anonymous class will be found in its host class.
 175     _packages = new PackageEntryTable(PackageEntryTable::_packagetable_entry_size);
 176     if (h_class_loader.is_null()) {
 177       // Create unnamed module for boot loader
 178       _unnamed_module = ModuleEntry::create_boot_unnamed_module(this);
 179     } else {
 180       // Create unnamed module for all other loaders
 181       _unnamed_module = ModuleEntry::create_unnamed_module(this);
 182     }
 183     _dictionary = create_dictionary();
 184   }
 185 
 186   NOT_PRODUCT(_dependency_count = 0); // number of class loader dependencies


 937 // If the class loader's _name has not been explicitly set, the class loader's
 938 // qualified class name is returned.
 939 const char* ClassLoaderData::loader_name() const {
 940    if (_class_loader_klass == NULL) {
 941      return BOOTSTRAP_LOADER_NAME;
 942    } else if (_name != NULL) {
 943      return _name->as_C_string();
 944    } else {
 945      return _class_loader_klass->external_name();
 946    }
 947 }
 948 
 949 // Caller needs ResourceMark
 950 // Format of the _name_and_id is as follows:
 951 //   If the defining loader has a name explicitly set then '<loader-name>' @<id>
 952 //   If the defining loader has no name then <qualified-class-name> @<id>
 953 //   If built-in loader, then omit '@<id>' as there is only one instance.
 954 const char* ClassLoaderData::loader_name_and_id() const {
 955   if (_class_loader_klass == NULL) {
 956     return "'" BOOTSTRAP_LOADER_NAME "'";
 957   } else if (_name_and_id != NULL) {

 958     return _name_and_id->as_C_string();
 959   } else {
 960     return _class_loader_klass->external_name();
 961   }
 962 }
 963 
 964 void ClassLoaderData::print_value_on(outputStream* out) const {
 965   if (!is_unloading() && class_loader() != NULL) {
 966     out->print("loader data: " INTPTR_FORMAT " for instance ", p2i(this));
 967     class_loader()->print_value_on(out);  // includes loader_name_and_id() and address of class loader instance
 968   } else {
 969     // loader data: 0xsomeaddr of 'bootstrap'
 970     out->print("loader data: " INTPTR_FORMAT " of %s", p2i(this), loader_name_and_id());
 971   }
 972   if (is_anonymous()) {
 973     out->print(" anonymous");
 974   }
 975 }
 976 
 977 #ifndef PRODUCT
 978 void ClassLoaderData::print_on(outputStream* out) const {
 979   out->print("ClassLoaderData CLD: " PTR_FORMAT ", loader: " PTR_FORMAT ", loader_klass: %s {",
 980               p2i(this), p2i(_class_loader.ptr_raw()), loader_name_and_id());


1059     if (exchanged == next) {
1060       LogTarget(Debug, class, loader, data) lt;
1061       if (lt.is_enabled()) {
1062         ResourceMark rm;
1063         LogStream ls(lt);
1064         ls.print("create ");
1065         cld->print_value_on(&ls);
1066         ls.cr();
1067       }
1068       return cld;
1069     }
1070     next = exchanged;
1071   } while (true);
1072 }
1073 
1074 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous) {
1075   ClassLoaderData* loader_data = add_to_graph(loader, is_anonymous);
1076   // Initialize name and class after the loader data is added to the CLDG
1077   // because adding the Symbol for the name might safepoint.
1078   if (loader.not_null()) {
1079     loader_data->initialize_name(loader);
1080   }
1081   return loader_data;
1082 }
1083 
1084 void ClassLoaderDataGraph::oops_do(OopClosure* f, bool must_claim) {
1085   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1086     cld->oops_do(f, must_claim);
1087   }
1088 }
1089 
1090 void ClassLoaderDataGraph::keep_alive_oops_do(OopClosure* f, bool must_claim) {
1091   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1092     if (cld->keep_alive()) {
1093       cld->oops_do(f, must_claim);
1094     }
1095   }
1096 }
1097 
1098 void ClassLoaderDataGraph::always_strong_oops_do(OopClosure* f, bool must_claim) {
1099   if (ClassUnloading) {


< prev index next >