<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    Hi Samuel,<br>
    <br>
    I’ll try to answer your questions below.<br>
    <br>
    <div class="moz-cite-prefix">On 5/1/25 5:43 AM, Samuel Chee wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:AS2PR08MB100348649F4923C6470BBF1C2ED822@AS2PR08MB10034.eurprd08.prod.outlook.com">
      
      <style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
      <div class="elementToProof" style="font-family: Aptos,
        Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica,
        sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        Hello,<br>
        <br>
      </div>
      <div class="elementToProof" style="font-family: Aptos,
        Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica,
        sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        I was looking at whether it would be valid to remove the acquire
        from safepoint_poll completely from here which emits an ldar
        instead of a ldr for memory ordering. [1] As currently, there is
        only a single instance of this argument being used, in the
        panama downstream ffi. [2]</div>
      <div class="elementToProof" style="font-family: Aptos,
        Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica,
        sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        And similar changes have been made to remove the acquire
        argument from other native methods [3] with the reasoning being
        that threads now disarm their own poll value and hence an ldar
        is no longer needed. Hence the same reasoning should apply when
        removing the acquire from the safepoint_poll used in the panama
        ffi and all other uses of safepoint_poll (especially since
        panama ffi is the only one which uses acquire). If it applies,
        this means the acquire argument functionality should be able to
        be removed completely from the safepoint_poll method.<br>
        <br>
      </div>
      <div style="font-family: Aptos, Aptos_EmbeddedFont,
        Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size:
        12pt; color: rgb(0, 0, 0);">
        This change seemed to have been allowed when concurrent
        thread-stack processing and watermarking was introduced and the
        SafepointMechanism::update_poll_values method was updated such
        that the poll value could not be armed when leaving this method.
        [4] [5] As previously this may have not been the case as it
        could exit this function with an armed poll value. [6]</div>
      <div class="elementToProof" style="font-family: Aptos,
        Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica,
        sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        Given the complexity of the code - particularly around
        safepoints and thread-handshake mechanisms, which have evolved
        significantly over time - I’d like to clarify a few aspects to
        ensure this change is correct.<br>
        My questions are:<br>
        <br>
      </div>
      <div class="elementToProof" style="font-family: Aptos,
        Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica,
        sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        1. What specifically allowed this change to be made to the other
        JNIs? Why is the ldar acquire no longer needed?<br>
      </div>
    </blockquote>
    As you found out from [1], the race is no longer present after
    JavaThreads disarm themselves. The race is well described by Erik in
    the links posted on that initial email.<br>
    <br>
    <blockquote type="cite" cite="mid:AS2PR08MB100348649F4923C6470BBF1C2ED822@AS2PR08MB10034.eurprd08.prod.outlook.com">
      <div class="elementToProof" style="font-family: Aptos,
        Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica,
        sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        2. Is there a reason why this was not done to the panama FFI
        safepoint_poll when the acquire arguments were removed from the
        other JNIs in [3]?<br>
      </div>
    </blockquote>
    Seems the patch just meant to address the overhead on the JNI path,
    but this applies to the Panama one as well so we should be able to
    also use ldr. Let me know if you need help creating the JBS issue.<br>
    <br>
    <blockquote type="cite" cite="mid:AS2PR08MB100348649F4923C6470BBF1C2ED822@AS2PR08MB10034.eurprd08.prod.outlook.com">
      <div class="elementToProof" style="font-family: Aptos,
        Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica,
        sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        3. Why is a load_acquire required here [7] for before the
        handshake operation or global state but not from some of the
        existing jit-emitted code?<br>
      </div>
    </blockquote>
    Good question. Once we see an armed poll we want to avoid memory
    operations to float up, otherwise we might for instance read stale
    values instead of the ones written by the arming thread before
    arming the poll. In particular, for handshakes we want to
    synchronize with the store release when arming the poll after the
    operation is added to the queue. For safepoints, the arming
    operation itself is done without extra fences but we previously
    executed storestore fences to order with some previous stores. I see
    SafepointMechanism::process() has a loadload fence and at least one
    early load acquire for the thread state so perhaps the acquire you
    mention when reading the poll word is not strictly needed. Erik and
    Robbin might have better insights.<br>
    <br>
    <blockquote type="cite" cite="mid:AS2PR08MB100348649F4923C6470BBF1C2ED822@AS2PR08MB10034.eurprd08.prod.outlook.com">
      <div class="elementToProof" style="font-family: Aptos,
        Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica,
        sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        4. Why did the introduction of watermarking introduce both a
        poll word and poll page? Why is both needed?<br>
      </div>
    </blockquote>
    Before 8253180 there were already two ways in which JavaThreads poll
    for safepoints/handshakes: testing the poll_bit of its polling_page
    or just trying to load from it (good page or bad page). Compiled
    methods use the latter method. I vaguely recall Erik trying to unify
    this and always test the poll_bit but I think there were some
    performance concerns. In any case, one field was enough. With
    8253180, we now have to also check if we need to process frames when
    returning from a method. This requires a comparison of sp/fp with
    some previously saved reference, so we need an extra field.<br>
    <br>
    Thanks,<br>
    Patricio<br>
    <br>
    [1]
