src/hotspot/share/classfile/classLoaderData.cpp
changeset 50759 00c4edaf2017
parent 50634 c349d409262a
child 50803 45c1fde86050
equal deleted inserted replaced
50758:afca3c78ea0f 50759:00c4edaf2017
   107 
   107 
   108 // Obtain and set the class loader's name within the ClassLoaderData so
   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
   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,
   110 // and klass are available after the class_loader oop is no longer alive,
   111 // during unloading.
   111 // during unloading.
   112 void ClassLoaderData::initialize_name_and_klass(Handle class_loader) {
   112 void ClassLoaderData::initialize_name(Handle class_loader) {
   113   Thread* THREAD = Thread::current();
   113   Thread* THREAD = Thread::current();
   114   ResourceMark rm(THREAD);
   114   ResourceMark rm(THREAD);
   115   _class_loader_klass = class_loader->klass();
       
   116 
   115 
   117   // Obtain the class loader's name.  If the class loader's name was not
   116   // 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.
   117   // explicitly set during construction, the CLD's _name field will be null.
   119   oop cl_name = java_lang_ClassLoader::name(class_loader());
   118   oop cl_name = java_lang_ClassLoader::name(class_loader());
   120   if (cl_name != NULL) {
   119   if (cl_name != NULL) {
   157   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true,
   156   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true,
   158                             Monitor::_safepoint_check_never)) {
   157                             Monitor::_safepoint_check_never)) {
   159 
   158 
   160   if (!h_class_loader.is_null()) {
   159   if (!h_class_loader.is_null()) {
   161     _class_loader = _handles.add(h_class_loader());
   160     _class_loader = _handles.add(h_class_loader());
       
   161     _class_loader_klass = h_class_loader->klass();
   162   }
   162   }
   163 
   163 
   164   if (!is_anonymous) {
   164   if (!is_anonymous) {
   165     // The holder is initialized later for anonymous classes, and before calling anything
   165     // The holder is initialized later for anonymous classes, and before calling anything
   166     // that call class_loader().
   166     // that call class_loader().
   949 //   If the defining loader has no name then <qualified-class-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.
   950 //   If built-in loader, then omit '@<id>' as there is only one instance.
   951 const char* ClassLoaderData::loader_name_and_id() const {
   951 const char* ClassLoaderData::loader_name_and_id() const {
   952   if (_class_loader_klass == NULL) {
   952   if (_class_loader_klass == NULL) {
   953     return "'" BOOTSTRAP_LOADER_NAME "'";
   953     return "'" BOOTSTRAP_LOADER_NAME "'";
       
   954   } else if (_name_and_id != NULL) {
       
   955     return _name_and_id->as_C_string();
   954   } else {
   956   } else {
   955     assert(_name_and_id != NULL, "encountered a class loader null name and id");
   957     // May be called in a race before _name_and_id is initialized.
   956     return _name_and_id->as_C_string();
   958     return _class_loader_klass->external_name();
   957   }
   959   }
   958 }
   960 }
   959 
   961 
   960 void ClassLoaderData::print_value_on(outputStream* out) const {
   962 void ClassLoaderData::print_value_on(outputStream* out) const {
   961   if (!is_unloading() && class_loader() != NULL) {
   963   if (!is_unloading() && class_loader() != NULL) {
  1067   } while (true);
  1069   } while (true);
  1068 }
  1070 }
  1069 
  1071 
  1070 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous) {
  1072 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous) {
  1071   ClassLoaderData* loader_data = add_to_graph(loader, is_anonymous);
  1073   ClassLoaderData* loader_data = add_to_graph(loader, is_anonymous);
  1072   // Initialize name and class after the loader data is added to the CLDG
  1074   // Initialize _name and _name_and_id after the loader data is added to the
  1073   // because adding the Symbol for the name might safepoint.
  1075   // CLDG because adding the Symbol for _name and _name_and_id might safepoint.
  1074   if (loader.not_null()) {
  1076   if (loader.not_null()) {
  1075     loader_data->initialize_name_and_klass(loader);
  1077     loader_data->initialize_name(loader);
  1076   }
  1078   }
  1077   return loader_data;
  1079   return loader_data;
  1078 }
  1080 }
  1079 
  1081 
  1080 void ClassLoaderDataGraph::oops_do(OopClosure* f, bool must_claim) {
  1082 void ClassLoaderDataGraph::oops_do(OopClosure* f, bool must_claim) {