487
488 // Do not check loader constraints for overpass methods because overpass
489 // methods are created by the jvm to throw exceptions.
490 if (checkconstraints && !target_method()->is_overpass()) {
491 // Override vtable entry if passes loader constraint check
492 // if loader constraint checking requested
493 // No need to visit his super, since he and his super
494 // have already made any needed loader constraints.
495 // Since loader constraints are transitive, it is enough
496 // to link to the first super, and we get all the others.
497 Handle super_loader(THREAD, super_klass->class_loader());
498
499 if (target_loader() != super_loader()) {
500 ResourceMark rm(THREAD);
501 Symbol* failed_type_symbol =
502 SystemDictionary::check_signature_loaders(signature, target_loader,
503 super_loader, true,
504 CHECK_(false));
505 if (failed_type_symbol != NULL) {
506 const char* msg = "loader constraint violation for class %s: when selecting "
507 "overriding method \"%s\" the class loader (instance of %s) of the "
508 "selected method's type %s, and the class loader (instance of %s) for its super "
509 "type %s have different Class objects for the type %s used in the signature";
510 char* curr_class = klass->name()->as_C_string();
511 char* sig = target_method()->name_and_sig_as_C_string();
512 const char* loader1 = SystemDictionary::loader_name(target_loader());
513 char* sel_class = target_klass->name()->as_C_string();
514 const char* loader2 = SystemDictionary::loader_name(super_loader());
515 char* super_class = super_klass->name()->as_C_string();
516 char* failed_type_name = failed_type_symbol->as_C_string();
517 size_t buflen = strlen(msg) + strlen(curr_class) + strlen(sig) +
518 strlen(loader1) + strlen(sel_class) + strlen(loader2) +
519 strlen(super_class) + strlen(failed_type_name);
520 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
521 jio_snprintf(buf, buflen, msg, curr_class, sig, loader1, sel_class, loader2,
522 super_class, failed_type_name);
523 THROW_MSG_(vmSymbols::java_lang_LinkageError(), buf, 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()
1217 // Entry does not resolve. Leave it empty for AbstractMethodError or other error.
1218 if (!(target == NULL) && !target->is_public()) {
1219 // Stuff an IllegalAccessError throwing method in there instead.
1220 itableOffsetEntry::method_entry(_klass, method_table_offset)[m->itable_index()].
1221 initialize(Universe::throw_illegal_access_error());
1222 }
1223 } else {
1224 // Entry did resolve, check loader constraints before initializing
1225 // if checkconstraints requested
1226 if (checkconstraints) {
1227 Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
1228 if (method_holder_loader() != interface_loader()) {
1229 ResourceMark rm(THREAD);
1230 Symbol* failed_type_symbol =
1231 SystemDictionary::check_signature_loaders(m->signature(),
1232 method_holder_loader,
1233 interface_loader,
1234 true, CHECK);
1235 if (failed_type_symbol != NULL) {
1236 const char* msg = "loader constraint violation in interface itable"
1237 " initialization for class %s: when selecting method \"%s\" the"
1238 " class loader (instance of %s) for super interface %s, and the class"
1239 " loader (instance of %s) of the selected method's type, %s have"
1240 " different Class objects for the type %s used in the signature";
1241 char* current = _klass->name()->as_C_string();
1242 char* sig = m->name_and_sig_as_C_string();
1243 const char* loader1 = SystemDictionary::loader_name(interface_loader());
1244 char* iface = InstanceKlass::cast(interf)->name()->as_C_string();
1245 const char* loader2 = SystemDictionary::loader_name(method_holder_loader());
1246 char* mclass = target()->method_holder()->name()->as_C_string();
1247 char* failed_type_name = failed_type_symbol->as_C_string();
1248 size_t buflen = strlen(msg) + strlen(current) + strlen(sig) +
1249 strlen(loader1) + strlen(iface) + strlen(loader2) + strlen(mclass) +
1250 strlen(failed_type_name);
1251 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
1252 jio_snprintf(buf, buflen, msg, current, sig, loader1, iface,
1253 loader2, mclass, failed_type_name);
1254 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
1255 }
1256 }
1257 }
1258
1259 // ime may have moved during GC so recalculate address
1260 int ime_num = m->itable_index();
1261 assert(ime_num < ime_count, "oob");
1262 itableOffsetEntry::method_entry(_klass, method_table_offset)[ime_num].initialize(target());
1263 if (log_develop_is_enabled(Trace, itables)) {
1264 ResourceMark rm(THREAD);
1265 if (target() != NULL) {
1266 LogTarget(Trace, itables) lt;
1267 LogStream ls(lt);
|
487
488 // Do not check loader constraints for overpass methods because overpass
489 // methods are created by the jvm to throw exceptions.
490 if (checkconstraints && !target_method()->is_overpass()) {
491 // Override vtable entry if passes loader constraint check
492 // if loader constraint checking requested
493 // No need to visit his super, since he and his super
494 // have already made any needed loader constraints.
495 // Since loader constraints are transitive, it is enough
496 // to link to the first super, and we get all the others.
497 Handle super_loader(THREAD, super_klass->class_loader());
498
499 if (target_loader() != super_loader()) {
500 ResourceMark rm(THREAD);
501 Symbol* failed_type_symbol =
502 SystemDictionary::check_signature_loaders(signature, target_loader,
503 super_loader, true,
504 CHECK_(false));
505 if (failed_type_symbol != NULL) {
506 const char* msg = "loader constraint violation for class %s: when selecting "
507 "overriding method %s the class loader %s of the "
508 "selected method's type %s, and the class loader %s for its super "
509 "type %s have different Class objects for the type %s used in the signature";
510 const char* curr_class = klass->external_name();
511 const char* sig = target_method()->name_and_sig_as_C_string();
512 const char* loader1 = java_lang_ClassLoader::describe_external(target_loader());
513 const char* sel_class = target_klass->external_name();
514 const char* loader2 = java_lang_ClassLoader::describe_external(super_loader());
515 const char* super_class = super_klass->external_name();
516 char* failed_type_name = failed_type_symbol->as_C_string();
517 size_t buflen = strlen(msg) + strlen(curr_class) + strlen(sig) +
518 strlen(loader1) + strlen(sel_class) + strlen(loader2) +
519 strlen(super_class) + strlen(failed_type_name);
520 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
521 jio_snprintf(buf, buflen, msg, curr_class, sig, loader1, sel_class, loader2,
522 super_class, failed_type_name);
523 THROW_MSG_(vmSymbols::java_lang_LinkageError(), buf, 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()
1217 // Entry does not resolve. Leave it empty for AbstractMethodError or other error.
1218 if (!(target == NULL) && !target->is_public()) {
1219 // Stuff an IllegalAccessError throwing method in there instead.
1220 itableOffsetEntry::method_entry(_klass, method_table_offset)[m->itable_index()].
1221 initialize(Universe::throw_illegal_access_error());
1222 }
1223 } else {
1224 // Entry did resolve, check loader constraints before initializing
1225 // if checkconstraints requested
1226 if (checkconstraints) {
1227 Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
1228 if (method_holder_loader() != interface_loader()) {
1229 ResourceMark rm(THREAD);
1230 Symbol* failed_type_symbol =
1231 SystemDictionary::check_signature_loaders(m->signature(),
1232 method_holder_loader,
1233 interface_loader,
1234 true, CHECK);
1235 if (failed_type_symbol != NULL) {
1236 const char* msg = "loader constraint violation in interface itable"
1237 " initialization for class %s: when selecting method %s the"
1238 " class loader %s for super interface %s, and the class"
1239 " loader %s of the selected method's type, %s have"
1240 " different Class objects for the type %s used in the signature";
1241 const char* current = _klass->external_name();
1242 const char* sig = m->name_and_sig_as_C_string();
1243 const char* loader1 = java_lang_ClassLoader::describe_external(interface_loader());
1244 const char* iface = InstanceKlass::cast(interf)->external_name();
1245 const char* loader2 = java_lang_ClassLoader::describe_external(method_holder_loader());
1246 const char* mclass = target()->method_holder()->external_name();
1247 const char* failed_type_name = failed_type_symbol->as_C_string();
1248 size_t buflen = strlen(msg) + strlen(current) + strlen(sig) +
1249 strlen(loader1) + strlen(iface) + strlen(loader2) + strlen(mclass) +
1250 strlen(failed_type_name);
1251 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
1252 jio_snprintf(buf, buflen, msg, current, sig, loader1, iface,
1253 loader2, mclass, failed_type_name);
1254 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
1255 }
1256 }
1257 }
1258
1259 // ime may have moved during GC so recalculate address
1260 int ime_num = m->itable_index();
1261 assert(ime_num < ime_count, "oob");
1262 itableOffsetEntry::method_entry(_klass, method_table_offset)[ime_num].initialize(target());
1263 if (log_develop_is_enabled(Trace, itables)) {
1264 ResourceMark rm(THREAD);
1265 if (target() != NULL) {
1266 LogTarget(Trace, itables) lt;
1267 LogStream ls(lt);
|