JDK-8222034 : Thread-SMR functions should be updated to remove work around
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 13
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2019-04-05
  • Updated: 2019-08-15
  • Resolved: 2019-04-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 13
13 b17Fixed
Related Reports
Relates :  
Relates :  
Description
On 4/5/19 12:01 PM, Daniel D. Daugherty wrote:
> On 4/5/19 8:37 AM, Doerr, Martin wrote:
>> Hi everybody,
>>
>>> I think was fixed with:
>>> 8202080: Introduce ordering semantics for Atomic::add/inc and other RMW atomics
>>> You should get a leading sync and trailing one with the default conservative
>>> model and thus get proper memory ordering.
>>> Martin, I'm I correct? 
>> Exactly. Thanks for pointing this out. PPC uses the strongest possible ordering semantics with memory_order_conservative (default parameter).
>> I've seen that comment about PPC in "void ThreadsList::inc_nested_handle_cnt()". This function could get replaced. 
>
> Okay so we need a new bug to update these two Thread-SMR functions:
>
> src/hotspot/share/runtime/threadSMR.cpp:
>
> void ThreadsList::dec_nested_handle_cnt() {
>   // The decrement needs to be MO_ACQ_REL. At the moment, the Atomic::dec
>   // backend on PPC does not yet conform to these requirements. Therefore
>   // the decrement is simulated with an Atomic::sub(1, &addr).
>   // Without this MO_ACQ_REL Atomic::dec simulation, the nested SMR mechanism
>   // is not generally safe to use.
>   Atomic::sub(1, &_nested_handle_cnt);
> }
>
> void ThreadsList::inc_nested_handle_cnt() {
>   // The increment needs to be MO_SEQ_CST. At the moment, the Atomic::inc
>   // backend on PPC does not yet conform to these requirements. Therefore
>   // the increment is simulated with a load phi; cas phi + 1; loop.
>   // Without this MO_SEQ_CST Atomic::inc simulation, the nested SMR mechanism
>   // is not generally safe to use.
>   intx sample = OrderAccess::load_acquire(&_nested_handle_cnt);
>   for (;;) {
>     if (Atomic::cmpxchg(sample + 1, &_nested_handle_cnt, sample) == sample) {
>       return;
>     } else {
>       sample = OrderAccess::load_acquire(&_nested_handle_cnt);
>     }
>   }
> }
>
> I'll file a new bug, loop in Robbin, Erik O and Martin, and make
> sure we're all in agreement. Once we decide that Thread-SMR's
> functions look like, I'll adapt my Async Monitor Deflation
> functions...
>
> Dan 
Comments
I went thru my email archive for JDK-8191798 and dug out the reason for using MO_SEQ_CST on the increment and MO_ACQ_REL on the decrement. I'm planning to change the comments and code to look like this: void ThreadsList::dec_nested_handle_cnt() { // The decrement only needs to be MO_ACQ_REL since the reference // counter is volatile (and the hazard ptr is already NULL). Atomic::dec(&_nested_handle_cnt); } void ThreadsList::inc_nested_handle_cnt() { // The increment needs to be MO_SEQ_CST so that the reference counter // update is seen before the subsequent hazard ptr update. Atomic::inc(&_nested_handle_cnt); } [~eosterlund] and [~mdoerr] - Are you guys good with this?
09-04-2019

An email comment from Martin on the other thread: On 4/8/19 12:23 PM, Doerr, Martin wrote: > Hi Dan, > > thanks for addressing this issue. I appreciate it. > > I wonder if the comments are correct. Does dec_nested_handle_cnt really only need MO_ACQ_REL while inc_nested_handle_cnt needs MO_SEQ_CST? > I don't see comments explaining what was intended to get ordered. > > I guess we can just use memory_order_conservative (default). Shouldn't be performance critical. > > Best regards, > Martin
09-04-2019

Right, I wrote that code as a work around for Atomic::inc/dec having the wrong memory ordering semantics on PPC, and I was being nice not wanting to break the PPC port. That has been fixed since then, and we should simply use Atomic::inc/dec now instead. I forgot about this code...
05-04-2019

$ hg annot src/hotspot/share/runtime/threadSMR.cpp | egrep 'The decrement needs to be MO_ACQ_REL|The increment needs to be MO_SEQ_CST' 49956: // The decrement needs to be MO_ACQ_REL. At the moment, the Atomic::dec 49956: // The increment needs to be MO_SEQ_CST. At the moment, the Atomic::inc $ hg log -v -r 49956 changeset: 49956:a87f2e7a527c user: dcubed date: Wed May 02 16:47:40 2018 -0400 files: src/hotspot/share/runtime/thread.cpp src/hotspot/share/runtime/thread.hpp src/hotspot/share/runtime/threadSMR.cpp src/hotspot/share/runtime/threadSMR.hpp src/hotspot/share/runtime/threadSMR.inline.hpp src/hotspot/share/services/threadService.hpp test/hotspot/jtreg/runtime/ErrorHandling/NestedThreadsListHandleInErrorHandlingTest.java test/hotspot/jtreg/runtime/ErrorHandling/ThreadsListHandleInErrorHandlingTest.java description: 8191798: redo nested ThreadsListHandle to drop Threads_lock Summary: Refactor Thread hazard ptrs and nested ThreadsLists into SafeThreadsListPtr. Reviewed-by: dcubed, eosterlund, rehn Contributed-by: erik.osterlund@oracle.com, daniel.daugherty@oracle.com If I remember correctly, I got the original patch from Erik, ran it through my stress testing setup in my lab and then I shepherded the fix thru review and push.
05-04-2019