<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi Moh,<br>
    <br>
    <div class="moz-cite-prefix">On 06/01/2015 04:42 AM, Rezaei,
      Mohammad A. wrote:<br>
    </div>
    <blockquote
cite="mid:6882C9A35DFB9B4FA2779F7BF5B9757D20761169E3@GSCMAMP06EX.firmwide.corp.gs.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <meta name="Generator" content="Microsoft Word 14 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Consolas","serif";
        color:black;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:654452916;
        mso-list-type:hybrid;
        mso-list-template-ids:-1544270820 -1870497856 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:-;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Calibri","sans-serif";
        mso-fareast-font-family:Calibri;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The
            problems start with the ReferenceQueue object and the heavy
            synchronization in it. Consider structures like
            j.u.WeakHashMap that need to expunge entries. If such
            structures are made somewhat concurrent, the lock in
            ReferenceQueue starts to become a serious problem:<o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-.25in;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><span
              style="mso-list:Ignore">-<span style="font:7.0pt
                "Times New Roman"">          </span></span></span><!--[endif]--><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">In
            structures that are concurrent at the entry level (like jdk
            8’s ConcurrentHashMap), if methods like get() or put() try
            to expunge, the lock in ReferenceQueue renders the
            structures non-concurrent.</span></p>
      </div>
    </blockquote>
    <br>
    The presented prototype changes the implementation of
    ReferenceQueue. It doesn't use a lock any more for enqueu-ing when
    there are no waiters and never for poll-ing. ReferenceQueue.poll()
    is a single volatile read when queue is empty and a read followed by
    CAS when it is not (with retries when contended). If there is a
    desire and new API could be extended, the method like the following:<br>
    <br>
    Iterator<Reference<? extends T>> pollChunk(int
    maxChunkSize);<br>
    <br>
    ...could return a chunk of enqueued references (or an empty
    iterator) so that the reduced number of CAS instructions per
    de-queued reference could be traded for the greater probability of
    retries because of contention.<br>
    <br>
    <blockquote
cite="mid:6882C9A35DFB9B4FA2779F7BF5B9757D20761169E3@GSCMAMP06EX.firmwide.corp.gs.com"
      type="cite">
      <div class="WordSection1">
        <p class="MsoListParagraph"
          style="text-indent:-.25in;mso-list:l0 level1 lfo1"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-.25in;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><span
              style="mso-list:Ignore">-<span style="font:7.0pt
                "Times New Roman"">          </span></span></span><!--[endif]--><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">In
            structures that are multi-reader-single-writer locked, read
            methods cannot expunge (because they have to promote to a
            writer), but they can’t even check the queue, because that
            turns the multi-reader structure into a synchronized one.</span></p>
      </div>
    </blockquote>
    <br>
    By checking you mean poll() which also de-queues a reference if
    available? What do you do when this happens. Would you need a peek()
    method maybe?<br>
    <br>
    <blockquote
cite="mid:6882C9A35DFB9B4FA2779F7BF5B9757D20761169E3@GSCMAMP06EX.firmwide.corp.gs.com"
      type="cite">
      <div class="WordSection1">
        <p class="MsoListParagraph"
          style="text-indent:-.25in;mso-list:l0 level1 lfo1"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-.25in;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><span
              style="mso-list:Ignore">-<span style="font:7.0pt
                "Times New Roman"">          </span></span></span><!--[endif]--><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">In
            addition to expunge calls contending on the ReferenceQueue
            lock, ReferenceHandler thread can also contend on the same
            lock.</span></p>
      </div>
    </blockquote>
    <br>
    That's right. And in the presented prototype, this is minimized by
    allowing ReferenceHandler thread to enqueue a chunk of pre-prepared
    references in one go, minimizing the need to frequently notify any
    possible waiters via a lock.notifyAll().<br>
    <br>
    <blockquote
cite="mid:6882C9A35DFB9B4FA2779F7BF5B9757D20761169E3@GSCMAMP06EX.firmwide.corp.gs.com"
      type="cite">
      <div class="WordSection1">
        <p class="MsoListParagraph"
          style="text-indent:-.25in;mso-list:l0 level1 lfo1"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-.25in;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><span
              style="mso-list:Ignore">-<span style="font:7.0pt
                "Times New Roman"">          </span></span></span><!--[endif]--><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">There
            is no fast clear() method on ReferenceQueue. That would be
            quite useful on a resize event.</span></p>
      </div>
    </blockquote>
    <br>
    This would be easy to implement if new API could be added.<br>
    <br>
    <blockquote
cite="mid:6882C9A35DFB9B4FA2779F7BF5B9757D20761169E3@GSCMAMP06EX.firmwide.corp.gs.com"
      type="cite">
      <div class="WordSection1">
        <p class="MsoListParagraph"
          style="text-indent:-.25in;mso-list:l0 level1 lfo1"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The
            above issues forced us to have a dedicated thread that does
            periodic expunging of References. This works ok under light
            load, but can fall behind under heavy load.</span></p>
      </div>
    </blockquote>
    <br>
    Because of the overhead/bottleneck of the reference processing I
    assume. It would be great if you could check whether the prototype
    in webrev.02 improves your situation. It should be simple. Just
    compile the sources and prepend the resulting classes to the
    bootclasspath of the JDK.<br>
    <br>
    Regards, Peter<br>
    <br>
    <blockquote
cite="mid:6882C9A35DFB9B4FA2779F7BF5B9757D20761169E3@GSCMAMP06EX.firmwide.corp.gs.com"
      type="cite">
      <div class="WordSection1">
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Thanks<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Moh<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
        <div style="border:none;border-left:solid blue 1.5pt;padding:0in
          0in 0in 4.0pt">
          <p class="MsoNormal" style="margin-left:5.25pt">@Moh<br>
            <br>
            Can you elaborate some more on what twists were necessary or
            what problems you had?<br>
            <br>
            <br>
            <span style="color:#1F497D"><o:p></o:p></span></p>
          <p class="MsoNormal" style="margin-bottom:12.0pt"><span
              style="color:#1F497D"><o:p> </o:p></span></p>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>