src/hotspot/share/oops/method.cpp
changeset 55005 9b70ebd131b4
parent 54927 1512d88b24c6
child 55105 9ad765641e8f
child 58678 9cf78a70fa4f
equal deleted inserted replaced
55004:4645b6d57f54 55005:9b70ebd131b4
   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   }
   813 void Method::clear_native_function() {
   813 void Method::clear_native_function() {
   814   // Note: is_method_handle_intrinsic() is allowed here.
   814   // Note: is_method_handle_intrinsic() is allowed here.
   815   set_native_function(
   815   set_native_function(
   816     SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
   816     SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
   817     !native_bind_event_is_interesting);
   817     !native_bind_event_is_interesting);
   818   clear_code();
   818   this->unlink_code();
   819 }
   819 }
   820 
   820 
   821 address Method::critical_native_function() {
   821 address Method::critical_native_function() {
   822   methodHandle mh(this);
   822   methodHandle mh(this);
   823   return NativeLookup::lookup_critical_entry(mh);
   823   return NativeLookup::lookup_critical_entry(mh);
   936   CompilationPolicy::policy()->disable_compilation(this);
   936   CompilationPolicy::policy()->disable_compilation(this);
   937   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
   937   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
   938 }
   938 }
   939 
   939 
   940 // Revert to using the interpreter and clear out the nmethod
   940 // Revert to using the interpreter and clear out the nmethod
   941 void Method::clear_code(bool acquire_lock /* = true */) {
   941 void Method::clear_code() {
   942   MutexLocker pl(acquire_lock ? Patching_lock : NULL, Mutex::_no_safepoint_check_flag);
       
   943   // this may be NULL if c2i adapters have not been made yet
   942   // this may be NULL if c2i adapters have not been made yet
   944   // Only should happen at allocate time.
   943   // Only should happen at allocate time.
   945   if (adapter() == NULL) {
   944   if (adapter() == NULL) {
   946     _from_compiled_entry    = NULL;
   945     _from_compiled_entry    = NULL;
   947   } else {
   946   } else {
   949   }
   948   }
   950   OrderAccess::storestore();
   949   OrderAccess::storestore();
   951   _from_interpreted_entry = _i2i_entry;
   950   _from_interpreted_entry = _i2i_entry;
   952   OrderAccess::storestore();
   951   OrderAccess::storestore();
   953   _code = NULL;
   952   _code = NULL;
       
   953 }
       
   954 
       
   955 void Method::unlink_code(CompiledMethod *compare) {
       
   956   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
       
   957   // We need to check if either the _code or _from_compiled_code_entry_point
       
   958   // refer to this nmethod because there is a race in setting these two fields
       
   959   // in Method* as seen in bugid 4947125.
       
   960   // If the vep() points to the zombie nmethod, the memory for the nmethod
       
   961   // could be flushed and the compiler and vtable stubs could still call
       
   962   // through it.
       
   963   if (code() == compare ||
       
   964       from_compiled_entry() == compare->verified_entry_point()) {
       
   965     clear_code();
       
   966   }
       
   967 }
       
   968 
       
   969 void Method::unlink_code() {
       
   970   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
       
   971   clear_code();
   954 }
   972 }
   955 
   973 
   956 #if INCLUDE_CDS
   974 #if INCLUDE_CDS
   957 // Called by class data sharing to remove any entry points (which are not shared)
   975 // Called by class data sharing to remove any entry points (which are not shared)
   958 void Method::unlink_method() {
   976 void Method::unlink_method() {
  1177   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
  1195   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
  1178 }
  1196 }
  1179 
  1197 
  1180 // Install compiled code.  Instantly it can execute.
  1198 // Install compiled code.  Instantly it can execute.
  1181 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
  1199 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
  1182   MutexLocker pl(Patching_lock, Mutex::_no_safepoint_check_flag);
  1200   MutexLocker pl(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
  1183   assert( code, "use clear_code to remove code" );
  1201   assert( code, "use clear_code to remove code" );
  1184   assert( mh->check_code(), "" );
  1202   assert( mh->check_code(), "" );
  1185 
  1203 
  1186   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
  1204   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
  1187 
  1205