RFR: 8329997: Add provisions for checking memory segment alignment constraints [v2]
Per Minborg
pminborg at openjdk.org
Mon Apr 15 12:59:41 UTC 2024
On Mon, 15 Apr 2024 10:05:44 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> Per Minborg has updated the pull request incrementally with three additional commits since the last revision:
>>
>> - Update src/java.base/share/classes/jdk/internal/foreign/HeapMemorySegmentImpl.java
>>
>> Co-authored-by: Jorn Vernee <JornVernee at users.noreply.github.com>
>> - Update src/java.base/share/classes/jdk/internal/foreign/NativeMemorySegmentImpl.java
>>
>> Co-authored-by: Jorn Vernee <JornVernee at users.noreply.github.com>
>> - Update src/java.base/share/classes/java/lang/foreign/MemorySegment.java
>>
>> Co-authored-by: Maurizio Cimadamore <54672762+mcimadamore at users.noreply.github.com>
>
> src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 408:
>
>> 406: * }
>> 407: *
>> 408: * In order to simplify determination of alignment, in the case of either native or heap
>
> This can be expressed more directly as follows:
>
> Clients can use the ... method to check if a memory segment supports the alignment constraint of a memory layout, as follows:
>
>
> I'd also advise against using a method in the snippet, as that looks like the method is part of the API. Perhaps something like this:
>
>
> MemoryLayout layout = ...
> MemorySegment segment = ...
> boolean isAligned = segment.maxByteAlignment() >= layout.byteAlignment()
The example was similar to an existing method shown in a snippet in the same class, but we could change it anyway.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18779#discussion_r1565751189
More information about the core-libs-dev
mailing list