RFR: 8268638: semaphores of AsyncLogWriter may be broken when JVM is exiting. [v2]

Xin Liu xliu at openjdk.java.net
Mon Jun 14 23:40:47 UTC 2021


On Mon, 14 Jun 2021 10:53:23 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> Xin Liu has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Support --with-debug-level=optimized.
>>   
>>   release build with debug level optimized doesn't define PRODUCT.
>>   use ASSERT instead.
>
> src/hotspot/share/logging/logAsyncWriter.cpp line 36:
> 
>> 34:  public:
>> 35:   AsyncLogLocker(Semaphore* sem): _sem(sem) {
>> 36:     assert(sem != nullptr && sem->value() == 1,
> 
> The value() check is not necessary. Please do not pollute the Semaphore API with this.
> 
> Rather than passing the Semaphore in it should just be accessed directly as there is only one Semaphore to ever be used here. Make AsyncLogLocker a friend class to allow access.

Thanks.  I remove Semaphore::value() and declare friend class SemaphoreLocker there. 

My intention is to do a sanity check. A semaphore can be used to implement a low-level lock if and only if its value is 1. It means that only one thread can enter the critical region at any time.  However, it's error-prone for the RAII class to accept any arbitrary semaphore. It's because its value could be any non-negative number.

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

PR: https://git.openjdk.java.net/jdk/pull/4479


More information about the hotspot-runtime-dev mailing list