Aligned long views over byte arrays and heap ByteBuffers

Paul Sandoz paul.sandoz at oracle.com
Thu Jan 28 09:18:09 UTC 2016


John and I tweaked things a little, here is an update pushed to the VHs sandbox:

  http://hg.openjdk.java.net/jdk9/sandbox/jdk/file/JEP-193-VarHandles-branch/src/java.base/share/classes/java/nio/X-Buffer.java.template#l1618 <http://hg.openjdk.java.net/jdk9/sandbox/jdk/file/JEP-193-VarHandles-branch/src/java.base/share/classes/java/nio/X-Buffer.java.template#l1618>

  http://hg.openjdk.java.net/jdk9/sandbox/jdk/file/JEP-193-VarHandles-branch/src/java.base/share/classes/java/nio/X-Buffer.java.template#l1660 <http://hg.openjdk.java.net/jdk9/sandbox/jdk/file/JEP-193-VarHandles-branch/src/java.base/share/classes/java/nio/X-Buffer.java.template#l1660>

It’s tempting to use short as the unit size to reduce the potentially for incorrect usages but resulting casts are painful.

New tests added pass on 64 and 32-bit platforms.

I will try and roll in such changes separately to VHs stuff.

Paul.

> On 20 Jan 2016, at 16:04, Vitaly Davidovich <vitalyd at gmail.com> wrote:
> 
> I like alignOffset and thought about that too.  Main issue is that isAligned is not idiomatic given it returns an offset adjustment.
> 
> On Wednesday, January 20, 2016, MacGregor, Duncan (GE Energy Management) <duncan.macgregor at ge.com <mailto:duncan.macgregor at ge.com>> wrote:
> On 20/01/2016, 14:15, "valhalla-dev on behalf of Paul Sandoz"
> <valhalla-dev-bounces at openjdk.java.net <javascript:;> on behalf of
> paul.sandoz at oracle.com <javascript:;>> wrote:
> 
> >
> >> On 20 Jan 2016, at 14:27, Vitaly Davidovich <vitalyd at gmail.com <javascript:;>> wrote:
> >>
> >>How about alignIndex(int,int)?
> >>
> >
> >That might work, although it implies returning an aligned index rather
> >than a modulus associated with the current index and unit size. I think
> >that would be more precise if we include boolean argument for rounding
> >up/down to the nearest aligned index:
> >
> >  alignedIndex(int index, int unitSize, boolean roundUp)
> >
> >For rounding down a negative value might be returned. I still prefer a
> >modulus returning method.
> 
> I kind of agree that alignedIndex suggests an actual index is returned.
> How about alignedOffset, or alignedDistance maybe?
> 
> Duncan.
> 
> 
> 
> --
> Sent from my phone




More information about the valhalla-dev mailing list