src/share/vm/code/nmethod.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File JDK-8027593 Sdiff src/share/vm/code

src/share/vm/code/nmethod.cpp

Print this page




1245     _method = NULL;            // Clear the method of this dead nmethod
1246   }
1247   // Make the class unloaded - i.e., change state and notify sweeper
1248   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1249   if (is_in_use()) {
1250     // Transitioning directly from live to unloaded -- so
1251     // we need to force a cache clean-up; remember this
1252     // for later on.
1253     CodeCache::set_needs_cache_clean(true);
1254   }
1255   _state = unloaded;
1256 
1257   // Log the unloading.
1258   log_state_change();
1259 
1260   // The Method* is gone at this point
1261   assert(_method == NULL, "Tautology");
1262 
1263   set_osr_link(NULL);
1264   //set_scavenge_root_link(NULL); // done by prune_scavenge_root_nmethods
1265   NMethodSweeper::notify();
1266 }
1267 
1268 void nmethod::invalidate_osr_method() {
1269   assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod");
1270   // Remove from list of active nmethods
1271   if (method() != NULL)
1272     method()->method_holder()->remove_osr_nmethod(this);
1273   // Set entry as invalid
1274   _entry_bci = InvalidOSREntryBci;
1275 }
1276 
1277 void nmethod::log_state_change() const {
1278   if (LogCompilation) {
1279     if (xtty != NULL) {
1280       ttyLocker ttyl;  // keep the following output all in one block
1281       if (_state == unloaded) {
1282         xtty->begin_elem("make_unloaded thread='" UINTX_FORMAT "'",
1283                          os::current_thread_id());
1284       } else {
1285         xtty->begin_elem("make_not_entrant thread='" UINTX_FORMAT "'%s",
1286                          os::current_thread_id(),
1287                          (_state == zombie ? " zombie='1'" : ""));
1288       }
1289       log_identity(xtty);
1290       xtty->stamp();
1291       xtty->end_elem();
1292     }
1293   }
1294   if (PrintCompilation && _state != unloaded) {
1295     print_on(tty, _state == zombie ? "made zombie" : "made not entrant");
1296   }
1297 }
1298 
1299 // Common functionality for both make_not_entrant and make_zombie


