[vector] Intrinsics for fromByteArray, fromByteBuffer, intoByteArray, intoByteBuffer
Lupusoru, Razvan A
razvan.a.lupusoru at intel.com
Wed May 2 18:18:22 UTC 2018
Hi Paul,
To me, it seems that the support is indeed uniform as long as the buffers are array-backed. So my guess is that you are referring to fact that non-array backed buffers are currently not intrinsified. Your recommendation seems doable - but I am wondering if it is safe to access raw addresses like this. Is it possible that "address" field of ByteBuffer is not properly initialized even if it has a proper backing array? What extra checks do we need in implementation to ensure that a vector store to that raw address will be safe?
Thanks,
Razvan
-----Original Message-----
From: Paul Sandoz [mailto:paul.sandoz at oracle.com]
Sent: Tuesday, May 01, 2018 5:39 PM
To: Lupusoru, Razvan A <razvan.a.lupusoru at intel.com>
Cc: panama-dev at openjdk.java.net
Subject: Re: [vector] Intrinsics for fromByteArray, fromByteBuffer, intoByteArray, intoByteBuffer
Hi Razvan,
That’s great progress, but i think we can do better to uniformly support arrays and buffers (both on and off-heap), perhaps as a further changeset.
I think we need to adjust the load/store intrinsics to support the same double register addressing mode as that for Unsafe, namely Object base and long offset.
For a Java array the base is the Java array, and the offset is say ARRAY_BYTE_BASE_OFFSET for a byte[] array.
For a ByteBuffer we can extract from it's fields using Unsafe:
See source code of java.lang.invoke.VarHandleByteArrayBase and its usages:
http://hg.openjdk.java.net/jdk/jdk/file/2f0c14b69efa/src/java.base/share/classes/java/lang/invoke/VarHandleByteArrayBase.java#l38
static final long BUFFER_ADDRESS
= UNSAFE.objectFieldOffset(Buffer.class, "address");
// ByteBuffer.hb
static final long BYTE_BUFFER_HB
= UNSAFE.objectFieldOffset(ByteBuffer.class, "hb");
The intrinsic might be represented as:
interface StoreVectorOperation<C, V extends Vector<?,?>> {
void store(C container, int index, V v); }
@HotSpotIntrinsicCandidate
static
<V extends Vector<?,?>>
<C>
void store(Class<?> vectorClass, Class<?> elementType, int vlen,
C container, Object base, long offset, int index, V v,
StoreVectorOperation<V> defaultImpl) {
defaultImpl.store(array, index, v);
}
where the container is just used for the default implementation and the base + offset is for the intrinsic.
—
I started making some progress on the load/store tests, hopefully i will have something by the end of the week.
Paul.
> On May 1, 2018, at 3:37 PM, Lupusoru, Razvan A <razvan.a.lupusoru at intel.com> wrote:
>
> Hi everyone,
>
> I have implemented intrinsics for fromByteArray and fromByteBuffer along with their store equivalents. These were tested locally in a limited fashion but since they use existing tested functionality of load/store, I do not expect any issues.
>
> Please take a look and let me know if you see any issues. Thanks!
> http://cr.openjdk.java.net/~rlupusoru/panama/webrev_frombytearr_01/
>
> --Razvan
More information about the panama-dev
mailing list