src/hotspot/share/oops/method.cpp
changeset 58226 408c445d04e8
parent 57777 90ead0febf56
child 58447 319173c62caa
equal deleted inserted replaced
58225:4eebb9aadbe3 58226:408c445d04e8
   101   set_vtable_index(Method::garbage_vtable_index);
   101   set_vtable_index(Method::garbage_vtable_index);
   102 
   102 
   103   // Fix and bury in Method*
   103   // Fix and bury in Method*
   104   set_interpreter_entry(NULL); // sets i2i entry and from_int
   104   set_interpreter_entry(NULL); // sets i2i entry and from_int
   105   set_adapter_entry(NULL);
   105   set_adapter_entry(NULL);
   106   clear_code(false /* don't need a lock */); // from_c/from_i get set to c2i/i2i
   106   Method::clear_code(); // from_c/from_i get set to c2i/i2i
   107 
   107 
   108   if (access_flags.is_native()) {
   108   if (access_flags.is_native()) {
   109     clear_native_function();
   109     clear_native_function();
   110     set_signature_handler(NULL);
   110     set_signature_handler(NULL);
   111   }
   111   }
   823 void Method::clear_native_function() {
   823 void Method::clear_native_function() {
   824   // Note: is_method_handle_intrinsic() is allowed here.
   824   // Note: is_method_handle_intrinsic() is allowed here.
   825   set_native_function(
   825   set_native_function(
   826     SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
   826     SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
   827     !native_bind_event_is_interesting);
   827     !native_bind_event_is_interesting);
   828   clear_code();
   828   this->unlink_code();
   829 }
   829 }
   830 
   830 
   831 
   831 
   832 void Method::set_signature_handler(address handler) {
   832 void Method::set_signature_handler(address handler) {
   833   address* signature_handler =  signature_handler_addr();
   833   address* signature_handler =  signature_handler_addr();
   939   CompilationPolicy::policy()->disable_compilation(this);
   939   CompilationPolicy::policy()->disable_compilation(this);
   940   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
   940   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
   941 }
   941 }
   942 
   942 
   943 // Revert to using the interpreter and clear out the nmethod
   943 // Revert to using the interpreter and clear out the nmethod
   944 void Method::clear_code(bool acquire_lock /* = true */) {
   944 void Method::clear_code() {
   945   MutexLocker pl(acquire_lock ? Patching_lock : NULL, Mutex::_no_safepoint_check_flag);
       
   946   // this may be NULL if c2i adapters have not been made yet
   945   // this may be NULL if c2i adapters have not been made yet
   947   // Only should happen at allocate time.
   946   // Only should happen at allocate time.
   948   if (adapter() == NULL) {
   947   if (adapter() == NULL) {
   949     _from_compiled_entry    = NULL;
   948     _from_compiled_entry    = NULL;
   950   } else {
   949   } else {
   952   }
   951   }
   953   OrderAccess::storestore();
   952   OrderAccess::storestore();
   954   _from_interpreted_entry = _i2i_entry;
   953   _from_interpreted_entry = _i2i_entry;
   955   OrderAccess::storestore();
   954   OrderAccess::storestore();
   956   _code = NULL;
   955   _code = NULL;
       
   956 }
       
   957 
       
   958 void Method::unlink_code(CompiledMethod *compare) {
       
   959   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
       
   960   // We need to check if either the _code or _from_compiled_code_entry_point
       
   961   // refer to this nmethod because there is a race in setting these two fields
       
   962   // in Method* as seen in bugid 4947125.
       
   963   // If the vep() points to the zombie nmethod, the memory for the nmethod
       
   964   // could be flushed and the compiler and vtable stubs could still call
       
   965   // through it.
       
   966   if (code() == compare ||
       
   967       from_compiled_entry() == compare->verified_entry_point()) {
       
   968     clear_code();
       
   969   }
       
   970 }
       
   971 
       
   972 void Method::unlink_code() {
       
   973   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
       
   974   clear_code();
   957 }
   975 }
   958 
   976 
   959 #if INCLUDE_CDS
   977 #if INCLUDE_CDS
   960 // Called by class data sharing to remove any entry points (which are not shared)
   978 // Called by class data sharing to remove any entry points (which are not shared)
   961 void Method::unlink_method() {
   979 void Method::unlink_method() {
  1180   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
  1198   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
  1181 }
  1199 }
  1182 
  1200 
  1183 // Install compiled code.  Instantly it can execute.
  1201 // Install compiled code.  Instantly it can execute.
  1184 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
  1202 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
  1185   MutexLocker pl(Patching_lock, Mutex::_no_safepoint_check_flag);
  1203   assert_lock_strong(CompiledMethod_lock);
  1186   assert( code, "use clear_code to remove code" );
  1204   assert( code, "use clear_code to remove code" );
  1187   assert( mh->check_code(), "" );
  1205   assert( mh->check_code(), "" );
  1188 
  1206 
  1189   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
  1207   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
  1190 
  1208