diff a/src/hotspot/share/code/compiledMethod.cpp b/src/hotspot/share/code/compiledMethod.cpp --- a/src/hotspot/share/code/compiledMethod.cpp +++ b/src/hotspot/share/code/compiledMethod.cpp @@ -28,10 +28,11 @@ #include "code/exceptionHandlerTable.hpp" #include "code/scopeDesc.hpp" #include "code/codeCache.hpp" #include "code/icBuffer.hpp" #include "gc/shared/barrierSet.hpp" +#include "gc/shared/barrierSetNMethod.hpp" #include "gc/shared/gcBehaviours.hpp" #include "interpreter/bytecode.inline.hpp" #include "logging/log.hpp" #include "logging/logTag.hpp" #include "memory/resourceArea.hpp" @@ -540,10 +541,22 @@ { CompiledICLocker ic_locker(this); if (cleanup_inline_caches_impl(false, clean_all)) { return; } } + BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod(); + if (bs_nm != NULL) { + // We want to keep an invariant that nmethods found through iterations of a Thread's + // nmethods found in safepoints have gone through an entry barrier and are not armed. + // By calling this nmethod entry barrier from the sweeper, it plays along and acts + // like any other nmethod found on the stack of a thread (fewer surprises). + nmethod* nm = as_nmethod_or_null(); + if (nm != NULL) { + bool alive = bs_nm->nmethod_entry_barrier(nm); + assert(alive, "should be alive"); + } + } InlineCacheBuffer::refill_ic_stubs(); } } // Called to clean up after class unloading for live nmethods and from the sweeper diff a/src/hotspot/share/gc/shared/barrierSetNMethod.hpp b/src/hotspot/share/gc/shared/barrierSetNMethod.hpp --- a/src/hotspot/share/gc/shared/barrierSetNMethod.hpp +++ b/src/hotspot/share/gc/shared/barrierSetNMethod.hpp @@ -35,15 +35,15 @@ bool supports_entry_barrier(nmethod* nm); void deoptimize(nmethod* nm, address* return_addr_ptr); protected: virtual int disarmed_value() const; - virtual bool nmethod_entry_barrier(nmethod* nm) = 0; public: virtual ByteSize thread_disarmed_offset() const = 0; + virtual bool nmethod_entry_barrier(nmethod* nm) = 0; static int nmethod_stub_entry_barrier(address* return_address_ptr); bool nmethod_osr_entry_barrier(nmethod* nm); bool is_armed(nmethod* nm); void disarm(nmethod* nm); };