1300 bool nmethod::make_not_entrant_or_zombie(unsigned 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   // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below.
1305   nmethodLocker nml(this);
1306   methodHandle the_method(method());
1307   No_Safepoint_Verifier nsv;
1308 
1309   // during patching, depending on the nmethod state we must notify the GC that
1310   // code has been unloaded, unregistering it. We cannot do this right while
1311   // holding the Patching_lock because we need to use the CodeCache_lock. This
1312   // would be prone to deadlocks.
1313   // This flag is used to remember whether we need to later lock and unregister.
1314   bool nmethod_needs_unregister = false;
1315 
1316   {
1317     // invalidate osr nmethod before acquiring the patching lock since
1318     // they both acquire leaf locks and we don't want a deadlock.
1319     // This logic is equivalent to the logic below for patching the


1403     // marked it for unloading). JvmtiDeferredEventQueue support means
1404     // we no longer go to a safepoint here.
1405     post_compiled_method_unload();
1406 
1407 #ifdef ASSERT
1408     // It's no longer safe to access the oops section since zombie
1409     // nmethods aren't scanned for GC.
1410     _oops_are_stale = true;
1411 #endif
1412      // the Method may be reclaimed by class unloading now that the
1413      // nmethod is in zombie state
1414     set_method(NULL);
1415   } else {
1416     assert(state == not_entrant, "other cases may need to be handled differently");
1417   }
1418 
1419   if (TraceCreateZombies) {
1420     tty->print_cr("nmethod <" INTPTR_FORMAT "> code made %s", this, (state == not_entrant) ? "not entrant" : "zombie");
1421   }
1422 
1423   // Make sweeper aware that there is a zombie method that needs to be removed
1424   NMethodSweeper::notify();
1425 
1426   return true;
1427 }
1428 
1429 void nmethod::flush() {
1430   // Note that there are no valid oops in the nmethod anymore.
1431   assert(is_zombie() || (is_osr_method() && is_unloaded()), "must be a zombie method");
1432   assert(is_marked_for_reclamation() || (is_osr_method() && is_unloaded()), "must be marked for reclamation");
1433 
1434   assert (!is_locked_by_vm(), "locked methods shouldn't be flushed");
1435   assert_locked_or_safepoint(CodeCache_lock);
1436 
1437   // completely deallocate this method
1438   Events::log(JavaThread::current(), "flushing nmethod " INTPTR_FORMAT, this);
1439   if (PrintMethodFlushing) {
1440     tty->print_cr("*flushing nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT "/Free CodeCache:" SIZE_FORMAT "Kb",
1441         _compile_id, this, CodeCache::nof_blobs(), CodeCache::unallocated_capacity()/1024);
1442   }
1443 
1444   // We need to deallocate any ExceptionCache data.
1445   // Note that we do not need to grab the nmethod lock for this, it




1245     _method = NULL;            // Clear the method of this dead nmethod
1246   }
1247   // Make the class unloaded - i.e., change state and notify sweeper
1248   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1249   if (is_in_use()) {
1250     // Transitioning directly from live to unloaded -- so
1251     // we need to force a cache clean-up; remember this
1252     // for later on.
1253     CodeCache::set_needs_cache_clean(true);
1254   }
1255   _state = unloaded;
1256 
1257   // Log the unloading.
1258   log_state_change();
1259 
1260   // The Method* is gone at this point
1261   assert(_method == NULL, "Tautology");
1262 
1263   set_osr_link(NULL);
1264   //set_scavenge_root_link(NULL); // done by prune_scavenge_root_nmethods
1265   NMethodSweeper::report_state_change(this);
1266 }
1267 
1268 void nmethod::invalidate_osr_method() {
1269   assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod");
1270   // Remove from list of active nmethods
1271   if (method() != NULL)
1272     method()->method_holder()->remove_osr_nmethod(this);
1273   // Set entry as invalid
1274   _entry_bci = InvalidOSREntryBci;
1275 }
1276 
1277 void nmethod::log_state_change() const {
1278   if (LogCompilation) {
1279     if (xtty != NULL) {
1280       ttyLocker ttyl;  // keep the following output all in one block
1281       if (_state == unloaded) {
1282         xtty->begin_elem("make_unloaded thread='" UINTX_FORMAT "'",
1283                          os::current_thread_id());
1284       } else {
1285         xtty->begin_elem("make_not_entrant thread='" UINTX_FORMAT "'%s",
1286                          os::current_thread_id(),
1287                          (_state == zombie ? " zombie='1'" : ""));
1288       }
1289       log_identity(xtty);
1290       xtty->stamp();
1291       xtty->end_elem();
1292     }
1293   }
1294   if (PrintCompilation && _state != unloaded) {
1295     print_on(tty, _state == zombie ? "made zombie" : "made not entrant");
1296   }
1297 }
1298 
1299 /**
1300  * Common functionality for both make_not_entrant and make_zombie
1301  */
1302 bool nmethod::make_not_entrant_or_zombie(unsigned int state) {
1303   assert(state == zombie || state == not_entrant, "must be zombie or not_entrant");
1304   assert(!is_zombie(), "should not already be a zombie");
1305 
1306   // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below.
1307   nmethodLocker nml(this);
1308   methodHandle the_method(method());
1309   No_Safepoint_Verifier nsv;
1310 
1311   // during patching, depending on the nmethod state we must notify the GC that
1312   // code has been unloaded, unregistering it. We cannot do this right while
1313   // holding the Patching_lock because we need to use the CodeCache_lock. This
1314   // would be prone to deadlocks.
1315   // This flag is used to remember whether we need to later lock and unregister.
1316   bool nmethod_needs_unregister = false;
1317 
1318   {
1319     // invalidate osr nmethod before acquiring the patching lock since
1320     // they both acquire leaf locks and we don't want a deadlock.
1321     // This logic is equivalent to the logic below for patching the


1405     // marked it for unloading). JvmtiDeferredEventQueue support means
1406     // we no longer go to a safepoint here.
1407     post_compiled_method_unload();
1408 
1409 #ifdef ASSERT
1410     // It's no longer safe to access the oops section since zombie
1411     // nmethods aren't scanned for GC.
1412     _oops_are_stale = true;
1413 #endif
1414      // the Method may be reclaimed by class unloading now that the
1415      // nmethod is in zombie state
1416     set_method(NULL);
1417   } else {
1418     assert(state == not_entrant, "other cases may need to be handled differently");
1419   }
1420 
1421   if (TraceCreateZombies) {
1422     tty->print_cr("nmethod <" INTPTR_FORMAT "> code made %s", this, (state == not_entrant) ? "not entrant" : "zombie");
1423   }
1424 
1425   NMethodSweeper::report_state_change(this);


1426   return true;
1427 }
1428 
1429 void nmethod::flush() {
1430   // Note that there are no valid oops in the nmethod anymore.
1431   assert(is_zombie() || (is_osr_method() && is_unloaded()), "must be a zombie method");
1432   assert(is_marked_for_reclamation() || (is_osr_method() && is_unloaded()), "must be marked for reclamation");
1433 
1434   assert (!is_locked_by_vm(), "locked methods shouldn't be flushed");
1435   assert_locked_or_safepoint(CodeCache_lock);
1436 
1437   // completely deallocate this method
1438   Events::log(JavaThread::current(), "flushing nmethod " INTPTR_FORMAT, this);
1439   if (PrintMethodFlushing) {
1440     tty->print_cr("*flushing nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT "/Free CodeCache:" SIZE_FORMAT "Kb",
1441         _compile_id, this, CodeCache::nof_blobs(), CodeCache::unallocated_capacity()/1024);
1442   }
1443 
1444   // We need to deallocate any ExceptionCache data.
1445   // Note that we do not need to grab the nmethod lock for this, it


src/share/vm/code/nmethod.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File