244 // Then look up local default methods |
244 // Then look up local default methods |
245 void LinkResolver::lookup_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, bool checkpolymorphism, bool in_imethod_resolve, TRAPS) { |
245 void LinkResolver::lookup_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, bool checkpolymorphism, bool in_imethod_resolve, TRAPS) { |
246 // Ignore overpasses so statics can be found during resolution |
246 // Ignore overpasses so statics can be found during resolution |
247 Method* result_oop = klass->uncached_lookup_method(name, signature, Klass::skip_overpass); |
247 Method* result_oop = klass->uncached_lookup_method(name, signature, Klass::skip_overpass); |
248 |
248 |
|
249 if (klass->oop_is_array()) { |
|
250 // Only consider klass and super klass for arrays |
|
251 result = methodHandle(THREAD, result_oop); |
|
252 return; |
|
253 } |
|
254 |
249 // JDK 8, JVMS 5.4.3.4: Interface method resolution should |
255 // JDK 8, JVMS 5.4.3.4: Interface method resolution should |
250 // ignore static and non-public methods of java.lang.Object, |
256 // ignore static and non-public methods of java.lang.Object, |
251 // like clone, finalize, registerNatives. |
257 // like clone, finalize, registerNatives. |
252 if (in_imethod_resolve && |
258 if (in_imethod_resolve && |
253 result_oop != NULL && |
259 result_oop != NULL && |
286 Method* result_oop = klass->uncached_lookup_method(name, signature, Klass::normal); |
292 Method* result_oop = klass->uncached_lookup_method(name, signature, Klass::normal); |
287 result = methodHandle(THREAD, result_oop); |
293 result = methodHandle(THREAD, result_oop); |
288 while (!result.is_null() && result->is_static() && result->method_holder()->super() != NULL) { |
294 while (!result.is_null() && result->is_static() && result->method_holder()->super() != NULL) { |
289 KlassHandle super_klass = KlassHandle(THREAD, result->method_holder()->super()); |
295 KlassHandle super_klass = KlassHandle(THREAD, result->method_holder()->super()); |
290 result = methodHandle(THREAD, super_klass->uncached_lookup_method(name, signature, Klass::normal)); |
296 result = methodHandle(THREAD, super_klass->uncached_lookup_method(name, signature, Klass::normal)); |
|
297 } |
|
298 |
|
299 if (klass->oop_is_array()) { |
|
300 // Only consider klass and super klass for arrays |
|
301 return; |
291 } |
302 } |
292 |
303 |
293 if (result.is_null()) { |
304 if (result.is_null()) { |
294 Array<Method*>* default_methods = InstanceKlass::cast(klass())->default_methods(); |
305 Array<Method*>* default_methods = InstanceKlass::cast(klass())->default_methods(); |
295 if (default_methods != NULL) { |
306 if (default_methods != NULL) { |
543 } |
554 } |
544 |
555 |
545 // 2. lookup method in resolved klass and its super klasses |
556 // 2. lookup method in resolved klass and its super klasses |
546 lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, true, false, CHECK); |
557 lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, true, false, CHECK); |
547 |
558 |
548 if (resolved_method.is_null()) { // not found in the class hierarchy |
559 if (resolved_method.is_null() && !resolved_klass->oop_is_array()) { // not found in the class hierarchy |
549 // 3. lookup method in all the interfaces implemented by the resolved klass |
560 // 3. lookup method in all the interfaces implemented by the resolved klass |
550 lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK); |
561 lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK); |
551 |
562 |
552 if (resolved_method.is_null()) { |
563 if (resolved_method.is_null()) { |
553 // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc |
564 // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc |
556 if (HAS_PENDING_EXCEPTION) { |
567 if (HAS_PENDING_EXCEPTION) { |
557 nested_exception = Handle(THREAD, PENDING_EXCEPTION); |
568 nested_exception = Handle(THREAD, PENDING_EXCEPTION); |
558 CLEAR_PENDING_EXCEPTION; |
569 CLEAR_PENDING_EXCEPTION; |
559 } |
570 } |
560 } |
571 } |
561 |
572 } |
562 if (resolved_method.is_null()) { |
573 |
563 // 4. method lookup failed |
574 if (resolved_method.is_null()) { |
564 ResourceMark rm(THREAD); |
575 // 4. method lookup failed |
565 THROW_MSG_CAUSE(vmSymbols::java_lang_NoSuchMethodError(), |
576 ResourceMark rm(THREAD); |
566 Method::name_and_sig_as_C_string(resolved_klass(), |
577 THROW_MSG_CAUSE(vmSymbols::java_lang_NoSuchMethodError(), |
567 method_name, |
578 Method::name_and_sig_as_C_string(resolved_klass(), |
568 method_signature), |
579 method_name, |
569 nested_exception); |
580 method_signature), |
570 } |
581 nested_exception); |
571 } |
582 } |
572 |
583 |
573 // 5. access checks, access checking may be turned off when calling from within the VM. |
584 // 5. access checks, access checking may be turned off when calling from within the VM. |
574 if (check_access) { |
585 if (check_access) { |
575 assert(current_klass.not_null() , "current_klass should not be null"); |
586 assert(current_klass.not_null() , "current_klass should not be null"); |
631 |
642 |
632 // lookup method in this interface or its super, java.lang.Object |
643 // lookup method in this interface or its super, java.lang.Object |
633 // JDK8: also look for static methods |
644 // JDK8: also look for static methods |
634 lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, false, true, CHECK); |
645 lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, false, true, CHECK); |
635 |
646 |
636 if (resolved_method.is_null()) { |
647 if (resolved_method.is_null() && !resolved_klass->oop_is_array()) { |
637 // lookup method in all the super-interfaces |
648 // lookup method in all the super-interfaces |
638 lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK); |
649 lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK); |
639 if (resolved_method.is_null()) { |
650 } |
640 // no method found |
651 |
641 ResourceMark rm(THREAD); |
652 if (resolved_method.is_null()) { |
642 THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), |
653 // no method found |
643 Method::name_and_sig_as_C_string(resolved_klass(), |
654 ResourceMark rm(THREAD); |
644 method_name, |
655 THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), |
645 method_signature)); |
656 Method::name_and_sig_as_C_string(resolved_klass(), |
646 } |
657 method_name, |
|
658 method_signature)); |
647 } |
659 } |
648 |
660 |
649 if (check_access) { |
661 if (check_access) { |
650 // JDK8 adds non-public interface methods, and accessability check requirement |
662 // JDK8 adds non-public interface methods, and accessability check requirement |
651 assert(current_klass.not_null() , "current_klass should not be null"); |
663 assert(current_klass.not_null() , "current_klass should not be null"); |
773 ResourceMark rm(THREAD); |
785 ResourceMark rm(THREAD); |
774 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); |
786 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); |
775 } |
787 } |
776 |
788 |
777 // Resolve instance field |
789 // Resolve instance field |
778 KlassHandle sel_klass(THREAD, InstanceKlass::cast(resolved_klass())->find_field(field, sig, &fd)); |
790 KlassHandle sel_klass(THREAD, resolved_klass->find_field(field, sig, &fd)); |
779 // check if field exists; i.e., if a klass containing the field def has been selected |
791 // check if field exists; i.e., if a klass containing the field def has been selected |
780 if (sel_klass.is_null()) { |
792 if (sel_klass.is_null()) { |
781 ResourceMark rm(THREAD); |
793 ResourceMark rm(THREAD); |
782 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); |
794 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); |
783 } |
795 } |