33 #include "ci/ciSymbol.hpp"
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/methodLiveness.hpp"
40 #include "interpreter/interpreter.hpp"
41 #include "interpreter/linkResolver.hpp"
42 #include "interpreter/oopMapCache.hpp"
43 #include "logging/log.hpp"
44 #include "logging/logStream.hpp"
45 #include "memory/allocation.inline.hpp"
46 #include "memory/resourceArea.hpp"
47 #include "oops/generateOopMap.hpp"
48 #include "oops/method.inline.hpp"
49 #include "oops/oop.inline.hpp"
50 #include "prims/methodHandles.hpp"
51 #include "runtime/deoptimization.hpp"
52 #include "runtime/handles.inline.hpp"
53 #include "utilities/bitMap.inline.hpp"
54 #include "utilities/xmlstream.hpp"
55 #ifdef COMPILER2
56 #include "ci/bcEscapeAnalyzer.hpp"
57 #include "ci/ciTypeFlow.hpp"
58 #include "oops/method.hpp"
59 #endif
60
61 // ciMethod
62 //
63 // This class represents a Method* in the HotSpot virtual
64 // machine.
65
66
67 // ------------------------------------------------------------------
68 // ciMethod::ciMethod
69 //
70 // Loaded method.
71 ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
72 ciMetadata(h_m()),
639 * Check whether profiling provides a type for the parameter i
640 *
641 * @param [in]i parameter number
642 * @param [out]type profiled type of parameter, null if none
643 * @param [out]ptr_kind whether always null, never null or maybe null
644 * @return true if profiling exists
645 *
646 */
647 bool ciMethod::parameter_profiled_type(int i, ciKlass*& type, ProfilePtrKind& ptr_kind) {
648 if (MethodData::profile_parameters() && method_data() != nullptr && method_data()->is_mature()) {
649 ciParametersTypeData* parameters = method_data()->parameters_type_data();
650 if (parameters != nullptr && i < parameters->number_of_parameters()) {
651 type = parameters->valid_parameter_type(i);
652 ptr_kind = parameters->parameter_ptr_kind(i);
653 return true;
654 }
655 }
656 return false;
657 }
658
659
660 // ------------------------------------------------------------------
661 // ciMethod::find_monomorphic_target
662 //
663 // Given a certain calling environment, find the monomorphic target
664 // for the call. Return null if the call is not monomorphic in
665 // its calling environment, or if there are only abstract methods.
666 // The returned method is never abstract.
667 // Note: If caller uses a non-null result, it must inform dependencies
668 // via assert_unique_concrete_method or assert_leaf_type.
669 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
670 ciInstanceKlass* callee_holder,
671 ciInstanceKlass* actual_recv,
672 bool check_access) {
673 check_is_loaded();
674
675 if (actual_recv->is_interface()) {
676 // %%% We cannot trust interface types, yet. See bug 6312651.
677 return nullptr;
678 }
939 //
940 // Return true if the method is an instance of the JVM-generated
941 // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
942 bool ciMethod::is_method_handle_intrinsic() const {
943 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
944 return (MethodHandles::is_signature_polymorphic(iid) &&
945 MethodHandles::is_signature_polymorphic_intrinsic(iid));
946 }
947
948 // ------------------------------------------------------------------
949 // ciMethod::is_compiled_lambda_form
950 //
951 // Return true if the method is a generated MethodHandle adapter.
952 // These are built by Java code.
953 bool ciMethod::is_compiled_lambda_form() const {
954 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
955 return iid == vmIntrinsics::_compiledLambdaForm;
956 }
957
958 // ------------------------------------------------------------------
959 // ciMethod::is_object_initializer
960 //
961 bool ciMethod::is_object_initializer() const {
962 return name() == ciSymbols::object_initializer_name();
963 }
964
965 // ------------------------------------------------------------------
966 // ciMethod::has_member_arg
967 //
968 // Return true if the method is a linker intrinsic like _linkToVirtual.
969 // These are built by the JVM.
970 bool ciMethod::has_member_arg() const {
971 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
972 return (MethodHandles::is_signature_polymorphic(iid) &&
973 MethodHandles::has_member_arg(iid));
974 }
975
976 // ------------------------------------------------------------------
977 // ciMethod::ensure_method_data
978 //
979 // Generate new MethodData* objects at compile time.
980 // Return true if allocation was successful or no MDO is required.
981 bool ciMethod::ensure_method_data(const methodHandle& h_m) {
982 EXCEPTION_CONTEXT;
1210 // ciMethod::print_codes
1211 //
1212 // Print the bytecodes for this method.
1213 void ciMethod::print_codes_on(outputStream* st) {
1214 check_is_loaded();
1215 GUARDED_VM_ENTRY(get_Method()->print_codes_on(st);)
1216 }
1217
1218
1219 #define FETCH_FLAG_FROM_VM(flag_accessor) { \
1220 check_is_loaded(); \
1221 VM_ENTRY_MARK; \
1222 return get_Method()->flag_accessor(); \
1223 }
1224
1225 bool ciMethod::has_loops () const { FETCH_FLAG_FROM_VM(has_loops); }
1226 bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); }
1227 bool ciMethod::is_getter () const { FETCH_FLAG_FROM_VM(is_getter); }
1228 bool ciMethod::is_setter () const { FETCH_FLAG_FROM_VM(is_setter); }
1229 bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); }
1230 bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); }
1231 bool ciMethod::is_empty () const { FETCH_FLAG_FROM_VM(is_empty_method); }
1232
1233 bool ciMethod::is_boxing_method() const {
1234 if (intrinsic_id() != vmIntrinsics::_none && holder()->is_box_klass()) {
1235 switch (intrinsic_id()) {
1236 case vmIntrinsics::_Boolean_valueOf:
1237 case vmIntrinsics::_Byte_valueOf:
1238 case vmIntrinsics::_Character_valueOf:
1239 case vmIntrinsics::_Short_valueOf:
1240 case vmIntrinsics::_Integer_valueOf:
1241 case vmIntrinsics::_Long_valueOf:
1242 case vmIntrinsics::_Float_valueOf:
1243 case vmIntrinsics::_Double_valueOf:
1244 return true;
1245 default:
1246 return false;
1247 }
1248 }
1249 return false;
1250 }
1370 name()->print_symbol_on(st);
1371 st->print(" holder=");
1372 holder()->print_name_on(st);
1373 st->print(" signature=");
1374 signature()->as_symbol()->print_symbol_on(st);
1375 if (is_loaded()) {
1376 st->print(" loaded=true");
1377 st->print(" arg_size=%d", arg_size());
1378 st->print(" flags=");
1379 flags().print_member_flags(st);
1380 } else {
1381 st->print(" loaded=false");
1382 }
1383 }
1384
1385 // ------------------------------------------------------------------
1386
1387 static BasicType erase_to_word_type(BasicType bt) {
1388 if (is_subword_type(bt)) return T_INT;
1389 if (is_reference_type(bt)) return T_OBJECT;
1390 return bt;
1391 }
1392
1393 static bool basic_types_match(ciType* t1, ciType* t2) {
1394 if (t1 == t2) return true;
1395 return erase_to_word_type(t1->basic_type()) == erase_to_word_type(t2->basic_type());
1396 }
1397
1398 bool ciMethod::is_consistent_info(ciMethod* declared_method, ciMethod* resolved_method) {
1399 bool invoke_through_mh_intrinsic = declared_method->is_method_handle_intrinsic() &&
1400 !resolved_method->is_method_handle_intrinsic();
1401
1402 if (!invoke_through_mh_intrinsic) {
1403 // Method name & descriptor should stay the same.
1404 // Signatures may reference unloaded types and thus they may be not strictly equal.
1405 ciSymbol* declared_signature = declared_method->signature()->as_symbol();
1406 ciSymbol* resolved_signature = resolved_method->signature()->as_symbol();
1407
1408 return (declared_method->name()->equals(resolved_method->name())) &&
1409 (declared_signature->equals(resolved_signature));
1457 default:
1458 break;
1459 }
1460 assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1461 int arg_count = target_sig->count() - rbase;
1462 for (int i = 0; i < arg_count; i++) {
1463 if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1464 return false;
1465 }
1466 }
1467 // Only check the return type if the symbolic info has non-void return type.
1468 // I.e. the return value of the resolved method can be dropped.
1469 if (!linker->return_type()->is_void() &&
1470 !basic_types_match(linker->return_type(), target->return_type())) {
1471 return false;
1472 }
1473 return true; // no mismatch found
1474 }
1475
1476 // ------------------------------------------------------------------
|
33 #include "ci/ciSymbol.hpp"
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/methodLiveness.hpp"
40 #include "interpreter/interpreter.hpp"
41 #include "interpreter/linkResolver.hpp"
42 #include "interpreter/oopMapCache.hpp"
43 #include "logging/log.hpp"
44 #include "logging/logStream.hpp"
45 #include "memory/allocation.inline.hpp"
46 #include "memory/resourceArea.hpp"
47 #include "oops/generateOopMap.hpp"
48 #include "oops/method.inline.hpp"
49 #include "oops/oop.inline.hpp"
50 #include "prims/methodHandles.hpp"
51 #include "runtime/deoptimization.hpp"
52 #include "runtime/handles.inline.hpp"
53 #include "runtime/sharedRuntime.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()),
640 * Check whether profiling provides a type for the parameter i
641 *
642 * @param [in]i parameter number
643 * @param [out]type profiled type of parameter, null if none
644 * @param [out]ptr_kind whether always null, never null or maybe null
645 * @return true if profiling exists
646 *
647 */
648 bool ciMethod::parameter_profiled_type(int i, ciKlass*& type, ProfilePtrKind& ptr_kind) {
649 if (MethodData::profile_parameters() && method_data() != nullptr && method_data()->is_mature()) {
650 ciParametersTypeData* parameters = method_data()->parameters_type_data();
651 if (parameters != nullptr && i < parameters->number_of_parameters()) {
652 type = parameters->valid_parameter_type(i);
653 ptr_kind = parameters->parameter_ptr_kind(i);
654 return true;
655 }
656 }
657 return false;
658 }
659
660 bool ciMethod::array_access_profiled_type(int bci, ciKlass*& array_type, ciKlass*& element_type, ProfilePtrKind& element_ptr, bool &flat_array, bool &null_free_array) {
661 if (method_data() != nullptr && method_data()->is_mature()) {
662 ciProfileData* data = method_data()->bci_to_data(bci);
663 if (data != nullptr && data->is_ArrayLoadStoreData()) {
664 ciArrayLoadStoreData* array_access = (ciArrayLoadStoreData*)data->as_ArrayLoadStoreData();
665 array_type = array_access->array()->valid_type();
666 element_type = array_access->element()->valid_type();
667 element_ptr = array_access->element()->ptr_kind();
668 flat_array = array_access->flat_array();
669 null_free_array = array_access->null_free_array();
670 return true;
671 }
672 }
673 return false;
674 }
675
676 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) {
677 if (method_data() != nullptr && method_data()->is_mature()) {
678 ciProfileData* data = method_data()->bci_to_data(bci);
679 if (data != nullptr && data->is_ACmpData()) {
680 ciACmpData* acmp = (ciACmpData*)data->as_ACmpData();
681 left_type = acmp->left()->valid_type();
682 right_type = acmp->right()->valid_type();
683 left_ptr = acmp->left()->ptr_kind();
684 right_ptr = acmp->right()->ptr_kind();
685 left_inline_type = acmp->left_inline_type();
686 right_inline_type = acmp->right_inline_type();
687 return true;
688 }
689 }
690 return false;
691 }
692
693
694 // ------------------------------------------------------------------
695 // ciMethod::find_monomorphic_target
696 //
697 // Given a certain calling environment, find the monomorphic target
698 // for the call. Return null if the call is not monomorphic in
699 // its calling environment, or if there are only abstract methods.
700 // The returned method is never abstract.
701 // Note: If caller uses a non-null result, it must inform dependencies
702 // via assert_unique_concrete_method or assert_leaf_type.
703 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
704 ciInstanceKlass* callee_holder,
705 ciInstanceKlass* actual_recv,
706 bool check_access) {
707 check_is_loaded();
708
709 if (actual_recv->is_interface()) {
710 // %%% We cannot trust interface types, yet. See bug 6312651.
711 return nullptr;
712 }
973 //
974 // Return true if the method is an instance of the JVM-generated
975 // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
976 bool ciMethod::is_method_handle_intrinsic() const {
977 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
978 return (MethodHandles::is_signature_polymorphic(iid) &&
979 MethodHandles::is_signature_polymorphic_intrinsic(iid));
980 }
981
982 // ------------------------------------------------------------------
983 // ciMethod::is_compiled_lambda_form
984 //
985 // Return true if the method is a generated MethodHandle adapter.
986 // These are built by Java code.
987 bool ciMethod::is_compiled_lambda_form() const {
988 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
989 return iid == vmIntrinsics::_compiledLambdaForm;
990 }
991
992 // ------------------------------------------------------------------
993 // ciMethod::is_object_constructor
994 //
995 bool ciMethod::is_object_constructor() const {
996 return (name() == ciSymbols::object_initializer_name()
997 && signature()->return_type()->is_void());
998 // Note: We can't test is_static, because that would
999 // require the method to be loaded. Sometimes it isn't.
1000 }
1001
1002 // ------------------------------------------------------------------
1003 // ciMethod::is_static_vnew_factory
1004 //
1005 bool ciMethod::is_static_vnew_factory() const {
1006 return (name() == ciSymbols::inline_factory_name()
1007 && !signature()->return_type()->is_void());
1008 // Note: We can't test is_static, because that would
1009 // require the method to be loaded. Sometimes it isn't.
1010 }
1011
1012 // ------------------------------------------------------------------
1013 // ciMethod::has_member_arg
1014 //
1015 // Return true if the method is a linker intrinsic like _linkToVirtual.
1016 // These are built by the JVM.
1017 bool ciMethod::has_member_arg() const {
1018 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
1019 return (MethodHandles::is_signature_polymorphic(iid) &&
1020 MethodHandles::has_member_arg(iid));
1021 }
1022
1023 // ------------------------------------------------------------------
1024 // ciMethod::ensure_method_data
1025 //
1026 // Generate new MethodData* objects at compile time.
1027 // Return true if allocation was successful or no MDO is required.
1028 bool ciMethod::ensure_method_data(const methodHandle& h_m) {
1029 EXCEPTION_CONTEXT;
1257 // ciMethod::print_codes
1258 //
1259 // Print the bytecodes for this method.
1260 void ciMethod::print_codes_on(outputStream* st) {
1261 check_is_loaded();
1262 GUARDED_VM_ENTRY(get_Method()->print_codes_on(st);)
1263 }
1264
1265
1266 #define FETCH_FLAG_FROM_VM(flag_accessor) { \
1267 check_is_loaded(); \
1268 VM_ENTRY_MARK; \
1269 return get_Method()->flag_accessor(); \
1270 }
1271
1272 bool ciMethod::has_loops () const { FETCH_FLAG_FROM_VM(has_loops); }
1273 bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); }
1274 bool ciMethod::is_getter () const { FETCH_FLAG_FROM_VM(is_getter); }
1275 bool ciMethod::is_setter () const { FETCH_FLAG_FROM_VM(is_setter); }
1276 bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); }
1277 bool ciMethod::is_object_constructor_or_class_initializer() const { FETCH_FLAG_FROM_VM(is_object_constructor_or_class_initializer); }
1278 bool ciMethod::is_empty () const { FETCH_FLAG_FROM_VM(is_empty_method); }
1279
1280 bool ciMethod::is_boxing_method() const {
1281 if (intrinsic_id() != vmIntrinsics::_none && holder()->is_box_klass()) {
1282 switch (intrinsic_id()) {
1283 case vmIntrinsics::_Boolean_valueOf:
1284 case vmIntrinsics::_Byte_valueOf:
1285 case vmIntrinsics::_Character_valueOf:
1286 case vmIntrinsics::_Short_valueOf:
1287 case vmIntrinsics::_Integer_valueOf:
1288 case vmIntrinsics::_Long_valueOf:
1289 case vmIntrinsics::_Float_valueOf:
1290 case vmIntrinsics::_Double_valueOf:
1291 return true;
1292 default:
1293 return false;
1294 }
1295 }
1296 return false;
1297 }
1417 name()->print_symbol_on(st);
1418 st->print(" holder=");
1419 holder()->print_name_on(st);
1420 st->print(" signature=");
1421 signature()->as_symbol()->print_symbol_on(st);
1422 if (is_loaded()) {
1423 st->print(" loaded=true");
1424 st->print(" arg_size=%d", arg_size());
1425 st->print(" flags=");
1426 flags().print_member_flags(st);
1427 } else {
1428 st->print(" loaded=false");
1429 }
1430 }
1431
1432 // ------------------------------------------------------------------
1433
1434 static BasicType erase_to_word_type(BasicType bt) {
1435 if (is_subword_type(bt)) return T_INT;
1436 if (is_reference_type(bt)) return T_OBJECT;
1437 if (bt == T_PRIMITIVE_OBJECT) return T_OBJECT;
1438 return bt;
1439 }
1440
1441 static bool basic_types_match(ciType* t1, ciType* t2) {
1442 if (t1 == t2) return true;
1443 return erase_to_word_type(t1->basic_type()) == erase_to_word_type(t2->basic_type());
1444 }
1445
1446 bool ciMethod::is_consistent_info(ciMethod* declared_method, ciMethod* resolved_method) {
1447 bool invoke_through_mh_intrinsic = declared_method->is_method_handle_intrinsic() &&
1448 !resolved_method->is_method_handle_intrinsic();
1449
1450 if (!invoke_through_mh_intrinsic) {
1451 // Method name & descriptor should stay the same.
1452 // Signatures may reference unloaded types and thus they may be not strictly equal.
1453 ciSymbol* declared_signature = declared_method->signature()->as_symbol();
1454 ciSymbol* resolved_signature = resolved_method->signature()->as_symbol();
1455
1456 return (declared_method->name()->equals(resolved_method->name())) &&
1457 (declared_signature->equals(resolved_signature));
1505 default:
1506 break;
1507 }
1508 assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1509 int arg_count = target_sig->count() - rbase;
1510 for (int i = 0; i < arg_count; i++) {
1511 if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1512 return false;
1513 }
1514 }
1515 // Only check the return type if the symbolic info has non-void return type.
1516 // I.e. the return value of the resolved method can be dropped.
1517 if (!linker->return_type()->is_void() &&
1518 !basic_types_match(linker->return_type(), target->return_type())) {
1519 return false;
1520 }
1521 return true; // no mismatch found
1522 }
1523
1524 // ------------------------------------------------------------------
1525
1526 bool ciMethod::is_scalarized_arg(int idx) const {
1527 VM_ENTRY_MARK;
1528 return get_Method()->is_scalarized_arg(idx);
1529 }
1530
1531 bool ciMethod::has_scalarized_args() const {
1532 VM_ENTRY_MARK;
1533 return get_Method()->has_scalarized_args();
1534 }
1535
1536 const GrowableArray<SigEntry>* ciMethod::get_sig_cc() const {
1537 VM_ENTRY_MARK;
1538 if (get_Method()->adapter() == nullptr) {
1539 return nullptr;
1540 }
1541 return get_Method()->adapter()->get_sig_cc();
1542 }
|