JDK-8242464 : Bug in the logic of ConcurrentHashMap.addCount() when used in Threads
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 12
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2020-04-08
  • Updated: 2020-08-05
Related Reports
Relates :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
At java.util.concurrent.ConcurrentHashMap#addCount:2339
i think the condition is if the thread is reach maximum or the new table size is twice as before or the nextTable is null or the transferIndex is lesss than zero; the bug in jdk8 is "https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8214427" , i think the main thing is not one is positive another is negtive, but the new table size is twice as before.
at jdk12 i think is not fix it, "sc == rs + 1" compare the work thread but not array size, i think the code should be 

if (sc == rs + MAX_RESIZERS || (sc >>>RESIZE_STAMP_SHIFT) == (rs>>>RESIZE_STAMP_SHIFT) + 1 ||
                        (nt = nextTable) == null || transferIndex <= 0)
                        break;
rather than 

if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
                        sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
                        transferIndex <= 0)
                        break;

REGRESSION : Last worked in version 8


FREQUENCY : always



Comments
Additional Information from Submiiter: I am so sorry for submiting it. at jdk 1.8 "java.util.concurrent.ConcurrentHashMap#helpTransfer:2304", i think "(sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 " is check the array size ,but yesterday i found that thinking of " sc == rs + 1" as checking the count of thread was better.
14-04-2020

I don't think it's useful for Chris to investigate. I will assign to Doug. But we need better input from the reporter.
09-04-2020

We need a clearer explanation of what we're fixing here. Please provide fixes in the form of a diff. We should have a simple repro of any misbehavior. Perhaps another test could be added to test/jdk/java/util/concurrent/ConcurrentHashMap/WhiteBox.java If there's a race in the resizing code, then yes that is hard to test.
09-04-2020

Moving to Dev Team for further evaluation
09-04-2020