< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page
rev 51756 : 8205611: Improve the wording of LinkageErrors to include module and class loader information
Summary: Clean up the wording of loader constraint violations to include the module and class loader information.
Reviewed-by: coleenp, goetz, hseigel


2074   stringStream ss;
2075   bool throwException = false;
2076 
2077   {
2078     Symbol *name = k->name();
2079     ClassLoaderData *loader_data = class_loader_data(class_loader);
2080 
2081     MutexLocker mu(SystemDictionary_lock, THREAD);
2082 
2083     InstanceKlass* check = find_class(d_hash, name, loader_data->dictionary());
2084     if (check != NULL) {
2085       // If different InstanceKlass - duplicate class definition,
2086       // else - ok, class loaded by a different thread in parallel.
2087       // We should only have found it if it was done loading and ok to use.
2088       // The dictionary only holds instance classes, placeholders
2089       // also hold array classes.
2090 
2091       assert(check->is_instance_klass(), "noninstance in systemdictionary");
2092       if ((defining == true) || (k != check)) {
2093         throwException = true;
2094         ss.print("loader %s", java_lang_ClassLoader::describe_external(class_loader()));
2095         ss.print(" attempted duplicate %s definition for %s.",
2096                  k->external_kind(), k->external_name());
2097       } else {
2098         return;
2099       }
2100     }
2101 
2102 #ifdef ASSERT
2103     Symbol* ph_check = find_placeholder(name, loader_data);
2104     assert(ph_check == NULL || ph_check == name, "invalid symbol");
2105 #endif
2106 
2107     if (throwException == false) {
2108       if (constraints()->check_or_update(k, class_loader, name) == false) {
2109         throwException = true;
2110         ss.print("loader constraint violation: loader %s",
2111                  java_lang_ClassLoader::describe_external(class_loader()));
2112         ss.print(" wants to load %s %s.",
2113                  k->external_kind(), k->external_name());
2114         Klass *existing_klass = constraints()->find_constrained_klass(name, class_loader);
2115         if (existing_klass->class_loader() != class_loader()) {
2116           ss.print(" A different %s with the same name was previously loaded by %s.",
2117                    existing_klass->external_kind(),
2118                    java_lang_ClassLoader::describe_external(existing_klass->class_loader()));



2119         }
2120       }
2121     }
2122   }
2123 
2124   // Throw error now if needed (cannot throw while holding
2125   // SystemDictionary_lock because of rank ordering)
2126   if (throwException == true) {
2127     THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
2128   }
2129 }
2130 
2131 // Update class loader data dictionary - done after check_constraint and add_to_hierachy
2132 // have been called.
2133 void SystemDictionary::update_dictionary(unsigned int d_hash,
2134                                          int p_index, unsigned int p_hash,
2135                                          InstanceKlass* k,
2136                                          Handle class_loader,
2137                                          TRAPS) {
2138   // Compile_lock prevents systemDictionary updates during compilations




2074   stringStream ss;
2075   bool throwException = false;
2076 
2077   {
2078     Symbol *name = k->name();
2079     ClassLoaderData *loader_data = class_loader_data(class_loader);
2080 
2081     MutexLocker mu(SystemDictionary_lock, THREAD);
2082 
2083     InstanceKlass* check = find_class(d_hash, name, loader_data->dictionary());
2084     if (check != NULL) {
2085       // If different InstanceKlass - duplicate class definition,
2086       // else - ok, class loaded by a different thread in parallel.
2087       // We should only have found it if it was done loading and ok to use.
2088       // The dictionary only holds instance classes, placeholders
2089       // also hold array classes.
2090 
2091       assert(check->is_instance_klass(), "noninstance in systemdictionary");
2092       if ((defining == true) || (k != check)) {
2093         throwException = true;
2094         ss.print("loader %s", loader_data->loader_name_and_id());
2095         ss.print(" attempted duplicate %s definition for %s. (%s)",
2096                  k->external_kind(), k->external_name(), k->class_in_module_of_loader(false, true));
2097       } else {
2098         return;
2099       }
2100     }
2101 
2102 #ifdef ASSERT
2103     Symbol* ph_check = find_placeholder(name, loader_data);
2104     assert(ph_check == NULL || ph_check == name, "invalid symbol");
2105 #endif
2106 
2107     if (throwException == false) {
2108       if (constraints()->check_or_update(k, class_loader, name) == false) {
2109         throwException = true;
2110         ss.print("loader constraint violation: loader %s", loader_data->loader_name_and_id());

2111         ss.print(" wants to load %s %s.",
2112                  k->external_kind(), k->external_name());
2113         Klass *existing_klass = constraints()->find_constrained_klass(name, class_loader);
2114         if (existing_klass->class_loader() != class_loader()) {
2115           ss.print(" A different %s with the same name was previously loaded by %s. (%s)",
2116                    existing_klass->external_kind(),
2117                    existing_klass->class_loader_data()->loader_name_and_id(),
2118                    existing_klass->class_in_module_of_loader(false, true));
2119         } else {
2120           ss.print(" (%s)", k->class_in_module_of_loader(false, true));
2121         }
2122       }
2123     }
2124   }
2125 
2126   // Throw error now if needed (cannot throw while holding
2127   // SystemDictionary_lock because of rank ordering)
2128   if (throwException == true) {
2129     THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
2130   }
2131 }
2132 
2133 // Update class loader data dictionary - done after check_constraint and add_to_hierachy
2134 // have been called.
2135 void SystemDictionary::update_dictionary(unsigned int d_hash,
2136                                          int p_index, unsigned int p_hash,
2137                                          InstanceKlass* k,
2138                                          Handle class_loader,
2139                                          TRAPS) {
2140   // Compile_lock prevents systemDictionary updates during compilations


< prev index next >