30 #include "ci/ciMethodBlocks.hpp"
31 #include "ci/ciMethodData.hpp"
32 #include "ci/ciStreams.hpp"
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/methodLiveness.hpp"
39 #include "interpreter/interpreter.hpp"
40 #include "interpreter/linkResolver.hpp"
41 #include "interpreter/oopMapCache.hpp"
42 #include "memory/allocation.inline.hpp"
43 #include "memory/resourceArea.hpp"
44 #include "oops/generateOopMap.hpp"
45 #include "oops/method.inline.hpp"
46 #include "oops/oop.inline.hpp"
47 #include "prims/methodHandles.hpp"
48 #include "runtime/deoptimization.hpp"
49 #include "runtime/handles.inline.hpp"
50 #include "utilities/bitMap.inline.hpp"
51 #include "utilities/xmlstream.hpp"
52 #ifdef COMPILER2
53 #include "ci/bcEscapeAnalyzer.hpp"
54 #include "ci/ciTypeFlow.hpp"
55 #include "oops/method.hpp"
56 #endif
57
58 // ciMethod
59 //
60 // This class represents a Method* in the HotSpot virtual
61 // machine.
62
63
64 // ------------------------------------------------------------------
65 // ciMethod::ciMethod
66 //
67 // Loaded method.
68 ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
69 ciMetadata(h_m()),
641 * Check whether profiling provides a type for the parameter i
642 *
643 * @param [in]i parameter number
644 * @param [out]type profiled type of parameter, NULL if none
645 * @param [out]ptr_kind whether always null, never null or maybe null
646 * @return true if profiling exists
647 *
648 */
649 bool ciMethod::parameter_profiled_type(int i, ciKlass*& type, ProfilePtrKind& ptr_kind) {
650 if (MethodData::profile_parameters() && method_data() != NULL && method_data()->is_mature()) {
651 ciParametersTypeData* parameters = method_data()->parameters_type_data();
652 if (parameters != NULL && i < parameters->number_of_parameters()) {
653 type = parameters->valid_parameter_type(i);
654 ptr_kind = parameters->parameter_ptr_kind(i);
655 return true;
656 }
657 }
658 return false;
659 }
660
661
662 // ------------------------------------------------------------------
663 // ciMethod::find_monomorphic_target
664 //
665 // Given a certain calling environment, find the monomorphic target
666 // for the call. Return NULL if the call is not monomorphic in
667 // its calling environment, or if there are only abstract methods.
668 // The returned method is never abstract.
669 // Note: If caller uses a non-null result, it must inform dependencies
670 // via assert_unique_concrete_method or assert_leaf_type.
671 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
672 ciInstanceKlass* callee_holder,
673 ciInstanceKlass* actual_recv,
674 bool check_access) {
675 check_is_loaded();
676
677 if (actual_recv->is_interface()) {
678 // %%% We cannot trust interface types, yet. See bug 6312651.
679 return NULL;
680 }
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;
1221 // ciMethod::print_codes
1222 //
1223 // Print the bytecodes for this method.
1224 void ciMethod::print_codes_on(outputStream* st) {
1225 check_is_loaded();
1226 GUARDED_VM_ENTRY(get_Method()->print_codes_on(st);)
1227 }
1228
1229
1230 #define FETCH_FLAG_FROM_VM(flag_accessor) { \
1231 check_is_loaded(); \
1232 VM_ENTRY_MARK; \
1233 return get_Method()->flag_accessor(); \
1234 }
1235
1236 bool ciMethod::has_loops () const { FETCH_FLAG_FROM_VM(has_loops); }
1237 bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); }
1238 bool ciMethod::is_getter () const { FETCH_FLAG_FROM_VM(is_getter); }
1239 bool ciMethod::is_setter () const { FETCH_FLAG_FROM_VM(is_setter); }
1240 bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); }
1241 bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); }
1242 bool ciMethod::is_empty () const { FETCH_FLAG_FROM_VM(is_empty_method); }
1243
1244 bool ciMethod::is_boxing_method() const {
1245 if (intrinsic_id() != vmIntrinsics::_none && holder()->is_box_klass()) {
1246 switch (intrinsic_id()) {
1247 case vmIntrinsics::_Boolean_valueOf:
1248 case vmIntrinsics::_Byte_valueOf:
1249 case vmIntrinsics::_Character_valueOf:
1250 case vmIntrinsics::_Short_valueOf:
1251 case vmIntrinsics::_Integer_valueOf:
1252 case vmIntrinsics::_Long_valueOf:
1253 case vmIntrinsics::_Float_valueOf:
1254 case vmIntrinsics::_Double_valueOf:
1255 return true;
1256 default:
1257 return false;
1258 }
1259 }
1260 return false;
1261 }
1381 name()->print_symbol_on(st);
1382 st->print(" holder=");
1383 holder()->print_name_on(st);
1384 st->print(" signature=");
1385 signature()->as_symbol()->print_symbol_on(st);
1386 if (is_loaded()) {
1387 st->print(" loaded=true");
1388 st->print(" arg_size=%d", arg_size());
1389 st->print(" flags=");
1390 flags().print_member_flags(st);
1391 } else {
1392 st->print(" loaded=false");
1393 }
1394 }
1395
1396 // ------------------------------------------------------------------
1397
1398 static BasicType erase_to_word_type(BasicType bt) {
1399 if (is_subword_type(bt)) return T_INT;
1400 if (is_reference_type(bt)) return T_OBJECT;
1401 return bt;
1402 }
1403
1404 static bool basic_types_match(ciType* t1, ciType* t2) {
1405 if (t1 == t2) return true;
1406 return erase_to_word_type(t1->basic_type()) == erase_to_word_type(t2->basic_type());
1407 }
1408
1409 bool ciMethod::is_consistent_info(ciMethod* declared_method, ciMethod* resolved_method) {
1410 bool invoke_through_mh_intrinsic = declared_method->is_method_handle_intrinsic() &&
1411 !resolved_method->is_method_handle_intrinsic();
1412
1413 if (!invoke_through_mh_intrinsic) {
1414 // Method name & descriptor should stay the same.
1415 // Signatures may reference unloaded types and thus they may be not strictly equal.
1416 ciSymbol* declared_signature = declared_method->signature()->as_symbol();
1417 ciSymbol* resolved_signature = resolved_method->signature()->as_symbol();
1418
1419 return (declared_method->name()->equals(resolved_method->name())) &&
1420 (declared_signature->equals(resolved_signature));
1468 default:
1469 break;
1470 }
1471 assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1472 int arg_count = target_sig->count() - rbase;
1473 for (int i = 0; i < arg_count; i++) {
1474 if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1475 return false;
1476 }
1477 }
1478 // Only check the return type if the symbolic info has non-void return type.
1479 // I.e. the return value of the resolved method can be dropped.
1480 if (!linker->return_type()->is_void() &&
1481 !basic_types_match(linker->return_type(), target->return_type())) {
1482 return false;
1483 }
1484 return true; // no mismatch found
1485 }
1486
1487 // ------------------------------------------------------------------
|
30 #include "ci/ciMethodBlocks.hpp"
31 #include "ci/ciMethodData.hpp"
32 #include "ci/ciStreams.hpp"
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/methodLiveness.hpp"
39 #include "interpreter/interpreter.hpp"
40 #include "interpreter/linkResolver.hpp"
41 #include "interpreter/oopMapCache.hpp"
42 #include "memory/allocation.inline.hpp"
43 #include "memory/resourceArea.hpp"
44 #include "oops/generateOopMap.hpp"
45 #include "oops/method.inline.hpp"
46 #include "oops/oop.inline.hpp"
47 #include "prims/methodHandles.hpp"
48 #include "runtime/deoptimization.hpp"
49 #include "runtime/handles.inline.hpp"
50 #include "runtime/sharedRuntime.hpp"
51 #include "utilities/bitMap.inline.hpp"
52 #include "utilities/xmlstream.hpp"
53 #ifdef COMPILER2
54 #include "ci/bcEscapeAnalyzer.hpp"
55 #include "ci/ciTypeFlow.hpp"
56 #include "oops/method.hpp"
57 #endif
58
59 // ciMethod
60 //
61 // This class represents a Method* in the HotSpot virtual
62 // machine.
63
64
65 // ------------------------------------------------------------------
66 // ciMethod::ciMethod
67 //
68 // Loaded method.
69 ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
70 ciMetadata(h_m()),
642 * Check whether profiling provides a type for the parameter i
643 *
644 * @param [in]i parameter number
645 * @param [out]type profiled type of parameter, NULL if none
646 * @param [out]ptr_kind whether always null, never null or maybe null
647 * @return true if profiling exists
648 *
649 */
650 bool ciMethod::parameter_profiled_type(int i, ciKlass*& type, ProfilePtrKind& ptr_kind) {
651 if (MethodData::profile_parameters() && method_data() != NULL && method_data()->is_mature()) {
652 ciParametersTypeData* parameters = method_data()->parameters_type_data();
653 if (parameters != NULL && i < parameters->number_of_parameters()) {
654 type = parameters->valid_parameter_type(i);
655 ptr_kind = parameters->parameter_ptr_kind(i);
656 return true;
657 }
658 }
659 return false;
660 }
661
662 bool ciMethod::array_access_profiled_type(int bci, ciKlass*& array_type, ciKlass*& element_type, ProfilePtrKind& element_ptr, bool &flat_array, bool &null_free_array) {
663 if (method_data() != NULL && method_data()->is_mature()) {
664 ciProfileData* data = method_data()->bci_to_data(bci);
665 if (data != NULL && data->is_ArrayLoadStoreData()) {
666 ciArrayLoadStoreData* array_access = (ciArrayLoadStoreData*)data->as_ArrayLoadStoreData();
667 array_type = array_access->array()->valid_type();
668 element_type = array_access->element()->valid_type();
669 element_ptr = array_access->element()->ptr_kind();
670 flat_array = array_access->flat_array();
671 null_free_array = array_access->null_free_array();
672 return true;
673 }
674 }
675 return false;
676 }
677
678 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) {
679 if (method_data() != NULL && method_data()->is_mature()) {
680 ciProfileData* data = method_data()->bci_to_data(bci);
681 if (data != NULL && data->is_ACmpData()) {
682 ciACmpData* acmp = (ciACmpData*)data->as_ACmpData();
683 left_type = acmp->left()->valid_type();
684 right_type = acmp->right()->valid_type();
685 left_ptr = acmp->left()->ptr_kind();
686 right_ptr = acmp->right()->ptr_kind();
687 left_inline_type = acmp->left_inline_type();
688 right_inline_type = acmp->right_inline_type();
689 return true;
690 }
691 }
692 return false;
693 }
694
695
696 // ------------------------------------------------------------------
697 // ciMethod::find_monomorphic_target
698 //
699 // Given a certain calling environment, find the monomorphic target
700 // for the call. Return NULL if the call is not monomorphic in
701 // its calling environment, or if there are only abstract methods.
702 // The returned method is never abstract.
703 // Note: If caller uses a non-null result, it must inform dependencies
704 // via assert_unique_concrete_method or assert_leaf_type.
705 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
706 ciInstanceKlass* callee_holder,
707 ciInstanceKlass* actual_recv,
708 bool check_access) {
709 check_is_loaded();
710
711 if (actual_recv->is_interface()) {
712 // %%% We cannot trust interface types, yet. See bug 6312651.
713 return NULL;
714 }
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_init_factory
1004 //
1005 bool ciMethod::is_static_init_factory() const {
1006 return (name() == ciSymbols::object_initializer_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;
1268 // ciMethod::print_codes
1269 //
1270 // Print the bytecodes for this method.
1271 void ciMethod::print_codes_on(outputStream* st) {
1272 check_is_loaded();
1273 GUARDED_VM_ENTRY(get_Method()->print_codes_on(st);)
1274 }
1275
1276
1277 #define FETCH_FLAG_FROM_VM(flag_accessor) { \
1278 check_is_loaded(); \
1279 VM_ENTRY_MARK; \
1280 return get_Method()->flag_accessor(); \
1281 }
1282
1283 bool ciMethod::has_loops () const { FETCH_FLAG_FROM_VM(has_loops); }
1284 bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); }
1285 bool ciMethod::is_getter () const { FETCH_FLAG_FROM_VM(is_getter); }
1286 bool ciMethod::is_setter () const { FETCH_FLAG_FROM_VM(is_setter); }
1287 bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); }
1288 bool ciMethod::is_object_constructor_or_class_initializer() const { FETCH_FLAG_FROM_VM(is_object_constructor_or_class_initializer); }
1289 bool ciMethod::is_empty () const { FETCH_FLAG_FROM_VM(is_empty_method); }
1290
1291 bool ciMethod::is_boxing_method() const {
1292 if (intrinsic_id() != vmIntrinsics::_none && holder()->is_box_klass()) {
1293 switch (intrinsic_id()) {
1294 case vmIntrinsics::_Boolean_valueOf:
1295 case vmIntrinsics::_Byte_valueOf:
1296 case vmIntrinsics::_Character_valueOf:
1297 case vmIntrinsics::_Short_valueOf:
1298 case vmIntrinsics::_Integer_valueOf:
1299 case vmIntrinsics::_Long_valueOf:
1300 case vmIntrinsics::_Float_valueOf:
1301 case vmIntrinsics::_Double_valueOf:
1302 return true;
1303 default:
1304 return false;
1305 }
1306 }
1307 return false;
1308 }
1428 name()->print_symbol_on(st);
1429 st->print(" holder=");
1430 holder()->print_name_on(st);
1431 st->print(" signature=");
1432 signature()->as_symbol()->print_symbol_on(st);
1433 if (is_loaded()) {
1434 st->print(" loaded=true");
1435 st->print(" arg_size=%d", arg_size());
1436 st->print(" flags=");
1437 flags().print_member_flags(st);
1438 } else {
1439 st->print(" loaded=false");
1440 }
1441 }
1442
1443 // ------------------------------------------------------------------
1444
1445 static BasicType erase_to_word_type(BasicType bt) {
1446 if (is_subword_type(bt)) return T_INT;
1447 if (is_reference_type(bt)) return T_OBJECT;
1448 if (bt == T_PRIMITIVE_OBJECT) return T_OBJECT;
1449 return bt;
1450 }
1451
1452 static bool basic_types_match(ciType* t1, ciType* t2) {
1453 if (t1 == t2) return true;
1454 return erase_to_word_type(t1->basic_type()) == erase_to_word_type(t2->basic_type());
1455 }
1456
1457 bool ciMethod::is_consistent_info(ciMethod* declared_method, ciMethod* resolved_method) {
1458 bool invoke_through_mh_intrinsic = declared_method->is_method_handle_intrinsic() &&
1459 !resolved_method->is_method_handle_intrinsic();
1460
1461 if (!invoke_through_mh_intrinsic) {
1462 // Method name & descriptor should stay the same.
1463 // Signatures may reference unloaded types and thus they may be not strictly equal.
1464 ciSymbol* declared_signature = declared_method->signature()->as_symbol();
1465 ciSymbol* resolved_signature = resolved_method->signature()->as_symbol();
1466
1467 return (declared_method->name()->equals(resolved_method->name())) &&
1468 (declared_signature->equals(resolved_signature));
1516 default:
1517 break;
1518 }
1519 assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1520 int arg_count = target_sig->count() - rbase;
1521 for (int i = 0; i < arg_count; i++) {
1522 if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1523 return false;
1524 }
1525 }
1526 // Only check the return type if the symbolic info has non-void return type.
1527 // I.e. the return value of the resolved method can be dropped.
1528 if (!linker->return_type()->is_void() &&
1529 !basic_types_match(linker->return_type(), target->return_type())) {
1530 return false;
1531 }
1532 return true; // no mismatch found
1533 }
1534
1535 // ------------------------------------------------------------------
1536
1537 bool ciMethod::is_scalarized_arg(int idx) const {
1538 VM_ENTRY_MARK;
1539 return get_Method()->is_scalarized_arg(idx);
1540 }
1541
1542 bool ciMethod::has_scalarized_args() const {
1543 VM_ENTRY_MARK;
1544 return get_Method()->has_scalarized_args();
1545 }
1546
1547 const GrowableArray<SigEntry>* ciMethod::get_sig_cc() const {
1548 VM_ENTRY_MARK;
1549 if (get_Method()->adapter() == NULL) {
1550 return NULL;
1551 }
1552 return get_Method()->adapter()->get_sig_cc();
1553 }
|