610 break;
611 default:
612 return false;
613 }
614 if (java_code_at(2) != Bytecodes::_putfield) return false;
615 if (java_code_at(5) != Bytecodes::_return) return false;
616 return true;
617 }
618
619 bool Method::is_constant_getter() const {
620 int last_index = code_size() - 1;
621 // Check if the first 1-3 bytecodes are a constant push
622 // and the last bytecode is a return.
623 return (2 <= code_size() && code_size() <= 4 &&
624 Bytecodes::is_const(java_code_at(0)) &&
625 Bytecodes::length_for(java_code_at(0)) == last_index &&
626 Bytecodes::is_return(java_code_at(last_index)));
627 }
628
629 bool Method::is_initializer() const {
630 return name() == vmSymbols::object_initializer_name() || is_static_initializer();
631 }
632
633 bool Method::has_valid_initializer_flags() const {
634 return (is_static() ||
635 method_holder()->major_version() < 51);
636 }
637
638 bool Method::is_static_initializer() const {
639 // For classfiles version 51 or greater, ensure that the clinit method is
640 // static. Non-static methods with the name "<clinit>" are not static
641 // initializers. (older classfiles exempted for backward compatibility)
642 return name() == vmSymbols::class_initializer_name() &&
643 has_valid_initializer_flags();
644 }
645
646
647 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
648 int length = method->checked_exceptions_length();
649 if (length == 0) { // common case
650 return objArrayHandle(THREAD, Universe::the_empty_class_klass_array());
651 } else {
652 methodHandle h_this(THREAD, method);
653 objArrayOop m_oop = oopFactory::new_objArray(SystemDictionary::Class_klass(), length, CHECK_(objArrayHandle()));
654 objArrayHandle mirrors (THREAD, m_oop);
655 for (int i = 0; i < length; i++) {
656 CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
657 Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
658 assert(k->is_subclass_of(SystemDictionary::Throwable_klass()), "invalid exception class");
659 mirrors->obj_at_put(i, k->java_mirror());
660 }
661 return mirrors;
662 }
663 };
664
665
|
610 break;
611 default:
612 return false;
613 }
614 if (java_code_at(2) != Bytecodes::_putfield) return false;
615 if (java_code_at(5) != Bytecodes::_return) return false;
616 return true;
617 }
618
619 bool Method::is_constant_getter() const {
620 int last_index = code_size() - 1;
621 // Check if the first 1-3 bytecodes are a constant push
622 // and the last bytecode is a return.
623 return (2 <= code_size() && code_size() <= 4 &&
624 Bytecodes::is_const(java_code_at(0)) &&
625 Bytecodes::length_for(java_code_at(0)) == last_index &&
626 Bytecodes::is_return(java_code_at(last_index)));
627 }
628
629 bool Method::is_initializer() const {
630 return is_object_initializer() || is_static_initializer();
631 }
632
633 bool Method::has_valid_initializer_flags() const {
634 return (is_static() ||
635 method_holder()->major_version() < 51);
636 }
637
638 bool Method::is_static_initializer() const {
639 // For classfiles version 51 or greater, ensure that the clinit method is
640 // static. Non-static methods with the name "<clinit>" are not static
641 // initializers. (older classfiles exempted for backward compatibility)
642 return name() == vmSymbols::class_initializer_name() &&
643 has_valid_initializer_flags();
644 }
645
646 bool Method::is_object_initializer() const {
647 return name() == vmSymbols::object_initializer_name();
648 }
649
650 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
651 int length = method->checked_exceptions_length();
652 if (length == 0) { // common case
653 return objArrayHandle(THREAD, Universe::the_empty_class_klass_array());
654 } else {
655 methodHandle h_this(THREAD, method);
656 objArrayOop m_oop = oopFactory::new_objArray(SystemDictionary::Class_klass(), length, CHECK_(objArrayHandle()));
657 objArrayHandle mirrors (THREAD, m_oop);
658 for (int i = 0; i < length; i++) {
659 CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
660 Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
661 assert(k->is_subclass_of(SystemDictionary::Throwable_klass()), "invalid exception class");
662 mirrors->obj_at_put(i, k->java_mirror());
663 }
664 return mirrors;
665 }
666 };
667
668
|