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 // MDO updates are racy. C2 can observe the array type before the profiling code has updated the
668 // corresponding flat/null-free flags. If the array type is known, prefer the properties it provides.
669 static void update_flags_from_type(ciKlass* array_type, bool& flat_array, bool& null_free_array) {
670 if (array_type != nullptr) {
671 flat_array |= array_type->is_flat_array_klass();
672 null_free_array |= array_type->as_array_klass()->is_elem_null_free();
673 }
674 }
675
676 bool ciMethod::array_access_profiled_type(int bci, ciKlass*& array_type, ciKlass*& element_type, ProfilePtrKind& element_ptr, bool &flat_array, bool &null_free_array) {
677 if (method_data() != nullptr && method_data()->is_mature()) {
678 ciProfileData* data = method_data()->bci_to_data(bci);
679 if (data != nullptr) {
680 if (data->is_ArrayLoadData()) {
681 ciArrayLoadData* array_access = (ciArrayLoadData*) data->as_ArrayLoadData();
682 array_type = array_access->array()->valid_type();
683 element_type = array_access->element()->valid_type();
684 element_ptr = array_access->element()->ptr_kind();
685 flat_array = array_access->flat_array();
686 null_free_array = array_access->null_free_array();
687 update_flags_from_type(array_type, flat_array, null_free_array);
688 return true;
689 } else if (data->is_ArrayStoreData()) {
690 ciArrayStoreData* array_access = (ciArrayStoreData*) data->as_ArrayStoreData();
691 array_type = array_access->array()->valid_type();
692 flat_array = array_access->flat_array();
693 null_free_array = array_access->null_free_array();
694 update_flags_from_type(array_type, flat_array, null_free_array);
695 ciCallProfile call_profile = call_profile_at_bci(bci);
696 if (call_profile.morphism() == 1) {
697 element_type = call_profile.receiver(0);
698 } else {
699 element_type = nullptr;
700 }
701 if (!array_access->null_seen()) {
702 element_ptr = ProfileNeverNull;
703 } else if (call_profile.count() == 0) {
704 element_ptr = ProfileAlwaysNull;
705 } else {
706 element_ptr = ProfileMaybeNull;
707 }
708 return true;
709 }
710 }
711 }
712 return false;
713 }
714
715 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) {
716 if (method_data() != nullptr && method_data()->is_mature()) {
717 ciProfileData* data = method_data()->bci_to_data(bci);
718 if (data != nullptr && data->is_ACmpData()) {
719 ciACmpData* acmp = (ciACmpData*)data->as_ACmpData();
720 left_type = acmp->left()->valid_type();
721 right_type = acmp->right()->valid_type();
722 left_ptr = acmp->left()->ptr_kind();
723 right_ptr = acmp->right()->ptr_kind();
724 left_inline_type = acmp->left_inline_type();
725 right_inline_type = acmp->right_inline_type();
726 return true;
727 }
728 }
729 return false;
730 }
731
732
733 // ------------------------------------------------------------------
734 // ciMethod::find_monomorphic_target
735 //
736 // Given a certain calling environment, find the monomorphic target
737 // for the call. Return null if the call is not monomorphic in
738 // its calling environment, or if there are only abstract methods.
739 // The returned method is never abstract.
740 // Note: If caller uses a non-null result, it must inform dependencies
741 // via assert_unique_concrete_method or assert_leaf_type.
742 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
743 ciInstanceKlass* callee_holder,
744 ciInstanceKlass* actual_recv,
745 bool check_access) {
746 check_is_loaded();
747
748 if (actual_recv->is_interface()) {
749 // %%% We cannot trust interface types, yet. See bug 6312651.
750 return nullptr;
751 }
1024 //
1025 // Return true if the method is an instance of the JVM-generated
1026 // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
1027 bool ciMethod::is_method_handle_intrinsic() const {
1028 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
1029 return (MethodHandles::is_signature_polymorphic(iid) &&
1030 MethodHandles::is_signature_polymorphic_intrinsic(iid));
1031 }
1032
1033 // ------------------------------------------------------------------
1034 // ciMethod::is_compiled_lambda_form
1035 //
1036 // Return true if the method is a generated MethodHandle adapter.
1037 // These are built by Java code.
1038 bool ciMethod::is_compiled_lambda_form() const {
1039 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
1040 return iid == vmIntrinsics::_compiledLambdaForm;
1041 }
1042
1043 // ------------------------------------------------------------------
1044 // ciMethod::is_object_constructor
1045 //
1046 bool ciMethod::is_object_constructor() const {
1047 return (name() == ciSymbols::object_initializer_name()
1048 && signature()->return_type()->is_void());
1049 // Note: We can't test is_static, because that would
1050 // require the method to be loaded. Sometimes it isn't.
1051 }
1052
1053 // ------------------------------------------------------------------
1054 // ciMethod::is_scoped
1055 //
1056 // Return true for methods annotated with @Scoped
1057 bool ciMethod::is_scoped() const {
1058 return get_Method()->is_scoped();
1059 }
1060
1061 // ------------------------------------------------------------------
1062 // ciMethod::has_member_arg
1063 //
1064 // Return true if the method is a linker intrinsic like _linkToVirtual.
1065 // These are built by the JVM.
1066 bool ciMethod::has_member_arg() const {
1067 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
1068 return (MethodHandles::is_signature_polymorphic(iid) &&
1069 MethodHandles::has_member_arg(iid));
1070 }
1582 default:
1583 break;
1584 }
1585 assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1586 int arg_count = target_sig->count() - rbase;
1587 for (int i = 0; i < arg_count; i++) {
1588 if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1589 return false;
1590 }
1591 }
1592 // Only check the return type if the symbolic info has non-void return type.
1593 // I.e. the return value of the resolved method can be dropped.
1594 if (!linker->return_type()->is_void() &&
1595 !basic_types_match(linker->return_type(), target->return_type())) {
1596 return false;
1597 }
1598 return true; // no mismatch found
1599 }
1600
1601 // ------------------------------------------------------------------
1602
1603 bool ciMethod::is_scalarized_arg(int idx) const {
1604 VM_ENTRY_MARK;
1605 return get_Method()->is_scalarized_arg(idx);
1606 }
1607
1608 bool ciMethod::is_scalarized_buffer_arg(int idx) const {
1609 VM_ENTRY_MARK;
1610 return get_Method()->is_scalarized_buffer_arg(idx);
1611 }
1612
1613 bool ciMethod::has_scalarized_args() const {
1614 GUARDED_VM_ENTRY(return get_Method()->has_scalarized_args();)
1615 }
1616
1617 const GrowableArray<SigEntry>* ciMethod::get_sig_cc() const {
1618 VM_ENTRY_MARK;
1619 if (get_Method()->adapter() == nullptr) {
1620 return nullptr;
1621 }
1622 return get_Method()->adapter()->get_sig_cc();
1623 }
1624
1625 bool ciMethod::mismatch() const {
1626 VM_ENTRY_MARK;
1627 return get_Method()->mismatch();
1628 }
1629
1630 bool ciMethod::c1_needs_stack_repair() const {
1631 GUARDED_VM_ENTRY(return get_Method()->c1_needs_stack_repair();)
1632 }
1633
1634 bool ciMethod::c2_needs_stack_repair() const {
1635 GUARDED_VM_ENTRY(return get_Method()->c2_needs_stack_repair();)
1636 }
1637
1638 // ciMethod::is_old
1639 //
1640 // Return true for redefined methods
1641 bool ciMethod::is_old() const {
1642 ASSERT_IN_VM;
1643 return get_Method()->is_old();
1644 }
1645
1646 // A larval object can be passed into a constructor, or it can be passed into
1647 // MethodHandle::linkToSpecial, which, in turn, will pass it into a constructor
1648 bool ciMethod::receiver_maybe_larval() const {
1649 bool res = is_object_constructor() || intrinsic_id() == vmIntrinsics::_linkToSpecial;
1650 assert(!res || !is_scalarized_arg(0), "larval argument must not be passed as fields");
1651 return res;
1652 }
1653
1654 // Normally, a larval object cannot be returned. However, Unsafe::allocateInstance and
1655 // DirectMethodHandle::allocateInstance return an uninitialized larval object, this is required for
1656 // the construction of an object using the reflection API.
1657 bool ciMethod::return_value_is_larval() const {
1658 if (intrinsic_id() == vmIntrinsics::_allocateInstance) {
1659 return true;
1660 }
1661 if (holder()->name()->equals(ciSymbols::java_lang_invoke_DirectMethodHandle()) && name()->equals(ciSymbols::allocateInstance_name())) {
1662 return true;
1663 }
1664 return false;
1665 }
|