Helpers for MethodHandles.byteArrayViewVarHandle VarHandle

Jaroslav Kameník jaroslav at kamenik.cz
Wed May 18 14:50:12 UTC 2016


Hi,

thank you for response!


> I would prefer not to spread such functionality beyond that of ByteBuffer
> and the VarHandle producing methods on MethodHandles. It’s an advanced
> feature so think ok if less visible.
>
>
On the other side, this would be easier to use and understand than
ByteBuffer in simple cases, I think.

I have looked into JVM sources briefly, and this functionality is
implemented often there, both inlined and methods as intAt/readLong/...
So it could be helpful even as private api.



> Separately, i may revisit the signatures for access to also include an
> alignment-offset argument (which is expected to be constant when looping)
> in addition to the index (e.g. byte-index = ao + (i << LOG_2_UNIT_SIZE)).
> Thus bringing alignment into the foreground where it is harder to forget
> about or ignore.
>

It is nice idea. So it could look like:

getLongFrom[LE/BE](byte[] data, int firstByteIndex)
         - for direct access
getLongFrom[LE/BE](byte[] data, int firstByteOffset, int longArrayIndex)
  - for loops/shifted array access

etc.

I'd like to ask about performance - how does wrapping of VH to another call
affect optimization to simple memory load?



Jaroslav



More information about the core-libs-dev mailing list