< prev index next >

src/hotspot/share/code/nmethod.cpp

Print this page




1296 
1297 /**
1298  * Common functionality for both make_not_entrant and make_zombie
1299  */
1300 bool nmethod::make_not_entrant_or_zombie(int state) {
1301   assert(state == zombie || state == not_entrant, "must be zombie or not_entrant");
1302   assert(!is_zombie(), "should not already be a zombie");
1303 
1304   if (Atomic::load(&_state) >= state) {
1305     // Avoid taking the lock if already in required state.
1306     // This is safe from races because the state is an end-state,
1307     // which the nmethod cannot back out of once entered.
1308     // No need for fencing either.
1309     return false;
1310   }
1311 
1312   // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below.
1313   nmethodLocker nml(this);
1314   methodHandle the_method(method());
1315   // This can be called while the system is already at a safepoint which is ok
1316   NoSafepointVerifier nsv(true, !SafepointSynchronize::is_at_safepoint());
1317 
1318   // during patching, depending on the nmethod state we must notify the GC that
1319   // code has been unloaded, unregistering it. We cannot do this right while
1320   // holding the Patching_lock because we need to use the CodeCache_lock. This
1321   // would be prone to deadlocks.
1322   // This flag is used to remember whether we need to later lock and unregister.
1323   bool nmethod_needs_unregister = false;
1324 
1325   {
1326     // invalidate osr nmethod before acquiring the patching lock since
1327     // they both acquire leaf locks and we don't want a deadlock.
1328     // This logic is equivalent to the logic below for patching the
1329     // verified entry point of regular methods. We check that the
1330     // nmethod is in use to ensure that it is invalidated only once.
1331     if (is_osr_method() && is_in_use()) {
1332       // this effectively makes the osr nmethod not entrant
1333       invalidate_osr_method();
1334     }
1335 
1336     // Enter critical section.  Does not block for safepoint.




1296 
1297 /**
1298  * Common functionality for both make_not_entrant and make_zombie
1299  */
1300 bool nmethod::make_not_entrant_or_zombie(int state) {
1301   assert(state == zombie || state == not_entrant, "must be zombie or not_entrant");
1302   assert(!is_zombie(), "should not already be a zombie");
1303 
1304   if (Atomic::load(&_state) >= state) {
1305     // Avoid taking the lock if already in required state.
1306     // This is safe from races because the state is an end-state,
1307     // which the nmethod cannot back out of once entered.
1308     // No need for fencing either.
1309     return false;
1310   }
1311 
1312   // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below.
1313   nmethodLocker nml(this);
1314   methodHandle the_method(method());
1315   // This can be called while the system is already at a safepoint which is ok
1316   NoSafepointVerifier nsv;
1317 
1318   // during patching, depending on the nmethod state we must notify the GC that
1319   // code has been unloaded, unregistering it. We cannot do this right while
1320   // holding the Patching_lock because we need to use the CodeCache_lock. This
1321   // would be prone to deadlocks.
1322   // This flag is used to remember whether we need to later lock and unregister.
1323   bool nmethod_needs_unregister = false;
1324 
1325   {
1326     // invalidate osr nmethod before acquiring the patching lock since
1327     // they both acquire leaf locks and we don't want a deadlock.
1328     // This logic is equivalent to the logic below for patching the
1329     // verified entry point of regular methods. We check that the
1330     // nmethod is in use to ensure that it is invalidated only once.
1331     if (is_osr_method() && is_in_use()) {
1332       // this effectively makes the osr nmethod not entrant
1333       invalidate_osr_method();
1334     }
1335 
1336     // Enter critical section.  Does not block for safepoint.


< prev index next >