[vector] Intrinsics for fromByteArray, fromByteBuffer, intoByteArray, intoByteBuffer
Paul Sandoz
paul.sandoz at oracle.com
Thu May 3 15:40:54 UTC 2018
To add some context. We modified ByteBuffer to ensure the buffer fields could be used uniformly for VarHandle access with on- and off-heap buffers. This was further enhanced to fix some edge cases so equals/lexicographical comparison could be performed uniformly using the vectorized mismatch functionality.
A desirable goal is to consolidate the number of concrete buffer implementations so on- and off-heap is the mostly same. To do that will require some careful performance analysis as off-heap buffers currently pass a null constant as the base, and any consolidated buffer will require a field read for the base.
—
Razvan, the fromByteBuffer methods will fail for read only buffers, as a quick fix you can do:
if (!bb.isReadOnly() && bb.hasArray()) { … }
My suggestion is you push what you have with the above fix and then we iterate to improve it. I suggest we stick to native endianness for the moment to keep things simpler initially, but we will need to revisit that (as previously discussed).
Paul.
> On May 2, 2018, at 7:41 PM, John Rose <john.r.rose at oracle.com> wrote:
>
> On May 2, 2018, at 11:18 AM, Lupusoru, Razvan A <razvan.a.lupusoru at intel.com <mailto:razvan.a.lupusoru at intel.com>> wrote:
>>
>> 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?
>
> The address field is always properly initialized by the buffer constructor.
> It is either an unscaled byte offset into the non-null "hb" array object,
> or else a raw virtual address off-heap (and "hb" is null). In all cases,
> the unsafe addressing modes work uniformly. To get the first byte of
> a buffer, Unsafe.getUnsafe().getByte(b.hb, b.address) should always
> work. And the unsafe addressing instructions do compile directly
> to two-register (or register-displaced or absolute) addressing modes,
> with the hb and the address operands being the two register values.
>
> So forming an address into a buffer started by adding an offset
> (after range checking, naturally) to b.address, and then ensuring
> that the code generator will add that to b.hb (or ignore b.hb if
> it is null, which amounts to the same thing).
>
> HTH
> — John
More information about the panama-dev
mailing list