564 }
565 }
566
567 bool Method::can_be_statically_bound(AccessFlags class_access_flags) const {
568 if (is_final_method(class_access_flags)) return true;
569 #ifdef ASSERT
570 ResourceMark rm;
571 bool is_nonv = (vtable_index() == nonvirtual_vtable_index);
572 if (class_access_flags.is_interface()) {
573 assert(is_nonv == is_static(), "is_nonv=%s", name_and_sig_as_C_string());
574 }
575 #endif
576 assert(valid_vtable_index() || valid_itable_index(), "method must be linked before we ask this question");
577 return vtable_index() == nonvirtual_vtable_index;
578 }
579
580 bool Method::can_be_statically_bound() const {
581 return can_be_statically_bound(method_holder()->access_flags());
582 }
583
584 bool Method::is_accessor() const {
585 if (code_size() != 5) return false;
586 if (size_of_parameters() != 1) return false;
587 if (java_code_at(0) != Bytecodes::_aload_0 ) return false;
588 if (java_code_at(1) != Bytecodes::_getfield) return false;
589 if (java_code_at(4) != Bytecodes::_areturn &&
590 java_code_at(4) != Bytecodes::_ireturn ) return false;
591 return true;
592 }
593
594 bool Method::is_constant_getter() const {
595 int last_index = code_size() - 1;
596 // Check if the first 1-3 bytecodes are a constant push
597 // and the last bytecode is a return.
598 return (2 <= code_size() && code_size() <= 4 &&
599 Bytecodes::is_const(java_code_at(0)) &&
600 Bytecodes::length_for(java_code_at(0)) == last_index &&
601 Bytecodes::is_return(java_code_at(last_index)));
602 }
603
604 bool Method::is_initializer() const {
605 return name() == vmSymbols::object_initializer_name() || is_static_initializer();
606 }
607
608 bool Method::has_valid_initializer_flags() const {
609 return (is_static() ||
610 method_holder()->major_version() < 51);
611 }
|
564 }
565 }
566
567 bool Method::can_be_statically_bound(AccessFlags class_access_flags) const {
568 if (is_final_method(class_access_flags)) return true;
569 #ifdef ASSERT
570 ResourceMark rm;
571 bool is_nonv = (vtable_index() == nonvirtual_vtable_index);
572 if (class_access_flags.is_interface()) {
573 assert(is_nonv == is_static(), "is_nonv=%s", name_and_sig_as_C_string());
574 }
575 #endif
576 assert(valid_vtable_index() || valid_itable_index(), "method must be linked before we ask this question");
577 return vtable_index() == nonvirtual_vtable_index;
578 }
579
580 bool Method::can_be_statically_bound() const {
581 return can_be_statically_bound(method_holder()->access_flags());
582 }
583
584 bool Method::is_simple_accessor() const {
585 if (code_size() != 5) return false;
586 if (size_of_parameters() != 1) return false;
587 if (java_code_at(0) != Bytecodes::_aload_0 ) return false;
588 if (java_code_at(1) != Bytecodes::_getfield) return false;
589 if (java_code_at(4) != Bytecodes::_areturn &&
590 java_code_at(4) != Bytecodes::_ireturn ) return false;
591 return true;
592 }
593
594 bool Method::is_accessor() const {
595 if (code_size() == 5) { // potential getter
596 if (size_of_parameters() != 1) return false;
597 if (java_code_at(0) != Bytecodes::_aload_0) return false;
598 if (java_code_at(1) != Bytecodes::_getfield) return false;
599 switch (java_code_at(4)) {
600 case Bytecodes::_ireturn:
601 case Bytecodes::_lreturn:
602 case Bytecodes::_freturn:
603 case Bytecodes::_dreturn:
604 case Bytecodes::_areturn:
605 break;
606 default:
607 return false;
608 }
609 return true;
610 }
611
612 if (code_size() == 6) { // potential setter
613 if (java_code_at(0) != Bytecodes::_aload_0) return false;
614 switch (java_code_at(1)) {
615 case Bytecodes::_iload_1:
616 case Bytecodes::_aload_1:
617 case Bytecodes::_fload_1:
618 if (size_of_parameters() != 2) return false;
619 break;
620 case Bytecodes::_dload_1:
621 case Bytecodes::_lload_1:
622 if (size_of_parameters() != 3) return false;
623 break;
624 default:
625 return false;
626 }
627 if (java_code_at(2) != Bytecodes::_putfield) return false;
628 if (java_code_at(5) != Bytecodes::_return) return false;
629 return true;
630 }
631
632 return false;
633 }
634
635 bool Method::is_constant_getter() const {
636 int last_index = code_size() - 1;
637 // Check if the first 1-3 bytecodes are a constant push
638 // and the last bytecode is a return.
639 return (2 <= code_size() && code_size() <= 4 &&
640 Bytecodes::is_const(java_code_at(0)) &&
641 Bytecodes::length_for(java_code_at(0)) == last_index &&
642 Bytecodes::is_return(java_code_at(last_index)));
643 }
644
645 bool Method::is_initializer() const {
646 return name() == vmSymbols::object_initializer_name() || is_static_initializer();
647 }
648
649 bool Method::has_valid_initializer_flags() const {
650 return (is_static() ||
651 method_holder()->major_version() < 51);
652 }
|