< prev index next >

src/hotspot/share/ci/ciMethod.cpp

Print this page

  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "ci/ciCallProfile.hpp"
  26 #include "ci/ciExceptionHandler.hpp"
  27 #include "ci/ciInstanceKlass.hpp"
  28 #include "ci/ciMethod.hpp"
  29 #include "ci/ciMethodBlocks.hpp"
  30 #include "ci/ciMethodData.hpp"
  31 #include "ci/ciReplay.hpp"
  32 #include "ci/ciStreams.hpp"
  33 #include "ci/ciSymbol.hpp"
  34 #include "ci/ciSymbols.hpp"
  35 #include "ci/ciUtilities.inline.hpp"

  36 #include "compiler/abstractCompiler.hpp"
  37 #include "compiler/compilerDefinitions.inline.hpp"
  38 #include "compiler/compilerOracle.hpp"
  39 #include "compiler/compileTask.hpp"
  40 #include "compiler/methodLiveness.hpp"
  41 #include "interpreter/interpreter.hpp"
  42 #include "interpreter/linkResolver.hpp"
  43 #include "interpreter/oopMapCache.hpp"
  44 #include "logging/log.hpp"
  45 #include "logging/logStream.hpp"
  46 #include "memory/allocation.inline.hpp"
  47 #include "memory/resourceArea.hpp"
  48 #include "oops/generateOopMap.hpp"
  49 #include "oops/method.inline.hpp"
  50 #include "oops/oop.inline.hpp"
  51 #include "oops/trainingData.hpp"
  52 #include "prims/methodHandles.hpp"
  53 #include "runtime/deoptimization.hpp"
  54 #include "runtime/handles.inline.hpp"

  55 #include "utilities/bitMap.inline.hpp"
  56 #include "utilities/xmlstream.hpp"
  57 #ifdef COMPILER2
  58 #include "ci/bcEscapeAnalyzer.hpp"
  59 #include "ci/ciTypeFlow.hpp"
  60 #include "oops/method.hpp"
  61 #endif
  62 
  63 // ciMethod
  64 //
  65 // This class represents a Method* in the HotSpot virtual
  66 // machine.
  67 
  68 
  69 // ------------------------------------------------------------------
  70 // ciMethod::ciMethod
  71 //
  72 // Loaded method.
  73 ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
  74   ciMetadata(h_m()),

 645  * Check whether profiling provides a type for the parameter i
 646  *
 647  * @param [in]i           parameter number
 648  * @param [out]type       profiled type of parameter, null if none
 649  * @param [out]ptr_kind   whether always null, never null or maybe null
 650  * @return                true if profiling exists
 651  *
 652  */
 653 bool ciMethod::parameter_profiled_type(int i, ciKlass*& type, ProfilePtrKind& ptr_kind) {
 654   if (MethodData::profile_parameters() && method_data() != nullptr && method_data()->is_mature()) {
 655     ciParametersTypeData* parameters = method_data()->parameters_type_data();
 656     if (parameters != nullptr && i < parameters->number_of_parameters()) {
 657       type = parameters->valid_parameter_type(i);
 658       ptr_kind = parameters->parameter_ptr_kind(i);
 659       return true;
 660     }
 661   }
 662   return false;
 663 }
 664 






































































 665 
 666 // ------------------------------------------------------------------
 667 // ciMethod::find_monomorphic_target
 668 //
 669 // Given a certain calling environment, find the monomorphic target
 670 // for the call.  Return null if the call is not monomorphic in
 671 // its calling environment, or if there are only abstract methods.
 672 // The returned method is never abstract.
 673 // Note: If caller uses a non-null result, it must inform dependencies
 674 // via assert_unique_concrete_method or assert_leaf_type.
 675 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
 676                                             ciInstanceKlass* callee_holder,
 677                                             ciInstanceKlass* actual_recv,
 678                                             bool check_access) {
 679   check_is_loaded();
 680 
 681   if (actual_recv->is_interface()) {
 682     // %%% We cannot trust interface types, yet.  See bug 6312651.
 683     return nullptr;
 684   }

 957 //
 958 // Return true if the method is an instance of the JVM-generated
 959 // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
 960 bool ciMethod::is_method_handle_intrinsic() const {
 961   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 962   return (MethodHandles::is_signature_polymorphic(iid) &&
 963           MethodHandles::is_signature_polymorphic_intrinsic(iid));
 964 }
 965 
 966 // ------------------------------------------------------------------
 967 // ciMethod::is_compiled_lambda_form
 968 //
 969 // Return true if the method is a generated MethodHandle adapter.
 970 // These are built by Java code.
 971 bool ciMethod::is_compiled_lambda_form() const {
 972   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 973   return iid == vmIntrinsics::_compiledLambdaForm;
 974 }
 975 
 976 // ------------------------------------------------------------------
 977 // ciMethod::is_object_initializer
 978 //
 979 bool ciMethod::is_object_initializer() const {
 980    return name() == ciSymbols::object_initializer_name();



 981 }
 982 
 983 // ------------------------------------------------------------------
 984 // ciMethod::is_scoped
 985 //
 986 // Return true for methods annotated with @Scoped
 987 bool ciMethod::is_scoped() const {
 988    return get_Method()->is_scoped();
 989 }
 990 
 991 // ------------------------------------------------------------------
 992 // ciMethod::has_member_arg
 993 //
 994 // Return true if the method is a linker intrinsic like _linkToVirtual.
 995 // These are built by the JVM.
 996 bool ciMethod::has_member_arg() const {
 997   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 998   return (MethodHandles::is_signature_polymorphic(iid) &&
 999           MethodHandles::has_member_arg(iid));
1000 }

1512     default:
1513       break;
1514   }
1515   assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1516   int arg_count = target_sig->count() - rbase;
1517   for (int i = 0; i < arg_count; i++) {
1518     if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1519       return false;
1520     }
1521   }
1522   // Only check the return type if the symbolic info has non-void return type.
1523   // I.e. the return value of the resolved method can be dropped.
1524   if (!linker->return_type()->is_void() &&
1525       !basic_types_match(linker->return_type(), target->return_type())) {
1526     return false;
1527   }
1528   return true; // no mismatch found
1529 }
1530 
1531 // ------------------------------------------------------------------
























