@@ -179,10 +179,6 @@ void BarrierSetNMethod::arm_all_nmethods() {
179179}
180180
181181int BarrierSetNMethod::nmethod_stub_entry_barrier (address* return_address_ptr) {
182- // Enable WXWrite: the function is called directly from nmethod_entry_barrier
183- // stub.
184- MACOS_AARCH64_ONLY (ThreadWXEnable wx (WXWrite, Thread::current ()));
185-
186182 address return_address = *return_address_ptr;
187183 AARCH64_PORT_ONLY (return_address = pauth_strip_pointer (return_address));
188184 CodeBlob* cb = CodeCache::find_blob (return_address);
@@ -191,25 +187,33 @@ int BarrierSetNMethod::nmethod_stub_entry_barrier(address* return_address_ptr) {
191187 nmethod* nm = cb->as_nmethod ();
192188 BarrierSetNMethod* bs_nm = BarrierSet::barrier_set ()->barrier_set_nmethod ();
193189
194- // Called upon first entry after being armed
195- bool may_enter = !bs_nm->is_not_entrant (nm) && bs_nm->nmethod_entry_barrier (nm);
196- assert (!nm->is_osr_method () || may_enter, " OSR nmethods should always be entrant after migration" );
190+ bool may_enter = !bs_nm->is_not_entrant (nm);
197191
198192 if (may_enter) {
199- // In case a concurrent thread disarmed the nmethod, we need to ensure the new instructions
200- // are made visible, by using a cross modify fence. Note that this is synchronous cross modifying
201- // code, where the existence of new instructions is communicated via data (the guard value).
202- // This cross modify fence is only needed when the nmethod entry barrier modifies the
203- // instructions. Not all platforms currently do that, so if this check becomes expensive,
204- // it can be made conditional on the nmethod_patching_type.
205- OrderAccess::cross_modify_fence ();
206-
207- // Diagnostic option to force deoptimization 1 in 10 times. It is otherwise
208- // a very rare event.
209- if (DeoptimizeNMethodBarriersALot && !nm->is_osr_method ()) {
210- static volatile uint32_t counter=0 ;
211- if (Atomic::add (&counter, 1u ) % 10 == 0 ) {
212- may_enter = false ;
193+ // Enable WXWrite: the function is called directly from nmethod_entry_barrier
194+ // stub.
195+ MACOS_AARCH64_ONLY (ThreadWXEnable wx (WXWrite, Thread::current ()));
196+
197+ // Called upon first entry after being armed
198+ may_enter = bs_nm->nmethod_entry_barrier (nm);
199+ assert (!nm->is_osr_method () || may_enter, " OSR nmethods should always be entrant after migration" );
200+
201+ if (may_enter) {
202+ // In case a concurrent thread disarmed the nmethod, we need to ensure the new instructions
203+ // are made visible, by using a cross modify fence. Note that this is synchronous cross modifying
204+ // code, where the existence of new instructions is communicated via data (the guard value).
205+ // This cross modify fence is only needed when the nmethod entry barrier modifies the
206+ // instructions. Not all platforms currently do that, so if this check becomes expensive,
207+ // it can be made conditional on the nmethod_patching_type.
208+ OrderAccess::cross_modify_fence ();
209+
210+ // Diagnostic option to force deoptimization 1 in 10 times. It is otherwise
211+ // a very rare event.
212+ if (DeoptimizeNMethodBarriersALot && !nm->is_osr_method ()) {
213+ static volatile uint32_t counter=0 ;
214+ if (Atomic::add (&counter, 1u ) % 10 == 0 ) {
215+ may_enter = false ;
216+ }
213217 }
214218 }
215219 }
0 commit comments