< 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;

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

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

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

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



















  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_init_factory
1000 //
1001 bool ciMethod::is_static_init_factory() const {
1002    return (name() == ciSymbols::object_initializer_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;

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

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

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