Skip to content

Commit 7208bfb

Browse files
author
duke
committed
Automatic merge of jdk:master into master
2 parents de22d5f + 2b15571 commit 7208bfb

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/hotspot/os/posix/os_posix.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ class PlatformParker : public CHeapObj<mtSynchronizer> {
211211
#define PLATFORM_MONITOR_IMPL_INDIRECT 0
212212
#endif
213213

214-
// Platform specific implementations that underpin VM Mutex/Monitor classes
214+
// Platform specific implementations that underpin VM Mutex/Monitor classes.
215+
// Note that we use "normal" pthread_mutex_t attributes so that recursive
216+
// locking is not supported, which matches the expected semantics of the
217+
// VM Mutex class.
215218

216219
class PlatformMutex : public CHeapObj<mtSynchronizer> {
217220
#if PLATFORM_MONITOR_IMPL_INDIRECT

src/hotspot/os/windows/os_windows.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ class PlatformParker : public CHeapObj<mtSynchronizer> {
187187

188188
} ;
189189

190-
// Platform specific implementations that underpin VM Mutex/Monitor classes
190+
// Platform specific implementations that underpin VM Mutex/Monitor classes.
191+
// Note that CRITICAL_SECTION supports recursive locking, while the semantics
192+
// of the VM Mutex class does not. It is up to the Mutex class to hide this
193+
// difference in behaviour.
191194

192195
class PlatformMutex : public CHeapObj<mtSynchronizer> {
193196
NONCOPYABLE(PlatformMutex);

src/hotspot/share/runtime/mutex.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,14 @@ void Mutex::lock_without_safepoint_check() {
137137

138138

139139
// Returns true if thread succeeds in grabbing the lock, otherwise false.
140-
141140
bool Mutex::try_lock() {
142141
Thread * const self = Thread::current();
143142
// Some safepoint_check_always locks use try_lock, so cannot check
144143
// safepoint state, but can check blocking state.
145144
check_block_state(self);
146-
if (_lock.try_lock()) {
145+
// Checking the owner hides the potential difference in recursive locking behaviour
146+
// on some platforms.
147+
if (_owner != self && _lock.try_lock()) {
147148
assert_owner(NULL);
148149
set_owner(self);
149150
return true;

src/hotspot/share/runtime/mutex.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
// variable that supports lock ownership tracking, lock ranking for deadlock
3333
// detection and coordinates with the safepoint protocol.
3434

35+
// Locking is non-recursive: if you try to lock a mutex you already own then you
36+
// will get an assertion failure in a debug build (which should suffice to expose
37+
// usage bugs). If you call try_lock on a mutex you already own it will return false.
38+
// The underlying PlatformMutex may support recursive locking but this is not exposed
39+
// and we account for that possibility in try_lock.
40+
3541
// The default length of mutex name was originally chosen to be 64 to avoid
3642
// false sharing. Now, PaddedMutex and PaddedMonitor are available for this purpose.
3743
// TODO: Check if _name[MUTEX_NAME_LEN] should better get replaced by const char*.

0 commit comments

Comments
 (0)