RFR (S): 8228857: Refactor PlatformMonitor into PlatformMutex and PlatformMonitor
    David Holmes 
    david.holmes at oracle.com
       
    Thu Aug  8 02:51:41 UTC 2019
    
    
  
Hi Kim,
On 8/08/2019 11:59 am, Kim Barrett wrote:
>> On Aug 1, 2019, at 7:03 PM, David Holmes <david.holmes at oracle.com> wrote:
>>
>> Bug: https://bugs.openjdk.java.net/browse/JDK-8228857
>> webrev: http://cr.openjdk.java.net/~dholmes/8228857/webrev/
>>
>> As suggested by Per Liden when PlatformMonitor was introduced by JDK-8210832 we should refactor PlatformMonitor into a simpler PlatformMutex extended by PlatformMonitor. That would potentially allow other synchronization objects e.g. Zlocks, to be replaced by a suitable PlatformX class, and allows us to redefine JVM_RawMonitor support to use it (forthcoming change).
>>
>> The refactoring would be obvious and simple if not for the macOS PThread allocation bug workaround. I had to change the Posix variant so that we only use the Impl helper class on macOS, so that we can separate the allocation of the pthread_mutex_t and pthread_cond_t. For macOS both get allocated in the PlatformMutex.
>>
>> There are not actual usage changes in this RFE.
>>
>> Testing: mach5 tiers 1-3
>>
>> Thanks,
>> David
>> -----
> 
> PlatformMutex should be noncopyable on all platforms.
I presume that is something PlatformMonitor should already be doing but 
is not? What is involved in making something non-copyable? (Sorry my 
basic C++ is pretty basic.)
> The inheritance runs the risk of destructor slicing, because the
> PlatformMutex base class has a public non-virtual destructor. I don't
> think we want to introduce a virtual destructor here. I don't know of
> a solution that doesn't lose the inheritance relationship between the
> classes. I don't know if that relationship is considered important.
Semantically a Monitor (as we define it) is a Mutex with a condition 
variable, so the inheritance seems quite appropriate, even if not essential.
IIUC the issue is when we have a PlatformMutex* that happens to point to 
a PlatformMonitor - if we delete it then we only call the PlatformMutex 
destructor. Why would we not just declare the destructor as virtual? 
What will it cost us? It seems the natural/right way to deal with 
inheritance in C++.
Thanks,
David
-----
    
    
More information about the hotspot-dev
mailing list