1026 if (mdo == NULL) return; |
1026 if (mdo == NULL) return; |
1027 // There is a benign race here. See comments in methodData.hpp. |
1027 // There is a benign race here. See comments in methodData.hpp. |
1028 mdo->inc_decompile_count(); |
1028 mdo->inc_decompile_count(); |
1029 } |
1029 } |
1030 |
1030 |
1031 void nmethod::make_unloaded(BoolObjectClosure* is_alive, oop cause) { |
1031 void nmethod::make_unloaded(oop cause) { |
1032 |
1032 |
1033 post_compiled_method_unload(); |
1033 post_compiled_method_unload(); |
1034 |
1034 |
1035 // Since this nmethod is being unloaded, make sure that dependencies |
1035 // This nmethod is being unloaded, make sure that dependencies |
1036 // recorded in instanceKlasses get flushed and pass non-NULL closure to |
1036 // recorded in instanceKlasses get flushed. |
1037 // indicate that this work is being done during a GC. |
1037 // Since this work is being done during a GC, defer deleting dependencies from the |
|
1038 // InstanceKlass. |
1038 assert(Universe::heap()->is_gc_active(), "should only be called during gc"); |
1039 assert(Universe::heap()->is_gc_active(), "should only be called during gc"); |
1039 assert(is_alive != NULL, "Should be non-NULL"); |
1040 flush_dependencies(/*delete_immediately*/false); |
1040 // A non-NULL is_alive closure indicates that this is being called during GC. |
|
1041 flush_dependencies(is_alive); |
|
1042 |
1041 |
1043 // Break cycle between nmethod & method |
1042 // Break cycle between nmethod & method |
1044 LogTarget(Trace, class, unload) lt; |
1043 LogTarget(Trace, class, unload) lt; |
1045 if (lt.is_enabled()) { |
1044 if (lt.is_enabled()) { |
1046 LogStream ls(lt); |
1045 LogStream ls(lt); |
1259 // dependency logic could have become stale. |
1258 // dependency logic could have become stale. |
1260 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
1259 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
1261 if (nmethod_needs_unregister) { |
1260 if (nmethod_needs_unregister) { |
1262 Universe::heap()->unregister_nmethod(this); |
1261 Universe::heap()->unregister_nmethod(this); |
1263 } |
1262 } |
1264 flush_dependencies(NULL); |
1263 flush_dependencies(/*delete_immediately*/true); |
1265 } |
1264 } |
1266 |
1265 |
1267 // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload |
1266 // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload |
1268 // event and it hasn't already been reported for this nmethod then |
1267 // event and it hasn't already been reported for this nmethod then |
1269 // report it now. The event may have been reported earlier if the GC |
1268 // report it now. The event may have been reported earlier if the GC |
1342 // During phase 1 of mark sweep class unloading may happen and as a |
1341 // During phase 1 of mark sweep class unloading may happen and as a |
1343 // result some nmethods may get unloaded. In this case the flushing |
1342 // result some nmethods may get unloaded. In this case the flushing |
1344 // of dependencies must happen during phase 1 since after GC any |
1343 // of dependencies must happen during phase 1 since after GC any |
1345 // dependencies in the unloaded nmethod won't be updated, so |
1344 // dependencies in the unloaded nmethod won't be updated, so |
1346 // traversing the dependency information in unsafe. In that case this |
1345 // traversing the dependency information in unsafe. In that case this |
1347 // function is called with a non-NULL argument and this function only |
1346 // function is called with a boolean argument and this function only |
1348 // notifies instanceKlasses that are reachable |
1347 // notifies instanceKlasses that are reachable |
1349 |
1348 |
1350 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) { |
1349 void nmethod::flush_dependencies(bool delete_immediately) { |
1351 assert_locked_or_safepoint(CodeCache_lock); |
1350 assert_locked_or_safepoint(CodeCache_lock); |
1352 assert(Universe::heap()->is_gc_active() == (is_alive != NULL), |
1351 assert(Universe::heap()->is_gc_active() != delete_immediately, |
1353 "is_alive is non-NULL if and only if we are called during GC"); |
1352 "delete_immediately is false if and only if we are called during GC"); |
1354 if (!has_flushed_dependencies()) { |
1353 if (!has_flushed_dependencies()) { |
1355 set_has_flushed_dependencies(); |
1354 set_has_flushed_dependencies(); |
1356 for (Dependencies::DepStream deps(this); deps.next(); ) { |
1355 for (Dependencies::DepStream deps(this); deps.next(); ) { |
1357 if (deps.type() == Dependencies::call_site_target_value) { |
1356 if (deps.type() == Dependencies::call_site_target_value) { |
1358 // CallSite dependencies are managed on per-CallSite instance basis. |
1357 // CallSite dependencies are managed on per-CallSite instance basis. |
1361 } else { |
1360 } else { |
1362 Klass* klass = deps.context_type(); |
1361 Klass* klass = deps.context_type(); |
1363 if (klass == NULL) { |
1362 if (klass == NULL) { |
1364 continue; // ignore things like evol_method |
1363 continue; // ignore things like evol_method |
1365 } |
1364 } |
1366 // During GC the is_alive closure is non-NULL, and is used to |
1365 // During GC delete_immediately is false, and liveness |
1367 // determine liveness of dependees that need to be updated. |
1366 // of dependee determines class that needs to be updated. |
1368 if (is_alive == NULL || klass->is_loader_alive()) { |
1367 if (delete_immediately || klass->is_loader_alive()) { |
1369 // The GC defers deletion of this entry, since there might be multiple threads |
1368 // The GC defers deletion of this entry, since there might be multiple threads |
1370 // iterating over the _dependencies graph. Other call paths are single-threaded |
1369 // iterating over the _dependencies graph. Other call paths are single-threaded |
1371 // and may delete it immediately. |
1370 // and may delete it immediately. |
1372 bool delete_immediately = is_alive == NULL; |
|
1373 InstanceKlass::cast(klass)->remove_dependent_nmethod(this, delete_immediately); |
1371 InstanceKlass::cast(klass)->remove_dependent_nmethod(this, delete_immediately); |
1374 } |
1372 } |
1375 } |
1373 } |
1376 } |
1374 } |
1377 } |
1375 } |
1388 |
1386 |
1389 // If ScavengeRootsInCode is true, an nmethod might be unloaded |
1387 // If ScavengeRootsInCode is true, an nmethod might be unloaded |
1390 // simply because one of its constant oops has gone dead. |
1388 // simply because one of its constant oops has gone dead. |
1391 // No actual classes need to be unloaded in order for this to occur. |
1389 // No actual classes need to be unloaded in order for this to occur. |
1392 assert(unloading_occurred || ScavengeRootsInCode, "Inconsistency in unloading"); |
1390 assert(unloading_occurred || ScavengeRootsInCode, "Inconsistency in unloading"); |
1393 make_unloaded(is_alive, obj); |
1391 make_unloaded(obj); |
1394 return true; |
1392 return true; |
1395 } |
1393 } |
1396 |
1394 |
1397 // ------------------------------------------------------------------ |
1395 // ------------------------------------------------------------------ |
1398 // post_compiled_method_load_event |
1396 // post_compiled_method_load_event |
1514 |
1512 |
1515 return do_unloading_scopes(is_alive, unloading_occurred); |
1513 return do_unloading_scopes(is_alive, unloading_occurred); |
1516 } |
1514 } |
1517 |
1515 |
1518 #if INCLUDE_JVMCI |
1516 #if INCLUDE_JVMCI |
1519 bool nmethod::do_unloading_jvmci(BoolObjectClosure* is_alive, bool unloading_occurred) { |
1517 bool nmethod::do_unloading_jvmci(bool unloading_occurred) { |
1520 if (_jvmci_installed_code != NULL) { |
1518 if (_jvmci_installed_code != NULL) { |
1521 if (JNIHandles::is_global_weak_cleared(_jvmci_installed_code)) { |
1519 if (JNIHandles::is_global_weak_cleared(_jvmci_installed_code)) { |
1522 if (_jvmci_installed_code_triggers_unloading) { |
1520 if (_jvmci_installed_code_triggers_unloading) { |
1523 // jweak reference processing has already cleared the referent |
1521 // jweak reference processing has already cleared the referent |
1524 make_unloaded(is_alive, NULL); |
1522 make_unloaded(NULL); |
1525 return true; |
1523 return true; |
1526 } else { |
1524 } else { |
1527 clear_jvmci_installed_code(); |
1525 clear_jvmci_installed_code(); |
1528 } |
1526 } |
1529 } |
1527 } |