RFR: 8264393: JDK-8258284 introduced dangling TLH race [v2]

David Holmes dholmes at openjdk.java.net
Wed Mar 31 00:31:08 UTC 2021


On Tue, 30 Mar 2021 21:13:35 GMT, Daniel D. Daugherty <dcubed at openjdk.org> wrote:

>> I ported some 20 year old tests using JDK-8262881 in order to help
>> test [~rehn]'s fix for JDK-8257831. These tests in combination with
>> one piece of the fix from JDK-8257831 revealed a bug in my fix for
>> JDK-8258284 from back in Dec 2020.
>> 
>> The race revealed by the ported tests from JDK-8262881 happens
>> only with nested ThreadsListHandles. When TLH2 is destroyed, the
>> thread updates its threads_hazard_ptr from the TLH2-list to the
>> TLH1-list; I made this change back in 2020.12 using JDK-8258284.
>> The threads_hazard_ptr can be observed by a thread calling
>> ThreadsSMRSupport::free_list() as a stable ThreadsList at the same
>> time as the TLH1 destructor is decrementing the nested_handle_cnt
>> that permits the ThreadsList to be freed. So the thread calling
>> ThreadsSMRSupport::free_list() thinks it has a stable hazard ptr
>> (TLH1-list), but that hazard ptr can be freed and causes lots of
>> confusion.
>> 
>> Update: This fix along with the fix from JDK-8264123 were stress
>> tested with the new tests from JDK-8262881.
>
> Daniel D. Daugherty has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix two more ThreadsListHandle tests.

Hi Dan,

So in a nutshell, when clearing a nested TLH you can't simply install the previous TLH as the threads_hazard_ptr, but instead set to NULL so that it is properly set by acquire_stable_list.

This seems reasonable to me.

Thanks,
David

src/hotspot/share/runtime/threadSMR.cpp line 542:

> 540:     // And that protocol cannot be properly done with a ThreadsList that
> 541:     // might not be the current system ThreadsList.
> 542:     assert(_previous->_list->_nested_handle_cnt > 0, "must be > than zero");

Nit: "> than" reads "greater than than".

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

Marked as reviewed by dholmes (Reviewer).

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


More information about the hotspot-runtime-dev mailing list