< prev index next >

src/hotspot/share/oops/method.cpp

Print this page




 453   // not an inline function, to avoid a header dependency on Interpreter
 454   return extra_stack_entries() * Interpreter::stackElementSize;
 455 }
 456 
 457 
 458 void Method::compute_size_of_parameters(Thread *thread) {
 459   ArgumentSizeComputer asc(signature());
 460   set_size_of_parameters(asc.size() + (is_static() ? 0 : 1));
 461 }
 462 
 463 BasicType Method::result_type() const {
 464   ResultTypeFinder rtf(signature());
 465   return rtf.type();
 466 }
 467 
 468 #ifdef ASSERT
 469 // ValueKlass the method is declared to return. This must not
 470 // safepoint as it is called with references live on the stack at
 471 // locations the GC is unaware of.
 472 ValueKlass* Method::returned_value_type(Thread* thread) const {
 473   assert(is_returning_vt(), "method return type should be value type");
 474   SignatureStream ss(signature());
 475   while (!ss.at_return_type()) {
 476     ss.next();
 477   }
 478   Handle class_loader(thread, method_holder()->class_loader());
 479   Handle protection_domain(thread, method_holder()->protection_domain());
 480   Klass* k = NULL;
 481   {
 482     NoSafepointVerifier nsv;
 483     k = ss.as_klass(class_loader, protection_domain, SignatureStream::ReturnNull, thread);
 484   }
 485   assert(k != NULL && !thread->has_pending_exception(), "can't resolve klass");
 486   return ValueKlass::cast(k);
 487 }
 488 #endif
 489 
 490 bool Method::has_value_args() const {
 491   return adapter()->get_sig_extended() != NULL;








 492 }
 493 
 494 bool Method::is_empty_method() const {
 495   return  code_size() == 1
 496       && *code_base() == Bytecodes::_return;
 497 }
 498 
 499 
 500 bool Method::is_vanilla_constructor() const {
 501   // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method
 502   // which only calls the superclass vanilla constructor and possibly does stores of
 503   // zero constants to local fields:
 504   //
 505   //   aload_0
 506   //   invokespecial
 507   //   indexbyte1
 508   //   indexbyte2
 509   //
 510   // followed by an (optional) sequence of:
 511   //


 923   } else {
 924     if (is_c1_compile(comp_level))
 925       set_not_c1_osr_compilable();
 926     if (is_c2_compile(comp_level))
 927       set_not_c2_osr_compilable();
 928   }
 929   CompilationPolicy::policy()->disable_compilation(this);
 930   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
 931 }
 932 
 933 // Revert to using the interpreter and clear out the nmethod
 934 void Method::clear_code(bool acquire_lock /* = true */) {
 935   MutexLockerEx pl(acquire_lock ? Patching_lock : NULL, Mutex::_no_safepoint_check_flag);
 936   // this may be NULL if c2i adapters have not been made yet
 937   // Only should happen at allocate time.
 938   if (adapter() == NULL) {
 939     _from_compiled_entry    = NULL;
 940     _from_compiled_value_entry = NULL;
 941   } else {
 942     _from_compiled_entry    = adapter()->get_c2i_entry();
 943     _from_compiled_value_entry = adapter()->get_c2i_entry();
 944   }
 945   OrderAccess::storestore();
 946   _from_interpreted_entry = _i2i_entry;
 947   OrderAccess::storestore();
 948   _code = NULL;
 949 }
 950 
 951 #if INCLUDE_CDS
 952 // Called by class data sharing to remove any entry points (which are not shared)
 953 void Method::unlink_method() {
 954   _code = NULL;
 955 
 956   assert(DumpSharedSpaces, "dump time only");
 957   // Set the values to what they should be at run time. Note that
 958   // this Method can no longer be executed during dump time.
 959   _i2i_entry = Interpreter::entry_for_cds_method(this);
 960   _from_interpreted_entry = _i2i_entry;
 961 
 962   if (is_native()) {
 963     *native_function_addr() = NULL;


1086   }
1087 
1088   // Setup compiler entrypoint.  This is made eagerly, so we do not need
1089   // special handling of vtables.  An alternative is to make adapters more
1090   // lazily by calling make_adapter() from from_compiled_entry() for the
1091   // normal calls.  For vtable calls life gets more complicated.  When a
1092   // call-site goes mega-morphic we need adapters in all methods which can be
1093   // called from the vtable.  We need adapters on such methods that get loaded
1094   // later.  Ditto for mega-morphic itable calls.  If this proves to be a
1095   // problem we'll make these lazily later.
1096   (void) make_adapters(h_method, CHECK);
1097 
1098   // ONLY USE the h_method now as make_adapter may have blocked
1099 
1100 }
1101 
1102 address Method::make_adapters(const methodHandle& mh, TRAPS) {
1103   // Adapters for compiled code are made eagerly here.  They are fairly
1104   // small (generally < 100 bytes) and quick to make (and cached and shared)
1105   // so making them eagerly shouldn't be too expensive.
1106   AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh, CHECK_0);
1107   if (adapter == NULL ) {
1108     if (!is_init_completed()) {
1109       // Don't throw exceptions during VM initialization because java.lang.* classes
1110       // might not have been initialized, causing problems when constructing the
1111       // Java exception object.
1112       vm_exit_during_initialization("Out of space in CodeCache for adapters");
1113     } else {
1114       THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
1115     }
1116   }
1117 
1118   if (mh->is_shared()) {
1119     assert(mh->adapter() == adapter, "must be");
1120     assert(mh->_from_compiled_entry != NULL, "must be");
1121     assert(mh->_from_compiled_value_entry != NULL, "must be");
1122   } else {
1123     mh->set_adapter_entry(adapter);
1124     mh->_from_compiled_entry = adapter->get_c2i_entry();
1125     mh->_from_compiled_value_entry = adapter->get_c2i_entry();
1126   }
1127   return adapter->get_c2i_entry();
1128 }
1129 
1130 void Method::restore_unshareable_info(TRAPS) {
1131   assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
1132 
1133   // Since restore_unshareable_info can be called more than once for a method, don't
1134   // redo any work.
1135   if (adapter() == NULL) {
1136     methodHandle mh(THREAD, this);
1137     link_method(mh, CHECK);
1138   }
1139 }
1140 
1141 address Method::from_compiled_entry_no_trampoline() const {
1142   CompiledMethod *code = OrderAccess::load_acquire(&_code);
1143   if (code) {
1144     return code->verified_entry_point();
1145   } else {


1174   MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
1175   assert( code, "use clear_code to remove code" );
1176   assert( mh->check_code(), "" );
1177 
1178   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1179 
1180   // These writes must happen in this order, because the interpreter will
1181   // directly jump to from_interpreted_entry which jumps to an i2c adapter
1182   // which jumps to _from_compiled_entry.
1183   mh->_code = code;             // Assign before allowing compiled code to exec
1184 
1185   int comp_level = code->comp_level();
1186   // In theory there could be a race here. In practice it is unlikely
1187   // and not worth worrying about.
1188   if (comp_level > mh->highest_comp_level()) {
1189     mh->set_highest_comp_level(comp_level);
1190   }
1191 
1192   OrderAccess::storestore();
1193   mh->_from_compiled_entry = code->verified_entry_point();
1194   mh->_from_compiled_value_entry = code->verified_entry_point();
1195   OrderAccess::storestore();
1196   // Instantly compiled code can execute.
1197   if (!mh->is_method_handle_intrinsic())
1198     mh->_from_interpreted_entry = mh->get_i2c_entry();
1199 }
1200 
1201 
1202 bool Method::is_overridden_in(Klass* k) const {
1203   InstanceKlass* ik = InstanceKlass::cast(k);
1204 
1205   if (ik->is_interface()) return false;
1206 
1207   // If method is an interface, we skip it - except if it
1208   // is a miranda method
1209   if (method_holder()->is_interface()) {
1210     // Check that method is not a miranda method
1211     if (ik->lookup_method(name(), signature()) == NULL) {
1212       // No implementation exist - so miranda method
1213       return false;
1214     }




 453   // not an inline function, to avoid a header dependency on Interpreter
 454   return extra_stack_entries() * Interpreter::stackElementSize;
 455 }
 456 
 457 
 458 void Method::compute_size_of_parameters(Thread *thread) {
 459   ArgumentSizeComputer asc(signature());
 460   set_size_of_parameters(asc.size() + (is_static() ? 0 : 1));
 461 }
 462 
 463 BasicType Method::result_type() const {
 464   ResultTypeFinder rtf(signature());
 465   return rtf.type();
 466 }
 467 
 468 #ifdef ASSERT
 469 // ValueKlass the method is declared to return. This must not
 470 // safepoint as it is called with references live on the stack at
 471 // locations the GC is unaware of.
 472 ValueKlass* Method::returned_value_type(Thread* thread) const {

 473   SignatureStream ss(signature());
 474   while (!ss.at_return_type()) {
 475     ss.next();
 476   }
 477   Handle class_loader(thread, method_holder()->class_loader());
 478   Handle protection_domain(thread, method_holder()->protection_domain());
 479   Klass* k = NULL;
 480   {
 481     NoSafepointVerifier nsv;
 482     k = ss.as_klass(class_loader, protection_domain, SignatureStream::ReturnNull, thread);
 483   }
 484   assert(k != NULL && !thread->has_pending_exception(), "can't resolve klass");
 485   return ValueKlass::cast(k);
 486 }
 487 #endif
 488 
 489 bool Method::has_scalarized_args() const {
 490   return adapter() != NULL ? (adapter()->get_sig_cc() != NULL) : false;
 491 }
 492 
 493 bool Method::needs_stack_repair() const {
 494   return adapter() != NULL ? (adapter()->get_res_entry()._offset != -1) : false;
 495 }
 496 
 497 SigEntry Method::get_res_entry() const {
 498   return adapter() != NULL ? adapter()->get_res_entry() : SigEntry();
 499 }
 500 
 501 bool Method::is_empty_method() const {
 502   return  code_size() == 1
 503       && *code_base() == Bytecodes::_return;
 504 }
 505 
 506 
 507 bool Method::is_vanilla_constructor() const {
 508   // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method
 509   // which only calls the superclass vanilla constructor and possibly does stores of
 510   // zero constants to local fields:
 511   //
 512   //   aload_0
 513   //   invokespecial
 514   //   indexbyte1
 515   //   indexbyte2
 516   //
 517   // followed by an (optional) sequence of:
 518   //


 930   } else {
 931     if (is_c1_compile(comp_level))
 932       set_not_c1_osr_compilable();
 933     if (is_c2_compile(comp_level))
 934       set_not_c2_osr_compilable();
 935   }
 936   CompilationPolicy::policy()->disable_compilation(this);
 937   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
 938 }
 939 
 940 // Revert to using the interpreter and clear out the nmethod
 941 void Method::clear_code(bool acquire_lock /* = true */) {
 942   MutexLockerEx pl(acquire_lock ? Patching_lock : NULL, Mutex::_no_safepoint_check_flag);
 943   // this may be NULL if c2i adapters have not been made yet
 944   // Only should happen at allocate time.
 945   if (adapter() == NULL) {
 946     _from_compiled_entry    = NULL;
 947     _from_compiled_value_entry = NULL;
 948   } else {
 949     _from_compiled_entry    = adapter()->get_c2i_entry();
 950     _from_compiled_value_entry = adapter()->get_c2i_value_entry();
 951   }
 952   OrderAccess::storestore();
 953   _from_interpreted_entry = _i2i_entry;
 954   OrderAccess::storestore();
 955   _code = NULL;
 956 }
 957 
 958 #if INCLUDE_CDS
 959 // Called by class data sharing to remove any entry points (which are not shared)
 960 void Method::unlink_method() {
 961   _code = NULL;
 962 
 963   assert(DumpSharedSpaces, "dump time only");
 964   // Set the values to what they should be at run time. Note that
 965   // this Method can no longer be executed during dump time.
 966   _i2i_entry = Interpreter::entry_for_cds_method(this);
 967   _from_interpreted_entry = _i2i_entry;
 968 
 969   if (is_native()) {
 970     *native_function_addr() = NULL;


1093   }
1094 
1095   // Setup compiler entrypoint.  This is made eagerly, so we do not need
1096   // special handling of vtables.  An alternative is to make adapters more
1097   // lazily by calling make_adapter() from from_compiled_entry() for the
1098   // normal calls.  For vtable calls life gets more complicated.  When a
1099   // call-site goes mega-morphic we need adapters in all methods which can be
1100   // called from the vtable.  We need adapters on such methods that get loaded
1101   // later.  Ditto for mega-morphic itable calls.  If this proves to be a
1102   // problem we'll make these lazily later.
1103   (void) make_adapters(h_method, CHECK);
1104 
1105   // ONLY USE the h_method now as make_adapter may have blocked
1106 
1107 }
1108 
1109 address Method::make_adapters(const methodHandle& mh, TRAPS) {
1110   // Adapters for compiled code are made eagerly here.  They are fairly
1111   // small (generally < 100 bytes) and quick to make (and cached and shared)
1112   // so making them eagerly shouldn't be too expensive.
1113   AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
1114   if (adapter == NULL ) {
1115     if (!is_init_completed()) {
1116       // Don't throw exceptions during VM initialization because java.lang.* classes
1117       // might not have been initialized, causing problems when constructing the
1118       // Java exception object.
1119       vm_exit_during_initialization("Out of space in CodeCache for adapters");
1120     } else {
1121       THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
1122     }
1123   }
1124 
1125   if (mh->is_shared()) {
1126     assert(mh->adapter() == adapter, "must be");
1127     assert(mh->_from_compiled_entry != NULL, "must be");
1128     assert(mh->_from_compiled_value_entry != NULL, "must be");
1129   } else {
1130     mh->set_adapter_entry(adapter);
1131     mh->_from_compiled_entry = adapter->get_c2i_entry();
1132     mh->_from_compiled_value_entry = adapter->get_c2i_value_entry();
1133   }
1134   return adapter->get_c2i_entry();
1135 }
1136 
1137 void Method::restore_unshareable_info(TRAPS) {
1138   assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
1139 
1140   // Since restore_unshareable_info can be called more than once for a method, don't
1141   // redo any work.
1142   if (adapter() == NULL) {
1143     methodHandle mh(THREAD, this);
1144     link_method(mh, CHECK);
1145   }
1146 }
1147 
1148 address Method::from_compiled_entry_no_trampoline() const {
1149   CompiledMethod *code = OrderAccess::load_acquire(&_code);
1150   if (code) {
1151     return code->verified_entry_point();
1152   } else {


1181   MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
1182   assert( code, "use clear_code to remove code" );
1183   assert( mh->check_code(), "" );
1184 
1185   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1186 
1187   // These writes must happen in this order, because the interpreter will
1188   // directly jump to from_interpreted_entry which jumps to an i2c adapter
1189   // which jumps to _from_compiled_entry.
1190   mh->_code = code;             // Assign before allowing compiled code to exec
1191 
1192   int comp_level = code->comp_level();
1193   // In theory there could be a race here. In practice it is unlikely
1194   // and not worth worrying about.
1195   if (comp_level > mh->highest_comp_level()) {
1196     mh->set_highest_comp_level(comp_level);
1197   }
1198 
1199   OrderAccess::storestore();
1200   mh->_from_compiled_entry = code->verified_entry_point();
1201   mh->_from_compiled_value_entry = code->verified_value_entry_point();
1202   OrderAccess::storestore();
1203   // Instantly compiled code can execute.
1204   if (!mh->is_method_handle_intrinsic())
1205     mh->_from_interpreted_entry = mh->get_i2c_entry();
1206 }
1207 
1208 
1209 bool Method::is_overridden_in(Klass* k) const {
1210   InstanceKlass* ik = InstanceKlass::cast(k);
1211 
1212   if (ik->is_interface()) return false;
1213 
1214   // If method is an interface, we skip it - except if it
1215   // is a miranda method
1216   if (method_holder()->is_interface()) {
1217     // Check that method is not a miranda method
1218     if (ik->lookup_method(name(), signature()) == NULL) {
1219       // No implementation exist - so miranda method
1220       return false;
1221     }


< prev index next >