src/share/vm/oops/method.cpp

Print this page




 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);




 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   return is_getter() || is_setter();
 586 }
 587 
 588 bool Method::is_getter() const {
 589   if (code_size() != 5) return false;
 590   if (size_of_parameters() != 1) return false;
 591   if (java_code_at(0) != Bytecodes::_aload_0)  return false;
 592   if (java_code_at(1) != Bytecodes::_getfield) return false;
 593   switch (java_code_at(4)) {
 594     case Bytecodes::_ireturn:
 595     case Bytecodes::_lreturn:
 596     case Bytecodes::_freturn:
 597     case Bytecodes::_dreturn:
 598     case Bytecodes::_areturn:
 599       break;
 600     default:
 601       return false;
 602   }
 603   return true;
 604 }
 605 
 606 bool Method::is_setter() const {
 607   if (code_size() != 6) return false;
 608   if (java_code_at(0) != Bytecodes::_aload_0) return false;
 609   switch (java_code_at(1)) {
 610     case Bytecodes::_iload_1:
 611     case Bytecodes::_aload_1:
 612     case Bytecodes::_fload_1:
 613       if (size_of_parameters() != 2) return false;
 614       break;
 615     case Bytecodes::_dload_1:
 616     case Bytecodes::_lload_1:
 617       if (size_of_parameters() != 3) return false;
 618       break;
 619     default:
 620       return false;
 621   }
 622   if (java_code_at(2) != Bytecodes::_putfield) return false;
 623   if (java_code_at(5) != Bytecodes::_return)   return false;
 624   return true;
 625 }
 626 
 627 bool Method::is_constant_getter() const {
 628   int last_index = code_size() - 1;
 629   // Check if the first 1-3 bytecodes are a constant push
 630   // and the last bytecode is a return.
 631   return (2 <= code_size() && code_size() <= 4 &&
 632           Bytecodes::is_const(java_code_at(0)) &&
 633           Bytecodes::length_for(java_code_at(0)) == last_index &&
 634           Bytecodes::is_return(java_code_at(last_index)));
 635 }
 636 
 637 bool Method::is_initializer() const {
 638   return name() == vmSymbols::object_initializer_name() || is_static_initializer();
 639 }
 640 
 641 bool Method::has_valid_initializer_flags() const {
 642   return (is_static() ||
 643           method_holder()->major_version() < 51);