<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@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;}
/* Style Definitions */
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;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.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]-->
</head>
<body lang="EN-CA" link="blue" vlink="purple" style="word-wrap:break-word">
<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://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/foreign/MemorySegment.html#wrapping-addresses">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>
<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 <maurizio.cimadamore@oracle.com>
<br>
<b>Sent:</b> May 3, 2023 9:47 AM<br>
<b>To:</b> Cheng Jin <jincheng@ca.ibm.com>; panama-dev@openjdk.org<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" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%;border-radius:4px">
<tbody>
<tr>
<td style="padding:12.0pt 0cm 12.0pt 0cm">
<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%;background:#D0D8DC;border:none;border-top:solid #90A4AE 3.0pt">
<tbody>
<tr>
<td valign="top" style="border:none;padding:0cm 7.5pt 3.75pt 4.5pt">
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="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)">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>
</body>
</html>