< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page




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



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




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

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


< prev index next >