Skip to content

Commit

Permalink
8264742: member variable _monitor of MonitorLocker is redundant
Browse files Browse the repository at this point in the history
Reviewed-by: coleenp, dholmes, phh
  • Loading branch information
Xin Liu authored and Paul Hohensee committed Apr 7, 2021
1 parent 7a99a98 commit 774e5ae
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/hotspot/share/runtime/mutexLocker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ void assert_locked_or_safepoint_or_handshake(const Mutex* lock, const JavaThread
class MutexLocker: public StackObj {
protected:
Mutex* _mutex;
private:
public:
MutexLocker(Mutex* mutex, Mutex::SafepointCheckFlag flag = Mutex::_safepoint_check_flag) :
_mutex(mutex) {
Expand Down Expand Up @@ -242,36 +241,41 @@ class MutexLocker: public StackObj {

class MonitorLocker: public MutexLocker {
Mutex::SafepointCheckFlag _flag;
Monitor* _monitor;

protected:
Monitor* as_monitor() const {
return static_cast<Monitor*>(_mutex);
}

public:
MonitorLocker(Monitor* monitor, Mutex::SafepointCheckFlag flag = Mutex::_safepoint_check_flag) :
MutexLocker(monitor, flag), _flag(flag), _monitor(monitor) {
MutexLocker(monitor, flag), _flag(flag) {
// Superclass constructor did locking
assert(_monitor != NULL, "NULL monitor not allowed");
assert(monitor != NULL, "NULL monitor not allowed");
}

MonitorLocker(Thread* thread, Monitor* monitor, Mutex::SafepointCheckFlag flag = Mutex::_safepoint_check_flag) :
MutexLocker(thread, monitor, flag), _flag(flag), _monitor(monitor) {
MutexLocker(thread, monitor, flag), _flag(flag) {
// Superclass constructor did locking
assert(_monitor != NULL, "NULL monitor not allowed");
assert(monitor != NULL, "NULL monitor not allowed");
}

bool wait(int64_t timeout = 0,
bool as_suspend_equivalent = !Mutex::_as_suspend_equivalent_flag) {
if (_flag == Mutex::_safepoint_check_flag) {
return _monitor->wait(timeout, as_suspend_equivalent);
return as_monitor()->wait(timeout, as_suspend_equivalent);
} else {
return _monitor->wait_without_safepoint_check(timeout);
return as_monitor()->wait_without_safepoint_check(timeout);
}
return false;
}

void notify_all() {
_monitor->notify_all();
as_monitor()->notify_all();
}

void notify() {
_monitor->notify();
as_monitor()->notify();
}
};

Expand Down

1 comment on commit 774e5ae

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.