Skip to content

Commit c0604fb

Browse files
committed
8334890: Missing unconditional cross modifying fence in nmethod entry barriers
Reviewed-by: aboldtch, kbarrett
1 parent cf1be87 commit c0604fb

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

src/hotspot/share/gc/shared/barrierSetNMethod.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,9 @@ int BarrierSetNMethod::nmethod_stub_entry_barrier(address* return_address_ptr) {
178178
nmethod* nm = cb->as_nmethod();
179179
BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
180180

181-
// Check for disarmed method here to avoid going into DeoptimizeNMethodBarriersALot code
182-
// too often. nmethod_entry_barrier checks for disarmed status itself,
183-
// but we have no visibility into whether the barrier acted or not.
184-
if (!bs_nm->is_armed(nm)) {
185-
return 0;
186-
}
187-
188-
assert(!nm->is_osr_method(), "Should not reach here");
189181
// Called upon first entry after being armed
190182
bool may_enter = bs_nm->nmethod_entry_barrier(nm);
183+
assert(!nm->is_osr_method() || may_enter, "OSR nmethods should always be entrant after migration");
191184

192185
// In case a concurrent thread disarmed the nmethod, we need to ensure the new instructions
193186
// are made visible, by using a cross modify fence. Note that this is synchronous cross modifying
@@ -197,11 +190,11 @@ int BarrierSetNMethod::nmethod_stub_entry_barrier(address* return_address_ptr) {
197190
// it can be made conditional on the nmethod_patching_type.
198191
OrderAccess::cross_modify_fence();
199192

200-
// Diagnostic option to force deoptimization 1 in 3 times. It is otherwise
193+
// Diagnostic option to force deoptimization 1 in 10 times. It is otherwise
201194
// a very rare event.
202-
if (DeoptimizeNMethodBarriersALot) {
195+
if (DeoptimizeNMethodBarriersALot && !nm->is_osr_method()) {
203196
static volatile uint32_t counter=0;
204-
if (Atomic::add(&counter, 1u) % 3 == 0) {
197+
if (Atomic::add(&counter, 1u) % 10 == 0) {
205198
may_enter = false;
206199
}
207200
}
@@ -214,15 +207,6 @@ int BarrierSetNMethod::nmethod_stub_entry_barrier(address* return_address_ptr) {
214207
}
215208

216209
bool BarrierSetNMethod::nmethod_osr_entry_barrier(nmethod* nm) {
217-
// This check depends on the invariant that all nmethods that are deoptimized / made not entrant
218-
// are NOT disarmed.
219-
// This invariant is important because a method can be deoptimized after the method have been
220-
// resolved / looked up by OSR by another thread. By not deoptimizing them we guarantee that
221-
// a deoptimized method will always hit the barrier and come to the same conclusion - deoptimize
222-
if (!is_armed(nm)) {
223-
return true;
224-
}
225-
226210
assert(nm->is_osr_method(), "Should not reach here");
227211
log_trace(nmethod, barrier)("Running osr nmethod entry barrier: " PTR_FORMAT, p2i(nm));
228212
bool result = nmethod_entry_barrier(nm);

0 commit comments

Comments
 (0)