< prev index next >

src/hotspot/share/interpreter/linkResolver.cpp

Print this page




 645     return resolve_method(link_info, code, THREAD);
 646   } else if (!resolved_klass->is_interface()) {
 647     return resolve_method(link_info, code, THREAD);
 648   } else {
 649     return resolve_interface_method(link_info, code, THREAD);
 650   }
 651 }
 652 
 653 // Check and print a loader constraint violation message for method or interface method
 654 void LinkResolver::check_method_loader_constraints(const LinkInfo& link_info,
 655                                                    const methodHandle& resolved_method,
 656                                                    const char* method_type, TRAPS) {
 657   Handle current_loader(THREAD, link_info.current_klass()->class_loader());
 658   Handle resolved_loader(THREAD, resolved_method->method_holder()->class_loader());
 659 
 660   ResourceMark rm(THREAD);
 661   Symbol* failed_type_symbol =
 662     SystemDictionary::check_signature_loaders(link_info.signature(), current_loader,
 663                                               resolved_loader, true, CHECK);
 664   if (failed_type_symbol != NULL) {







 665     const char* msg = "loader constraint violation: when resolving %s"
 666       " \"%s\" the class loader %s of the current class, %s,"
 667       " and the class loader %s for the method's defining class, %s, have"
 668       " different Class objects for the type %s used in the signature";
 669     char* sig = link_info.method_string();
 670     const char* loader1_name = java_lang_ClassLoader::describe_external(current_loader());
 671     char* current = link_info.current_klass()->name()->as_C_string();
 672     const char* loader2_name = java_lang_ClassLoader::describe_external(resolved_loader());
 673     char* target = resolved_method->method_holder()->name()->as_C_string();


 674     char* failed_type_name = failed_type_symbol->as_C_string();
 675     size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1_name) +
 676       strlen(current) + strlen(loader2_name) + strlen(target) +

 677       strlen(failed_type_name) + strlen(method_type) + 1;
 678     char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
 679     jio_snprintf(buf, buflen, msg, method_type, sig, loader1_name, current, loader2_name,
 680                  target, failed_type_name);
 681     THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
 682   }
 683 }
 684 
 685 void LinkResolver::check_field_loader_constraints(Symbol* field, Symbol* sig,
 686                                                   Klass* current_klass,
 687                                                   Klass* sel_klass, TRAPS) {
 688   Handle ref_loader(THREAD, current_klass->class_loader());
 689   Handle sel_loader(THREAD, sel_klass->class_loader());
 690 
 691   ResourceMark rm(THREAD);  // needed for check_signature_loaders
 692   Symbol* failed_type_symbol =
 693     SystemDictionary::check_signature_loaders(sig,
 694                                               ref_loader, sel_loader,
 695                                               false,
 696                                               CHECK);
 697   if (failed_type_symbol != NULL) {
 698     const char* msg = "loader constraint violation: when resolving field"
 699       " \"%s\" of type %s, the class loader %s of the current class, "
 700       "%s, and the class loader %s for the field's defining "
 701       "type, %s, have different Class objects for type %s";
 702     const char* field_name = field->as_C_string();
 703     const char* loader1_name = java_lang_ClassLoader::describe_external(ref_loader());
 704     const char* sel = sel_klass->external_name();
 705     const char* loader2_name = java_lang_ClassLoader::describe_external(sel_loader());



 706     const char* failed_type_name = failed_type_symbol->as_klass_external_name();
 707     const char* curr_klass_name = current_klass->external_name();
 708     size_t buflen = strlen(msg) + strlen(field_name) + 2 * strlen(failed_type_name) +
 709                     strlen(loader1_name) + strlen(curr_klass_name) +
 710                     strlen(loader2_name) + strlen(sel) + 1;
 711     char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
 712     jio_snprintf(buf, buflen, msg, field_name, failed_type_name, loader1_name,
 713                  curr_klass_name, loader2_name, sel, failed_type_name);

 714     THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
 715   }
 716 }
 717 
 718 methodHandle LinkResolver::resolve_method(const LinkInfo& link_info,
 719                                           Bytecodes::Code code, TRAPS) {
 720 
 721   Handle nested_exception;
 722   Klass* resolved_klass = link_info.resolved_klass();
 723 
 724   // 1. For invokevirtual, cannot call an interface method
 725   if (code == Bytecodes::_invokevirtual && resolved_klass->is_interface()) {
 726     ResourceMark rm(THREAD);
 727     char buf[200];
 728     jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected",
 729         resolved_klass->external_name());
 730     THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 731   }
 732 
 733   // 2. check constant pool tag for called method - must be JVM_CONSTANT_Methodref




 645     return resolve_method(link_info, code, THREAD);
 646   } else if (!resolved_klass->is_interface()) {
 647     return resolve_method(link_info, code, THREAD);
 648   } else {
 649     return resolve_interface_method(link_info, code, THREAD);
 650   }
 651 }
 652 
 653 // Check and print a loader constraint violation message for method or interface method
 654 void LinkResolver::check_method_loader_constraints(const LinkInfo& link_info,
 655                                                    const methodHandle& resolved_method,
 656                                                    const char* method_type, TRAPS) {
 657   Handle current_loader(THREAD, link_info.current_klass()->class_loader());
 658   Handle resolved_loader(THREAD, resolved_method->method_holder()->class_loader());
 659 
 660   ResourceMark rm(THREAD);
 661   Symbol* failed_type_symbol =
 662     SystemDictionary::check_signature_loaders(link_info.signature(), current_loader,
 663                                               resolved_loader, true, CHECK);
 664   if (failed_type_symbol != NULL) {
 665     Klass* current_class = link_info.current_klass();
 666     ClassLoaderData* current_loader_data = current_class->class_loader_data();
 667     assert(current_loader_data != NULL, "current class has no class loader data");
 668     Klass* resolved_method_class = resolved_method->method_holder();
 669     ClassLoaderData* target_loader_data = resolved_method_class->class_loader_data();
 670     assert(target_loader_data != NULL, "resolved method's class has no class loader data");
 671 
 672     const char* msg = "loader constraint violation: when resolving %s"
 673       " \"%s\" the class loader %s of the current class, %s,"
 674       " and the class loader %s for the method's defining class, %s, have"
 675       " different Class objects for the type %s used in the signature (%s; %s)";
 676     char* sig = link_info.method_string();
 677     const char* loader1_name = current_loader_data->loader_name_and_id();
 678     char* current = current_class->name()->as_C_string();
 679     const char* current_class_description = current_class->class_in_module_of_loader(false,true);
 680     const char* loader2_name = target_loader_data->loader_name_and_id();
 681     char* target = resolved_method_class->name()->as_C_string();
 682     const char* target_class_description = resolved_method_class->class_in_module_of_loader(false,true);
 683     char* failed_type_name = failed_type_symbol->as_C_string();
 684     size_t buflen = strlen(msg) + strlen(sig) +
 685                     strlen(loader1_name) + strlen(current) + strlen(current_class_description) +
 686                     strlen(loader2_name) + strlen(target) + strlen(target_class_description) +
 687                     strlen(failed_type_name) + strlen(method_type) + 1;
 688     char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
 689     jio_snprintf(buf, buflen, msg, method_type, sig, loader1_name, current, loader2_name,
 690                  target, failed_type_name, current_class_description, target_class_description);
 691     THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
 692   }
 693 }
 694 
 695 void LinkResolver::check_field_loader_constraints(Symbol* field, Symbol* sig,
 696                                                   Klass* current_klass,
 697                                                   Klass* sel_klass, TRAPS) {
 698   Handle ref_loader(THREAD, current_klass->class_loader());
 699   Handle sel_loader(THREAD, sel_klass->class_loader());
 700 
 701   ResourceMark rm(THREAD);  // needed for check_signature_loaders
 702   Symbol* failed_type_symbol =
 703     SystemDictionary::check_signature_loaders(sig,
 704                                               ref_loader, sel_loader,
 705                                               false,
 706                                               CHECK);
 707   if (failed_type_symbol != NULL) {
 708     const char* msg = "loader constraint violation: when resolving field"
 709       " \"%s\" of type %s, the class loader %s of the current class, "
 710       "%s, and the class loader %s for the field's defining "
 711       "type, %s, have different Class objects for type %s (%s; %s)";
 712     const char* field_name = field->as_C_string();
 713     const char* loader1_name = current_klass->class_loader_data()->loader_name_and_id();
 714     const char* curr_name = current_klass->external_name();
 715     const char* curr_class_description = current_klass->class_in_module_of_loader(false,true);
 716     const char* loader2_name = sel_klass->class_loader_data()->loader_name_and_id();
 717     const char* sel_name = sel_klass->external_name();
 718     const char* sel_class_description = sel_klass->class_in_module_of_loader(false,true);
 719     const char* failed_type_name = failed_type_symbol->as_klass_external_name();

 720     size_t buflen = strlen(msg) + strlen(field_name) + 2 * strlen(failed_type_name) +
 721                     strlen(loader1_name) + strlen(curr_name) + strlen(curr_class_description) +
 722                     strlen(loader2_name) + strlen(sel_name) + strlen(sel_class_description) + 1;
 723     char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
 724     jio_snprintf(buf, buflen, msg, field_name, failed_type_name, loader1_name,
 725                  curr_name, loader2_name, sel_name, failed_type_name,
 726                  curr_class_description, sel_class_description);
 727     THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
 728   }
 729 }
 730 
 731 methodHandle LinkResolver::resolve_method(const LinkInfo& link_info,
 732                                           Bytecodes::Code code, TRAPS) {
 733 
 734   Handle nested_exception;
 735   Klass* resolved_klass = link_info.resolved_klass();
 736 
 737   // 1. For invokevirtual, cannot call an interface method
 738   if (code == Bytecodes::_invokevirtual && resolved_klass->is_interface()) {
 739     ResourceMark rm(THREAD);
 740     char buf[200];
 741     jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected",
 742         resolved_klass->external_name());
 743     THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
 744   }
 745 
 746   // 2. check constant pool tag for called method - must be JVM_CONSTANT_Methodref


< prev index next >