Skip to content

Commit c30e040

Browse files
neethu-prasadshipilev
authored andcommitted
8331911: Reconsider locking for recently disarmed nmethods
Reviewed-by: shade, eosterlund
1 parent 974dca8 commit c30e040

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

src/hotspot/share/code/nmethod.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,10 +844,8 @@ void nmethod::run_nmethod_entry_barrier() {
844844
// By calling this nmethod entry barrier, it plays along and acts
845845
// like any other nmethod found on the stack of a thread (fewer surprises).
846846
nmethod* nm = this;
847-
if (bs_nm->is_armed(nm)) {
848-
bool alive = bs_nm->nmethod_entry_barrier(nm);
849-
assert(alive, "should be alive");
850-
}
847+
bool alive = bs_nm->nmethod_entry_barrier(nm);
848+
assert(alive, "should be alive");
851849
}
852850
}
853851

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ bool BarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) {
100100
virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
101101
};
102102

103+
if (!is_armed(nm)) {
104+
// Some other thread got here first and healed the oops
105+
// and disarmed the nmethod. No need to continue.
106+
return true;
107+
}
108+
103109
// If the nmethod is the only thing pointing to the oops, and we are using a
104110
// SATB GC, then it is important that this code marks them live.
105111
// Also, with concurrent GC, it is possible that frames in continuation stack
@@ -172,6 +178,9 @@ int BarrierSetNMethod::nmethod_stub_entry_barrier(address* return_address_ptr) {
172178
nmethod* nm = cb->as_nmethod();
173179
BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
174180

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.
175184
if (!bs_nm->is_armed(nm)) {
176185
return 0;
177186
}

src/hotspot/share/gc/x/xBarrierSetNMethod.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@
3232
#include "runtime/threadWXSetters.inline.hpp"
3333

3434
bool XBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) {
35+
if (!is_armed(nm)) {
36+
// Some other thread got here first and healed the oops
37+
// and disarmed the nmethod. No need to continue.
38+
return true;
39+
}
40+
3541
XLocker<XReentrantLock> locker(XNMethod::lock_for_nmethod(nm));
3642
log_trace(nmethod, barrier)("Entered critical zone for %p", nm);
3743

3844
if (!is_armed(nm)) {
39-
// Some other thread got here first and healed the oops
40-
// and disarmed the nmethod.
45+
// Some other thread managed to complete while we were
46+
// waiting for lock. No need to continue.
4147
return true;
4248
}
4349

src/hotspot/share/gc/z/zBarrierSetNMethod.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,22 @@
3737
#include "runtime/threadWXSetters.inline.hpp"
3838

3939
bool ZBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) {
40+
if (!is_armed(nm)) {
41+
log_develop_trace(gc, nmethod)("nmethod: " PTR_FORMAT " visited by entry (disarmed before lock)", p2i(nm));
42+
// Some other thread got here first and healed the oops
43+
// and disarmed the nmethod. No need to continue.
44+
return true;
45+
}
46+
4047
ZLocker<ZReentrantLock> locker(ZNMethod::lock_for_nmethod(nm));
4148
log_trace(nmethod, barrier)("Entered critical zone for %p", nm);
4249

4350
log_develop_trace(gc, nmethod)("nmethod: " PTR_FORMAT " visited by entry (try)", p2i(nm));
4451

4552
if (!is_armed(nm)) {
4653
log_develop_trace(gc, nmethod)("nmethod: " PTR_FORMAT " visited by entry (disarmed)", p2i(nm));
47-
// Some other thread got here first and healed the oops
48-
// and disarmed the nmethod.
54+
// Some other thread managed to complete while we were
55+
// waiting for lock. No need to continue.
4956
return true;
5057
}
5158

0 commit comments

Comments
 (0)