< prev index next >

src/hotspot/share/ci/ciMethod.cpp

Print this page

  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()),

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

































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

 922 //
 923 // Return true if the method is an instance of the JVM-generated
 924 // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
 925 bool ciMethod::is_method_handle_intrinsic() const {
 926   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 927   return (MethodHandles::is_signature_polymorphic(iid) &&
 928           MethodHandles::is_signature_polymorphic_intrinsic(iid));
 929 }
 930 
 931 // ------------------------------------------------------------------
 932 // ciMethod::is_compiled_lambda_form
 933 //
 934 // Return true if the method is a generated MethodHandle adapter.
 935 // These are built by Java code.
 936 bool ciMethod::is_compiled_lambda_form() const {
 937   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 938   return iid == vmIntrinsics::_compiledLambdaForm;
 939 }
 940 
 941 // ------------------------------------------------------------------
 942 // ciMethod::is_object_initializer
 943 //
 944 bool ciMethod::is_object_initializer() const {
 945    return name() == ciSymbols::object_initializer_name();













 946 }
 947 
 948 // ------------------------------------------------------------------
 949 // ciMethod::has_member_arg
 950 //
 951 // Return true if the method is a linker intrinsic like _linkToVirtual.
 952 // These are built by the JVM.
 953 bool ciMethod::has_member_arg() const {
 954   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 955   return (MethodHandles::is_signature_polymorphic(iid) &&
 956           MethodHandles::has_member_arg(iid));
 957 }
 958 
 959 // ------------------------------------------------------------------
 960 // ciMethod::ensure_method_data
 961 //
 962 // Generate new MethodData* objects at compile time.
 963 // Return true if allocation was successful or no MDO is required.
 964 bool ciMethod::ensure_method_data(const methodHandle& h_m) {
 965   EXCEPTION_CONTEXT;

1204 // ciMethod::print_codes
1205 //
1206 // Print the bytecodes for this method.
1207 void ciMethod::print_codes_on(outputStream* st) {
1208   check_is_loaded();
1209   GUARDED_VM_ENTRY(get_Method()->print_codes_on(st);)
1210 }
1211 
1212 
1213 #define FETCH_FLAG_FROM_VM(flag_accessor) { \
1214   check_is_loaded(); \
1215   VM_ENTRY_MARK; \
1216   return get_Method()->flag_accessor(); \
1217 }
1218 
1219 bool ciMethod::has_loops      () const {         FETCH_FLAG_FROM_VM(has_loops); }
1220 bool ciMethod::has_jsrs       () const {         FETCH_FLAG_FROM_VM(has_jsrs);  }
1221 bool ciMethod::is_getter      () const {         FETCH_FLAG_FROM_VM(is_getter); }
1222 bool ciMethod::is_setter      () const {         FETCH_FLAG_FROM_VM(is_setter); }
1223 bool ciMethod::is_accessor    () const {         FETCH_FLAG_FROM_VM(is_accessor); }
1224 bool ciMethod::is_initializer () const {         FETCH_FLAG_FROM_VM(is_initializer); }
1225 bool ciMethod::is_empty       () const {         FETCH_FLAG_FROM_VM(is_empty_method); }
1226 
1227 bool ciMethod::is_boxing_method() const {
1228   if (intrinsic_id() != vmIntrinsics::_none && holder()->is_box_klass()) {
1229     switch (intrinsic_id()) {
1230       case vmIntrinsics::_Boolean_valueOf:
1231       case vmIntrinsics::_Byte_valueOf:
1232       case vmIntrinsics::_Character_valueOf:
1233       case vmIntrinsics::_Short_valueOf:
1234       case vmIntrinsics::_Integer_valueOf:
1235       case vmIntrinsics::_Long_valueOf:
1236       case vmIntrinsics::_Float_valueOf:
1237       case vmIntrinsics::_Double_valueOf:
1238         return true;
1239       default:
1240         return false;
1241     }
1242   }
1243   return false;
1244 }

