680 if (size_of_parameters() != 3) return false;
681 break;
682 default:
683 return false;
684 }
685 if (java_code_at(2) != Bytecodes::_putfield) return false;
686 if (java_code_at(5) != Bytecodes::_return) return false;
687 return true;
688 }
689
690 bool Method::is_constant_getter() const {
691 int last_index = code_size() - 1;
692 // Check if the first 1-3 bytecodes are a constant push
693 // and the last bytecode is a return.
694 return (2 <= code_size() && code_size() <= 4 &&
695 Bytecodes::is_const(java_code_at(0)) &&
696 Bytecodes::length_for(java_code_at(0)) == last_index &&
697 Bytecodes::is_return(java_code_at(last_index)));
698 }
699
700 bool Method::is_initializer() const {
701 return is_object_initializer() || is_static_initializer();
702 }
703
704 bool Method::has_valid_initializer_flags() const {
705 return (is_static() ||
706 method_holder()->major_version() < 51);
707 }
708
709 bool Method::is_static_initializer() const {
710 // For classfiles version 51 or greater, ensure that the clinit method is
711 // static. Non-static methods with the name "<clinit>" are not static
712 // initializers. (older classfiles exempted for backward compatibility)
713 return name() == vmSymbols::class_initializer_name() &&
714 has_valid_initializer_flags();
715 }
716
717 bool Method::is_object_initializer() const {
718 return name() == vmSymbols::object_initializer_name();
719 }
720
721 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
722 int length = method->checked_exceptions_length();
723 if (length == 0) { // common case
724 return objArrayHandle(THREAD, Universe::the_empty_class_klass_array());
725 } else {
726 methodHandle h_this(THREAD, method);
727 objArrayOop m_oop = oopFactory::new_objArray(SystemDictionary::Class_klass(), length, CHECK_(objArrayHandle()));
728 objArrayHandle mirrors (THREAD, m_oop);
729 for (int i = 0; i < length; i++) {
730 CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
731 Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
732 assert(k->is_subclass_of(SystemDictionary::Throwable_klass()), "invalid exception class");
733 mirrors->obj_at_put(i, k->java_mirror());
734 }
735 return mirrors;
736 }
737 };
738
|
680 if (size_of_parameters() != 3) return false;
681 break;
682 default:
683 return false;
684 }
685 if (java_code_at(2) != Bytecodes::_putfield) return false;
686 if (java_code_at(5) != Bytecodes::_return) return false;
687 return true;
688 }
689
690 bool Method::is_constant_getter() const {
691 int last_index = code_size() - 1;
692 // Check if the first 1-3 bytecodes are a constant push
693 // and the last bytecode is a return.
694 return (2 <= code_size() && code_size() <= 4 &&
695 Bytecodes::is_const(java_code_at(0)) &&
696 Bytecodes::length_for(java_code_at(0)) == last_index &&
697 Bytecodes::is_return(java_code_at(last_index)));
698 }
699
700 bool Method::is_object_constructor_or_class_initializer() const {
701 return (is_object_constructor() || is_class_initializer());
702 }
703
704 bool Method::is_class_initializer() const {
705 // For classfiles version 51 or greater, ensure that the clinit method is
706 // static. Non-static methods with the name "<clinit>" are not static
707 // initializers. (older classfiles exempted for backward compatibility)
708 return (name() == vmSymbols::class_initializer_name() &&
709 (is_static() ||
710 method_holder()->major_version() < 51));
711 }
712
713 // A method named <init>, if non-static, is a classic object constructor.
714 bool Method::is_object_constructor() const {
715 return name() == vmSymbols::object_initializer_name() && !is_static();
716 }
717
718 // A static method named <init> is a factory for an inline class.
719 bool Method::is_static_init_factory() const {
720 return name() == vmSymbols::object_initializer_name() && is_static();
721 }
722
723 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
724 int length = method->checked_exceptions_length();
725 if (length == 0) { // common case
726 return objArrayHandle(THREAD, Universe::the_empty_class_klass_array());
727 } else {
728 methodHandle h_this(THREAD, method);
729 objArrayOop m_oop = oopFactory::new_objArray(SystemDictionary::Class_klass(), length, CHECK_(objArrayHandle()));
730 objArrayHandle mirrors (THREAD, m_oop);
731 for (int i = 0; i < length; i++) {
732 CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
733 Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
734 assert(k->is_subclass_of(SystemDictionary::Throwable_klass()), "invalid exception class");
735 mirrors->obj_at_put(i, k->java_mirror());
736 }
737 return mirrors;
738 }
739 };
740
|