[foreign-abi] RFR: 8248499: Add methods to allocate off heap arrays from Java arrays [v2]
Jorn Vernee
jvernee at openjdk.java.net
Wed Jul 1 10:25:07 UTC 2020
On Tue, 30 Jun 2020 21:24:07 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> This patch adds methods to NativeScope which allow clients to allocate off-heap arrays from Java on-heap arrays.
>>
>> While in most cases the code for copying is straightforward, we have to take into account endianness mismatches (in
>> case the user wants to store the array elements off-heap in an endianness that doesn't match that of the platform).
>> To allow for that, I've added a new implementation method in AbstractMemorySegmentImpl, which is the same as
>> `copyFrom`, but adds the byte swap (a wrapper around `Unsafe::copySwapMemory`).
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
>
> Add extra method to NativeScope to allocate (empty) arrays with arbitrary element layouts
Marked as reviewed by jvernee (Committer).
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/NativeScope.java line 366:
> 365: * @param elementLayout the array element layout.
> 366: * @param size the array size.
> 367: * @return an address which points to the newly allocated memory block.
Maybe useful to mention that the size is the element count, and not in bytes.
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/NativeScope.java line 370:
> 369: * {@code limit() - size() < (elementLayout.byteSize() * size)}.
> 370: * @throws IllegalArgumentException if {@code elementLayout.byteSize()} does not conform to the size of a
> double value. 371: */
This looks like a remnant of copy-pasting?
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/222
More information about the panama-dev
mailing list