Loading... (original) (raw)

I think the issue can also be solved with VM intrinsics, but it seems simpler to do it with s.m.Unsafe. Current code for non-byte ByteBuffer calls all the way down to Bits, which does:

static void putIntB(ByteBuffer bb, int bi, int x) {
bb._put(bi , int3(x));
bb._put(bi + 1, int2(x));
bb._put(bi + 2, int1(x));
bb._put(bi + 3, int0(x));
}

The compiler is known to produce distinct writes in these cases. It is beneficial to replace byte-wide stores into the full-width stores. The caveats include: misaligned reads/writes, handling endianness, etc.