src/hotspot/share/ci/ciEnv.cpp
changeset 58226 408c445d04e8
parent 58177 4932dce35882
child 58358 d658f4379c63
--- a/src/hotspot/share/ci/ciEnv.cpp	Thu Sep 19 09:50:11 2019 +0200
+++ b/src/hotspot/share/ci/ciEnv.cpp	Thu Sep 19 10:52:22 2019 +0200
@@ -1072,7 +1072,10 @@
                     task()->comp_level(), method_name);
         }
         // Allow the code to be executed
-        method->set_code(method, nm);
+        MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
+        if (nm->make_in_use()) {
+          method->set_code(method, nm);
+        }
       } else {
         LogTarget(Info, nmethod, install) lt;
         if (lt.is_enabled()) {
@@ -1081,9 +1084,11 @@
           lt.print("Installing osr method (%d) %s @ %d",
                     task()->comp_level(), method_name, entry_bci);
         }
-        method->method_holder()->add_osr_nmethod(nm);
+        MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
+        if (nm->make_in_use()) {
+          method->method_holder()->add_osr_nmethod(nm);
+        }
       }
-      nm->make_in_use();
     }
   }  // safepoints are allowed again