Why asUnbounded()/isUnbounded() was removed in JDK21?
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed May 3 13:47:03 UTC 2023
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 toplevel class. An address layout has a
_target layout_ [1] which is used to describe the layout of the pointed
region of memory.
This means that you can still get a behavior similar to `asUnbounded`,
by doing:
```java
ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE))
```
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).
But, if you know the layout of the pointed region of memory statically,
you can also use a sharper target layout - e.g.
```java
ADDRESS.withTargetLayout(JAVA_INT)
```
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).
Hope this helps.
Maurizio
[1] -
https://cr.openjdk.org/~pminborg/panama/21/v2/javadoc/api/java.base/java/lang/foreign/AddressLayout.html#withTargetLayout(java.lang.foreign.MemoryLayout)
On 03/05/2023 14:34, Cheng Jin wrote:
>
> Hi there,
>
> 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.
>
> Is there any reason for deleting them all (or moving them somewhere
> else which I ignored) for the unbounded segment (pointer)?
>
> Best Regards
>
> Cheng Jin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20230503/c27e800d/attachment.htm>
More information about the panama-dev
mailing list