8059846: InstanceKlass should use MutexLockerEx to acquire OsrList_lock

Replace explicit locking of OsrList_lock by a MutexLockerEx instantiation.

Reviewed-by: kvn, anoll, drchase, dholmes, dlong, coleenp
This commit is contained in:
Tobias Hartmann 2014-10-16 12:57:04 +02:00
parent ed26c7e640
commit a87b3d13df

View file

@ -2779,19 +2779,18 @@ void InstanceKlass::adjust_default_methods(Method** old_methods, Method** new_me
// On-stack replacement stuff // On-stack replacement stuff
void InstanceKlass::add_osr_nmethod(nmethod* n) { void InstanceKlass::add_osr_nmethod(nmethod* n) {
// only one compilation can be active // only one compilation can be active
NEEDS_CLEANUP {
// This is a short non-blocking critical region, so the no safepoint check is ok. // This is a short non-blocking critical region, so the no safepoint check is ok.
OsrList_lock->lock_without_safepoint_check(); MutexLockerEx ml(OsrList_lock, Mutex::_no_safepoint_check_flag);
assert(n->is_osr_method(), "wrong kind of nmethod"); assert(n->is_osr_method(), "wrong kind of nmethod");
n->set_osr_link(osr_nmethods_head()); n->set_osr_link(osr_nmethods_head());
set_osr_nmethods_head(n); set_osr_nmethods_head(n);
// Raise the highest osr level if necessary // Raise the highest osr level if necessary
if (TieredCompilation) { if (TieredCompilation) {
Method* m = n->method(); Method* m = n->method();
m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level())); m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level()));
}
} }
// Remember to unlock again
OsrList_lock->unlock();
// Get rid of the osr methods for the same bci that have lower levels. // Get rid of the osr methods for the same bci that have lower levels.
if (TieredCompilation) { if (TieredCompilation) {
@ -2807,7 +2806,7 @@ void InstanceKlass::add_osr_nmethod(nmethod* n) {
void InstanceKlass::remove_osr_nmethod(nmethod* n) { void InstanceKlass::remove_osr_nmethod(nmethod* n) {
// This is a short non-blocking critical region, so the no safepoint check is ok. // This is a short non-blocking critical region, so the no safepoint check is ok.
OsrList_lock->lock_without_safepoint_check(); MutexLockerEx ml(OsrList_lock, Mutex::_no_safepoint_check_flag);
assert(n->is_osr_method(), "wrong kind of nmethod"); assert(n->is_osr_method(), "wrong kind of nmethod");
nmethod* last = NULL; nmethod* last = NULL;
nmethod* cur = osr_nmethods_head(); nmethod* cur = osr_nmethods_head();
@ -2844,13 +2843,11 @@ void InstanceKlass::remove_osr_nmethod(nmethod* n) {
} }
m->set_highest_osr_comp_level(max_level); m->set_highest_osr_comp_level(max_level);
} }
// Remember to unlock again
OsrList_lock->unlock();
} }
nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const { nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const {
// This is a short non-blocking critical region, so the no safepoint check is ok. // This is a short non-blocking critical region, so the no safepoint check is ok.
OsrList_lock->lock_without_safepoint_check(); MutexLockerEx ml(OsrList_lock, Mutex::_no_safepoint_check_flag);
nmethod* osr = osr_nmethods_head(); nmethod* osr = osr_nmethods_head();
nmethod* best = NULL; nmethod* best = NULL;
while (osr != NULL) { while (osr != NULL) {
@ -2866,14 +2863,12 @@ nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_le
if (match_level) { if (match_level) {
if (osr->comp_level() == comp_level) { if (osr->comp_level() == comp_level) {
// Found a match - return it. // Found a match - return it.
OsrList_lock->unlock();
return osr; return osr;
} }
} else { } else {
if (best == NULL || (osr->comp_level() > best->comp_level())) { if (best == NULL || (osr->comp_level() > best->comp_level())) {
if (osr->comp_level() == CompLevel_highest_tier) { if (osr->comp_level() == CompLevel_highest_tier) {
// Found the best possible - return it. // Found the best possible - return it.
OsrList_lock->unlock();
return osr; return osr;
} }
best = osr; best = osr;
@ -2882,7 +2877,6 @@ nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_le
} }
osr = osr->osr_link(); osr = osr->osr_link();
} }
OsrList_lock->unlock();
if (best != NULL && best->comp_level() >= comp_level && match_level == false) { if (best != NULL && best->comp_level() >= comp_level && match_level == false) {
return best; return best;
} }