< prev index next >

src/hotspot/share/ci/ciMethod.cpp

Print this page

  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/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 "memory/allocation.inline.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "oops/generateOopMap.hpp"
  46 #include "oops/method.inline.hpp"
  47 #include "oops/oop.inline.hpp"
  48 #include "prims/methodHandles.hpp"
  49 #include "runtime/deoptimization.hpp"
  50 #include "runtime/handles.inline.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()),

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

































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

 935 //
 936 // Return true if the method is an instance of the JVM-generated
 937 // signature-polymorphic MethodHandle methods, _invokeBasic, _linkToVirtual, etc.
 938 bool ciMethod::is_method_handle_intrinsic() const {
 939   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 940   return (MethodHandles::is_signature_polymorphic(iid) &&
 941           MethodHandles::is_signature_polymorphic_intrinsic(iid));
 942 }
 943 
 944 // ------------------------------------------------------------------
 945 // ciMethod::is_compiled_lambda_form
 946 //
 947 // Return true if the method is a generated MethodHandle adapter.
 948 // These are built by Java code.
 949 bool ciMethod::is_compiled_lambda_form() const {
 950   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 951   return iid == vmIntrinsics::_compiledLambdaForm;
 952 }
 953 
 954 // ------------------------------------------------------------------
 955 // ciMethod::is_object_initializer
 956 //
 957 bool ciMethod::is_object_initializer() const {
 958    return name() == ciSymbols::object_initializer_name();













 959 }
 960 
 961 // ------------------------------------------------------------------
 962 // ciMethod::has_member_arg
 963 //
 964 // Return true if the method is a linker intrinsic like _linkToVirtual.
 965 // These are built by the JVM.
 966 bool ciMethod::has_member_arg() const {
 967   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 968   return (MethodHandles::is_signature_polymorphic(iid) &&
 969           MethodHandles::has_member_arg(iid));
 970 }
 971 
 972 // ------------------------------------------------------------------
 973 // ciMethod::ensure_method_data
 974 //
 975 // Generate new MethodData* objects at compile time.
 976 // Return true if allocation was successful or no MDO is required.
 977 bool ciMethod::ensure_method_data(const methodHandle& h_m) {
 978   EXCEPTION_CONTEXT;

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

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

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

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



















  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/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 "memory/allocation.inline.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "oops/generateOopMap.hpp"
  46 #include "oops/method.inline.hpp"
  47 #include "oops/oop.inline.hpp"
  48 #include "prims/methodHandles.hpp"
  49 #include "runtime/deoptimization.hpp"
  50 #include "runtime/handles.inline.hpp"
  51 #include "runtime/sharedRuntime.hpp"
  52 #include "utilities/bitMap.inline.hpp"
  53 #include "utilities/xmlstream.hpp"
  54 #ifdef COMPILER2
  55 #include "ci/bcEscapeAnalyzer.hpp"
  56 #include "ci/ciTypeFlow.hpp"
  57 #include "oops/method.hpp"
  58 #endif
  59 
  60 // ciMethod
  61 //
  62 // This class represents a Method* in the HotSpot virtual
  63 // machine.
  64 
  65 
  66 // ------------------------------------------------------------------
  67 // ciMethod::ciMethod
  68 //
  69 // Loaded method.
  70 ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
  71   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 bool ciMethod::array_access_profiled_type(int bci, ciKlass*& array_type, ciKlass*& element_type, ProfilePtrKind& element_ptr, bool &flat_array, bool &null_free_array) {
 659   if (method_data() != NULL && method_data()->is_mature()) {
 660     ciProfileData* data = method_data()->bci_to_data(bci);
 661     if (data != NULL && data->is_ArrayLoadStoreData()) {
 662       ciArrayLoadStoreData* array_access = (ciArrayLoadStoreData*)data->as_ArrayLoadStoreData();
 663       array_type = array_access->array()->valid_type();
 664       element_type = array_access->element()->valid_type();
 665       element_ptr = array_access->element()->ptr_kind();
 666       flat_array = array_access->flat_array();
 667       null_free_array = array_access->null_free_array();
 668       return true;
 669     }
 670   }
 671   return false;
 672 }
 673 
 674 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) {
 675   if (method_data() != NULL && method_data()->is_mature()) {
 676     ciProfileData* data = method_data()->bci_to_data(bci);
 677     if (data != NULL && data->is_ACmpData()) {
 678       ciACmpData* acmp = (ciACmpData*)data->as_ACmpData();
 679       left_type = acmp->left()->valid_type();
 680       right_type = acmp->right()->valid_type();
 681       left_ptr = acmp->left()->ptr_kind();
 682       right_ptr = acmp->right()->ptr_kind();
 683       left_inline_type = acmp->left_inline_type();
 684       right_inline_type = acmp->right_inline_type();
 685       return true;
 686     }
 687   }
 688   return false;
 689 }
 690 
 691 
 692 // ------------------------------------------------------------------
 693 // ciMethod::find_monomorphic_target
 694 //
 695 // Given a certain calling environment, find the monomorphic target
 696 // for the call.  Return NULL if the call is not monomorphic in
 697 // its calling environment, or if there are only abstract methods.
 698 // The returned method is never abstract.
 699 // Note: If caller uses a non-null result, it must inform dependencies
 700 // via assert_unique_concrete_method or assert_leaf_type.
 701 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
 702                                             ciInstanceKlass* callee_holder,
 703                                             ciInstanceKlass* actual_recv,
 704                                             bool check_access) {
 705   check_is_loaded();
 706 
 707   if (actual_recv->is_interface()) {
 708     // %%% We cannot trust interface types, yet.  See bug 6312651.
 709     return NULL;
 710   }

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

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

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

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