1532 // ciMethod::is_old
1533 //
1534 // Return true for redefined methods
1535 bool ciMethod::is_old() const {
1536   ASSERT_IN_VM;
1537   return get_Method()->is_old();
1538 }






















  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "ci/ciCallProfile.hpp"
  26 #include "ci/ciExceptionHandler.hpp"
  27 #include "ci/ciInstanceKlass.hpp"
  28 #include "ci/ciMethod.hpp"
  29 #include "ci/ciMethodBlocks.hpp"
  30 #include "ci/ciMethodData.hpp"
  31 #include "ci/ciReplay.hpp"
  32 #include "ci/ciStreams.hpp"
  33 #include "ci/ciSymbol.hpp"
  34 #include "ci/ciSymbols.hpp"
  35 #include "ci/ciUtilities.inline.hpp"
  36 #include "classfile/vmIntrinsics.hpp"
  37 #include "compiler/abstractCompiler.hpp"
  38 #include "compiler/compilerDefinitions.inline.hpp"
  39 #include "compiler/compilerOracle.hpp"
  40 #include "compiler/compileTask.hpp"
  41 #include "compiler/methodLiveness.hpp"
  42 #include "interpreter/interpreter.hpp"
  43 #include "interpreter/linkResolver.hpp"
  44 #include "interpreter/oopMapCache.hpp"
  45 #include "logging/log.hpp"
  46 #include "logging/logStream.hpp"
  47 #include "memory/allocation.inline.hpp"
  48 #include "memory/resourceArea.hpp"
  49 #include "oops/generateOopMap.hpp"
  50 #include "oops/method.inline.hpp"
  51 #include "oops/oop.inline.hpp"
  52 #include "oops/trainingData.hpp"
  53 #include "prims/methodHandles.hpp"
  54 #include "runtime/deoptimization.hpp"
  55 #include "runtime/handles.inline.hpp"
  56 #include "runtime/sharedRuntime.hpp"
  57 #include "utilities/bitMap.inline.hpp"
  58 #include "utilities/xmlstream.hpp"
  59 #ifdef COMPILER2
  60 #include "ci/bcEscapeAnalyzer.hpp"
  61 #include "ci/ciTypeFlow.hpp"
  62 #include "oops/method.hpp"
  63 #endif
  64 
  65 // ciMethod
  66 //
  67 // This class represents a Method* in the HotSpot virtual
  68 // machine.
  69 
  70 
  71 // ------------------------------------------------------------------
  72 // ciMethod::ciMethod
  73 //
  74 // Loaded method.
  75 ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
  76   ciMetadata(h_m()),

 647  * Check whether profiling provides a type for the parameter i
 648  *
 649  * @param [in]i           parameter number
 650  * @param [out]type       profiled type of parameter, null if none
 651  * @param [out]ptr_kind   whether always null, never null or maybe null
 652  * @return                true if profiling exists
 653  *
 654  */
 655 bool ciMethod::parameter_profiled_type(int i, ciKlass*& type, ProfilePtrKind& ptr_kind) {
 656   if (MethodData::profile_parameters() && method_data() != nullptr && method_data()->is_mature()) {
 657     ciParametersTypeData* parameters = method_data()->parameters_type_data();
 658     if (parameters != nullptr && i < parameters->number_of_parameters()) {
 659       type = parameters->valid_parameter_type(i);
 660       ptr_kind = parameters->parameter_ptr_kind(i);
 661       return true;
 662     }
 663   }
 664   return false;
 665 }
 666 
 667 bool ciMethod::array_access_profiled_type(int bci, ciKlass*& array_type, ciKlass*& element_type, ProfilePtrKind& element_ptr, bool &flat_array, bool &null_free_array) {
 668   if (method_data() != nullptr && method_data()->is_mature()) {
 669     ciProfileData* data = method_data()->bci_to_data(bci);
 670     if (data != nullptr) {
 671       if (data->is_ArrayLoadData()) {
 672         ciArrayLoadData* array_access = (ciArrayLoadData*) data->as_ArrayLoadData();
 673         array_type = array_access->array()->valid_type();
 674         element_type = array_access->element()->valid_type();
 675         element_ptr = array_access->element()->ptr_kind();
 676         flat_array = array_access->flat_array();
 677         null_free_array = array_access->null_free_array();
 678 #ifdef ASSERT
 679         if (array_type != nullptr) {
 680           bool flat = array_type->is_flat_array_klass();
 681           bool null_free = array_type->as_array_klass()->is_elem_null_free();
 682           assert(!flat || flat_array, "inconsistency");
 683           assert(!null_free || null_free_array, "inconsistency");
 684         }
 685 #endif
 686         return true;
 687       } else if (data->is_ArrayStoreData()) {
 688         ciArrayStoreData* array_access = (ciArrayStoreData*) data->as_ArrayStoreData();
 689         array_type = array_access->array()->valid_type();
 690         flat_array = array_access->flat_array();
 691         null_free_array = array_access->null_free_array();
 692         ciCallProfile call_profile = call_profile_at_bci(bci);
 693         if (call_profile.morphism() == 1) {
 694           element_type = call_profile.receiver(0);
 695         } else {
 696           element_type = nullptr;
 697         }
 698         if (!array_access->null_seen()) {
 699           element_ptr = ProfileNeverNull;
 700         } else if (call_profile.count() == 0) {
 701           element_ptr = ProfileAlwaysNull;
 702         } else {
 703           element_ptr = ProfileMaybeNull;
 704         }
 705 #ifdef ASSERT
 706         if (array_type != nullptr) {
 707           bool flat = array_type->is_flat_array_klass();
 708           bool null_free = array_type->as_array_klass()->is_elem_null_free();
 709           assert(!flat || flat_array, "inconsistency");
 710           assert(!null_free || null_free_array, "inconsistency");
 711         }
 712 #endif
 713         return true;
 714       }
 715     }
 716   }
 717   return false;
 718 }
 719 
 720 bool ciMethod::acmp_profiled_type(int bci, ciKlass*& left_type, ciKlass*& right_type, ProfilePtrKind& left_ptr, ProfilePtrKind& right_ptr, bool &left_inline_type, bool &right_inline_type) {
 721   if (method_data() != nullptr && method_data()->is_mature()) {
 722     ciProfileData* data = method_data()->bci_to_data(bci);
 723     if (data != nullptr && data->is_ACmpData()) {
 724       ciACmpData* acmp = (ciACmpData*)data->as_ACmpData();
 725       left_type = acmp->left()->valid_type();
 726       right_type = acmp->right()->valid_type();
 727       left_ptr = acmp->left()->ptr_kind();
 728       right_ptr = acmp->right()->ptr_kind();
 729       left_inline_type = acmp->left_inline_type();
 730       right_inline_type = acmp->right_inline_type();
 731       return true;
 732     }
 733   }
 734   return false;
 735 }
 736 
 737 
 738 // ------------------------------------------------------------------
 739 // ciMethod::find_monomorphic_target
 740 //
 741 // Given a certain calling environment, find the monomorphic target
 742 // for the call.  Return null if the call is not monomorphic in
 743 // its calling environment, or if there are only abstract methods.
 744 // The returned method is never abstract.
 745 // Note: If caller uses a non-null result, it must inform dependencies
 746 // via assert_unique_concrete_method or assert_leaf_type.
 747 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
 748                                             ciInstanceKlass* callee_holder,
 749                                             ciInstanceKlass* actual_recv,
 750                                             bool check_access) {
 751   check_is_loaded();
 752 
 753   if (actual_recv->is_interface()) {
 754     // %%% We cannot trust interface types, yet.  See bug 6312651.
 755     return nullptr;
 756   }

1029 //
1030 // Return true if the method is an instance of the JVM-generated
1031 // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
1032 bool ciMethod::is_method_handle_intrinsic() const {
1033   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
1034   return (MethodHandles::is_signature_polymorphic(iid) &&
1035           MethodHandles::is_signature_polymorphic_intrinsic(iid));
1036 }
1037 
1038 // ------------------------------------------------------------------
1039 // ciMethod::is_compiled_lambda_form
1040 //
1041 // Return true if the method is a generated MethodHandle adapter.
1042 // These are built by Java code.
1043 bool ciMethod::is_compiled_lambda_form() const {
1044   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
1045   return iid == vmIntrinsics::_compiledLambdaForm;
1046 }
1047 
1048 // ------------------------------------------------------------------
1049 // ciMethod::is_object_constructor
1050 //
1051 bool ciMethod::is_object_constructor() const {
1052    return (name() == ciSymbols::object_initializer_name()
1053            && signature()->return_type()->is_void());
1054    // Note:  We can't test is_static, because that would
1055    // require the method to be loaded.  Sometimes it isn't.
1056 }
1057 
1058 // ------------------------------------------------------------------
1059 // ciMethod::is_scoped
1060 //
1061 // Return true for methods annotated with @Scoped
1062 bool ciMethod::is_scoped() const {
1063    return get_Method()->is_scoped();
1064 }
1065 
1066 // ------------------------------------------------------------------
1067 // ciMethod::has_member_arg
1068 //
1069 // Return true if the method is a linker intrinsic like _linkToVirtual.
1070 // These are built by the JVM.
1071 bool ciMethod::has_member_arg() const {
1072   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
1073   return (MethodHandles::is_signature_polymorphic(iid) &&
1074           MethodHandles::has_member_arg(iid));
1075 }

1587     default:
1588       break;
1589   }
1590   assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1591   int arg_count = target_sig->count() - rbase;
1592   for (int i = 0; i < arg_count; i++) {
1593     if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1594       return false;
1595     }
1596   }
1597   // Only check the return type if the symbolic info has non-void return type.
1598   // I.e. the return value of the resolved method can be dropped.
1599   if (!linker->return_type()->is_void() &&
1600       !basic_types_match(linker->return_type(), target->return_type())) {
1601     return false;
1602   }
1603   return true; // no mismatch found
1604 }
1605 
1606 // ------------------------------------------------------------------
1607 
1608 bool ciMethod::is_scalarized_arg(int idx) const {
1609   VM_ENTRY_MARK;
1610   return get_Method()->is_scalarized_arg(idx);
1611 }
1612 
1613 bool ciMethod::has_scalarized_args() const {
1614   VM_ENTRY_MARK;
1615   return get_Method()->has_scalarized_args();
1616 }
1617 
1618 const GrowableArray<SigEntry>* ciMethod::get_sig_cc() const {
1619   VM_ENTRY_MARK;
1620   if (get_Method()->adapter() == nullptr) {
1621     return nullptr;
1622   }
1623   return get_Method()->adapter()->get_sig_cc();
1624 }
1625 
1626 bool ciMethod::mismatch() const {
1627   VM_ENTRY_MARK;
1628   return get_Method()->mismatch();
1629 }
1630 
1631 // ciMethod::is_old
1632 //
1633 // Return true for redefined methods
1634 bool ciMethod::is_old() const {
1635   ASSERT_IN_VM;
1636   return get_Method()->is_old();
1637 }
1638 
1639 // A larval object can be passed into a constructor, or it can be passed into
1640 // MethodHandle::linkToSpecial, which, in turn, will pass it into a constructor
1641 bool ciMethod::receiver_maybe_larval() const {
1642   bool res = is_object_constructor() || intrinsic_id() == vmIntrinsics::_linkToSpecial;
1643   assert(!res || !is_scalarized_arg(0), "larval argument must not be passed as fields");
1644   return res;
1645 }
1646 
1647 // Normally, a larval object cannot be returned. However, Unsafe::allocateInstance and
1648 // DirectMethodHandle::allocateInstance return an uninitialized larval object, this is required for
1649 // the construction of an object using the reflection API.
1650 bool ciMethod::return_value_is_larval() const {
1651   if (intrinsic_id() == vmIntrinsics::_allocateInstance) {
1652     return true;
1653   }
1654   if (holder()->name()->equals(ciSymbols::java_lang_invoke_DirectMethodHandle()) && name()->equals(ciSymbols::allocateInstance_name())) {
1655     return true;
1656   }
1657   return false;
1658 }
< prev index next >