< prev index next >

src/hotspot/share/oops/method.cpp

Print this page
rev 54621 : imported patch 8221734-v1

@@ -99,11 +99,11 @@
   set_vtable_index(Method::garbage_vtable_index);
 
   // Fix and bury in Method*
   set_interpreter_entry(NULL); // sets i2i entry and from_int
   set_adapter_entry(NULL);
-  clear_code(false /* don't need a lock */); // from_c/from_i get set to c2i/i2i
+  Method::unlink_code(this);
 
   if (access_flags.is_native()) {
     clear_native_function();
     set_signature_handler(NULL);
   }

@@ -802,11 +802,11 @@
 void Method::clear_native_function() {
   // Note: is_method_handle_intrinsic() is allowed here.
   set_native_function(
     SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
     !native_bind_event_is_interesting);
-  clear_code();
+  Method::unlink_code(this);
 }
 
 address Method::critical_native_function() {
   methodHandle mh(this);
   return NativeLookup::lookup_critical_entry(mh);

@@ -925,12 +925,11 @@
   CompilationPolicy::policy()->disable_compilation(this);
   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
 }
 
 // Revert to using the interpreter and clear out the nmethod
-void Method::clear_code(bool acquire_lock /* = true */) {
-  MutexLockerEx pl(acquire_lock ? Patching_lock : NULL, Mutex::_no_safepoint_check_flag);
+void Method::locked_unlink_code() {
   // this may be NULL if c2i adapters have not been made yet
   // Only should happen at allocate time.
   if (adapter() == NULL) {
     _from_compiled_entry    = NULL;
   } else {

@@ -940,10 +939,27 @@
   _from_interpreted_entry = _i2i_entry;
   OrderAccess::storestore();
   _code = NULL;
 }
 
+void Method::unlink_code(Method *method, CompiledMethod *compare) {
+  if (method != NULL) {
+    MutexLockerEx ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
+    if (method->code() != compare && method->from_compiled_entry() != compare->verified_entry_point()) {
+      return;
+    }
+    method->locked_unlink_code();
+  }
+}
+
+void Method::unlink_code(Method *method) {
+  if (method != NULL) {
+    MutexLockerEx ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
+    method->locked_unlink_code();
+  }
+}
+
 #if INCLUDE_CDS
 // Called by class data sharing to remove any entry points (which are not shared)
 void Method::unlink_method() {
   _code = NULL;
 
< prev index next >