RFR: 8291714: Implement a Multi-Reader Single-Writer mutex for Hotspot

Kim Barrett kbarrett at openjdk.org
Tue Aug 16 20:38:11 UTC 2022


On Thu, 11 Aug 2022 15:18:10 GMT, Johan Sjölén <duke at openjdk.org> wrote:

> May I please have a review for this PR which implements a `MRWMutex` class for Hotspot?
> 
> This PR does 3 things:
> 
> * Adds a port of ZGC's MRSW mutex (see [0]) to Hotspot
> * Adds some new utilities for writing multi-threaded tests.
> * Adds some tests for MRSW Mutex using these new utilities
> 
> The ticket has some comments which might be worth checking out: https://bugs.openjdk.org/browse/JDK-8291714
> 
> [0] Original source code here: https://github.com/openjdk/zgc/blob/zgc_generational/src/hotspot/share/gc/z/zJNICritical.cpp

src/hotspot/share/runtime/mrswMutex.hpp line 63:

> 61:     Locker(T* lock)
> 62:       : _lock(lock) {
> 63:       if (_lock != nullptr) {

When would it ever make sense for the `lock` argument to be nullptr?  Instead assert in the constructor that it is not?

src/hotspot/share/runtime/mrswMutex.hpp line 126:

> 124:       if (count != 0) {
> 125:         // Do requested transition before blocking
> 126:         WriterTransition tbivm(JavaThread::current());

These are only usable from JavaThreads.  One of the intended use-cases
involves UL.  UL is used from non-JavaThreads.  That seems like a problem
for the intended use-case, and possibly for others.  At the very least it should
be documented as being limited to JavaThread.

-------------

PR: https://git.openjdk.org/jdk/pull/9838


More information about the hotspot-dev mailing list