1364   name()->print_symbol_on(st);
1365   st->print(" holder=");
1366   holder()->print_name_on(st);
1367   st->print(" signature=");
1368   signature()->as_symbol()->print_symbol_on(st);
1369   if (is_loaded()) {
1370     st->print(" loaded=true");
1371     st->print(" arg_size=%d", arg_size());
1372     st->print(" flags=");
1373     flags().print_member_flags(st);
1374   } else {
1375     st->print(" loaded=false");
1376   }
1377 }
1378 
1379 // ------------------------------------------------------------------
1380 
1381 static BasicType erase_to_word_type(BasicType bt) {
1382   if (is_subword_type(bt))   return T_INT;
1383   if (is_reference_type(bt)) return T_OBJECT;

1384   return bt;
1385 }
1386 
1387 static bool basic_types_match(ciType* t1, ciType* t2) {
1388   if (t1 == t2)  return true;
1389   return erase_to_word_type(t1->basic_type()) == erase_to_word_type(t2->basic_type());
1390 }
1391 
1392 bool ciMethod::is_consistent_info(ciMethod* declared_method, ciMethod* resolved_method) {
1393   bool invoke_through_mh_intrinsic = declared_method->is_method_handle_intrinsic() &&
1394                                   !resolved_method->is_method_handle_intrinsic();
1395 
1396   if (!invoke_through_mh_intrinsic) {
1397     // Method name & descriptor should stay the same.
1398     // Signatures may reference unloaded types and thus they may be not strictly equal.
1399     ciSymbol* declared_signature = declared_method->signature()->as_symbol();
1400     ciSymbol* resolved_signature = resolved_method->signature()->as_symbol();
1401 
1402     return (declared_method->name()->equals(resolved_method->name())) &&
1403            (declared_signature->equals(resolved_signature));

1451     default:
1452       break;
1453   }
1454   assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1455   int arg_count = target_sig->count() - rbase;
1456   for (int i = 0; i < arg_count; i++) {
1457     if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1458       return false;
1459     }
1460   }
1461   // Only check the return type if the symbolic info has non-void return type.
1462   // I.e. the return value of the resolved method can be dropped.
1463   if (!linker->return_type()->is_void() &&
1464       !basic_types_match(linker->return_type(), target->return_type())) {
1465     return false;
1466   }
1467   return true; // no mismatch found
1468 }
1469 
1470 // ------------------------------------------------------------------














  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()),

 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() != NULL && method_data()->is_mature()) {
 649     ciParametersTypeData* parameters = method_data()->parameters_type_data();
 650     if (parameters != NULL && 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 bool ciMethod::array_access_profiled_type(int bci, ciKlass*& array_type, ciKlass*& element_type, ProfilePtrKind& element_ptr, bool &flat_array, bool &null_free_array) {
 660   if (method_data() != NULL && method_data()->is_mature()) {
 661     ciProfileData* data = method_data()->bci_to_data(bci);
 662     if (data != NULL && data->is_ArrayLoadStoreData()) {
 663       ciArrayLoadStoreData* array_access = (ciArrayLoadStoreData*)data->as_ArrayLoadStoreData();
 664       array_type = array_access->array()->valid_type();
 665       element_type = array_access->element()->valid_type();
 666       element_ptr = array_access->element()->ptr_kind();
 667       flat_array = array_access->flat_array();
 668       null_free_array = array_access->null_free_array();
 669       return true;
 670     }
 671   }
 672   return false;
 673 }
 674 
 675 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) {
 676   if (method_data() != NULL && method_data()->is_mature()) {
 677     ciProfileData* data = method_data()->bci_to_data(bci);
 678     if (data != NULL && data->is_ACmpData()) {
 679       ciACmpData* acmp = (ciACmpData*)data->as_ACmpData();
 680       left_type = acmp->left()->valid_type();
 681       right_type = acmp->right()->valid_type();
 682       left_ptr = acmp->left()->ptr_kind();
 683       right_ptr = acmp->right()->ptr_kind();
 684       left_inline_type = acmp->left_inline_type();
 685       right_inline_type = acmp->right_inline_type();
 686       return true;
 687     }
 688   }
 689   return false;
 690 }
 691 
 692 
 693 // ------------------------------------------------------------------
 694 // ciMethod::find_monomorphic_target
 695 //
 696 // Given a certain calling environment, find the monomorphic target
 697 // for the call.  Return NULL if the call is not monomorphic in
 698 // its calling environment, or if there are only abstract methods.
 699 // The returned method is never abstract.
 700 // Note: If caller uses a non-null result, it must inform dependencies
 701 // via assert_unique_concrete_method or assert_leaf_type.
 702 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
 703                                             ciInstanceKlass* callee_holder,
 704                                             ciInstanceKlass* actual_recv,
 705                                             bool check_access) {
 706   check_is_loaded();
 707 
 708   if (actual_recv->is_interface()) {
 709     // %%% We cannot trust interface types, yet.  See bug 6312651.
 710     return NULL;
 711   }

 956 //
 957 // Return true if the method is an instance of the JVM-generated
 958 // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
 959 bool ciMethod::is_method_handle_intrinsic() const {
 960   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 961   return (MethodHandles::is_signature_polymorphic(iid) &&
 962           MethodHandles::is_signature_polymorphic_intrinsic(iid));
 963 }
 964 
 965 // ------------------------------------------------------------------
 966 // ciMethod::is_compiled_lambda_form
 967 //
 968 // Return true if the method is a generated MethodHandle adapter.
 969 // These are built by Java code.
 970 bool ciMethod::is_compiled_lambda_form() const {
 971   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 972   return iid == vmIntrinsics::_compiledLambdaForm;
 973 }
 974 
 975 // ------------------------------------------------------------------
 976 // ciMethod::is_object_constructor
 977 //
 978 bool ciMethod::is_object_constructor() const {
 979    return (name() == ciSymbols::object_initializer_name()
 980            && signature()->return_type()->is_void());
 981    // Note:  We can't test is_static, because that would
 982    // require the method to be loaded.  Sometimes it isn't.
 983 }
 984 
 985 // ------------------------------------------------------------------
 986 // ciMethod::is_static_init_factory
 987 //
 988 bool ciMethod::is_static_init_factory() const {
 989    return (name() == ciSymbols::object_initializer_name()
 990            && !signature()->return_type()->is_void());
 991    // Note:  We can't test is_static, because that would
 992    // require the method to be loaded.  Sometimes it isn't.
 993 }
 994 
 995 // ------------------------------------------------------------------
 996 // ciMethod::has_member_arg
 997 //
 998 // Return true if the method is a linker intrinsic like _linkToVirtual.
 999 // These are built by the JVM.
1000 bool ciMethod::has_member_arg() const {
1001   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
1002   return (MethodHandles::is_signature_polymorphic(iid) &&
1003           MethodHandles::has_member_arg(iid));
1004 }
1005 
1006 // ------------------------------------------------------------------
1007 // ciMethod::ensure_method_data
1008 //
1009 // Generate new MethodData* objects at compile time.
1010 // Return true if allocation was successful or no MDO is required.
1011 bool ciMethod::ensure_method_data(const methodHandle& h_m) {
1012   EXCEPTION_CONTEXT;

1251 // ciMethod::print_codes
1252 //
1253 // Print the bytecodes for this method.
1254 void ciMethod::print_codes_on(outputStream* st) {
1255   check_is_loaded();
1256   GUARDED_VM_ENTRY(get_Method()->print_codes_on(st);)
1257 }
1258 
1259 
1260 #define FETCH_FLAG_FROM_VM(flag_accessor) { \
1261   check_is_loaded(); \
1262   VM_ENTRY_MARK; \
1263   return get_Method()->flag_accessor(); \
1264 }
1265 
1266 bool ciMethod::has_loops      () const {         FETCH_FLAG_FROM_VM(has_loops); }
1267 bool ciMethod::has_jsrs       () const {         FETCH_FLAG_FROM_VM(has_jsrs);  }
1268 bool ciMethod::is_getter      () const {         FETCH_FLAG_FROM_VM(is_getter); }
1269 bool ciMethod::is_setter      () const {         FETCH_FLAG_FROM_VM(is_setter); }
1270 bool ciMethod::is_accessor    () const {         FETCH_FLAG_FROM_VM(is_accessor); }
1271 bool ciMethod::is_object_constructor_or_class_initializer() const { FETCH_FLAG_FROM_VM(is_object_constructor_or_class_initializer); }
1272 bool ciMethod::is_empty       () const {         FETCH_FLAG_FROM_VM(is_empty_method); }
1273 
1274 bool ciMethod::is_boxing_method() const {
1275   if (intrinsic_id() != vmIntrinsics::_none && holder()->is_box_klass()) {
1276     switch (intrinsic_id()) {
1277       case vmIntrinsics::_Boolean_valueOf:
1278       case vmIntrinsics::_Byte_valueOf:
1279       case vmIntrinsics::_Character_valueOf:
1280       case vmIntrinsics::_Short_valueOf:
1281       case vmIntrinsics::_Integer_valueOf:
1282       case vmIntrinsics::_Long_valueOf:
1283       case vmIntrinsics::_Float_valueOf:
1284       case vmIntrinsics::_Double_valueOf:
1285         return true;
1286       default:
1287         return false;
1288     }
1289   }
1290   return false;
1291 }

1411   name()->print_symbol_on(st);
1412   st->print(" holder=");
1413   holder()->print_name_on(st);
1414   st->print(" signature=");
1415   signature()->as_symbol()->print_symbol_on(st);
1416   if (is_loaded()) {
1417     st->print(" loaded=true");
1418     st->print(" arg_size=%d", arg_size());
1419     st->print(" flags=");
1420     flags().print_member_flags(st);
1421   } else {
1422     st->print(" loaded=false");
1423   }
1424 }
1425 
1426 // ------------------------------------------------------------------
1427 
1428 static BasicType erase_to_word_type(BasicType bt) {
1429   if (is_subword_type(bt))   return T_INT;
1430   if (is_reference_type(bt)) return T_OBJECT;
1431   if (bt == T_INLINE_TYPE)   return T_OBJECT;
1432   return bt;
1433 }
1434 
1435 static bool basic_types_match(ciType* t1, ciType* t2) {
1436   if (t1 == t2)  return true;
1437   return erase_to_word_type(t1->basic_type()) == erase_to_word_type(t2->basic_type());
1438 }
1439 
1440 bool ciMethod::is_consistent_info(ciMethod* declared_method, ciMethod* resolved_method) {
1441   bool invoke_through_mh_intrinsic = declared_method->is_method_handle_intrinsic() &&
1442                                   !resolved_method->is_method_handle_intrinsic();
1443 
1444   if (!invoke_through_mh_intrinsic) {
1445     // Method name & descriptor should stay the same.
1446     // Signatures may reference unloaded types and thus they may be not strictly equal.
1447     ciSymbol* declared_signature = declared_method->signature()->as_symbol();
1448     ciSymbol* resolved_signature = resolved_method->signature()->as_symbol();
1449 
1450     return (declared_method->name()->equals(resolved_method->name())) &&
1451            (declared_signature->equals(resolved_signature));

1499     default:
1500       break;
1501   }
1502   assert(target_sig->count() - rbase == linker_sig->count() - sbase - has_appendix, "argument count mismatch");
1503   int arg_count = target_sig->count() - rbase;
1504   for (int i = 0; i < arg_count; i++) {
1505     if (!basic_types_match(linker_sig->type_at(sbase + i), target_sig->type_at(rbase + i))) {
1506       return false;
1507     }
1508   }
1509   // Only check the return type if the symbolic info has non-void return type.
1510   // I.e. the return value of the resolved method can be dropped.
1511   if (!linker->return_type()->is_void() &&
1512       !basic_types_match(linker->return_type(), target->return_type())) {
1513     return false;
1514   }
1515   return true; // no mismatch found
1516 }
1517 
1518 // ------------------------------------------------------------------
1519 
1520 bool ciMethod::has_scalarized_args() const {
1521   VM_ENTRY_MARK;
1522   return get_Method()->has_scalarized_args();
1523 }
1524 
1525 const GrowableArray<SigEntry>* ciMethod::get_sig_cc() {
1526   VM_ENTRY_MARK;
1527   if (get_Method()->adapter() == NULL) {
1528     return NULL;
1529   }
1530   return get_Method()->adapter()->get_sig_cc();
1531 }
< prev index next >