< prev index next >

src/hotspot/share/oops/klassVtable.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


 489         }
 490 
 491         // Do not check loader constraints for overpass methods because overpass
 492         // methods are created by the jvm to throw exceptions.
 493         if (checkconstraints && !target_method()->is_overpass()) {
 494           // Override vtable entry if passes loader constraint check
 495           // if loader constraint checking requested
 496           // No need to visit his super, since he and his super
 497           // have already made any needed loader constraints.
 498           // Since loader constraints are transitive, it is enough
 499           // to link to the first super, and we get all the others.
 500           Handle super_loader(THREAD, super_klass->class_loader());
 501 
 502           if (!oopDesc::equals(target_loader(), super_loader())) {
 503             ResourceMark rm(THREAD);
 504             Symbol* failed_type_symbol =
 505               SystemDictionary::check_signature_loaders(signature, target_loader,
 506                                                         super_loader, true,
 507                                                         CHECK_(false));
 508             if (failed_type_symbol != NULL) {
 509               const char* msg = "loader constraint violation for class %s: when selecting "

 510                 "overriding method %s the class loader %s of the "
 511                 "selected method's type %s, and the class loader %s for its super "
 512                 "type %s have different Class objects for the type %s used in the signature";
 513               const char* curr_class = klass->external_name();
 514               const char* method = target_method()->name_and_sig_as_C_string();
 515               const char* loader1 = java_lang_ClassLoader::describe_external(target_loader());
 516               const char* sel_class = target_klass->external_name();
 517               const char* loader2 = java_lang_ClassLoader::describe_external(super_loader());
 518               const char* super_class = super_klass->external_name();
 519               const char* failed_type_name = failed_type_symbol->as_klass_external_name();
 520               size_t buflen = strlen(msg) + strlen(curr_class) + strlen(method) +
 521                 strlen(loader1) + strlen(sel_class) + strlen(loader2) +
 522                 strlen(super_class) + strlen(failed_type_name);
 523               char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
 524               jio_snprintf(buf, buflen, msg, curr_class, method, loader1, sel_class, loader2,
 525                            super_class, failed_type_name);
 526               THROW_MSG_(vmSymbols::java_lang_LinkageError(), buf, false);
 527             }
 528           }
 529         }
 530 
 531         put_method_at(target_method(), i);
 532         overrides = true;
 533         if (!is_default) {
 534           target_method()->set_vtable_index(i);
 535         } else {
 536           if (def_vtable_indices != NULL) {
 537             if (is_preinitialized_vtable()) {
 538               // At runtime initialize_vtable is rerun as part of link_class_impl()
 539               // for a shared class loaded by the non-boot loader.
 540               // The dumptime vtable index should be the same as the runtime index.
 541               assert(def_vtable_indices->at(default_index) == i,
 542                      "dump time vtable index is different from runtime index");
 543             } else {
 544               def_vtable_indices->at_put(default_index, i);
 545             }
 546           }


1224              "Non-public overpass method!");
1225       // Entry does not resolve. Leave it empty for AbstractMethodError or other error.
1226       if (!(target == NULL) && !target->is_public()) {
1227         // Stuff an IllegalAccessError throwing method in there instead.
1228         itableOffsetEntry::method_entry(_klass, method_table_offset)[m->itable_index()].
1229             initialize(Universe::throw_illegal_access_error());
1230       }
1231     } else {
1232       // Entry did resolve, check loader constraints before initializing
1233       // if checkconstraints requested
1234       if (checkconstraints) {
1235         Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
1236         if (!oopDesc::equals(method_holder_loader(), interface_loader())) {
1237           ResourceMark rm(THREAD);
1238           Symbol* failed_type_symbol =
1239             SystemDictionary::check_signature_loaders(m->signature(),
1240                                                       method_holder_loader,
1241                                                       interface_loader,
1242                                                       true, CHECK);
1243           if (failed_type_symbol != NULL) {
1244             const char* msg = "loader constraint violation in interface itable"

1245               " initialization for class %s: when selecting method %s the"
1246               " class loader %s for super interface %s, and the class"
1247               " loader %s of the selected method's type, %s have"
1248               " different Class objects for the type %s used in the signature";
1249             const char* current = _klass->external_name();
1250             const char* sig = m->name_and_sig_as_C_string();
1251             const char* loader1 = java_lang_ClassLoader::describe_external(interface_loader());
1252             const char* iface = InstanceKlass::cast(interf)->external_name();
1253             const char* loader2 = java_lang_ClassLoader::describe_external(method_holder_loader());
1254             const char* mclass = target()->method_holder()->external_name();
1255             const char* failed_type_name = failed_type_symbol->as_klass_external_name();
1256             size_t buflen = strlen(msg) + strlen(current) + strlen(sig) +
1257               strlen(loader1) + strlen(iface) + strlen(loader2) + strlen(mclass) +
1258               strlen(failed_type_name);
1259             char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
1260             jio_snprintf(buf, buflen, msg, current, sig, loader1, iface,
1261                          loader2, mclass, failed_type_name);
1262             THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
1263           }
1264         }
1265       }
1266 
1267       // ime may have moved during GC so recalculate address
1268       int ime_num = m->itable_index();
1269       assert(ime_num < ime_count, "oob");
1270       itableOffsetEntry::method_entry(_klass, method_table_offset)[ime_num].initialize(target());
1271       if (log_develop_is_enabled(Trace, itables)) {
1272         ResourceMark rm(THREAD);
1273         if (target() != NULL) {
1274           LogTarget(Trace, itables) lt;
1275           LogStream ls(lt);
1276           char* sig = target()->name_and_sig_as_C_string();
1277           ls.print("interface: %s, ime_num: %d, target: %s, method_holder: %s ",
1278                        interf->internal_name(), ime_num, sig,
1279                        target()->method_holder()->internal_name());
1280           ls.print("target_method flags: ");
1281           target()->print_linkage_flags(&ls);
1282           ls.cr();




 489         }
 490 
 491         // Do not check loader constraints for overpass methods because overpass
 492         // methods are created by the jvm to throw exceptions.
 493         if (checkconstraints && !target_method()->is_overpass()) {
 494           // Override vtable entry if passes loader constraint check
 495           // if loader constraint checking requested
 496           // No need to visit his super, since he and his super
 497           // have already made any needed loader constraints.
 498           // Since loader constraints are transitive, it is enough
 499           // to link to the first super, and we get all the others.
 500           Handle super_loader(THREAD, super_klass->class_loader());
 501 
 502           if (!oopDesc::equals(target_loader(), super_loader())) {
 503             ResourceMark rm(THREAD);
 504             Symbol* failed_type_symbol =
 505               SystemDictionary::check_signature_loaders(signature, target_loader,
 506                                                         super_loader, true,
 507                                                         CHECK_(false));
 508             if (failed_type_symbol != NULL) {
 509               stringStream ss;
 510               ss.print("loader constraint violation for class %s: when selecting "
 511                        "overriding method %s the class loader %s of the "
 512                        "selected method's type %s, and the class loader %s for its super "
 513                        "type %s have different Class objects for the type %s used in the signature (%s; %s)",
 514                        klass->external_name(),
 515                        target_method()->name_and_sig_as_C_string(),
 516                        target_klass->class_loader_data()->loader_name_and_id(),
 517                        target_klass->external_name(),
 518                        super_klass->class_loader_data()->loader_name_and_id(),
 519                        super_klass->external_name(),
 520                        failed_type_symbol->as_klass_external_name(),
 521                        target_klass->class_in_module_of_loader(false, true),
 522                        super_klass->class_in_module_of_loader(false, true));
 523               THROW_MSG_(vmSymbols::java_lang_LinkageError(), ss.as_string(), false);




 524             }
 525           }
 526         }
 527 
 528         put_method_at(target_method(), i);
 529         overrides = true;
 530         if (!is_default) {
 531           target_method()->set_vtable_index(i);
 532         } else {
 533           if (def_vtable_indices != NULL) {
 534             if (is_preinitialized_vtable()) {
 535               // At runtime initialize_vtable is rerun as part of link_class_impl()
 536               // for a shared class loaded by the non-boot loader.
 537               // The dumptime vtable index should be the same as the runtime index.
 538               assert(def_vtable_indices->at(default_index) == i,
 539                      "dump time vtable index is different from runtime index");
 540             } else {
 541               def_vtable_indices->at_put(default_index, i);
 542             }
 543           }


1221              "Non-public overpass method!");
1222       // Entry does not resolve. Leave it empty for AbstractMethodError or other error.
1223       if (!(target == NULL) && !target->is_public()) {
1224         // Stuff an IllegalAccessError throwing method in there instead.
1225         itableOffsetEntry::method_entry(_klass, method_table_offset)[m->itable_index()].
1226             initialize(Universe::throw_illegal_access_error());
1227       }
1228     } else {
1229       // Entry did resolve, check loader constraints before initializing
1230       // if checkconstraints requested
1231       if (checkconstraints) {
1232         Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
1233         if (!oopDesc::equals(method_holder_loader(), interface_loader())) {
1234           ResourceMark rm(THREAD);
1235           Symbol* failed_type_symbol =
1236             SystemDictionary::check_signature_loaders(m->signature(),
1237                                                       method_holder_loader,
1238                                                       interface_loader,
1239                                                       true, CHECK);
1240           if (failed_type_symbol != NULL) {
1241             stringStream ss;
1242             ss.print("loader constraint violation in interface itable"
1243                      " initialization for class %s: when selecting method %s the"
1244                      " class loader %s for super interface %s, and the class"
1245                      " loader %s of the selected method's type, %s have"
1246                      " different Class objects for the type %s used in the signature (%s; %s)",
1247                      _klass->external_name(),
1248                      m->name_and_sig_as_C_string(),
1249                      interf->class_loader_data()->loader_name_and_id(),
1250                      interf->external_name(),
1251                      target()->method_holder()->class_loader_data()->loader_name_and_id(),
1252                      target()->method_holder()->external_name(),
1253                      failed_type_symbol->as_klass_external_name(),
1254                      interf->class_in_module_of_loader(false, true),
1255                      target()->method_holder()->class_in_module_of_loader(false, true));
1256             THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());




1257           }
1258         }
1259       }
1260 
1261       // ime may have moved during GC so recalculate address
1262       int ime_num = m->itable_index();
1263       assert(ime_num < ime_count, "oob");
1264       itableOffsetEntry::method_entry(_klass, method_table_offset)[ime_num].initialize(target());
1265       if (log_develop_is_enabled(Trace, itables)) {
1266         ResourceMark rm(THREAD);
1267         if (target() != NULL) {
1268           LogTarget(Trace, itables) lt;
1269           LogStream ls(lt);
1270           char* sig = target()->name_and_sig_as_C_string();
1271           ls.print("interface: %s, ime_num: %d, target: %s, method_holder: %s ",
1272                        interf->internal_name(), ime_num, sig,
1273                        target()->method_holder()->internal_name());
1274           ls.print("target_method flags: ");
1275           target()->print_linkage_flags(&ls);
1276           ls.cr();


< prev index next >