RFR: 8322853: Should use ConditionalMutexLocker in NativeHeapTrimmerThread::print_state

Denghui Dong ddong at openjdk.org
Wed Jan 3 03:36:46 UTC 2024


On Wed, 3 Jan 2024 01:49:40 GMT, David Holmes <dholmes at openjdk.org> wrote:

> ConditionalMutexLocker change is fine
> 
> > Also, this patch made '_stop' volatile, since it will be read twice in run() but may be changed.
> 
> The only way it can be changed is if a `wait` is done which releases and reacquires the mutex, and the variable is only set while holding the mutex, so reading it twice in run is perfectly safe without it being volatile.

Thanks for the review.

Regarding `_stop`,  I think the compiler can optimize out the second `if` branch(L127) if `_stop` is not volatile.

![image](https://github.com/openjdk/jdk/assets/33491035/2cd38545-3279-4f6b-9b9f-b3647e785cf3)

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

PR Comment: https://git.openjdk.org/jdk/pull/17226#issuecomment-1874810511


More information about the hotspot-runtime-dev mailing list