34 #include "ci/ciReplay.hpp"
35 #include "ci/ciSymbols.hpp"
36 #include "ci/ciUtilities.inline.hpp"
37 #include "compiler/abstractCompiler.hpp"
38 #include "compiler/compilerDefinitions.inline.hpp"
39 #include "compiler/compilerOracle.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 "prims/methodHandles.hpp"
52 #include "runtime/deoptimization.hpp"
53 #include "runtime/handles.inline.hpp"
54 #include "utilities/bitMap.inline.hpp"
55 #include "utilities/xmlstream.hpp"
56 #ifdef COMPILER2
57 #include "ci/bcEscapeAnalyzer.hpp"
58 #include "ci/ciTypeFlow.hpp"
59 #include "oops/method.hpp"
60 #endif
61
62 // ciMethod
63 //
64 // This class represents a Method* in the HotSpot virtual
65 // machine.
66
67
68 // ------------------------------------------------------------------
69 // ciMethod::ciMethod
70 //
71 // Loaded method.
72 ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
73 ciMetadata(h_m()),
644 * Check whether profiling provides a type for the parameter i
645 *
646 * @param [in]i parameter number
647 * @param [out]type profiled type of parameter, null if none
648 * @param [out]ptr_kind whether always null, never null or maybe null
649 * @return true if profiling exists
650 *
651 */
652 bool ciMethod::parameter_profiled_type(int i, ciKlass*& type, ProfilePtrKind& ptr_kind) {
653 if (MethodData::profile_parameters() && method_data() != nullptr && method_data()->is_mature()) {
654 ciParametersTypeData* parameters = method_data()->parameters_type_data();
655 if (parameters != nullptr && i < parameters->number_of_parameters()) {
656 type = parameters->valid_parameter_type(i);
657 ptr_kind = parameters->parameter_ptr_kind(i);
658 return true;
659 }
660 }
661 return false;
662 }
663
664
665 // ------------------------------------------------------------------
666 // ciMethod::find_monomorphic_target
667 //
668 // Given a certain calling environment, find the monomorphic target
669 // for the call. Return null if the call is not monomorphic in
670 // its calling environment, or if there are only abstract methods.
671 // The returned method is never abstract.
672 // Note: If caller uses a non-null result, it must inform dependencies
673 // via assert_unique_concrete_method or assert_leaf_type.
674 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
675 ciInstanceKlass* callee_holder,
676 ciInstanceKlass* actual_recv,
677 bool check_access) {
678 check_is_loaded();
679
680 if (actual_recv->is_interface()) {
681 // %%% We cannot trust interface types, yet. See bug 6312651.
682 return nullptr;
683 }
953 //
954 // Return true if the method is an instance of the JVM-generated
955 // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
956 bool ciMethod::is_method_handle_intrinsic() const {
957 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
958 return (MethodHandles::is_signature_polymorphic(iid) &&
959 MethodHandles::is_signature_polymorphic_intrinsic(iid));
960 }
961
962 // ------------------------------------------------------------------
963 // ciMethod::is_compiled_lambda_form
964 //
965 // Return true if the method is a generated MethodHandle adapter.
966 // These are built by Java code.
967 bool ciMethod::is_compiled_lambda_form() const {
968 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
969 return iid == vmIntrinsics::_compiledLambdaForm;
970 }
971
972 // ------------------------------------------------------------------
973 // ciMethod::is_object_initializer
974 //
975 bool ciMethod::is_object_initializer() const {
976 return name() == ciSymbols::object_initializer_name();
977 }
978
979 // ------------------------------------------------------------------
980 // ciMethod::is_scoped
981 //
982 // Return true for methods annotated with @Scoped
983 bool ciMethod::is_scoped() const {
984 return get_Method()->is_scoped();
985 }
986
987 // ------------------------------------------------------------------
988 // ciMethod::has_member_arg
989 //
990 // Return true if the method is a linker intrinsic like _linkToVirtual.
991 // These are built by the JVM.
992 bool ciMethod::has_member_arg() const {
993 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
994 return (MethodHandles::is_signature_polymorphic(iid) &&
995 MethodHandles::has_member_arg(iid));
996 }
1478 default:
1479 break;
1480 }
1481 assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1482 int arg_count = target_sig->count() - rbase;
1483 for (int i = 0; i < arg_count; i++) {
1484 if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1485 return false;
1486 }
1487 }
1488 // Only check the return type if the symbolic info has non-void return type.
1489 // I.e. the return value of the resolved method can be dropped.
1490 if (!linker->return_type()->is_void() &&
1491 !basic_types_match(linker->return_type(), target->return_type())) {
1492 return false;
1493 }
1494 return true; // no mismatch found
1495 }
1496
1497 // ------------------------------------------------------------------
|
34 #include "ci/ciReplay.hpp"
35 #include "ci/ciSymbols.hpp"
36 #include "ci/ciUtilities.inline.hpp"
37 #include "compiler/abstractCompiler.hpp"
38 #include "compiler/compilerDefinitions.inline.hpp"
39 #include "compiler/compilerOracle.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 "prims/methodHandles.hpp"
52 #include "runtime/deoptimization.hpp"
53 #include "runtime/handles.inline.hpp"
54 #include "runtime/sharedRuntime.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 bool ciMethod::array_access_profiled_type(int bci, ciKlass*& array_type, ciKlass*& element_type, ProfilePtrKind& element_ptr, bool &flat_array, bool &null_free_array) {
666 if (method_data() != nullptr && method_data()->is_mature()) {
667 ciProfileData* data = method_data()->bci_to_data(bci);
668 if (data != nullptr) {
669 if (data->is_ArrayLoadData()) {
670 ciArrayLoadData* array_access = (ciArrayLoadData*) data->as_ArrayLoadData();
671 array_type = array_access->array()->valid_type();
672 element_type = array_access->element()->valid_type();
673 element_ptr = array_access->element()->ptr_kind();
674 flat_array = array_access->flat_array();
675 null_free_array = array_access->null_free_array();
676 return true;
677 } else if (data->is_ArrayStoreData()) {
678 ciArrayStoreData* array_access = (ciArrayStoreData*) data->as_ArrayStoreData();
679 array_type = array_access->array()->valid_type();
680 flat_array = array_access->flat_array();
681 null_free_array = array_access->null_free_array();
682 ciCallProfile call_profile = call_profile_at_bci(bci);
683 if (call_profile.morphism() == 1) {
684 element_type = call_profile.receiver(0);
685 } else {
686 element_type = nullptr;
687 }
688 if (!array_access->null_seen()) {
689 element_ptr = ProfileNeverNull;
690 } else if (call_profile.count() == 0) {
691 element_ptr = ProfileAlwaysNull;
692 } else {
693 element_ptr = ProfileMaybeNull;
694 }
695 return true;
696 }
697 }
698 }
699 return false;
700 }
701
702 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) {
703 if (method_data() != nullptr && method_data()->is_mature()) {
704 ciProfileData* data = method_data()->bci_to_data(bci);
705 if (data != nullptr && data->is_ACmpData()) {
706 ciACmpData* acmp = (ciACmpData*)data->as_ACmpData();
707 left_type = acmp->left()->valid_type();
708 right_type = acmp->right()->valid_type();
709 left_ptr = acmp->left()->ptr_kind();
710 right_ptr = acmp->right()->ptr_kind();
711 left_inline_type = acmp->left_inline_type();
712 right_inline_type = acmp->right_inline_type();
713 return true;
714 }
715 }
716 return false;
717 }
718
719
720 // ------------------------------------------------------------------
721 // ciMethod::find_monomorphic_target
722 //
723 // Given a certain calling environment, find the monomorphic target
724 // for the call. Return null if the call is not monomorphic in
725 // its calling environment, or if there are only abstract methods.
726 // The returned method is never abstract.
727 // Note: If caller uses a non-null result, it must inform dependencies
728 // via assert_unique_concrete_method or assert_leaf_type.
729 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
730 ciInstanceKlass* callee_holder,
731 ciInstanceKlass* actual_recv,
732 bool check_access) {
733 check_is_loaded();
734
735 if (actual_recv->is_interface()) {
736 // %%% We cannot trust interface types, yet. See bug 6312651.
737 return nullptr;
738 }
1008 //
1009 // Return true if the method is an instance of the JVM-generated
1010 // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
1011 bool ciMethod::is_method_handle_intrinsic() const {
1012 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
1013 return (MethodHandles::is_signature_polymorphic(iid) &&
1014 MethodHandles::is_signature_polymorphic_intrinsic(iid));
1015 }
1016
1017 // ------------------------------------------------------------------
1018 // ciMethod::is_compiled_lambda_form
1019 //
1020 // Return true if the method is a generated MethodHandle adapter.
1021 // These are built by Java code.
1022 bool ciMethod::is_compiled_lambda_form() const {
1023 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
1024 return iid == vmIntrinsics::_compiledLambdaForm;
1025 }
1026
1027 // ------------------------------------------------------------------
1028 // ciMethod::is_object_constructor
1029 //
1030 bool ciMethod::is_object_constructor() const {
1031 return (name() == ciSymbols::object_initializer_name()
1032 && signature()->return_type()->is_void());
1033 // Note: We can't test is_static, because that would
1034 // require the method to be loaded. Sometimes it isn't.
1035 }
1036
1037 // ------------------------------------------------------------------
1038 // ciMethod::is_scoped
1039 //
1040 // Return true for methods annotated with @Scoped
1041 bool ciMethod::is_scoped() const {
1042 return get_Method()->is_scoped();
1043 }
1044
1045 // ------------------------------------------------------------------
1046 // ciMethod::has_member_arg
1047 //
1048 // Return true if the method is a linker intrinsic like _linkToVirtual.
1049 // These are built by the JVM.
1050 bool ciMethod::has_member_arg() const {
1051 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
1052 return (MethodHandles::is_signature_polymorphic(iid) &&
1053 MethodHandles::has_member_arg(iid));
1054 }
1536 default:
1537 break;
1538 }
1539 assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1540 int arg_count = target_sig->count() - rbase;
1541 for (int i = 0; i < arg_count; i++) {
1542 if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1543 return false;
1544 }
1545 }
1546 // Only check the return type if the symbolic info has non-void return type.
1547 // I.e. the return value of the resolved method can be dropped.
1548 if (!linker->return_type()->is_void() &&
1549 !basic_types_match(linker->return_type(), target->return_type())) {
1550 return false;
1551 }
1552 return true; // no mismatch found
1553 }
1554
1555 // ------------------------------------------------------------------
1556
1557 bool ciMethod::is_scalarized_arg(int idx) const {
1558 VM_ENTRY_MARK;
1559 return get_Method()->is_scalarized_arg(idx);
1560 }
1561
1562 bool ciMethod::has_scalarized_args() const {
1563 VM_ENTRY_MARK;
1564 return get_Method()->has_scalarized_args();
1565 }
1566
1567 const GrowableArray<SigEntry>* ciMethod::get_sig_cc() const {
1568 VM_ENTRY_MARK;
1569 if (get_Method()->adapter() == nullptr) {
1570 return nullptr;
1571 }
1572 return get_Method()->adapter()->get_sig_cc();
1573 }
|