<a class="moz-txt-link-freetext" href="https://mail.openjdk.org/pipermail/hotspot-compiler-dev/2024-July/078698.html">https://mail.openjdk.org/pipermail/hotspot-compiler-dev/2024-July/078698.html</a><br>
    <blockquote type="cite" cite="mid:AS2PR08MB100348649F4923C6470BBF1C2ED822@AS2PR08MB10034.eurprd08.prod.outlook.com">
      <div class="elementToProof" style="font-family: Aptos,
        Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica,
        sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        5. And any more additional context on how safepointing and poll
        values work.<br>
        <br>
        Any clarification on the matter would be much appreciated!</div>
      <div class="elementToProof" style="font-family: Aptos,
        Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica,
        sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        Samuel Chee<br>
        <br>
        <br>
      </div>
      <div style="font-family: Aptos, Aptos_EmbeddedFont,
        Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size:
        12pt; color: rgb(0, 0, 0);">
        [1] <span style="color:
          rgba(var(--sk_highlight,18,100,163),1);"><u><a href="https://github.com/openjdk/jdk/blob/4c695fa8a459adcdb8cdfe9e90783007c65fb90e/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp#L556" target="_blank" id="OWAb621448b-22f4-2f2e-affc-2a405c162309" class="c-link
              c-link--underline OWAAutoLink elementToProof
              moz-txt-link-freetext" rel="noopener noreferrer" style="color: rgba(var(--sk_highlight,18,100,163),1);
              text-align: left;" data-sk="tooltip_parent" data-stringify-link="https://github.com/openjdk/jdk/blob/4c695fa8a459adcdb8cdfe9e90783007c65fb90e/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp#L556" moz-do-not-send="true">https://github.com/openjdk/jdk/blob/4c695fa8a459adcdb8cdfe9e90783007c65fb90e/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp#L556</a></u></span></div>
      <div style="font-family: Aptos, Aptos_EmbeddedFont,
        Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size:
        12pt; color: rgb(0, 0, 0);">
        [2] <span style="color:
          rgba(var(--sk_highlight,18,100,163),1);"><u><a href="https://github.com/openjdk/jdk/blob/482538b100856afe2252395d47e576e6c6d885ce/src/hotspot/cpu/aarch64/downcallLinker_aarch64.cpp#L292" target="_blank" id="OWAeb591916-e5b5-6797-9985-04f54044efdb" class="c-link
              c-link--underline OWAAutoLink elementToProof
              moz-txt-link-freetext" rel="noopener noreferrer" style="color: rgba(var(--sk_highlight,18,100,163),1);
              text-align: left;" data-sk="tooltip_parent" data-stringify-link="https://github.com/openjdk/jdk/blob/482538b100856afe2252395d47e576e6c6d885ce/src/hotspot/cpu/aarch64/downcallLinker_aarch64.cpp#L292" moz-do-not-send="true">https://github.com/openjdk/jdk/blob/482538b100856afe2252395d47e576e6c6d885ce/src/hotspot/cpu/aarch64/downcallLinker_aarch64.cpp#L292</a></u></span></div>
      <div style="font-family: Aptos, Aptos_EmbeddedFont,
        Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size:
        12pt; color: rgb(0, 0, 0);">
        [3] <span style="color:
          rgba(var(--sk_highlight,18,100,163),1);"><u><a href="https://bugs.openjdk.org/browse/JDK-8337657" target="_blank" id="OWA46a228ec-a659-7744-3f12-e06365b1b77c" class="c-link
              c-link--underline OWAAutoLink elementToProof
              moz-txt-link-freetext" rel="noopener noreferrer" style="color: rgba(var(--sk_highlight,18,100,163),1);
              text-align: left;" data-sk="tooltip_parent" data-stringify-link="https://bugs.openjdk.org/browse/JDK-8337657" moz-do-not-send="true">https://bugs.openjdk.org/browse/JDK-8337657</a></u></span></div>
      <div style="font-family: Aptos, Aptos_EmbeddedFont,
        Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size:
        12pt; color: rgb(0, 0, 0);">
        [4] <span style="color:
          rgba(var(--sk_highlight,18,100,163),1);"><u><a href="https://github.com/openjdk/jdk/pull/296/files#diff-2a18ec5d55c3c0c18669d55ff48fb455b633d152132915caf65766e41a5a58ab" target="_blank" id="OWA9455b9a4-28e9-cecb-c1be-e6efbda5094a" class="c-link
              c-link--underline OWAAutoLink elementToProof
              moz-txt-link-freetext" rel="noopener noreferrer" style="color: rgba(var(--sk_highlight,18,100,163),1);
              text-align: left;" data-sk="tooltip_parent" data-stringify-link="https://github.com/openjdk/jdk/pull/296/files#diff-2a18ec5d55c3c0c18669d55ff48fb455b633d152132915caf65766e41a5a58ab" moz-do-not-send="true">https://github.com/openjdk/jdk/pull/296/files#diff-2a18ec5d55c3c0c18669d55ff48fb455b633d152132915caf65766e41a5a58ab</a></u></span></div>
      <div style="font-family: Aptos, Aptos_EmbeddedFont,
        Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size:
        12pt; color: rgb(0, 0, 0);">
        [5] <span style="color:
          rgba(var(--sk_highlight,18,100,163),1);"><u><a href="https://openjdk.org/jeps/376" target="_blank" id="OWA58a180f7-2f6d-f9bf-f489-07f0ccb84f2c" class="c-link
              c-link--underline OWAAutoLink elementToProof
              moz-txt-link-freetext" rel="noopener noreferrer" style="color: rgba(var(--sk_highlight,18,100,163),1);
              text-align: left;" data-sk="tooltip_parent" data-stringify-link="https://openjdk.org/jeps/376" moz-do-not-send="true">https://openjdk.org/jeps/376</a></u></span></div>
      <div style="font-family: Aptos, Aptos_EmbeddedFont,
        Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size:
        12pt; color: rgb(0, 0, 0);">
        [6] <span style="color:
          rgba(var(--sk_highlight,18,100,163),1);"><u><a href="https://github.com/openjdk/jdk/blob/a2f651904d1a1fdb14428be5485709b8ff252331/src/hotspot/share/runtime/safepointMechanism.cpp#L86" target="_blank" id="OWAe888e568-edff-4289-344e-8c1144364470" class="c-link
              c-link--underline OWAAutoLink elementToProof
              moz-txt-link-freetext" rel="noopener noreferrer" style="color: rgba(var(--sk_highlight,18,100,163),1);
              text-align: left;" data-sk="tooltip_parent" data-stringify-link="https://github.com/openjdk/jdk/blob/a2f651904d1a1fdb14428be5485709b8ff252331/src/hotspot/share/runtime/safepointMechanism.cpp#L86" moz-do-not-send="true">https://github.com/openjdk/jdk/blob/a2f651904d1a1fdb14428be5485709b8ff252331/src/hotspot/share/runtime/safepointMechanism.cpp#L86</a></u></span>,</div>
      <div style="font-family: Aptos, Aptos_EmbeddedFont,
        Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size:
        12pt; color: rgb(0, 0, 0);">
        [7] <span style="color:
          rgba(var(--sk_highlight,18,100,163),1);"><u><a href="https://github.com/openjdk/jdk/blob/765cef45465806e53f11fa7d92b9c184899b0932/src/hotspot/share/runtime/safepointMechanism.inline.hpp#L48" target="_blank" id="OWAc623aae8-d232-a338-4cd0-019065bce9ee" class="c-link
              c-link--underline OWAAutoLink elementToProof
              moz-txt-link-freetext" rel="noopener noreferrer" style="color: rgba(var(--sk_highlight,18,100,163),1);
              text-align: left;" data-sk="tooltip_parent" data-stringify-link="https://github.com/openjdk/jdk/blob/765cef45465806e53f11fa7d92b9c184899b0932/src/hotspot/share/runtime/safepointMechanism.inline.hpp#L48" moz-do-not-send="true">https://github.com/openjdk/jdk/blob/765cef45465806e53f11fa7d92b9c184899b0932/src/hotspot/share/runtime/safepointMechanism.inline.hpp#L48</a></u></span></div>
      <div class="elementToProof" style="font-family: Aptos,
        Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica,
        sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        <br>
      </div>
      IMPORTANT NOTICE: The contents of this email and any attachments
      are confidential and may also be privileged. If you are not the
      intended recipient, please notify the sender immediately and do
      not disclose the contents to any other person, use it for any
      purpose, or store or copy the information in any medium. Thank
      you.
    </blockquote>
    <br>
  </body>
</html>