8267653: Remove Mutex::_safepoint_check_sometimes

Reviewed-by: dholmes, pchilanomate
This commit is contained in:
Coleen Phillimore 2021-05-26 19:07:53 +00:00
parent de91643bfa
commit c59484e715
5 changed files with 7 additions and 22 deletions

View File

@ -540,7 +540,7 @@ void ShenandoahReferenceProcessor::enqueue_references(bool concurrent) {
enqueue_references_locked();
} else {
// Heap_lock protects external pending list
MonitorLocker ml(Heap_lock, Mutex::_no_safepoint_check_flag);
MonitorLocker ml(Heap_lock);
enqueue_references_locked();

View File

@ -261,11 +261,6 @@ Mutex::~Mutex() {
os::free(const_cast<char*>(_name));
}
// Only Threads_lock and Heap_lock may be safepoint_check_sometimes.
bool is_sometimes_ok(const char* name) {
return (strcmp(name, "Threads_lock") == 0 || strcmp(name, "Heap_lock") == 0);
}
Mutex::Mutex(int Rank, const char * name, bool allow_vm_block,
SafepointCheckRequired safepoint_check_required) : _owner(NULL) {
assert(os::mutex_init_done(), "Too early!");
@ -277,9 +272,6 @@ Mutex::Mutex(int Rank, const char * name, bool allow_vm_block,
_safepoint_check_required = safepoint_check_required;
_skip_rank_check = false;
assert(_safepoint_check_required != _safepoint_check_sometimes || is_sometimes_ok(name),
"Lock has _safepoint_check_sometimes %s", name);
assert(_rank > special || _safepoint_check_required == _safepoint_check_never,
"Special locks or below should never safepoint");
#endif
@ -306,7 +298,6 @@ void Mutex::print_on_error(outputStream* st) const {
const char* print_safepoint_check(Mutex::SafepointCheckRequired safepoint_check) {
switch (safepoint_check) {
case Mutex::_safepoint_check_never: return "safepoint_check_never";
case Mutex::_safepoint_check_sometimes: return "safepoint_check_sometimes";
case Mutex::_safepoint_check_always: return "safepoint_check_always";
default: return "";
}

View File

@ -132,11 +132,6 @@ class Mutex : public CHeapObj<mtSynchronizer> {
// _safepoint_check_never, that means that whenever the lock is acquired by a JavaThread
// it will verify that it is done without a safepoint check.
// There are a couple of existing locks that will sometimes have a safepoint check and
// sometimes not when acquired by a JavaThread, but these locks are set up carefully
// to avoid deadlocks. TODO: Fix these locks and remove _safepoint_check_sometimes.
// TODO: Locks that are shared between JavaThreads and NonJavaThreads
// should never encounter a safepoint check while they are held, or else a
// deadlock can occur. We should check this by noting which
@ -155,17 +150,12 @@ class Mutex : public CHeapObj<mtSynchronizer> {
enum class SafepointCheckRequired {
_safepoint_check_never, // Mutexes with this value will cause errors
// when acquired by a JavaThread with a safepoint check.
_safepoint_check_sometimes, // A couple of special locks are acquired by JavaThreads sometimes
// with and sometimes without safepoint checks. These
// locks will not produce errors when locked.
_safepoint_check_always // Mutexes with this value will cause errors
// when acquired by a JavaThread without a safepoint check.
};
// Bring the enumerator names into class scope.
static const SafepointCheckRequired _safepoint_check_never =
SafepointCheckRequired::_safepoint_check_never;
static const SafepointCheckRequired _safepoint_check_sometimes =
SafepointCheckRequired::_safepoint_check_sometimes;
static const SafepointCheckRequired _safepoint_check_always =
SafepointCheckRequired::_safepoint_check_always;

View File

@ -285,7 +285,7 @@ void mutex_init() {
def(JNICritical_lock , PaddedMonitor, nonleaf, true, _safepoint_check_always); // used for JNI critical regions
def(AdapterHandlerLibrary_lock , PaddedMutex , nonleaf, true, _safepoint_check_always);
def(Heap_lock , PaddedMonitor, nonleaf+1, false, _safepoint_check_sometimes); // Doesn't safepoint check during termination.
def(Heap_lock , PaddedMonitor, nonleaf+1, false, _safepoint_check_always); // Doesn't safepoint check during termination.
def(JfieldIdCreation_lock , PaddedMutex , nonleaf+1, true, _safepoint_check_always); // jfieldID, Used in VM_Operation
def(CompiledIC_lock , PaddedMutex , nonleaf+2, false, _safepoint_check_never); // locks VtableStubs_lock, InlineCacheBuffer_lock

View File

@ -3416,8 +3416,12 @@ void Threads::destroy_vm() {
// to prevent this. The GC vm_operations will not be able to
// queue until after the vm thread is dead. After this point,
// we'll never emerge out of the safepoint before the VM exits.
// Assert that the thread is terminated so that acquiring the
// Heap_lock doesn't cause the terminated thread to participate in
// the safepoint protocol.
MutexLocker ml(Heap_lock, Mutex::_no_safepoint_check_flag);
assert(thread->is_terminated(), "must be terminated here");
MutexLocker ml(Heap_lock);
VMThread::wait_for_vm_thread_exit();
assert(SafepointSynchronize::is_at_safepoint(), "VM thread should exit at Safepoint");