583 _nmethod_end_offset = _nul_chk_table_offset;
584 _compile_id = compile_id;
585 _comp_level = CompLevel_none;
586 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
587 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
588 _osr_entry_point = NULL;
589 _exception_cache = NULL;
590 _pc_desc_container.reset_to(NULL);
591 _hotness_counter = NMethodSweeper::hotness_counter_reset_val();
592
593 _scopes_data_begin = (address) this + scopes_data_offset;
594 _deopt_handler_begin = (address) this + deoptimize_offset;
595 _deopt_mh_handler_begin = (address) this + deoptimize_mh_offset;
596
597 code_buffer->copy_code_and_locs_to(this);
598 code_buffer->copy_values_to(this);
599 if (ScavengeRootsInCode) {
600 if (detect_scavenge_root_oops()) {
601 CodeCache::add_scavenge_root_nmethod(this);
602 }
603 Universe::heap()->register_nmethod(this);
604 }
605 debug_only(verify_scavenge_root_oops());
606 CodeCache::commit(this);
607 }
608
609 if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
610 ttyLocker ttyl; // keep the following output all in one block
611 // This output goes directly to the tty, not the compiler log.
612 // To enable tools to match it up with the compilation activity,
613 // be sure to tag this tty output with the compile ID.
614 if (xtty != NULL) {
615 xtty->begin_head("print_native_nmethod");
616 xtty->method(_method);
617 xtty->stamp();
618 xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
619 }
620 // print the header part first
621 print();
622 // then print the requested information
623 if (PrintNativeNMethods) {
738 _nul_chk_table_offset = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize);
739 _nmethod_end_offset = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize);
740 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
741 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
742 _osr_entry_point = code_begin() + offsets->value(CodeOffsets::OSR_Entry);
743 _exception_cache = NULL;
744
745 _scopes_data_begin = (address) this + scopes_data_offset;
746
747 _pc_desc_container.reset_to(scopes_pcs_begin());
748
749 code_buffer->copy_code_and_locs_to(this);
750 // Copy contents of ScopeDescRecorder to nmethod
751 code_buffer->copy_values_to(this);
752 debug_info->copy_to(this);
753 dependencies->copy_to(this);
754 if (ScavengeRootsInCode) {
755 if (detect_scavenge_root_oops()) {
756 CodeCache::add_scavenge_root_nmethod(this);
757 }
758 Universe::heap()->register_nmethod(this);
759 }
760 debug_only(verify_scavenge_root_oops());
761
762 CodeCache::commit(this);
763
764 // Copy contents of ExceptionHandlerTable to nmethod
765 handler_table->copy_to(this);
766 nul_chk_table->copy_to(this);
767
768 // we use the information of entry points to find out if a method is
769 // static or non static
770 assert(compiler->is_c2() || compiler->is_jvmci() ||
771 _method->is_static() == (entry_point() == _verified_entry_point),
772 " entry points must be same for static methods and vice versa");
773 }
774 }
775
776 // Print a short set of xml attributes to identify this nmethod. The
777 // output should be embedded in some other element.
778 void nmethod::log_identity(xmlStream* log) const {
1012 }
1013
1014 void nmethod::inc_decompile_count() {
1015 if (!is_compiled_by_c2() && !is_compiled_by_jvmci()) return;
1016 // Could be gated by ProfileTraps, but do not bother...
1017 Method* m = method();
1018 if (m == NULL) return;
1019 MethodData* mdo = m->method_data();
1020 if (mdo == NULL) return;
1021 // There is a benign race here. See comments in methodData.hpp.
1022 mdo->inc_decompile_count();
1023 }
1024
1025 void nmethod::make_unloaded(BoolObjectClosure* is_alive, oop cause) {
1026
1027 post_compiled_method_unload();
1028
1029 // Since this nmethod is being unloaded, make sure that dependencies
1030 // recorded in instanceKlasses get flushed and pass non-NULL closure to
1031 // indicate that this work is being done during a GC.
1032 assert(Universe::heap()->is_gc_active(), "should only be called during gc");
1033 assert(is_alive != NULL, "Should be non-NULL");
1034 // A non-NULL is_alive closure indicates that this is being called during GC.
1035 flush_dependencies(is_alive);
1036
1037 // Break cycle between nmethod & method
1038 if (log_is_enabled(Trace, class, unload)) {
1039 outputStream* log = Log(class, unload)::trace_stream();
1040 log->print_cr("making nmethod " INTPTR_FORMAT
1041 " unloadable, Method*(" INTPTR_FORMAT
1042 "), cause(" INTPTR_FORMAT ")",
1043 p2i(this), p2i(_method), p2i(cause));
1044 if (!Universe::heap()->is_gc_active())
1045 cause->klass()->print_on(log);
1046 }
1047 // Unlink the osr method, so we do not look this up again
1048 if (is_osr_method()) {
1049 // Invalidate the osr nmethod only once
1050 if (is_in_use()) {
1051 invalidate_osr_method();
1052 }
1053 #ifdef ASSERT
1054 if (method() != NULL) {
1055 // Make sure osr nmethod is invalidated, i.e. not on the list
1056 bool found = method()->method_holder()->remove_osr_nmethod(this);
1057 assert(!found, "osr nmethod should have been invalidated");
1058 }
1059 #endif
1060 }
1061
1062 // If _method is already NULL the Method* is about to be unloaded,
1063 // so we don't have to break the cycle. Note that it is possible to
1064 // have the Method* live here, in case we unload the nmethod because
1065 // it is pointing to some oop (other than the Method*) being unloaded.
1066 if (_method != NULL) {
1067 // OSR methods point to the Method*, but the Method* does not
1068 // point back!
1069 if (_method->code() == this) {
1070 _method->clear_code(); // Break a cycle
1071 }
1072 _method = NULL; // Clear the method of this dead nmethod
1073 }
1074
1075 // Make the class unloaded - i.e., change state and notify sweeper
1076 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1077 if (is_in_use()) {
1078 // Transitioning directly from live to unloaded -- so
1079 // we need to force a cache clean-up; remember this
1080 // for later on.
1081 CodeCache::set_needs_cache_clean(true);
1082 }
1083
1084 // Unregister must be done before the state change
1085 Universe::heap()->unregister_nmethod(this);
1086
1087 _state = unloaded;
1088
1089 // Log the unloading.
1090 log_state_change();
1091
1092 #if INCLUDE_JVMCI
1093 // The method can only be unloaded after the pointer to the installed code
1094 // Java wrapper is no longer alive. Here we need to clear out this weak
1095 // reference to the dead object. Nulling out the reference has to happen
1096 // after the method is unregistered since the original value may be still
1097 // tracked by the rset.
1098 maybe_invalidate_installed_code();
1099 // Clear these out after the nmethod has been unregistered and any
1100 // updates to the InstalledCode instance have been performed.
1101 _jvmci_installed_code = NULL;
1102 _speculation_log = NULL;
1103 #endif
1104
1105 // The Method* is gone at this point
1243
1244 #ifdef ASSERT
1245 if (is_osr_method() && method() != NULL) {
1246 // Make sure osr nmethod is invalidated, i.e. not on the list
1247 bool found = method()->method_holder()->remove_osr_nmethod(this);
1248 assert(!found, "osr nmethod should have been invalidated");
1249 }
1250 #endif
1251
1252 // When the nmethod becomes zombie it is no longer alive so the
1253 // dependencies must be flushed. nmethods in the not_entrant
1254 // state will be flushed later when the transition to zombie
1255 // happens or they get unloaded.
1256 if (state == zombie) {
1257 {
1258 // Flushing dependencies must be done before any possible
1259 // safepoint can sneak in, otherwise the oops used by the
1260 // dependency logic could have become stale.
1261 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1262 if (nmethod_needs_unregister) {
1263 Universe::heap()->unregister_nmethod(this);
1264 #ifdef JVMCI
1265 _jvmci_installed_code = NULL;
1266 _speculation_log = NULL;
1267 #endif
1268 }
1269 flush_dependencies(NULL);
1270 }
1271
1272 // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload
1273 // event and it hasn't already been reported for this nmethod then
1274 // report it now. The event may have been reported earlier if the GC
1275 // marked it for unloading). JvmtiDeferredEventQueue support means
1276 // we no longer go to a safepoint here.
1277 post_compiled_method_unload();
1278
1279 #ifdef ASSERT
1280 // It's no longer safe to access the oops section since zombie
1281 // nmethods aren't scanned for GC.
1282 _oops_are_stale = true;
1283 #endif
1336 CodeBlob::flush();
1337 CodeCache::free(this);
1338 }
1339
1340 //
1341 // Notify all classes this nmethod is dependent on that it is no
1342 // longer dependent. This should only be called in two situations.
1343 // First, when a nmethod transitions to a zombie all dependents need
1344 // to be clear. Since zombification happens at a safepoint there's no
1345 // synchronization issues. The second place is a little more tricky.
1346 // During phase 1 of mark sweep class unloading may happen and as a
1347 // result some nmethods may get unloaded. In this case the flushing
1348 // of dependencies must happen during phase 1 since after GC any
1349 // dependencies in the unloaded nmethod won't be updated, so
1350 // traversing the dependency information in unsafe. In that case this
1351 // function is called with a non-NULL argument and this function only
1352 // notifies instanceKlasses that are reachable
1353
1354 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) {
1355 assert_locked_or_safepoint(CodeCache_lock);
1356 assert(Universe::heap()->is_gc_active() == (is_alive != NULL),
1357 "is_alive is non-NULL if and only if we are called during GC");
1358 if (!has_flushed_dependencies()) {
1359 set_has_flushed_dependencies();
1360 for (Dependencies::DepStream deps(this); deps.next(); ) {
1361 if (deps.type() == Dependencies::call_site_target_value) {
1362 // CallSite dependencies are managed on per-CallSite instance basis.
1363 oop call_site = deps.argument_oop(0);
1364 MethodHandles::remove_dependent_nmethod(call_site, this);
1365 } else {
1366 Klass* klass = deps.context_type();
1367 if (klass == NULL) {
1368 continue; // ignore things like evol_method
1369 }
1370 // During GC the is_alive closure is non-NULL, and is used to
1371 // determine liveness of dependees that need to be updated.
1372 if (is_alive == NULL || klass->is_loader_alive(is_alive)) {
1373 // The GC defers deletion of this entry, since there might be multiple threads
1374 // iterating over the _dependencies graph. Other call paths are single-threaded
1375 // and may delete it immediately.
1376 bool delete_immediately = is_alive == NULL;
1510 bool nmethod::do_unloading_oops(address low_boundary, BoolObjectClosure* is_alive, bool unloading_occurred) {
1511 // Compiled code
1512 {
1513 RelocIterator iter(this, low_boundary);
1514 while (iter.next()) {
1515 if (iter.type() == relocInfo::oop_type) {
1516 if (unload_if_dead_at(&iter, is_alive, unloading_occurred)) {
1517 return true;
1518 }
1519 }
1520 }
1521 }
1522
1523 return do_unloading_scopes(is_alive, unloading_occurred);
1524 }
1525
1526 #if INCLUDE_JVMCI
1527 bool nmethod::do_unloading_jvmci(BoolObjectClosure* is_alive, bool unloading_occurred) {
1528 bool is_unloaded = false;
1529 // Follow JVMCI method
1530 BarrierSet* bs = Universe::heap()->barrier_set();
1531 if (_jvmci_installed_code != NULL) {
1532 if (_jvmci_installed_code->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isDefault(_jvmci_installed_code)) {
1533 if (!is_alive->do_object_b(_jvmci_installed_code)) {
1534 clear_jvmci_installed_code();
1535 }
1536 } else {
1537 if (can_unload(is_alive, (oop*)&_jvmci_installed_code, unloading_occurred)) {
1538 return true;
1539 }
1540 }
1541 }
1542
1543 if (_speculation_log != NULL) {
1544 if (!is_alive->do_object_b(_speculation_log)) {
1545 bs->write_ref_nmethod_pre(&_speculation_log, this);
1546 _speculation_log = NULL;
1547 bs->write_ref_nmethod_post(&_speculation_log, this);
1548 }
1549 }
1550 return is_unloaded;
2897 #endif
2898 unknown_java_nmethod_stats.print_nmethod_stats("Unknown");
2899 DebugInformationRecorder::print_statistics();
2900 #ifndef PRODUCT
2901 pc_nmethod_stats.print_pc_stats();
2902 #endif
2903 Dependencies::print_statistics();
2904 if (xtty != NULL) xtty->tail("statistics");
2905 }
2906
2907 #endif // !PRODUCT
2908
2909 #if INCLUDE_JVMCI
2910 void nmethod::clear_jvmci_installed_code() {
2911 // write_ref_method_pre/post can only be safely called at a
2912 // safepoint or while holding the CodeCache_lock
2913 assert(CodeCache_lock->is_locked() ||
2914 SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
2915 if (_jvmci_installed_code != NULL) {
2916 // This must be done carefully to maintain nmethod remembered sets properly
2917 BarrierSet* bs = Universe::heap()->barrier_set();
2918 bs->write_ref_nmethod_pre(&_jvmci_installed_code, this);
2919 _jvmci_installed_code = NULL;
2920 bs->write_ref_nmethod_post(&_jvmci_installed_code, this);
2921 }
2922 }
2923
2924 void nmethod::maybe_invalidate_installed_code() {
2925 assert(Patching_lock->is_locked() ||
2926 SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
2927 oop installed_code = jvmci_installed_code();
2928 if (installed_code != NULL) {
2929 nmethod* nm = (nmethod*)InstalledCode::address(installed_code);
2930 if (nm == NULL || nm != this) {
2931 // The link has been broken or the InstalledCode instance is
2932 // associated with another nmethod so do nothing.
2933 return;
2934 }
2935 if (!is_alive()) {
2936 // Break the link between nmethod and InstalledCode such that the nmethod
2937 // can subsequently be flushed safely. The link must be maintained while
|
583 _nmethod_end_offset = _nul_chk_table_offset;
584 _compile_id = compile_id;
585 _comp_level = CompLevel_none;
586 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
587 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
588 _osr_entry_point = NULL;
589 _exception_cache = NULL;
590 _pc_desc_container.reset_to(NULL);
591 _hotness_counter = NMethodSweeper::hotness_counter_reset_val();
592
593 _scopes_data_begin = (address) this + scopes_data_offset;
594 _deopt_handler_begin = (address) this + deoptimize_offset;
595 _deopt_mh_handler_begin = (address) this + deoptimize_mh_offset;
596
597 code_buffer->copy_code_and_locs_to(this);
598 code_buffer->copy_values_to(this);
599 if (ScavengeRootsInCode) {
600 if (detect_scavenge_root_oops()) {
601 CodeCache::add_scavenge_root_nmethod(this);
602 }
603 GC::gc()->heap()->register_nmethod(this);
604 }
605 debug_only(verify_scavenge_root_oops());
606 CodeCache::commit(this);
607 }
608
609 if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
610 ttyLocker ttyl; // keep the following output all in one block
611 // This output goes directly to the tty, not the compiler log.
612 // To enable tools to match it up with the compilation activity,
613 // be sure to tag this tty output with the compile ID.
614 if (xtty != NULL) {
615 xtty->begin_head("print_native_nmethod");
616 xtty->method(_method);
617 xtty->stamp();
618 xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
619 }
620 // print the header part first
621 print();
622 // then print the requested information
623 if (PrintNativeNMethods) {
738 _nul_chk_table_offset = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize);
739 _nmethod_end_offset = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize);
740 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
741 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
742 _osr_entry_point = code_begin() + offsets->value(CodeOffsets::OSR_Entry);
743 _exception_cache = NULL;
744
745 _scopes_data_begin = (address) this + scopes_data_offset;
746
747 _pc_desc_container.reset_to(scopes_pcs_begin());
748
749 code_buffer->copy_code_and_locs_to(this);
750 // Copy contents of ScopeDescRecorder to nmethod
751 code_buffer->copy_values_to(this);
752 debug_info->copy_to(this);
753 dependencies->copy_to(this);
754 if (ScavengeRootsInCode) {
755 if (detect_scavenge_root_oops()) {
756 CodeCache::add_scavenge_root_nmethod(this);
757 }
758 GC::gc()->heap()->register_nmethod(this);
759 }
760 debug_only(verify_scavenge_root_oops());
761
762 CodeCache::commit(this);
763
764 // Copy contents of ExceptionHandlerTable to nmethod
765 handler_table->copy_to(this);
766 nul_chk_table->copy_to(this);
767
768 // we use the information of entry points to find out if a method is
769 // static or non static
770 assert(compiler->is_c2() || compiler->is_jvmci() ||
771 _method->is_static() == (entry_point() == _verified_entry_point),
772 " entry points must be same for static methods and vice versa");
773 }
774 }
775
776 // Print a short set of xml attributes to identify this nmethod. The
777 // output should be embedded in some other element.
778 void nmethod::log_identity(xmlStream* log) const {
1012 }
1013
1014 void nmethod::inc_decompile_count() {
1015 if (!is_compiled_by_c2() && !is_compiled_by_jvmci()) return;
1016 // Could be gated by ProfileTraps, but do not bother...
1017 Method* m = method();
1018 if (m == NULL) return;
1019 MethodData* mdo = m->method_data();
1020 if (mdo == NULL) return;
1021 // There is a benign race here. See comments in methodData.hpp.
1022 mdo->inc_decompile_count();
1023 }
1024
1025 void nmethod::make_unloaded(BoolObjectClosure* is_alive, oop cause) {
1026
1027 post_compiled_method_unload();
1028
1029 // Since this nmethod is being unloaded, make sure that dependencies
1030 // recorded in instanceKlasses get flushed and pass non-NULL closure to
1031 // indicate that this work is being done during a GC.
1032 assert(GC::gc()->heap()->is_gc_active(), "should only be called during gc");
1033 assert(is_alive != NULL, "Should be non-NULL");
1034 // A non-NULL is_alive closure indicates that this is being called during GC.
1035 flush_dependencies(is_alive);
1036
1037 // Break cycle between nmethod & method
1038 if (log_is_enabled(Trace, class, unload)) {
1039 outputStream* log = Log(class, unload)::trace_stream();
1040 log->print_cr("making nmethod " INTPTR_FORMAT
1041 " unloadable, Method*(" INTPTR_FORMAT
1042 "), cause(" INTPTR_FORMAT ")",
1043 p2i(this), p2i(_method), p2i(cause));
1044 if (!GC::gc()->heap()->is_gc_active())
1045 cause->klass()->print_on(log);
1046 }
1047 // Unlink the osr method, so we do not look this up again
1048 if (is_osr_method()) {
1049 // Invalidate the osr nmethod only once
1050 if (is_in_use()) {
1051 invalidate_osr_method();
1052 }
1053 #ifdef ASSERT
1054 if (method() != NULL) {
1055 // Make sure osr nmethod is invalidated, i.e. not on the list
1056 bool found = method()->method_holder()->remove_osr_nmethod(this);
1057 assert(!found, "osr nmethod should have been invalidated");
1058 }
1059 #endif
1060 }
1061
1062 // If _method is already NULL the Method* is about to be unloaded,
1063 // so we don't have to break the cycle. Note that it is possible to
1064 // have the Method* live here, in case we unload the nmethod because
1065 // it is pointing to some oop (other than the Method*) being unloaded.
1066 if (_method != NULL) {
1067 // OSR methods point to the Method*, but the Method* does not
1068 // point back!
1069 if (_method->code() == this) {
1070 _method->clear_code(); // Break a cycle
1071 }
1072 _method = NULL; // Clear the method of this dead nmethod
1073 }
1074
1075 // Make the class unloaded - i.e., change state and notify sweeper
1076 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1077 if (is_in_use()) {
1078 // Transitioning directly from live to unloaded -- so
1079 // we need to force a cache clean-up; remember this
1080 // for later on.
1081 CodeCache::set_needs_cache_clean(true);
1082 }
1083
1084 // Unregister must be done before the state change
1085 GC::gc()->heap()->unregister_nmethod(this);
1086
1087 _state = unloaded;
1088
1089 // Log the unloading.
1090 log_state_change();
1091
1092 #if INCLUDE_JVMCI
1093 // The method can only be unloaded after the pointer to the installed code
1094 // Java wrapper is no longer alive. Here we need to clear out this weak
1095 // reference to the dead object. Nulling out the reference has to happen
1096 // after the method is unregistered since the original value may be still
1097 // tracked by the rset.
1098 maybe_invalidate_installed_code();
1099 // Clear these out after the nmethod has been unregistered and any
1100 // updates to the InstalledCode instance have been performed.
1101 _jvmci_installed_code = NULL;
1102 _speculation_log = NULL;
1103 #endif
1104
1105 // The Method* is gone at this point
1243
1244 #ifdef ASSERT
1245 if (is_osr_method() && method() != NULL) {
1246 // Make sure osr nmethod is invalidated, i.e. not on the list
1247 bool found = method()->method_holder()->remove_osr_nmethod(this);
1248 assert(!found, "osr nmethod should have been invalidated");
1249 }
1250 #endif
1251
1252 // When the nmethod becomes zombie it is no longer alive so the
1253 // dependencies must be flushed. nmethods in the not_entrant
1254 // state will be flushed later when the transition to zombie
1255 // happens or they get unloaded.
1256 if (state == zombie) {
1257 {
1258 // Flushing dependencies must be done before any possible
1259 // safepoint can sneak in, otherwise the oops used by the
1260 // dependency logic could have become stale.
1261 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1262 if (nmethod_needs_unregister) {
1263 GC::gc()->heap()->unregister_nmethod(this);
1264 #ifdef JVMCI
1265 _jvmci_installed_code = NULL;
1266 _speculation_log = NULL;
1267 #endif
1268 }
1269 flush_dependencies(NULL);
1270 }
1271
1272 // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload
1273 // event and it hasn't already been reported for this nmethod then
1274 // report it now. The event may have been reported earlier if the GC
1275 // marked it for unloading). JvmtiDeferredEventQueue support means
1276 // we no longer go to a safepoint here.
1277 post_compiled_method_unload();
1278
1279 #ifdef ASSERT
1280 // It's no longer safe to access the oops section since zombie
1281 // nmethods aren't scanned for GC.
1282 _oops_are_stale = true;
1283 #endif
1336 CodeBlob::flush();
1337 CodeCache::free(this);
1338 }
1339
1340 //
1341 // Notify all classes this nmethod is dependent on that it is no
1342 // longer dependent. This should only be called in two situations.
1343 // First, when a nmethod transitions to a zombie all dependents need
1344 // to be clear. Since zombification happens at a safepoint there's no
1345 // synchronization issues. The second place is a little more tricky.
1346 // During phase 1 of mark sweep class unloading may happen and as a
1347 // result some nmethods may get unloaded. In this case the flushing
1348 // of dependencies must happen during phase 1 since after GC any
1349 // dependencies in the unloaded nmethod won't be updated, so
1350 // traversing the dependency information in unsafe. In that case this
1351 // function is called with a non-NULL argument and this function only
1352 // notifies instanceKlasses that are reachable
1353
1354 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) {
1355 assert_locked_or_safepoint(CodeCache_lock);
1356 assert(GC::gc()->heap()->is_gc_active() == (is_alive != NULL),
1357 "is_alive is non-NULL if and only if we are called during GC");
1358 if (!has_flushed_dependencies()) {
1359 set_has_flushed_dependencies();
1360 for (Dependencies::DepStream deps(this); deps.next(); ) {
1361 if (deps.type() == Dependencies::call_site_target_value) {
1362 // CallSite dependencies are managed on per-CallSite instance basis.
1363 oop call_site = deps.argument_oop(0);
1364 MethodHandles::remove_dependent_nmethod(call_site, this);
1365 } else {
1366 Klass* klass = deps.context_type();
1367 if (klass == NULL) {
1368 continue; // ignore things like evol_method
1369 }
1370 // During GC the is_alive closure is non-NULL, and is used to
1371 // determine liveness of dependees that need to be updated.
1372 if (is_alive == NULL || klass->is_loader_alive(is_alive)) {
1373 // The GC defers deletion of this entry, since there might be multiple threads
1374 // iterating over the _dependencies graph. Other call paths are single-threaded
1375 // and may delete it immediately.
1376 bool delete_immediately = is_alive == NULL;
1510 bool nmethod::do_unloading_oops(address low_boundary, BoolObjectClosure* is_alive, bool unloading_occurred) {
1511 // Compiled code
1512 {
1513 RelocIterator iter(this, low_boundary);
1514 while (iter.next()) {
1515 if (iter.type() == relocInfo::oop_type) {
1516 if (unload_if_dead_at(&iter, is_alive, unloading_occurred)) {
1517 return true;
1518 }
1519 }
1520 }
1521 }
1522
1523 return do_unloading_scopes(is_alive, unloading_occurred);
1524 }
1525
1526 #if INCLUDE_JVMCI
1527 bool nmethod::do_unloading_jvmci(BoolObjectClosure* is_alive, bool unloading_occurred) {
1528 bool is_unloaded = false;
1529 // Follow JVMCI method
1530 BarrierSet* bs = GC::gc()->heap()->barrier_set();
1531 if (_jvmci_installed_code != NULL) {
1532 if (_jvmci_installed_code->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isDefault(_jvmci_installed_code)) {
1533 if (!is_alive->do_object_b(_jvmci_installed_code)) {
1534 clear_jvmci_installed_code();
1535 }
1536 } else {
1537 if (can_unload(is_alive, (oop*)&_jvmci_installed_code, unloading_occurred)) {
1538 return true;
1539 }
1540 }
1541 }
1542
1543 if (_speculation_log != NULL) {
1544 if (!is_alive->do_object_b(_speculation_log)) {
1545 bs->write_ref_nmethod_pre(&_speculation_log, this);
1546 _speculation_log = NULL;
1547 bs->write_ref_nmethod_post(&_speculation_log, this);
1548 }
1549 }
1550 return is_unloaded;
2897 #endif
2898 unknown_java_nmethod_stats.print_nmethod_stats("Unknown");
2899 DebugInformationRecorder::print_statistics();
2900 #ifndef PRODUCT
2901 pc_nmethod_stats.print_pc_stats();
2902 #endif
2903 Dependencies::print_statistics();
2904 if (xtty != NULL) xtty->tail("statistics");
2905 }
2906
2907 #endif // !PRODUCT
2908
2909 #if INCLUDE_JVMCI
2910 void nmethod::clear_jvmci_installed_code() {
2911 // write_ref_method_pre/post can only be safely called at a
2912 // safepoint or while holding the CodeCache_lock
2913 assert(CodeCache_lock->is_locked() ||
2914 SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
2915 if (_jvmci_installed_code != NULL) {
2916 // This must be done carefully to maintain nmethod remembered sets properly
2917 BarrierSet* bs = GC::gc()->heap()->barrier_set();
2918 bs->write_ref_nmethod_pre(&_jvmci_installed_code, this);
2919 _jvmci_installed_code = NULL;
2920 bs->write_ref_nmethod_post(&_jvmci_installed_code, this);
2921 }
2922 }
2923
2924 void nmethod::maybe_invalidate_installed_code() {
2925 assert(Patching_lock->is_locked() ||
2926 SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
2927 oop installed_code = jvmci_installed_code();
2928 if (installed_code != NULL) {
2929 nmethod* nm = (nmethod*)InstalledCode::address(installed_code);
2930 if (nm == NULL || nm != this) {
2931 // The link has been broken or the InstalledCode instance is
2932 // associated with another nmethod so do nothing.
2933 return;
2934 }
2935 if (!is_alive()) {
2936 // Break the link between nmethod and InstalledCode such that the nmethod
2937 // can subsequently be flushed safely. The link must be maintained while
|