Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8215409

probable bug in logic of ConcurrentHashMap.tryPresize()

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
       private final void tryPresize(int size) {
              int c = (size >= (MAXIMUM_CAPACITY >>> 1)) ? MAXIMUM_CAPACITY :
                  tableSizeFor(size + (size >>> 1) + 1);
              int sc;
              while ((sc = sizeCtl) >= 0) {
                  Node<K,V>[] tab = table; int n;
                  if (tab == null || (n = tab.length) == 0) {
                     ...
                  }
                  else if (c <= sc || n >= MAXIMUM_CAPACITY)
                      break;
                  else if (tab == table) {
                      int rs = resizeStamp(n);
                      if (sc < 0) {
                          Node<K,V>[] nt;
                          if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
                              sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
                              transferIndex <= 0)
                              break;
                          if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1))
                              transfer(tab, nt);
                      }
                      else if (U.compareAndSwapInt(this, SIZECTL, sc,
                                                   (rs << RESIZE_STAMP_SHIFT) + 2))
                          transfer(tab, null);
                  }
              }
          }

      In the above code, condition of sc<0 would never be true , since the condition of while ((sc = sizeCtl) >= 0) would be true .






        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: