<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 03/05/2023 18:16, Cheng Jin wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:BN8PR15MB25777B33B17965E4B593C446F56C9@BN8PR15MB2577.namprd15.prod.outlook.com">
      
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style>@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}div.WordSection1
        {page:WordSection1;}</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">Hi Maurizio,<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">Many thanks for your quick response with
          detailed clarification.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">There is another question that confused me
          is:  why the pointer segment should be granted with
          Long.MAX_VALUE given users should know the actual size of the
          segment.  My understanding is they should convert a zero-sized
          segment (pointer) to a segment with the whatever size it is
          supposed to be for safety as explained in terms of zero-length
          memory segments at
          <a href="https://urldefense.com/v3/__https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/foreign/MemorySegment.html*wrapping-addresses__;Iw!!ACWV5N9M2RV99hQ!LqVLAbaqhXIVSJ6q9ag4POc8JTH3yNv8N9Est_-g566HIwIl5w5byhodf_2TQxWdRG_kpQeXMAAB4NhQFW-kuqE0$" moz-do-not-send="true">https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/foreign/MemorySegment.html#wrapping-addresses</a><o:p></o:p></p>
      </div>
    </blockquote>
    <p>There are two cases:</p>
    <p>* the address layout has no target layout - in this case the
      pointer segment has zero size (as you'd expect). Resizing is done,
      unsafely, using MemorySegment::reinterpret<br>
      * the address layout has a target layout - in this case the
      pointer segment has the size of the target layout</p>
    <p>In my example I was using the target layout machinery to create a
      target layout whose size is Long.MAX_VALUE - as that is
      semantically equivalent to an "unbounded" address layout in the
      Java 20 API.</p>
    <p>Maurizio<br>
    </p>
    <blockquote type="cite" cite="mid:BN8PR15MB25777B33B17965E4B593C446F56C9@BN8PR15MB2577.namprd15.prod.outlook.com">
      <div class="WordSection1">
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">Best Regards<o:p></o:p></p>
        <p class="MsoNormal">Cheng Jin<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <div style="border:none;border-top:solid #E1E1E1
          1.0pt;padding:3.0pt 0cm 0cm 0cm">
          <p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Maurizio Cimadamore
              <a class="moz-txt-link-rfc2396E" href="mailto:maurizio.cimadamore@oracle.com"><maurizio.cimadamore@oracle.com></a>
              <br>
              <b>Sent:</b> May 3, 2023 9:47 AM<br>
              <b>To:</b> Cheng Jin <a class="moz-txt-link-rfc2396E" href="mailto:jincheng@ca.ibm.com"><jincheng@ca.ibm.com></a>;
              <a class="moz-txt-link-abbreviated" href="mailto:panama-dev@openjdk.org">panama-dev@openjdk.org</a><br>
              <b>Subject:</b> [EXTERNAL] Re: Why
              asUnbounded()/isUnbounded() was removed in JDK21?<o:p></o:p></span></p>
        </div>
        <p class="MsoNormal"><o:p> </o:p></p>
        <div>
          <p class="MsoNormal" style="mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">Hi, the functionality
              is there - it has just been renamed to make it more
              general. In 20, one could only create an address layout
              that was _unbounded_ e. g. that pointed to a region of
              memory of unbounded size. In 21, AddressLayout is a new <o:p>
              </o:p></span></p>
        </div>
        <div>
          <p class="MsoNormal" style="mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerStart<o:p></o:p></span></p>
        </div>
        <table class="MsoNormalTable" style="width:100.0%;border-radius:4px" width="100%" cellspacing="0" cellpadding="0" border="0">
          <tbody>
            <tr>
              <td style="padding:12.0pt 0cm 12.0pt 0cm">
                <table class="MsoNormalTable" style="width:100.0%;background:#D0D8DC;border:none;border-top:solid
                  #90A4AE 3.0pt" width="100%" cellspacing="0" cellpadding="0" border="1">
                  <tbody>
                    <tr>
                      <td style="border:none;padding:0cm 7.5pt 3.75pt
                        4.5pt" valign="top">
                        <table class="MsoNormalTable" cellspacing="0" cellpadding="0" border="0" align="left">
                          <tbody>
                            <tr>
                              <td style="padding:3.0pt 6.0pt 3.0pt
                                6.0pt">
                                <p class="MsoNormal"><b><span style="font-size:10.5pt;font-family:"Arial",sans-serif;color:black">This
                                      Message Is From an External Sender
                                      <o:p></o:p></span></b></p>
                              </td>
                            </tr>
                            <tr>
                              <td style="padding:3.0pt 6.0pt 3.0pt
                                6.0pt">
                                <p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:black">This
                                    message came from outside your
                                    organization.
                                    <o:p></o:p></span></p>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </td>
            </tr>
          </tbody>
        </table>
        <div>
          <p class="MsoNormal" style="mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerEnd<o:p></o:p></span></p>
        </div>
        <p>Hi,<br>
          the functionality is there - it has just been renamed to make
          it more general.<o:p></o:p></p>
        <p>In 20, one could only create an address layout that was
          _unbounded_ e.g. that pointed to a region of memory of
          unbounded size.<o:p></o:p></p>
        <p>In 21, AddressLayout is a new toplevel class. An address
          layout has a _target layout_ [1] which is used to describe the
          layout of the pointed region of memory.<o:p></o:p></p>
        <p>This means that you can still get a behavior similar to
          `asUnbounded`, by doing:<br>
          <br>
          ```java<br>
ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE))<br>
          ```<o:p></o:p></p>
        <p>The above will create a sequence layout of unbound size (so,
          the size of that layout would be Long.MAX_VALUE), and use that
          layout as the target for the address layout. Which means that
          when this address is passed to
          MemorySegment::get(AddressLayout), or to the Linker, you will
          get back a MemorySegment whose size is Long.MAX_VALUE (as in
          21).<o:p></o:p></p>
        <p>But, if you know the layout of the pointed region of memory
          statically, you can also use a sharper target layout - e.g.<o:p></o:p></p>
        <p>```java<br>
          ADDRESS.withTargetLayout(JAVA_INT)<br>
          ```<o:p></o:p></p>
        <p>The latter will create an address layout whose target layout
          is _exactly_ one int layout. This means that when you pass
          this address layout to MemorySegment::get(AddressLayout),or to
          the Linker, you will get back a MemorySegment whose size is
          precisely 4 bytes. This is especially useful for upcalls (as
          the qsort example in JEP 442 demonstrates).<o:p></o:p></p>
        <p>Hope this helps.<o:p></o:p></p>
        <p>Maurizio<o:p></o:p></p>
        <p>[1] - <a href="https://cr.openjdk.org/~pminborg/panama/21/v2/javadoc/api/java.base/java/lang/foreign/AddressLayout.html#withTargetLayout(java.lang.foreign.MemoryLayout)" moz-do-not-send="true" class="moz-txt-link-freetext">https://cr.openjdk.org/~pminborg/panama/21/v2/javadoc/api/java.base/java/lang/foreign/AddressLayout.html#withTargetLayout(java.lang.foreign.MemoryLayout)</a><o:p></o:p></p>
        <p><o:p> </o:p></p>
        <div>
          <p class="MsoNormal">On 03/05/2023 14:34, Cheng Jin wrote:<o:p></o:p></p>
        </div>
        <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
          <p class="MsoNormal">Hi there,<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">I am wondering why
            asUnbounded()/isUnbounded() (existing in JDK20) related code
            was removed from
            java.base/share/classes/java/lang/foreign/ValueLayout.java
            in JDK21.<o:p></o:p></p>
          <p class="MsoNormal">Is there any reason for deleting them all
            (or moving them somewhere else which I ignored) for the
            unbounded segment (pointer)?<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">Best Regards<o:p></o:p></p>
          <p class="MsoNormal">Cheng Jin<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
        </blockquote>
      </div>
    </blockquote>
  </body>
</html>