[foreign-memaccess+abi] RFR: Add benchmarks to MemorySegmentVsBits

Uwe Schindler uschindler at openjdk.org
Tue Jan 3 14:01:15 UTC 2023


On Tue, 3 Jan 2023 10:28:52 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Nevermind - that seems to be correct - it's equivalent to `ByteBuffer.getLong`
>
> Might be worth trying this benchmark with the VM flag: `-Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false`, to see if VH guards are contributing to a major speedup here.

> Is this offset multiplication correct? e.g. I would assume that var handles created with `byteArrayView` would take a logical index?

No the coordinate of those handles is always raw byte offset. It is a bit confusing in the documentation as it also tells you about unaligned accesses.

https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/lang/invoke/MethodHandles.html#byteArrayViewVarHandle(java.lang.Class,java.nio.ByteOrder) says:

"Produces a VarHandle giving access to elements of a byte[] array viewed as if it were a different primitive array type, such as int[] or long[]. The VarHandle's variable type is the component type of viewArrayClass and the list of coordinate types is (byte[], int), **where the int coordinate type corresponds to an argument that is an index into a byte[] array. The returned VarHandle accesses bytes at an index in a byte[] array, composing bytes to or from a value of the component type of viewArrayClass according to the given endianness.**"

-------------

PR: https://git.openjdk.org/panama-foreign/pull/762


More information about the panama-dev mailing list